feat(blockchain):update call

dev
neeboo 5 years ago
parent d3302931cc
commit a60a5f8a92
  1. 21
      README.md
  2. 2
      package.json
  3. 37
      packages/harmony-core/src/blockchain.ts

@ -27,6 +27,15 @@ yarn add tslib
* [harmony-sdk-examples](https://github.com/FireStack-Lab/harmony-sdk-examples) * [harmony-sdk-examples](https://github.com/FireStack-Lab/harmony-sdk-examples)
# Packages
1. [@harmony-js/core](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-core)
2. [@harmony-js/account](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-account)
3. [@harmony-js/crypto](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-crypto)
4. [@harmony-js/network](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-network)
5. [@harmony-js/utils](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-utils)
6. [@harmony-js/transaction](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-transaction)
7. [@harmony-js/contract](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-contract)
# Hacking from source files # Hacking from source files
@ -48,18 +57,6 @@ yarn watch
- [E2E Tests](#E2E-tests) - [E2E Tests](#E2E-tests)
# Packages
1. [@harmony-js/core](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-core)
2. [@harmony-js/account](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-account)
3. [@harmony-js/crypto](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-crypto)
4. [@harmony-js/network](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-network)
5. [@harmony-js/utils](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-utils)
6. [@harmony-js/transaction](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-transaction)
7. [@harmony-js/contract](https://github.com/FireStack-Lab/Harmony-sdk-core/tree/master/packages/harmony-contract)
# Manually Build/bundle # Manually Build/bundle
## Build ## Build

@ -7,7 +7,7 @@
"scripts": { "scripts": {
"bootstrap": "lerna bootstrap && yarn build:ts", "bootstrap": "lerna bootstrap && yarn build:ts",
"watch":"yarn build:ts -w", "watch":"yarn build:ts -w",
"build": "gulp cleanServer && gulp cleanUnexpected && yarn build:ts", "build": "yarn packages:clean && yarn build:ts",
"build:ts": "tsc -b tsconfig.json", "build:ts": "tsc -b tsconfig.json",
"build:test":"tsc -b tsconfig.test.json", "build:test":"tsc -b tsconfig.test.json",
"build:e2e":"tsc -b tsconfig.e2e.json", "build:e2e":"tsc -b tsconfig.e2e.json",

@ -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};

Loading…
Cancel
Save