s/contract/program/
This commit is contained in:
@ -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,
|
||||
});
|
||||
}
|
@ -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';
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
@ -22,7 +22,7 @@ export type TransactionId = string;
|
||||
type TransactionCtorFields = {|
|
||||
signature?: Buffer;
|
||||
keys?: Array<PublicKey>;
|
||||
contractId?: PublicKey;
|
||||
programId?: PublicKey;
|
||||
fee?: number;
|
||||
userdata?: Buffer;
|
||||
|};
|
||||
@ -44,9 +44,9 @@ export class Transaction {
|
||||
keys: Array<PublicKey> = [];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
Reference in New Issue
Block a user