diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 03c41b0fe4..57f91cc57a 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -214,13 +214,13 @@ declare module '@solana/web3.js' { declare export type TransactionSignature = string; declare type TransactionInstructionCtorFields = {| - keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>, + keys: ?Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>, programId?: PublicKey, data?: Buffer, |}; declare export class TransactionInstruction { - keys: Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>; + keys: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>; programId: PublicKey; data: Buffer; diff --git a/web3.js/src/budget-program.js b/web3.js/src/budget-program.js index a75aadcf28..a56661c12a 100644 --- a/web3.js/src/budget-program.js +++ b/web3.js/src/budget-program.js @@ -201,8 +201,8 @@ export class BudgetProgram { return transaction.add({ keys: [ - {pubkey: to, isSigner: false, isDebitable: false}, - {pubkey: program, isSigner: false, isDebitable: true}, + {pubkey: to, isSigner: false, isWritable: true}, + {pubkey: program, isSigner: false, isWritable: true}, ], programId: this.programId, data: trimmedData, @@ -236,7 +236,7 @@ export class BudgetProgram { ); return transaction.add({ - keys: [{pubkey: program, isSigner: false, isDebitable: true}], + keys: [{pubkey: program, isSigner: false, isWritable: true}], programId: this.programId, data: trimmedData, }); @@ -269,7 +269,7 @@ export class BudgetProgram { ); return transaction.add({ - keys: [{pubkey: program, isSigner: false, isDebitable: true}], + keys: [{pubkey: program, isSigner: false, isWritable: true}], programId: this.programId, data: trimmedData, }); @@ -325,7 +325,7 @@ export class BudgetProgram { ); return transaction.add({ - keys: [{pubkey: program, isSigner: false, isDebitable: true}], + keys: [{pubkey: program, isSigner: false, isWritable: true}], programId: this.programId, data: trimmedData, }); @@ -349,9 +349,9 @@ export class BudgetProgram { return new Transaction().add({ keys: [ - {pubkey: from, isSigner: true, isDebitable: true}, - {pubkey: program, isSigner: false, isDebitable: true}, - {pubkey: to, isSigner: false, isDebitable: false}, + {pubkey: from, isSigner: true, isWritable: true}, + {pubkey: program, isSigner: false, isWritable: true}, + {pubkey: to, isSigner: false, isWritable: false}, ], programId: this.programId, data, @@ -379,9 +379,9 @@ export class BudgetProgram { return new Transaction().add({ keys: [ - {pubkey: from, isSigner: true, isDebitable: true}, - {pubkey: program, isSigner: false, isDebitable: true}, - {pubkey: to, isSigner: false, isDebitable: false}, + {pubkey: from, isSigner: true, isWritable: true}, + {pubkey: program, isSigner: false, isWritable: true}, + {pubkey: to, isSigner: false, isWritable: true}, ], programId: this.programId, data, diff --git a/web3.js/src/loader.js b/web3.js/src/loader.js index 5407feca10..c840a99678 100644 --- a/web3.js/src/loader.js +++ b/web3.js/src/loader.js @@ -97,7 +97,7 @@ export class Loader { ); const transaction = new Transaction().add({ - keys: [{pubkey: program.publicKey, isSigner: true, isDebitable: true}], + keys: [{pubkey: program.publicKey, isSigner: true, isWritable: true}], programId, data, }); @@ -137,8 +137,8 @@ export class Loader { const transaction = new Transaction().add({ keys: [ - {pubkey: program.publicKey, isSigner: true, isDebitable: true}, - {pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isDebitable: false}, + {pubkey: program.publicKey, isSigner: true, isWritable: true}, + {pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false}, ], programId, data, diff --git a/web3.js/src/system-program.js b/web3.js/src/system-program.js index 63e9f341bf..1d843e2bdb 100644 --- a/web3.js/src/system-program.js +++ b/web3.js/src/system-program.js @@ -183,8 +183,8 @@ export class SystemProgram { return new Transaction().add({ keys: [ - {pubkey: from, isSigner: true, isDebitable: true}, - {pubkey: newAccount, isSigner: false, isDebitable: true}, + {pubkey: from, isSigner: true, isWritable: true}, + {pubkey: newAccount, isSigner: false, isWritable: true}, ], programId: SystemProgram.programId, data, @@ -200,10 +200,8 @@ export class SystemProgram { return new Transaction().add({ keys: [ - {pubkey: from, isSigner: true, isDebitable: true}, - // TEMP FIX: a better proposed solution is here: - // https://github.com/solana-labs/solana-web3.js/issues/542 - {pubkey: to, isSigner: false, isDebitable: true}, + {pubkey: from, isSigner: true, isWritable: true}, + {pubkey: to, isSigner: false, isWritable: true}, ], programId: SystemProgram.programId, data, @@ -218,7 +216,7 @@ export class SystemProgram { const data = encodeData(type, {programId: programId.toBuffer()}); return new Transaction().add({ - keys: [{pubkey: from, isSigner: true, isDebitable: true}], + keys: [{pubkey: from, isSigner: true, isWritable: true}], programId: SystemProgram.programId, data, }); diff --git a/web3.js/src/transaction.js b/web3.js/src/transaction.js index 738c652cc2..7257fceade 100644 --- a/web3.js/src/transaction.js +++ b/web3.js/src/transaction.js @@ -41,7 +41,7 @@ export const PACKET_DATA_SIZE = 1280 - 40 - 8; * @property {?Buffer} data */ export type TransactionInstructionCtorFields = {| - keys?: Array<{pubkey: PublicKey, isSigner: boolean, isDebitable: boolean}>, + keys?: Array<{pubkey: PublicKey, isSigner: boolean, isWritable: boolean}>, programId?: PublicKey, data?: Buffer, |}; @@ -57,7 +57,7 @@ export class TransactionInstruction { keys: Array<{ pubkey: PublicKey, isSigner: boolean, - isDebitable: boolean, + isWritable: boolean, }> = []; /** @@ -171,8 +171,8 @@ export class Transaction { } const keys = this.signatures.map(({publicKey}) => publicKey.toString()); - let numCreditOnlySignedAccounts = 0; - let numCreditOnlyUnsignedAccounts = 0; + let numReadonlySignedAccounts = 0; + let numReadonlyUnsignedAccounts = 0; const programIds = []; @@ -185,12 +185,12 @@ export class Transaction { signature: null, publicKey: keySignerPair.pubkey, }); - if (!keySignerPair.isDebitable) { - numCreditOnlySignedAccounts += 1; + if (!keySignerPair.isWritable) { + numReadonlySignedAccounts += 1; } } else { - if (!keySignerPair.isDebitable) { - numCreditOnlyUnsignedAccounts += 1; + if (!keySignerPair.isWritable) { + numReadonlyUnsignedAccounts += 1; } } keys.push(keyStr); @@ -206,7 +206,7 @@ export class Transaction { programIds.forEach(programId => { if (!keys.includes(programId)) { keys.push(programId); - numCreditOnlyUnsignedAccounts += 1; + numReadonlyUnsignedAccounts += 1; } }); @@ -274,8 +274,8 @@ export class Transaction { const signDataLayout = BufferLayout.struct([ BufferLayout.blob(1, 'numRequiredSignatures'), - BufferLayout.blob(1, 'numCreditOnlySignedAccounts'), - BufferLayout.blob(1, 'numCreditOnlyUnsignedAccounts'), + BufferLayout.blob(1, 'numReadonlySignedAccounts'), + BufferLayout.blob(1, 'numReadonlyUnsignedAccounts'), BufferLayout.blob(keyCount.length, 'keyCount'), BufferLayout.seq(Layout.publicKey('key'), keys.length, 'keys'), Layout.publicKey('recentBlockhash'), @@ -283,10 +283,8 @@ export class Transaction { const transaction = { numRequiredSignatures: Buffer.from([this.signatures.length]), - numCreditOnlySignedAccounts: Buffer.from([numCreditOnlySignedAccounts]), - numCreditOnlyUnsignedAccounts: Buffer.from([ - numCreditOnlyUnsignedAccounts, - ]), + numReadonlySignedAccounts: Buffer.from([numReadonlySignedAccounts]), + numReadonlyUnsignedAccounts: Buffer.from([numReadonlyUnsignedAccounts]), keyCount: Buffer.from(keyCount), keys: keys.map(key => new PublicKey(key).toBuffer()), recentBlockhash: Buffer.from(bs58.decode(recentBlockhash)), @@ -450,14 +448,14 @@ export class Transaction { function isCreditDebit( i: number, numRequiredSignatures: number, - numCreditOnlySignedAccounts: number, - numCreditOnlyUnsignedAccounts: number, + numReadonlySignedAccounts: number, + numReadonlyUnsignedAccounts: number, numKeys: number, ): boolean { return ( - i < numRequiredSignatures - numCreditOnlySignedAccounts || + i < numRequiredSignatures - numReadonlySignedAccounts || (i >= numRequiredSignatures && - i < numKeys - numCreditOnlyUnsignedAccounts) + i < numKeys - numReadonlyUnsignedAccounts) ); } @@ -476,10 +474,10 @@ export class Transaction { const numRequiredSignatures = byteArray.shift(); // byteArray = byteArray.slice(1); // Skip numRequiredSignatures byte - const numCreditOnlySignedAccounts = byteArray.shift(); - // byteArray = byteArray.slice(1); // Skip numCreditOnlySignedAccounts byte - const numCreditOnlyUnsignedAccounts = byteArray.shift(); - // byteArray = byteArray.slice(1); // Skip numCreditOnlyUnsignedAccounts byte + const numReadonlySignedAccounts = byteArray.shift(); + // byteArray = byteArray.slice(1); // Skip numReadonlySignedAccounts byte + const numReadonlyUnsignedAccounts = byteArray.shift(); + // byteArray = byteArray.slice(1); // Skip numReadonlyUnsignedAccounts byte const accountCount = shortvec.decodeLength(byteArray); let accounts = []; @@ -532,11 +530,11 @@ export class Transaction { isSigner: transaction.signatures.some( keyObj => keyObj.publicKey.toString() === pubkey.toString(), ), - isDebitable: isCreditDebit( + isWritable: isCreditDebit( j, numRequiredSignatures, - numCreditOnlySignedAccounts, - numCreditOnlyUnsignedAccounts, + numReadonlySignedAccounts, + numReadonlyUnsignedAccounts, accounts.length, ), }); diff --git a/web3.js/test/bpf-loader.test.js b/web3.js/test/bpf-loader.test.js index 4a63e755b3..b69c5bd0dc 100644 --- a/web3.js/test/bpf-loader.test.js +++ b/web3.js/test/bpf-loader.test.js @@ -36,7 +36,7 @@ test('load BPF C program', async () => { const programId = await BpfLoader.load(connection, from, data); const transaction = new Transaction().add({ - keys: [{pubkey: from.publicKey, isSigner: true, isDebitable: true}], + keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}], programId, }); await sendAndConfirmTransaction(connection, transaction, from); @@ -61,7 +61,7 @@ test('load BPF Rust program', async () => { const programId = await BpfLoader.load(connection, from, data); const transaction = new Transaction().add({ - keys: [{pubkey: from.publicKey, isSigner: true, isDebitable: true}], + keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}], programId, }); await sendAndConfirmTransaction(connection, transaction, from); diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 47e4630321..95863cfd6c 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -681,11 +681,6 @@ test('transaction', async () => { 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); }); diff --git a/web3.js/test/system-program.test.js b/web3.js/test/system-program.test.js index 869996eb98..8965628dd3 100644 --- a/web3.js/test/system-program.test.js +++ b/web3.js/test/system-program.test.js @@ -111,8 +111,8 @@ test('non-SystemInstruction error', () => { const badProgramId = { keys: [ - {pubkey: from.publicKey, isSigner: true, isDebitable: true}, - {pubkey: to.publicKey, isSigner: false, isDebitable: false}, + {pubkey: from.publicKey, isSigner: true, isWritable: true}, + {pubkey: to.publicKey, isSigner: false, isWritable: true}, ], programId: BudgetProgram.programId, data: Buffer.from([2, 0, 0, 0]),