Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO: imports and functions goes here
- /** A high-level interface to a blockchain node */
- export class MyBlockchainConnection implements BlockchainConnection {
- public static async establish(myBlockchainParameters):
- Promise<MyBlockchainConnection> {
- // TODO: logic to load blockchain parameters (nethash, chainId, etc)
- return new MyBlockchainConnection(myBlockchainParameters);
- }
- constructor(){
- // TODO: initialize your private variables (url, chainId, etc)
- }
- /** disconect the client */
- public disconnect(): void {
- // TODO: based on your blockchain close the socket or call disconnect, etc
- }
- /** the chain ID this connection is connected to */
- public chainId(): ChainId {
- // TODO: get your chain id
- return myBlockchainChainId;
- }
- /** last block height from node*/
- public async height(): Promise<number> {
- // TODO: get last block height from blockchain node
- return myBlockchainHeight;
- }
- /** current account information or undefined */
- public async getAccount(query: AccountQuery): Promise<Account | undefined> {
- // TODO: based on input query, search the account in the blockchain
- // and get the address, pubkey and balance if exists
- return {address, pubkey, balance}
- }
- /** blockchain parameters */
- public async getAllTickers(): Promise<ReadonlyArray<BcpTicker>> {
- // TODO: use your blockchain constants here
- return { tokenTicker, tokenName, fractionalDigits };
- }
- /** nonce for the next transaction signature */
- public async getNonce(query: AddressQuery | PubkeyQuery): Promise<Nonce> {
- // TODO: calculate the nonce of the account
- return nonceOnMyBlockchain;
- }
- /** post new transaction in the blockchain */
- public async postTx(bytes: PostableBytes): Promise<PostTxResponse> {
- // TODO: send a transaction to your blockchain and wait the
- // confirmation
- return { blockInfo, transactionId }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement