Universal instruction decoder
Closed this issue · 8 comments
Would be cool to have a function similar to tensorswaps SDKs swapSdk.coder.instruction.decode(Buffer.from(CompiledInstruction.data))
that decodes the data based on the instruction indentifier.
It would also be cool if you could decode an instruction so accounts are included aswell smilar to tensorswaps SDKs swapSdk.coder.instruction.format(instruction, instructionAccounts)
An example, I want to deseralize all bubblegum instructions. Or I would atleast like a way to get the discriminator of an instruction
const connection = (umi.rpc as any).connection as Connection;
let txnIndex = 0;
connection.onLogs(
new PublicKey(MPL_BUBBLEGUM_PROGRAM_ID.toString()),
async (logs) => {
if (logs.err) return;
txnIndex++;
//console.log(txnIndex);
umi.rpc
.getTransaction(base58.serialize(logs.signature), {
commitment: "confirmed",
})
.then((txn) => {
try {
if (!txn) return;
//console.log(logs.signature, txn);
const bubblegumInstruction = txn.message.instructions.find(
(i) =>
txn.message.accounts[i.programIndex] ===
MPL_BUBBLEGUM_PROGRAM_ID.toString()
)!;
if (!bubblegumInstruction) return;
if (
isEqualBytes(
bubblegumInstruction.data.slice(0, 8),
mintDiscriminator
)
) {
const data =
MintToCollectionV1InstructionDataSerializer.deserialize(
bubblegumInstruction.data
);
console.log(data[0]);
} else {
console.log(bubblegumInstruction.data.slice(0, 8));
}
} catch (error) {
//console.error(error);
}
});
},
"confirmed"
);
Hi there, that exists for the new js-experimental
renderer but not the Umi-compatible one.
Where can I find the compatible one?
You must use the RenderJavaScriptExperimentalVisitor
instead of the RenderJavaScriptVisitor
. Beware though, the former uses the brand new web3.js which is still under the experimental
tag.
I'm using that, what is the import of the decoder? Last time I checked I couldn't find it in any imports
What version of Kinobi are you using? This is pretty new.
It should generate things like that inside your program files.
Thanks, will check it out when I'm home
Hi there, I'm closing this issue due to inactivity but feel free to open a new one if you have more questions.