diff --git a/web3.js/examples/budget.js b/web3.js/examples/budget.js index 25cf71fc10..2f9c37ab61 100644 --- a/web3.js/examples/budget.js +++ b/web3.js/examples/budget.js @@ -54,12 +54,12 @@ showBalance() .then(showBalance) .then(() => { console.log(`\n== Creating account for the contract funds`); - const transaction = solanaWeb3.SystemContract.createAccount( + const transaction = solanaWeb3.SystemProgram.createAccount( account1.publicKey, contractFunds.publicKey, 50, // number of tokens to transfer 0, - solanaWeb3.BudgetContract.contractId, + solanaWeb3.BudgetProgram.programId, ); return connection.sendTransaction(account1, transaction); }) @@ -67,12 +67,12 @@ showBalance() .then(showBalance) .then(() => { console.log(`\n== Creating account for the contract state`); - const transaction = solanaWeb3.SystemContract.createAccount( + const transaction = solanaWeb3.SystemProgram.createAccount( account1.publicKey, contractState.publicKey, - 1, // sender pays 1 token to hold the contract state - solanaWeb3.BudgetContract.space, - solanaWeb3.BudgetContract.contractId, + 1, // account1 pays 1 token to hold the contract state + solanaWeb3.BudgetProgram.space, + solanaWeb3.BudgetProgram.programId, ); return connection.sendTransaction(account1, transaction); }) @@ -80,12 +80,12 @@ showBalance() .then(showBalance) .then(() => { console.log(`\n== Initializing contract`); - const transaction = solanaWeb3.BudgetContract.pay( + const transaction = solanaWeb3.BudgetProgram.pay( contractFunds.publicKey, contractState.publicKey, account2.publicKey, 50, - solanaWeb3.BudgetContract.timestampCondition(account1.publicKey, new Date("2050")), + solanaWeb3.BudgetProgram.timestampCondition(account1.publicKey, new Date('2050')), ); return connection.sendTransaction(contractFunds, transaction); }) @@ -93,11 +93,11 @@ showBalance() .then(showBalance) .then(() => { console.log(`\n== Witness contract`); - const transaction = solanaWeb3.BudgetContract.applyTimestamp( + const transaction = solanaWeb3.BudgetProgram.applyTimestamp( account1.publicKey, contractState.publicKey, account2.publicKey, - new Date("2050"), + new Date('2050'), ); return connection.sendTransaction(account1, transaction); }) diff --git a/web3.js/src/budget-contract.js b/web3.js/src/budget-program.js similarity index 93% rename from web3.js/src/budget-contract.js rename to web3.js/src/budget-program.js index 08fa8357c1..78bb40f317 100644 --- a/web3.js/src/budget-contract.js +++ b/web3.js/src/budget-program.js @@ -107,19 +107,19 @@ function serializeCondition(condition: BudgetCondition) { /** - * Factory class for transactions to interact with the Budget contract + * Factory class for transactions to interact with the Budget program */ -export class BudgetContract { +export class BudgetProgram { /** - * Public key that identifies the Budget Contract + * Public key that identifies the Budget program */ - static get contractId(): PublicKey { + static get programId(): PublicKey { return '4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM'; } /** - * The amount of space this contract requires + * The amount of space this program requires */ static get space(): number { return 128; @@ -184,7 +184,7 @@ export class BudgetContract { return new Transaction({ fee: 0, keys: [from, to], - contractId: this.contractId, + programId: this.programId, userdata: userdata.slice(0, pos), }); case 1: @@ -205,7 +205,7 @@ export class BudgetContract { return new Transaction({ fee: 0, keys: [from, contract, to], - contractId: this.contractId, + programId: this.programId, userdata: userdata.slice(0, pos), }); @@ -226,7 +226,7 @@ export class BudgetContract { return new Transaction({ fee: 0, keys: [from, contract, to], - contractId: this.contractId, + programId: this.programId, userdata: userdata.slice(0, pos), }); @@ -245,7 +245,7 @@ export class BudgetContract { return new Transaction({ fee: 0, keys: [from, contract, to], - contractId: this.contractId, + programId: this.programId, userdata, }); } @@ -257,7 +257,7 @@ export class BudgetContract { return new Transaction({ fee: 0, keys: [from, contract, to], - contractId: this.contractId, + programId: this.programId, userdata, }); } diff --git a/web3.js/src/index.js b/web3.js/src/index.js index 3bc0faff0d..f613a2d68d 100644 --- a/web3.js/src/index.js +++ b/web3.js/src/index.js @@ -2,5 +2,5 @@ export {Account} from './account'; export {Connection} from './connection'; export {Transaction} from './transaction'; -export {SystemContract} from './system-contract'; -export {BudgetContract} from './budget-contract'; +export {SystemProgram} from './system-program'; +export {BudgetProgram} from './budget-program'; diff --git a/web3.js/src/system-contract.js b/web3.js/src/system-program.js similarity index 69% rename from web3.js/src/system-contract.js rename to web3.js/src/system-program.js index b2ccd2992b..2bbd00fa00 100644 --- a/web3.js/src/system-contract.js +++ b/web3.js/src/system-program.js @@ -6,13 +6,13 @@ import {Transaction} from './transaction'; import type {PublicKey} from './account'; /** - * Factory class for transactions to interact with the System contract + * Factory class for transactions to interact with the System program */ -export class SystemContract { +export class SystemProgram { /** - * Public key that identifies the System Contract + * Public key that identifies the System program */ - static get contractId(): PublicKey { + static get programId(): PublicKey { return '11111111111111111111111111111111'; } @@ -24,7 +24,7 @@ export class SystemContract { newAccount: PublicKey, tokens: number, space: number, - contractId: ?PublicKey + programId: ?PublicKey ): Transaction { const userdata = Buffer.alloc(4 + 8 + 8 + 1 + 32); let pos = 0; @@ -38,12 +38,12 @@ export class SystemContract { userdata.writeUInt32LE(space, pos); // space as u64 pos += 8; - if (contractId) { + if (programId) { userdata.writeUInt8(1, pos); // 'Some' pos += 1; - const contractIdBytes = Transaction.serializePublicKey(contractId); - contractIdBytes.copy(userdata, pos); + const programIdBytes = Transaction.serializePublicKey(programId); + programIdBytes.copy(userdata, pos); pos += 32; } else { userdata.writeUInt8(0, pos); // 'None' @@ -55,7 +55,7 @@ export class SystemContract { return new Transaction({ fee: 0, keys: [from, newAccount], - contractId: SystemContract.contractId, + programId: SystemProgram.programId, userdata, }); } @@ -77,31 +77,31 @@ export class SystemContract { return new Transaction({ fee: 0, keys: [from, to], - contractId: SystemContract.contractId, + programId: SystemProgram.programId, userdata, }); } /** - * Generate a Transaction that assigns an account to a contract id + * Generate a Transaction that assigns an account to a program */ - static assign(from: PublicKey, contractId: PublicKey): Transaction { + static assign(from: PublicKey, programId: PublicKey): Transaction { const userdata = Buffer.alloc(4 + 32); let pos = 0; userdata.writeUInt32LE(1, pos); // Assign instruction pos += 4; - const contractIdBytes = Transaction.serializePublicKey(contractId); - contractIdBytes.copy(userdata, pos); - pos += contractIdBytes.length; + const programIdBytes = Transaction.serializePublicKey(programId); + programIdBytes.copy(userdata, pos); + pos += programIdBytes.length; assert(pos === userdata.length); return new Transaction({ fee: 0, keys: [from], - contractId: SystemContract.contractId, + programId: SystemProgram.programId, userdata, }); } diff --git a/web3.js/src/transaction.js b/web3.js/src/transaction.js index 9be1837627..aa9faff12e 100644 --- a/web3.js/src/transaction.js +++ b/web3.js/src/transaction.js @@ -22,7 +22,7 @@ export type TransactionId = string; type TransactionCtorFields = {| signature?: Buffer; keys?: Array; - contractId?: PublicKey; + programId?: PublicKey; fee?: number; userdata?: Buffer; |}; @@ -44,9 +44,9 @@ export class Transaction { keys: Array = []; /** - * Contract Id to execute + * Program Id to execute */ - contractId: ?PublicKey; + programId: ?PublicKey; /** * A recent transaction id. Must be populated by the caller @@ -59,7 +59,7 @@ export class Transaction { fee: number = 0; /** - * Contract input userdata to include + * Program input */ userdata: Buffer = Buffer.alloc(0); @@ -90,9 +90,9 @@ export class Transaction { pos += 32; } - // serialize `this.contractId` - if (this.contractId) { - const keyBytes = Transaction.serializePublicKey(this.contractId); + // serialize `this.programId` + if (this.programId) { + const keyBytes = Transaction.serializePublicKey(this.programId); keyBytes.copy(transactionData, pos); } pos += 32; diff --git a/web3.js/test/budget-contract.test.js b/web3.js/test/budget-program.test.js similarity index 60% rename from web3.js/test/budget-contract.test.js rename to web3.js/test/budget-program.test.js index f87153b574..b5b2381c34 100644 --- a/web3.js/test/budget-contract.test.js +++ b/web3.js/test/budget-program.test.js @@ -1,7 +1,7 @@ // @flow import {Account} from '../src/account'; -import {BudgetContract} from '../src/budget-contract'; +import {BudgetProgram} from '../src/budget-program'; test('pay', () => { const from = new Account(); @@ -9,7 +9,7 @@ test('pay', () => { const to = new Account(); let transaction; - transaction = BudgetContract.pay( + transaction = BudgetProgram.pay( from.publicKey, contract.publicKey, to.publicKey, @@ -17,22 +17,22 @@ test('pay', () => { ); console.log('Pay:', transaction); - transaction = BudgetContract.pay( + transaction = BudgetProgram.pay( from.publicKey, contract.publicKey, to.publicKey, 123, - BudgetContract.signatureCondition(from.publicKey), + BudgetProgram.signatureCondition(from.publicKey), ); console.log('After:', transaction); - transaction = BudgetContract.pay( + transaction = BudgetProgram.pay( from.publicKey, contract.publicKey, to.publicKey, 123, - BudgetContract.signatureCondition(from.publicKey), - BudgetContract.timestampCondition(from.publicKey, new Date()), + BudgetProgram.signatureCondition(from.publicKey), + BudgetProgram.timestampCondition(from.publicKey, new Date()), ); console.log('Or:', transaction); }); diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index f832b28be9..6eabe34705 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -2,7 +2,7 @@ import {Account} from '../src/account'; import {Connection} from '../src/connection'; -import {SystemContract} from '../src/system-contract'; +import {SystemProgram} from '../src/system-program'; import {mockRpc} from './__mocks__/node-fetch'; const url = 'http://testnet.solana.com:8899'; @@ -274,7 +274,7 @@ test('transaction', async () => { ] ); - const transaction = SystemContract.move( + const transaction = SystemProgram.move( accountFrom.publicKey, accountTo.publicKey, 10