-
Notifications
You must be signed in to change notification settings - Fork 5.7k
feat: add support for creating version 0 transactions #27142
Changes from all commits
a1250b0
f3419b1
6818741
38eb503
c657363
e92391c
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {PublicKey} from '../publickey'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './legacy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './versioned'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export * from './v0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The message header, identifying signed and read-only account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,18 +19,27 @@ export type MessageHeader = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numReadonlyUnsignedAccounts: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * An address table lookup used to load additional accounts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type MessageAddressTableLookup = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountKey: PublicKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| writableIndexes: Array<number>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readonlyIndexes: Array<number>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+28
Contributor
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. I was looking for a way that you could architect this type such that it was impossible to screw it up. As written, you could create malformed data like this: const matl: MessageAddressTableLookup = {
accountKey: /* ... */,
writableIndexes: [0, 1],
readonlyIndexes: [1, 2],
};If the storage was, instead, implemented as a sparse array, it would be impossible to overlap a readable/writeable index. type Readable = 0; // or 'r'
type Writeable = 1; // or 'w'
type IndexesWithWriteability = (Readable | Writeable | undefined)[];
const indexes: IndexesWithWriteability = [];
indexes[0] = 1;
indexes[1] = 1;
indexes[1] = 0; // OVERWRITTEN! Note how overlapping index 1 is impossible here.
indexes[2] = 0;Then you'd do stuff like this at the point of serialization: const readonlyIndexes = [];
const writeableIndexes = [];
indexes.forEach((writeability, index) => {
if (writeability === 0) {
readonlyIndexes.push(index);
} else if (writeability === 1) {
writeableIndexes.push(index);
}
});
const writeableIndexesLength = shortvec.encodeLength(
encodedWriteableIndexesLength,
writeableIndexes.length,
);
Contributor
Author
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. Oh yeah great point, it's definitely possible to create invalid transaction messages with the solana/web3.js/src/message/v0.ts Lines 71 to 80 in 25d2566
solana/web3.js/src/message/compiled-keys.ts Lines 104 to 123 in 25d2566
Contributor
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. Yeah, only thing is that
Contributor
Author
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. I think that's fine. The same holds for any other field in |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * An instruction to execute by a program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @property {number} programIdIndex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @property {number[]} accounts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @property {string} data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @property {number[]} accountKeyIndexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @property {Uint8Array} data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type CompiledInstruction = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type MessageCompiledInstruction = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Index into the transaction keys array indicating the program account that executes this instruction */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| programIdIndex: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Ordered indices into the transaction keys array indicating which accounts to pass to the program */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accounts: number[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** The program input data encoded as base 58 */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountKeyIndexes: number[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. Feels like this should be
Contributor
Author
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.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** The program input data */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: Uint8Array; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Should we add this to https://github.com/solana-labs/buffer-layout-utils/blob/master/src/web3.ts and consume it here? Could move most or all of these into it and eliminate some duplication
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.
I'd be happy with that but I don't feel it's a big priority for simple layouts for signatures and public keys