Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. // TODO: imports and functions goes here
  2.  
  3. /** A high-level interface to a blockchain node */
  4. export class MyBlockchainConnection implements BlockchainConnection {
  5. public static async establish(myBlockchainParameters):
  6. Promise<MyBlockchainConnection> {
  7. // TODO: logic to load blockchain parameters (nethash, chainId, etc)
  8. return new MyBlockchainConnection(myBlockchainParameters);
  9. }
  10.  
  11. constructor(){
  12. // TODO: initialize your private variables (url, chainId, etc)
  13. }
  14.  
  15. /** disconect the client */
  16. public disconnect(): void {
  17. // TODO: based on your blockchain close the socket or call disconnect, etc
  18. }
  19.  
  20. /** the chain ID this connection is connected to */
  21. public chainId(): ChainId {
  22. // TODO: get your chain id
  23. return myBlockchainChainId;
  24. }
  25.  
  26. /** last block height from node*/
  27. public async height(): Promise<number> {
  28. // TODO: get last block height from blockchain node
  29. return myBlockchainHeight;
  30. }
  31.  
  32. /** current account information or undefined */
  33. public async getAccount(query: AccountQuery): Promise<Account | undefined> {
  34. // TODO: based on input query, search the account in the blockchain
  35. // and get the address, pubkey and balance if exists
  36. return {address, pubkey, balance}
  37. }
  38.  
  39. /** blockchain parameters */
  40. public async getAllTickers(): Promise<ReadonlyArray<BcpTicker>> {
  41. // TODO: use your blockchain constants here
  42. return { tokenTicker, tokenName, fractionalDigits };
  43. }
  44.  
  45. /** nonce for the next transaction signature */
  46. public async getNonce(query: AddressQuery | PubkeyQuery): Promise<Nonce> {
  47. // TODO: calculate the nonce of the account
  48. return nonceOnMyBlockchain;
  49. }
  50.  
  51. /** post new transaction in the blockchain */
  52. public async postTx(bytes: PostableBytes): Promise<PostTxResponse> {
  53. // TODO: send a transaction to your blockchain and wait the
  54. // confirmation
  55. return { blockInfo, transactionId }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement