2021-01-01 13:58:20 -08:00
|
|
|
import { PublicKey } from '@solana/web3.js';
|
|
|
|
import { RpcFactory } from './rpc';
|
|
|
|
import { Idl } from './idl';
|
|
|
|
import Coder from './coder';
|
2021-01-01 15:10:26 -08:00
|
|
|
import { Rpcs, Ixs, Accounts } from './rpc';
|
2021-01-01 13:58:20 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Program is the IDL deserialized representation of a Solana program.
|
|
|
|
*/
|
|
|
|
export class Program {
|
|
|
|
/**
|
|
|
|
* Address of the program.
|
|
|
|
*/
|
|
|
|
readonly programId: PublicKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDL describing this program's interface.
|
|
|
|
*/
|
|
|
|
readonly idl: Idl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Async functions to invoke instructions against a Solana priogram running
|
|
|
|
* on a cluster.
|
|
|
|
*/
|
|
|
|
readonly rpc: Rpcs;
|
|
|
|
|
2021-01-01 15:10:26 -08:00
|
|
|
/**
|
|
|
|
* Async functions to fetch deserialized program accounts from a cluster.
|
|
|
|
*/
|
|
|
|
readonly account: Accounts;
|
|
|
|
|
2021-01-01 13:58:20 -08:00
|
|
|
/**
|
|
|
|
* Functions to build `TransactionInstruction` objects.
|
|
|
|
*/
|
|
|
|
readonly instruction: Ixs;
|
|
|
|
|
|
|
|
public constructor(idl: Idl, programId: PublicKey) {
|
|
|
|
this.idl = idl;
|
|
|
|
this.programId = programId;
|
|
|
|
|
|
|
|
// Build the serializer.
|
|
|
|
const coder = new Coder(idl);
|
|
|
|
|
|
|
|
// Build the dynamic RPC functions.
|
2021-01-01 15:10:26 -08:00
|
|
|
const [rpcs, ixs, accounts] = RpcFactory.build(idl, coder, programId);
|
2021-01-01 13:58:20 -08:00
|
|
|
this.rpc = rpcs;
|
|
|
|
this.instruction = ixs;
|
2021-01-01 15:10:26 -08:00
|
|
|
this.account = accounts;
|
2021-01-01 13:58:20 -08:00
|
|
|
}
|
|
|
|
}
|