[WIP] added blockchain to @harmony/network

@types
neeboo 6 years ago
parent 40ae81a5bc
commit d61358d7cf
  1. 2
      examples/testNode.js
  2. 4
      packages/harmony-core/src/core.ts
  3. 22
      packages/harmony-network/src/blockchain/blockchain.ts
  4. 1
      packages/harmony-network/src/index.ts

@ -125,4 +125,4 @@ const acc = wallet.addByPrivateKey(
// console.log(getContractAddress(acc.publicKey, 248));
const harmony = new Harmony('https://devnet.harmony.one');
console.log(harmony);
console.log(harmony.blockchain);

@ -1,7 +1,7 @@
import * as crypto from '@harmony/crypto';
import * as utils from '@harmony/utils';
import { HttpProvider, Messenger } from '@harmony/network';
import { HttpProvider, Messenger, Blockchain } from '@harmony/network';
import { TransactionFactory } from '@harmony/transaction';
import { Wallet } from '@harmony/account';
@ -9,6 +9,7 @@ class Harmony {
messenger: Messenger;
transactions: TransactionFactory;
wallet: Wallet;
blockchain: Blockchain;
crypto: any;
utils: any;
private provider: HttpProvider;
@ -16,6 +17,7 @@ class Harmony {
constructor(url: string) {
this.provider = new HttpProvider(url);
this.messenger = new Messenger(this.provider);
this.blockchain = new Blockchain(this.messenger);
this.transactions = new TransactionFactory(this.messenger);
this.wallet = new Wallet(this.messenger);
this.crypto = crypto;

@ -0,0 +1,22 @@
import { RPCMethod } from './rpc';
import { Messenger } from '../messenger/messenger';
class Blockchain {
messenger: Messenger;
constructor(messenger: Messenger) {
this.messenger = messenger;
}
getBalance = async (address: string) => {
const result = await this.messenger.send(RPCMethod.GetBalance, address);
return result;
};
getLatestBlock = async () => {
const result = await this.messenger.send(RPCMethod.GetLatestBlock, '');
return result;
};
}
export { Blockchain };

@ -9,6 +9,7 @@ export * from './messenger/responseMiddleware';
export * from './blockchain/rpcBuilder';
export * from './blockchain/net';
export * from './blockchain/rpc';
export * from './blockchain/blockchain';
// utils
export * from './util';
// types

Loading…
Cancel
Save