adding get blocks method based on API docs

pull/82/head
Isaac Adams 4 years ago
parent 99a827782f
commit 75a7118e1b
  1. 50
      packages/harmony-core/src/blockchain.ts
  2. 2
      packages/harmony-network/src/rpcMethod/rpc.ts

@ -382,6 +382,56 @@ class Blockchain {
return this.getRpcResult(result);
}
/**
* Returns blocks in range [from; to]
*
* @param from starting block number in 0x format
* @param to ending block number in 0x format
* @param blockArgs optional args struct in json format (should be used just with { })
* @param shardID `shardID` is binding with the endpoint, IGNORE it!
* @returns `Promise` - An array of block objects
*
* @example
* ```javascript
* hmy.blockchain.getBlockByNumber({
* blockNumber: '0x89',
* }).then((value) => {
* console.log(value);
* });
* ```
*/
@assertObject({
from: ['isString', AssertType.required],
to: ['isString', AssertType.required],
blockArgs: ['isObject', AssertType.optional],
shardID: ['isNumber', AssertType.optional],
})
async getBlocks({
from,
to,
blockArgs = {
fullTx: false,
withSigners: false,
},
shardID = this.messenger.currentShard,
}: {
from: string;
to: string;
blockArgs: {
fullTx: boolean;
withSigners: boolean;
};
shardID?: number;
}) {
const result = await this.messenger.send(
RPCMethod.GetBlocks,
[from, to, blockArgs],
this.messenger.chainPrefix,
shardID,
);
return this.getRpcResult(result);
}
/**
* Returns the number of transaction in a given block.
*

@ -103,6 +103,8 @@ export enum RPCMethod {
SendRawStakingTransaction = 'hmy_sendRawStakingTransaction',
// 34. hmy_getAccountNonce
GetAccountNonce = 'hmy_getAccountNonce',
// 35. hmy_getBlocks
GetBlocks = 'hmy_getBlocks',
}
/**@ignore */

Loading…
Cancel
Save