solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
1.97k stars 792 forks source link

lack of Decode/Encode Log or transaction #2841

Closed ad7090 closed 1 week ago

ad7090 commented 2 weeks ago

Hey all , I hope you are doing well!

Overview

For three days now I have been trying to figure out how to Decode these codes when there is no proper documentation and no proper instructions. I tried lots of thing to achieve a answer but But unfortunately this is a bug

This is my Logs


  log =>  {
  signature: '5333hEQWwnuaY6tJcxbpEBzZNJrRYG48KmMGidQT4wcnR49YJqn9wqFsgyBuUCSfKfNUKf3KNsonvQ6pHfL6G7Pj',
  err: null,
  logs: [
    'Program ComputeBudget111111111111111111111111111111 invoke [1]',
    'Program ComputeBudget111111111111111111111111111111 success',
    'Program ComputeBudget111111111111111111111111111111 invoke [1]',
    'Program ComputeBudget111111111111111111111111111111 success',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]',
    'Program log: CreateIdempotent',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: GetAccountDataSize',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 129632 compute units',
    'Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 11111111111111111111111111111111 invoke [2]',
    'Program 11111111111111111111111111111111 success',
    'Program log: Initialize the associated token account',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeImmutableOwner',
    'Program log: Please upgrade to SPL Token 2022 for immutable owner support',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 123045 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: InitializeAccount3',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3158 of 119163 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 22315 of 138037 compute units',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success',
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
    'Program log: Instruction: SyncNative',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3045 of 115572 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 invoke [1]',
    'Program log: Instruction: Route',
    'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [2]',
    'Program log: ray_log: AwDh9QUAAAAAAAAAAAAAAAABAAAAAAAAAADh9QUAAAAA790dTfvDWg1BJ6mzVwYAAJfCybeEDAAA',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]',
    'Program log: Instruction: Transfer',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4736 of 64503 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]',
    'Program log: Instruction: Transfer',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 56786 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 29406 of 80967 compute units',
    'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 success',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 invoke [2]',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 consumed 2025 of 48582 compute units',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
    'Program log: Instruction: TransferChecked',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6147 of 42317 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 invoke [2]',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 consumed 2025 of 33986 compute units',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 success',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 consumed 82095 of 112527 compute units',
    'Program return: JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 xWlSemkMAAA=',
    'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
    'Program log: Instruction: CloseAccount',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2915 of 30432 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success'
  ]
## I'm using this Func : 

  new PublicKey(MAINNET_PROGRAM_ID.OPENBOOK_MARKET), 
    async (logs, ctx) => {
    console.log('log => ',logs, 'ctx => ',ctx)

  }, 'processed',);

How can fetch like this without using getAccount and getTransaction or others func like this

I achieve a script but dont work at all

const borsh = require('borsh');
const bs58 = require('bs58');
const {Transaction} = require('@solana/web3.js')

const hexToBytes = (hex) => {
  let bytes = [];
  for (let c = 0; c < hex.length; c += 2) {
    bytes.push(parseInt(hex.substr(c, 2), 16));
  }
  return bytes;
};

function encodedToHex(encodedData) {
  // Decode the base58 encoded data into a buffer
  const buffer = Buffer.from(bs58.decode(encodedData));

  return buffer.toString('hex');
}

const decodeInstruction = (hexData) => {
  const bytes = hexToBytes(hexData);
  console.log(bytes.length);

  return {   
    amount: bytes.slice(0, 16).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0),
    maxSolCost: bytes.slice(16, 23).reduce((acc, byte, index) => acc + (byte << (8 * index)), 0)
  }
};

const schema = { 'struct': { 'amount': 'u64', 
  'maxSolCost': 'u64' 
} };
const encodeddata = "3TF3cGand1jm";

const hexData = encodedToHex(encodeddata);
const decodedData = decodeInstruction(hexData);
console.log(JSON.stringify(decodedData));

I need some like that :

Screenshot 2024-06-23 at 7 41 38 PM

buffalojoec commented 1 week ago

How can fetch like this without using getAccount and getTransaction or others func like this

Hello, it looks like you're trying to decode encoded instructions. This is definitely not a bug, since the library supports decoding instructions over a generic layout, and provides a handful of layouts for common instructions.

https://github.com/solana-labs/solana-web3.js/blob/91732c88fcb90b191a74658779d7f335aad31e31/packages/library-legacy/src/instruction.ts#L36-L58

The context of your question is not very clear, since it looks like you've only provided part of the code.

Please ask on https://solana.stackexchange.com/ and provide more context!

github-actions[bot] commented 1 week ago

Hi @ad7090,

Thanks for your question!

We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of the Solana JavaScript SDK itself.

Questions like yours deserve a purpose-built Q&A forum. Unless there exists evidence that this is a bug with the Solana JavaScript SDK itself, please post your question to the Solana Stack Exchange using this link: https://solana.stackexchange.com/questions/ask


This automated message is a result of having added the ‘question’ tag.

ad7090 commented 1 week ago

Thx mate @buffalojoec

github-actions[bot] commented 4 days ago

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.