-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change IInstruction to use ReadonlyUint8Array for data #3632
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@solana/transaction-messages': patch | ||
'@solana/instructions': patch | ||
'@solana/errors': patch | ||
--- | ||
|
||
Change `data` field of transaction message instructions to use `ReadonlyUint8Array` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,7 +381,13 @@ if (identifiedInstruction === SystemInstruction.TransferSol) { | |
log.info('[step 4] The first instruction calls the TransferSol instruction of the system program'); | ||
// Narrow the type again, the instruction must have accounts to be parsed as a transfer SOL instruction | ||
assertIsInstructionWithAccounts(firstInstruction); | ||
const parsedFirstInstruction = parseTransferSolInstruction(firstInstruction); | ||
|
||
// TODO: This can just be `parseTransferSolInstruction(firstInstruction)` when the client is updated | ||
// with the `@solana/web3.js` version that changes the instruction data type to `ReadonlyUint8Array` | ||
const parsedFirstInstruction = parseTransferSolInstruction({ | ||
...firstInstruction, | ||
data: firstInstruction.data as unknown as Uint8Array, | ||
}); | ||
Comment on lines
+385
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want to create a new build of the Codama JS clients with this change to make this go away. This was actually where I first hit this issue. I was using an API that returned instruction data as base58, and then trying to convert its output into an |
||
log.info(parsedFirstInstruction, '[step 4] The parsed Transfer SOL instruction'); | ||
|
||
// This gives us an understanding of what exactly is happening in the instruction | ||
|
@@ -406,7 +412,13 @@ if (secondInstruction.programAddress === MEMO_PROGRAM_ADDRESS) { | |
// We know it's always an addMemo instruction | ||
|
||
assertIsInstructionWithData(secondInstruction); | ||
const parsedSecondInstruction = parseAddMemoInstruction(secondInstruction); | ||
|
||
// TODO: This can just be `parseAddMemoInstruction(secondInstruction)` when the client is updated | ||
// with the `@solana/web3.js` version that changes the instruction data type to `ReadonlyUint8Array` | ||
const parsedSecondInstruction = parseAddMemoInstruction({ | ||
...secondInstruction, | ||
data: secondInstruction.data as unknown as Uint8Array, | ||
}); | ||
log.info(parsedSecondInstruction, '[step 4] The parsed Add Memo instruction'); | ||
log.info(`[step 4] The second instruction adds a memo with message "${parsedSecondInstruction.data.memo}"`); | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is debatable. I'm widening the type of
IInstruction
, so any code that creates one of those is unaffected, but any code that treats its data as mutable (relying on the existing narrower type) is affected. In our code nothing relies on it being mutable, but I needed to update some type params. Downstream consumers like Codama clients need to be updated to avoid any code changes for their dependencies. Happy to change this to whatever we think is best.