fix: update accounts to readonly/writable
This commit is contained in:
committed by
Michael Vines
parent
58550733fb
commit
d0c89f7fa3
@ -214,13 +214,13 @@ declare module '@solana/web3.js' {
|
|||||||
declare export type TransactionSignature = string;
|
declare export type TransactionSignature = string;
|
||||||
|
|
||||||
declare type TransactionInstructionCtorFields = {|
|
declare type TransactionInstructionCtorFields = {|
|
||||||
keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>,
|
keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>,
|
||||||
programId?: PublicKey,
|
programId?: PublicKey,
|
||||||
data?: Buffer,
|
data?: Buffer,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
declare export class TransactionInstruction {
|
declare export class TransactionInstruction {
|
||||||
keys: Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>;
|
keys: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>;
|
||||||
programId: PublicKey;
|
programId: PublicKey;
|
||||||
data: Buffer;
|
data: Buffer;
|
||||||
|
|
||||||
|
@ -201,8 +201,8 @@ export class BudgetProgram {
|
|||||||
|
|
||||||
return transaction.add({
|
return transaction.add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: to, isSigner: false, isDebitable: false},
|
{pubkey: to, isSigner: false, isWritable: true},
|
||||||
{pubkey: program, isSigner: false, isDebitable: true},
|
{pubkey: program, isSigner: false, isWritable: true},
|
||||||
],
|
],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data: trimmedData,
|
data: trimmedData,
|
||||||
@ -236,7 +236,7 @@ export class BudgetProgram {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return transaction.add({
|
return transaction.add({
|
||||||
keys: [{pubkey: program, isSigner: false, isDebitable: true}],
|
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data: trimmedData,
|
data: trimmedData,
|
||||||
});
|
});
|
||||||
@ -269,7 +269,7 @@ export class BudgetProgram {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return transaction.add({
|
return transaction.add({
|
||||||
keys: [{pubkey: program, isSigner: false, isDebitable: true}],
|
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data: trimmedData,
|
data: trimmedData,
|
||||||
});
|
});
|
||||||
@ -325,7 +325,7 @@ export class BudgetProgram {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return transaction.add({
|
return transaction.add({
|
||||||
keys: [{pubkey: program, isSigner: false, isDebitable: true}],
|
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data: trimmedData,
|
data: trimmedData,
|
||||||
});
|
});
|
||||||
@ -349,9 +349,9 @@ export class BudgetProgram {
|
|||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: from, isSigner: true, isDebitable: true},
|
{pubkey: from, isSigner: true, isWritable: true},
|
||||||
{pubkey: program, isSigner: false, isDebitable: true},
|
{pubkey: program, isSigner: false, isWritable: true},
|
||||||
{pubkey: to, isSigner: false, isDebitable: false},
|
{pubkey: to, isSigner: false, isWritable: false},
|
||||||
],
|
],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data,
|
data,
|
||||||
@ -379,9 +379,9 @@ export class BudgetProgram {
|
|||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: from, isSigner: true, isDebitable: true},
|
{pubkey: from, isSigner: true, isWritable: true},
|
||||||
{pubkey: program, isSigner: false, isDebitable: true},
|
{pubkey: program, isSigner: false, isWritable: true},
|
||||||
{pubkey: to, isSigner: false, isDebitable: false},
|
{pubkey: to, isSigner: false, isWritable: true},
|
||||||
],
|
],
|
||||||
programId: this.programId,
|
programId: this.programId,
|
||||||
data,
|
data,
|
||||||
|
@ -97,7 +97,7 @@ export class Loader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
keys: [{pubkey: program.publicKey, isSigner: true, isDebitable: true}],
|
keys: [{pubkey: program.publicKey, isSigner: true, isWritable: true}],
|
||||||
programId,
|
programId,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
@ -137,8 +137,8 @@ export class Loader {
|
|||||||
|
|
||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: program.publicKey, isSigner: true, isDebitable: true},
|
{pubkey: program.publicKey, isSigner: true, isWritable: true},
|
||||||
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isDebitable: false},
|
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
|
||||||
],
|
],
|
||||||
programId,
|
programId,
|
||||||
data,
|
data,
|
||||||
|
@ -183,8 +183,8 @@ export class SystemProgram {
|
|||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: from, isSigner: true, isDebitable: true},
|
{pubkey: from, isSigner: true, isWritable: true},
|
||||||
{pubkey: newAccount, isSigner: false, isDebitable: true},
|
{pubkey: newAccount, isSigner: false, isWritable: true},
|
||||||
],
|
],
|
||||||
programId: SystemProgram.programId,
|
programId: SystemProgram.programId,
|
||||||
data,
|
data,
|
||||||
@ -200,10 +200,8 @@ export class SystemProgram {
|
|||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: from, isSigner: true, isDebitable: true},
|
{pubkey: from, isSigner: true, isWritable: true},
|
||||||
// TEMP FIX: a better proposed solution is here:
|
{pubkey: to, isSigner: false, isWritable: true},
|
||||||
// https://github.com/solana-labs/solana-web3.js/issues/542
|
|
||||||
{pubkey: to, isSigner: false, isDebitable: true},
|
|
||||||
],
|
],
|
||||||
programId: SystemProgram.programId,
|
programId: SystemProgram.programId,
|
||||||
data,
|
data,
|
||||||
@ -218,7 +216,7 @@ export class SystemProgram {
|
|||||||
const data = encodeData(type, {programId: programId.toBuffer()});
|
const data = encodeData(type, {programId: programId.toBuffer()});
|
||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
keys: [{pubkey: from, isSigner: true, isDebitable: true}],
|
keys: [{pubkey: from, isSigner: true, isWritable: true}],
|
||||||
programId: SystemProgram.programId,
|
programId: SystemProgram.programId,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
@ -41,7 +41,7 @@ export const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|||||||
* @property {?Buffer} data
|
* @property {?Buffer} data
|
||||||
*/
|
*/
|
||||||
export type TransactionInstructionCtorFields = {|
|
export type TransactionInstructionCtorFields = {|
|
||||||
keys?: Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>,
|
keys?: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>,
|
||||||
programId?: PublicKey,
|
programId?: PublicKey,
|
||||||
data?: Buffer,
|
data?: Buffer,
|
||||||
|};
|
|};
|
||||||
@ -57,7 +57,7 @@ export class TransactionInstruction {
|
|||||||
keys: Array<{
|
keys: Array<{
|
||||||
pubkey: PublicKey,
|
pubkey: PublicKey,
|
||||||
isSigner: boolean,
|
isSigner: boolean,
|
||||||
isDebitable: boolean,
|
isWritable: boolean,
|
||||||
}> = [];
|
}> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,8 +171,8 @@ export class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const keys = this.signatures.map(({publicKey}) => publicKey.toString());
|
const keys = this.signatures.map(({publicKey}) => publicKey.toString());
|
||||||
let numCreditOnlySignedAccounts = 0;
|
let numReadonlySignedAccounts = 0;
|
||||||
let numCreditOnlyUnsignedAccounts = 0;
|
let numReadonlyUnsignedAccounts = 0;
|
||||||
|
|
||||||
const programIds = [];
|
const programIds = [];
|
||||||
|
|
||||||
@ -185,12 +185,12 @@ export class Transaction {
|
|||||||
signature: null,
|
signature: null,
|
||||||
publicKey: keySignerPair.pubkey,
|
publicKey: keySignerPair.pubkey,
|
||||||
});
|
});
|
||||||
if (!keySignerPair.isDebitable) {
|
if (!keySignerPair.isWritable) {
|
||||||
numCreditOnlySignedAccounts += 1;
|
numReadonlySignedAccounts += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!keySignerPair.isDebitable) {
|
if (!keySignerPair.isWritable) {
|
||||||
numCreditOnlyUnsignedAccounts += 1;
|
numReadonlyUnsignedAccounts += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keys.push(keyStr);
|
keys.push(keyStr);
|
||||||
@ -206,7 +206,7 @@ export class Transaction {
|
|||||||
programIds.forEach(programId => {
|
programIds.forEach(programId => {
|
||||||
if (!keys.includes(programId)) {
|
if (!keys.includes(programId)) {
|
||||||
keys.push(programId);
|
keys.push(programId);
|
||||||
numCreditOnlyUnsignedAccounts += 1;
|
numReadonlyUnsignedAccounts += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -274,8 +274,8 @@ export class Transaction {
|
|||||||
|
|
||||||
const signDataLayout = BufferLayout.struct([
|
const signDataLayout = BufferLayout.struct([
|
||||||
BufferLayout.blob(1, 'numRequiredSignatures'),
|
BufferLayout.blob(1, 'numRequiredSignatures'),
|
||||||
BufferLayout.blob(1, 'numCreditOnlySignedAccounts'),
|
BufferLayout.blob(1, 'numReadonlySignedAccounts'),
|
||||||
BufferLayout.blob(1, 'numCreditOnlyUnsignedAccounts'),
|
BufferLayout.blob(1, 'numReadonlyUnsignedAccounts'),
|
||||||
BufferLayout.blob(keyCount.length, 'keyCount'),
|
BufferLayout.blob(keyCount.length, 'keyCount'),
|
||||||
BufferLayout.seq(Layout.publicKey('key'), keys.length, 'keys'),
|
BufferLayout.seq(Layout.publicKey('key'), keys.length, 'keys'),
|
||||||
Layout.publicKey('recentBlockhash'),
|
Layout.publicKey('recentBlockhash'),
|
||||||
@ -283,10 +283,8 @@ export class Transaction {
|
|||||||
|
|
||||||
const transaction = {
|
const transaction = {
|
||||||
numRequiredSignatures: Buffer.from([this.signatures.length]),
|
numRequiredSignatures: Buffer.from([this.signatures.length]),
|
||||||
numCreditOnlySignedAccounts: Buffer.from([numCreditOnlySignedAccounts]),
|
numReadonlySignedAccounts: Buffer.from([numReadonlySignedAccounts]),
|
||||||
numCreditOnlyUnsignedAccounts: Buffer.from([
|
numReadonlyUnsignedAccounts: Buffer.from([numReadonlyUnsignedAccounts]),
|
||||||
numCreditOnlyUnsignedAccounts,
|
|
||||||
]),
|
|
||||||
keyCount: Buffer.from(keyCount),
|
keyCount: Buffer.from(keyCount),
|
||||||
keys: keys.map(key => new PublicKey(key).toBuffer()),
|
keys: keys.map(key => new PublicKey(key).toBuffer()),
|
||||||
recentBlockhash: Buffer.from(bs58.decode(recentBlockhash)),
|
recentBlockhash: Buffer.from(bs58.decode(recentBlockhash)),
|
||||||
@ -450,14 +448,14 @@ export class Transaction {
|
|||||||
function isCreditDebit(
|
function isCreditDebit(
|
||||||
i: number,
|
i: number,
|
||||||
numRequiredSignatures: number,
|
numRequiredSignatures: number,
|
||||||
numCreditOnlySignedAccounts: number,
|
numReadonlySignedAccounts: number,
|
||||||
numCreditOnlyUnsignedAccounts: number,
|
numReadonlyUnsignedAccounts: number,
|
||||||
numKeys: number,
|
numKeys: number,
|
||||||
): boolean {
|
): boolean {
|
||||||
return (
|
return (
|
||||||
i < numRequiredSignatures - numCreditOnlySignedAccounts ||
|
i < numRequiredSignatures - numReadonlySignedAccounts ||
|
||||||
(i >= numRequiredSignatures &&
|
(i >= numRequiredSignatures &&
|
||||||
i < numKeys - numCreditOnlyUnsignedAccounts)
|
i < numKeys - numReadonlyUnsignedAccounts)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,10 +474,10 @@ export class Transaction {
|
|||||||
|
|
||||||
const numRequiredSignatures = byteArray.shift();
|
const numRequiredSignatures = byteArray.shift();
|
||||||
// byteArray = byteArray.slice(1); // Skip numRequiredSignatures byte
|
// byteArray = byteArray.slice(1); // Skip numRequiredSignatures byte
|
||||||
const numCreditOnlySignedAccounts = byteArray.shift();
|
const numReadonlySignedAccounts = byteArray.shift();
|
||||||
// byteArray = byteArray.slice(1); // Skip numCreditOnlySignedAccounts byte
|
// byteArray = byteArray.slice(1); // Skip numReadonlySignedAccounts byte
|
||||||
const numCreditOnlyUnsignedAccounts = byteArray.shift();
|
const numReadonlyUnsignedAccounts = byteArray.shift();
|
||||||
// byteArray = byteArray.slice(1); // Skip numCreditOnlyUnsignedAccounts byte
|
// byteArray = byteArray.slice(1); // Skip numReadonlyUnsignedAccounts byte
|
||||||
|
|
||||||
const accountCount = shortvec.decodeLength(byteArray);
|
const accountCount = shortvec.decodeLength(byteArray);
|
||||||
let accounts = [];
|
let accounts = [];
|
||||||
@ -532,11 +530,11 @@ export class Transaction {
|
|||||||
isSigner: transaction.signatures.some(
|
isSigner: transaction.signatures.some(
|
||||||
keyObj => keyObj.publicKey.toString() === pubkey.toString(),
|
keyObj => keyObj.publicKey.toString() === pubkey.toString(),
|
||||||
),
|
),
|
||||||
isDebitable: isCreditDebit(
|
isWritable: isCreditDebit(
|
||||||
j,
|
j,
|
||||||
numRequiredSignatures,
|
numRequiredSignatures,
|
||||||
numCreditOnlySignedAccounts,
|
numReadonlySignedAccounts,
|
||||||
numCreditOnlyUnsignedAccounts,
|
numReadonlyUnsignedAccounts,
|
||||||
accounts.length,
|
accounts.length,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,7 @@ test('load BPF C program', async () => {
|
|||||||
|
|
||||||
const programId = await BpfLoader.load(connection, from, data);
|
const programId = await BpfLoader.load(connection, from, data);
|
||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
keys: [{pubkey: from.publicKey, isSigner: true, isDebitable: true}],
|
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
|
||||||
programId,
|
programId,
|
||||||
});
|
});
|
||||||
await sendAndConfirmTransaction(connection, transaction, from);
|
await sendAndConfirmTransaction(connection, transaction, from);
|
||||||
@ -61,7 +61,7 @@ test('load BPF Rust program', async () => {
|
|||||||
|
|
||||||
const programId = await BpfLoader.load(connection, from, data);
|
const programId = await BpfLoader.load(connection, from, data);
|
||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
keys: [{pubkey: from.publicKey, isSigner: true, isDebitable: true}],
|
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
|
||||||
programId,
|
programId,
|
||||||
});
|
});
|
||||||
await sendAndConfirmTransaction(connection, transaction, from);
|
await sendAndConfirmTransaction(connection, transaction, from);
|
||||||
|
@ -681,11 +681,6 @@ test('transaction', async () => {
|
|||||||
result: 31,
|
result: 31,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
if (!mockRpcEnabled) {
|
|
||||||
// Credit-only account credits are committed at the end of every slot;
|
|
||||||
// this sleep is to ensure a full slot has elapsed
|
|
||||||
await sleep((1000 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
|
||||||
}
|
|
||||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(31);
|
expect(await connection.getBalance(accountTo.publicKey)).toBe(31);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ test('non-SystemInstruction error', () => {
|
|||||||
|
|
||||||
const badProgramId = {
|
const badProgramId = {
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: from.publicKey, isSigner: true, isDebitable: true},
|
{pubkey: from.publicKey, isSigner: true, isWritable: true},
|
||||||
{pubkey: to.publicKey, isSigner: false, isDebitable: false},
|
{pubkey: to.publicKey, isSigner: false, isWritable: true},
|
||||||
],
|
],
|
||||||
programId: BudgetProgram.programId,
|
programId: BudgetProgram.programId,
|
||||||
data: Buffer.from([2, 0, 0, 0]),
|
data: Buffer.from([2, 0, 0, 0]),
|
||||||
|
Reference in New Issue
Block a user