|
|
@ -16,9 +16,9 @@ import { |
|
|
|
DefaultBlockParams, |
|
|
|
DefaultBlockParams, |
|
|
|
} from '@harmony-js/utils'; |
|
|
|
} from '@harmony-js/utils'; |
|
|
|
|
|
|
|
|
|
|
|
import { getAddress } from '@harmony-js/crypto'; |
|
|
|
import {getAddress} from '@harmony-js/crypto'; |
|
|
|
|
|
|
|
|
|
|
|
import { Transaction } from '@harmony-js/transaction'; |
|
|
|
import {Transaction} from '@harmony-js/transaction'; |
|
|
|
|
|
|
|
|
|
|
|
class Blockchain extends HarmonyCore { |
|
|
|
class Blockchain extends HarmonyCore { |
|
|
|
messenger: Messenger; |
|
|
|
messenger: Messenger; |
|
|
@ -115,7 +115,7 @@ class Blockchain extends HarmonyCore { |
|
|
|
@assertObject({ |
|
|
|
@assertObject({ |
|
|
|
blockHash: ['isHash', AssertType.required], |
|
|
|
blockHash: ['isHash', AssertType.required], |
|
|
|
}) |
|
|
|
}) |
|
|
|
async getBlockTransactionCountByHash({ blockHash }: { blockHash: string }) { |
|
|
|
async getBlockTransactionCountByHash({blockHash}: {blockHash: string}) { |
|
|
|
const result = await this.messenger.send( |
|
|
|
const result = await this.messenger.send( |
|
|
|
RPCMethod.GetBlockTransactionCountByHash, |
|
|
|
RPCMethod.GetBlockTransactionCountByHash, |
|
|
|
[blockHash], |
|
|
|
[blockHash], |
|
|
@ -127,11 +127,7 @@ class Blockchain extends HarmonyCore { |
|
|
|
@assertObject({ |
|
|
|
@assertObject({ |
|
|
|
blockNumber: ['isBlockNumber', AssertType.required], |
|
|
|
blockNumber: ['isBlockNumber', AssertType.required], |
|
|
|
}) |
|
|
|
}) |
|
|
|
async getBlockTransactionCountByNumber({ |
|
|
|
async getBlockTransactionCountByNumber({blockNumber}: {blockNumber: string}) { |
|
|
|
blockNumber, |
|
|
|
|
|
|
|
}: { |
|
|
|
|
|
|
|
blockNumber: string; |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const result = await this.messenger.send( |
|
|
|
const result = await this.messenger.send( |
|
|
|
RPCMethod.GetBlockTransactionCountByNumber, |
|
|
|
RPCMethod.GetBlockTransactionCountByNumber, |
|
|
|
[blockNumber], |
|
|
|
[blockNumber], |
|
|
@ -184,7 +180,7 @@ class Blockchain extends HarmonyCore { |
|
|
|
@assertObject({ |
|
|
|
@assertObject({ |
|
|
|
txnHash: ['isHash', AssertType.required], |
|
|
|
txnHash: ['isHash', AssertType.required], |
|
|
|
}) |
|
|
|
}) |
|
|
|
async getTransactionByHash({ txnHash }: { txnHash: string }) { |
|
|
|
async getTransactionByHash({txnHash}: {txnHash: string}) { |
|
|
|
const result = await this.messenger.send( |
|
|
|
const result = await this.messenger.send( |
|
|
|
RPCMethod.GetTransactionByHash, |
|
|
|
RPCMethod.GetTransactionByHash, |
|
|
|
[txnHash], |
|
|
|
[txnHash], |
|
|
@ -199,7 +195,7 @@ class Blockchain extends HarmonyCore { |
|
|
|
@assertObject({ |
|
|
|
@assertObject({ |
|
|
|
txnHash: ['isString', AssertType.required], |
|
|
|
txnHash: ['isString', AssertType.required], |
|
|
|
}) |
|
|
|
}) |
|
|
|
async getTransactionReceipt({ txnHash }: { txnHash: string }) { |
|
|
|
async getTransactionReceipt({txnHash}: {txnHash: string}) { |
|
|
|
const result = await this.messenger.send( |
|
|
|
const result = await this.messenger.send( |
|
|
|
RPCMethod.GetTransactionReceipt, |
|
|
|
RPCMethod.GetTransactionReceipt, |
|
|
|
[txnHash], |
|
|
|
[txnHash], |
|
|
@ -331,10 +327,10 @@ class Blockchain extends HarmonyCore { |
|
|
|
to: ['isValidAddress', AssertType.optional], |
|
|
|
to: ['isValidAddress', AssertType.optional], |
|
|
|
data: ['isHex', AssertType.optional], |
|
|
|
data: ['isHex', AssertType.optional], |
|
|
|
}) |
|
|
|
}) |
|
|
|
async estimateGas({ to, data }: { to: string; data: string }) { |
|
|
|
async estimateGas({to, data}: {to: string; data: string}) { |
|
|
|
const result = await this.messenger.send( |
|
|
|
const result = await this.messenger.send( |
|
|
|
RPCMethod.EstimateGas, |
|
|
|
RPCMethod.EstimateGas, |
|
|
|
[{ to: getAddress(to).checksum, data }], |
|
|
|
[{to: getAddress(to).checksum, data}], |
|
|
|
this.chainPrefix, |
|
|
|
this.chainPrefix, |
|
|
|
); |
|
|
|
); |
|
|
|
return this.getRpcResult(result); |
|
|
|
return this.getRpcResult(result); |
|
|
@ -349,6 +345,21 @@ class Blockchain extends HarmonyCore { |
|
|
|
return this.getRpcResult(result); |
|
|
|
return this.getRpcResult(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async call({ |
|
|
|
|
|
|
|
payload, |
|
|
|
|
|
|
|
blockNumber = DefaultBlockParams.latest, |
|
|
|
|
|
|
|
}: { |
|
|
|
|
|
|
|
payload: any; |
|
|
|
|
|
|
|
blockNumber?: string; |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const result = await this.messenger.send( |
|
|
|
|
|
|
|
RPCMethod.Call, |
|
|
|
|
|
|
|
[payload, blockNumber], |
|
|
|
|
|
|
|
this.chainPrefix, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return this.getRpcResult(result); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
newPendingTransactions() { |
|
|
|
newPendingTransactions() { |
|
|
|
if (this.messenger.provider instanceof WSProvider) { |
|
|
|
if (this.messenger.provider instanceof WSProvider) { |
|
|
|
return new NewPendingTransactions(this.messenger); |
|
|
|
return new NewPendingTransactions(this.messenger); |
|
|
@ -382,4 +393,4 @@ class Blockchain extends HarmonyCore { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export { Blockchain }; |
|
|
|
export {Blockchain}; |
|
|
|