kevinheavey / solders

A high-performance Python toolkit for Solana, written in Rust
https://kevinheavey.github.io/solders/
Apache License 2.0
205 stars 23 forks source link

VersionedTransaction.from_json Not Working #67

Closed Dassy23 closed 7 months ago

Dassy23 commented 9 months ago

I get the following error when trying to convert a tx to json and back

ValueError: invalid type: integer 128, expected message prefix byte at line 1 column 164

url = f'https://quote-api.jup.ag/v6/quote?inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000&slippageBps=1'
resp = requests.get(url)
quote = resp.json()
swap_transaction = requests.post(
    'https://quote-api.jup.ag/v6/swap',
    headers={'Content-Type': 'application/json'},
    json={
        'quoteResponse': quote,
        'userPublicKey': authority,
        'wrapAndUnwrapSol': True
    }
).json()
swapTransactionBuf = base64.b64decode(swap_transaction['swapTransaction'])
tx = VersionedTransaction.from_bytes(swapTransactionBuf)
t = tx.to_json()
t1 = VersionedTransaction.from_json(t)
Dassy23 commented 9 months ago

packing a new versiontx with a messagev0 is a good way im getting around this now

 msg = MessageV0.from_json(json.dumps(txn['message'][1]))
 signed_transaction = VersionedTransaction(msg,[payer.entity])
kevinheavey commented 9 months ago

can you post the raw transaction bytes please? This thing: swapTransactionBuf

Dassy23 commented 9 months ago

yupp see below

b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x08\r\x05\xd6]S\x86q\xf1I6\x04!\xd3\xbe\x18u\x13\xb7\x14uCY\x8fU\xfcl`msq.M\x86\x0bH\x07Ou\xb8\xea0i\xc9\xed?\x06\xbc2\x19x*\xe4\xcd\x8e\\\x9d7I\x82V\xb1\x98K\x9dPB\xe4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94\x0f\x07\x06\x00\x05\x02\xc0\\\x15\x00\x06\x00\t\x03\x10'\x00\x00\x00\x00\x00\x00\n\x06\x00\x02\x00\x1c\x05\x08\x01\x01\x05\x02\x00\x02\x0c\x02\x00\x00\x00\x00\xe4\x0bT\x02\x00\x00\x00\x08\x01\x02\x01\x11\x07$\x08\t\x00\x02\x03\x01\x04\x1c\x0c\x07\x07\x0b\x07\x16\x1b\x10\t\x03\x01\x0f\x12\x14\x13\x08\x19\x1a\x18\x15\x17\x0e\t\x03\x01\x11\r\x08)\xc1 \x9b3A\xd6\x9c\x81\x04\x02\x00\x00\x00\x19(\x00\x02\x1c\x01<\x00\x02\x00\xe4\x0bT\x02\x00\x00\x00\x0b\xeb\xb30\x00\x00\x00\x00\x01\x00\x00\x08\x03\x02\x00\x00\x01\t\x02\xfa\x9f\xf6v\xf1\xeb\nLh\x9f:\xa3\xff|AxJ\\\xea\xc5J]:\x03!?KE^\xa6\xa68\x08\x02\x03@A\x05<?=\x07\x04\x13\x06>B\x0b;\xcc'\xedks\xaf\x15O\xdb}@\x0f\xb2\xff\xccQ\xd4\x7f\x15}}\xdepa\xcft\x96\xae\xfd<dj\x00\x01]"
kevinheavey commented 8 months ago

The issue lies in the Solana Rust SDK: https://github.com/solana-labs/solana/issues/34608

kevinheavey commented 7 months ago

Fixed by #80