Move more shared utils into utils package and reuse them
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import {schemas, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import {intervalUtils, bigNumberConfigs} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {artifacts} from './artifacts';
|
||||
import {bigNumberConfigs} from './bignumber_config';
|
||||
import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper';
|
||||
import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
|
||||
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
import {AbiDecoder} from './utils/abi_decoder';
|
||||
import {assert} from './utils/assert';
|
||||
import {constants} from './utils/constants';
|
||||
import {intervalUtils} from './utils/interval_utils';
|
||||
import {OrderStateUtils} from './utils/order_state_utils';
|
||||
import {signatureUtils} from './utils/signature_utils';
|
||||
import {utils} from './utils/utils';
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {constants} from '../utils/constants';
|
||||
import {filterUtils} from '../utils/filter_utils';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
|
||||
const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = {
|
||||
ZRX: ZeroExError.ZRXContractDoesNotExist,
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
} from '../types';
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import {RBTree} from 'bintrees';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {ZeroEx} from '../0x';
|
||||
import {SignedOrder, ZeroExError} from '../types';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
const DEFAULT_EXPIRATION_MARGIN_MS = 0;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {schemas} from '@0xproject/json-schemas';
|
||||
import {intervalUtils} from '@0xproject/utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -29,7 +30,6 @@ import {
|
||||
} from '../types';
|
||||
import {AbiDecoder} from '../utils/abi_decoder';
|
||||
import {assert} from '../utils/assert';
|
||||
import {intervalUtils} from '../utils/interval_utils';
|
||||
import {OrderStateUtils} from '../utils/order_state_utils';
|
||||
import {utils} from '../utils/utils';
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -6,13 +7,12 @@ import * as Sinon from 'sinon';
|
||||
|
||||
import {ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx, ZeroExError} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
@@ -5,14 +6,13 @@ import * as Web3 from 'web3';
|
||||
|
||||
import {ZeroEx, ZeroExError} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
// Since the address depositing/withdrawing ETH/WETH also needs to pay gas costs for the transaction,
|
||||
// a small amount of ETH will be used to pay this gas cost. We therefore check that the difference between
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
|
||||
@@ -5,14 +6,13 @@ import {ExchangeContractErrs, Token, ZeroEx} from '../src';
|
||||
import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
|
||||
import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('ExchangeTransferSimulator', () => {
|
||||
const web3 = web3Factory.create();
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -28,7 +28,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
const NON_EXISTENT_ORDER_HASH = '0x79370342234e7acd6bbeac335bd3bb1d368383294b64b8160a00f4060e4d3777';
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
@@ -12,8 +13,8 @@ import {DoneCallback, Token} from '../src/types';
|
||||
import {constants} from '../src/utils/constants';
|
||||
import {utils} from '../src/utils/utils';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants as testConstants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
import {reportCallbackErrors} from './utils/report_callback_errors';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
@@ -21,7 +22,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(testConstants.RPC_URL);
|
||||
|
||||
describe('ExpirationWatcher', () => {
|
||||
let web3: Web3;
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
import {OrderStateWatcher} from '../src/order_watcher/order_state_watcher';
|
||||
import {DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -33,7 +33,7 @@ const TIMEOUT_MS = 150;
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('OrderStateWatcher', () => {
|
||||
let web3: Web3;
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as Sinon from 'sinon';
|
||||
@@ -8,7 +9,6 @@ import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
|
||||
import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
|
||||
import {OrderValidationUtils} from '../src/utils/order_validation_utils';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {FillScenarios} from './utils/fill_scenarios';
|
||||
@@ -17,7 +17,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('OrderValidation', () => {
|
||||
let web3: Web3;
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
@@ -15,7 +16,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {reportCallbackErrors} from './utils/report_callback_errors';
|
||||
@@ -24,7 +24,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('SubscriptionTest', () => {
|
||||
let web3: Web3;
|
||||
|
@@ -1,18 +1,18 @@
|
||||
import {schemas, SchemaValidator} from '@0xproject/json-schemas';
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
import 'mocha';
|
||||
|
||||
import {Token, ZeroEx} from '../src';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7;
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BlockchainLifecycle} from '@0xproject/dev-utils';
|
||||
import {Web3Wrapper} from '@0xproject/web3-wrapper';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
} from '../src';
|
||||
import {BlockParamLiteral, DoneCallback} from '../src/types';
|
||||
|
||||
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
import {constants} from './utils/constants';
|
||||
import {TokenUtils} from './utils/token_utils';
|
||||
@@ -29,7 +29,7 @@ import {web3Factory} from './utils/web3_factory';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
|
||||
|
||||
describe('TokenWrapper', () => {
|
||||
let web3: Web3;
|
||||
|
@@ -1,26 +0,0 @@
|
||||
import {RPC} from './rpc';
|
||||
|
||||
export class BlockchainLifecycle {
|
||||
private rpc: RPC;
|
||||
private snapshotIdsStack: number[];
|
||||
constructor() {
|
||||
this.rpc = new RPC();
|
||||
this.snapshotIdsStack = [];
|
||||
}
|
||||
// TODO: In order to run these tests on an actual node, we should check if we are running against
|
||||
// TestRPC, if so, use snapshots, otherwise re-deploy contracts before every test
|
||||
public async startAsync(): Promise<void> {
|
||||
const snapshotId = await this.rpc.takeSnapshotAsync();
|
||||
this.snapshotIdsStack.push(snapshotId);
|
||||
}
|
||||
public async revertAsync(): Promise<void> {
|
||||
const snapshotId = this.snapshotIdsStack.pop() as number;
|
||||
const didRevert = await this.rpc.revertSnapshotAsync(snapshotId);
|
||||
if (!didRevert) {
|
||||
throw new Error(`Snapshot with id #${snapshotId} failed to revert`);
|
||||
}
|
||||
}
|
||||
public async mineABlock(): Promise<void> {
|
||||
await this.rpc.mineBlockAsync();
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
export const constants = {
|
||||
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
|
||||
RPC_HOST: 'localhost',
|
||||
RPC_PORT: 8545,
|
||||
RPC_URL: 'http://localhost:8545',
|
||||
ROPSTEN_NETWORK_ID: 3,
|
||||
KOVAN_NETWORK_ID: 42,
|
||||
TESTRPC_NETWORK_ID: 50,
|
||||
|
@@ -1,58 +0,0 @@
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as request from 'request-promise-native';
|
||||
|
||||
import {constants} from './constants';
|
||||
|
||||
export class RPC {
|
||||
private host: string;
|
||||
private port: number;
|
||||
private id: number;
|
||||
constructor() {
|
||||
this.host = constants.RPC_HOST;
|
||||
this.port = constants.RPC_PORT;
|
||||
this.id = 0;
|
||||
}
|
||||
public async takeSnapshotAsync(): Promise<number> {
|
||||
const method = 'evm_snapshot';
|
||||
const params: any[] = [];
|
||||
const payload = this.toPayload(method, params);
|
||||
const snapshotIdHex = await this.sendAsync(payload);
|
||||
const snapshotId = ethUtil.bufferToInt(ethUtil.toBuffer(snapshotIdHex));
|
||||
return snapshotId;
|
||||
}
|
||||
public async revertSnapshotAsync(snapshotId: number): Promise<boolean> {
|
||||
const method = 'evm_revert';
|
||||
const params = [snapshotId];
|
||||
const payload = this.toPayload(method, params);
|
||||
const didRevert = await this.sendAsync(payload);
|
||||
return didRevert;
|
||||
}
|
||||
public async mineBlockAsync(): Promise<void> {
|
||||
const method = 'evm_mine';
|
||||
const params: any[] = [];
|
||||
const payload = this.toPayload(method, params);
|
||||
await this.sendAsync(payload);
|
||||
}
|
||||
private toPayload(method: string, params: any[] = []): string {
|
||||
const payload = JSON.stringify({
|
||||
id: this.id,
|
||||
method,
|
||||
params,
|
||||
});
|
||||
this.id += 1;
|
||||
return payload;
|
||||
}
|
||||
private async sendAsync(payload: string): Promise<any> {
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
uri: `http://${this.host}:${this.port}`,
|
||||
body: payload,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
};
|
||||
const bodyString = await request(opts);
|
||||
const body = JSON.parse(bodyString);
|
||||
return body.result;
|
||||
}
|
||||
}
|
@@ -21,13 +21,12 @@ export const web3Factory = {
|
||||
},
|
||||
getRpcProvider(hasAddresses: boolean = true): Web3.Provider {
|
||||
const provider = new ProviderEngine();
|
||||
const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
|
||||
if (!hasAddresses) {
|
||||
provider.addProvider(new EmptyWalletSubprovider());
|
||||
}
|
||||
provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE));
|
||||
provider.addProvider(new RpcSubprovider({
|
||||
rpcUrl,
|
||||
rpcUrl: constants.RPC_URL,
|
||||
}));
|
||||
provider.start();
|
||||
return provider;
|
||||
|
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md",
|
||||
"devDependencies": {
|
||||
"@0xproject/dev-utils": "^0.0.1",
|
||||
"@0xproject/tslint-config": "^0.2.1",
|
||||
"@0xproject/types": "^0.1.0",
|
||||
"@types/bluebird": "^3.5.3",
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import {RPC} from '@0xproject/dev-utils';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as chai from 'chai';
|
||||
import Web3 = require('web3');
|
||||
|
||||
import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json';
|
||||
import * as truffleConf from '../../truffle.js';
|
||||
import {Artifacts} from '../../util/artifacts';
|
||||
import {constants} from '../../util/constants';
|
||||
import {MultiSigWrapper} from '../../util/multi_sig_wrapper';
|
||||
import {RPC} from '../../util/rpc';
|
||||
import {ContractInstance} from '../../util/types';
|
||||
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
@@ -38,7 +39,8 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
|
||||
|
||||
const secondsTimeLocked = await multiSig.secondsTimeLocked.call();
|
||||
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
|
||||
rpc = new RPC();
|
||||
const rpcUrl = `http://${truffleConf.networks.development.host}:${truffleConf.networks.development.port}`;
|
||||
rpc = new RPC(rpcUrl);
|
||||
});
|
||||
|
||||
describe('changeTimeLock', () => {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import {bigNumberConfigs} from '@0xproject/utils';
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import {bigNumberConfigs} from './bignumber_config';
|
||||
import {BalancesByOwner, ContractInstance} from './types';
|
||||
|
||||
bigNumberConfigs.configure();
|
||||
|
@@ -1,11 +0,0 @@
|
||||
import {BigNumber} from 'bignumber.js';
|
||||
|
||||
export const bigNumberConfigs = {
|
||||
configure() {
|
||||
// By default BigNumber's `toString` method converts to exponential notation if the value has
|
||||
// more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
|
||||
BigNumber.config({
|
||||
EXPONENTIAL_AT: 1000,
|
||||
});
|
||||
},
|
||||
};
|
@@ -1,43 +0,0 @@
|
||||
import 'isomorphic-fetch';
|
||||
|
||||
import * as truffleConf from '../truffle.js';
|
||||
|
||||
export class RPC {
|
||||
private host: string;
|
||||
private port: number;
|
||||
private id: number;
|
||||
constructor() {
|
||||
this.host = truffleConf.networks.development.host;
|
||||
this.port = truffleConf.networks.development.port;
|
||||
this.id = 0;
|
||||
}
|
||||
public async increaseTimeAsync(time: number) {
|
||||
const method = 'evm_increaseTime';
|
||||
const params = [time];
|
||||
const payload = this.toPayload(method, params);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
public async mineBlockAsync() {
|
||||
const method = 'evm_mine';
|
||||
const payload = this.toPayload(method);
|
||||
return this.sendAsync(payload);
|
||||
}
|
||||
private toPayload(method: string, params: any[] = []) {
|
||||
const payload = JSON.stringify({
|
||||
id: this.id,
|
||||
method,
|
||||
params,
|
||||
});
|
||||
this.id++;
|
||||
return payload;
|
||||
}
|
||||
private async sendAsync(payload: string): Promise<any> {
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
};
|
||||
const response = await fetch(`http://${this.host}:${this.port}`, opts);
|
||||
const responsePayload = await response.json();
|
||||
return responsePayload;
|
||||
}
|
||||
}
|
@@ -8,6 +8,10 @@ export interface TxData {
|
||||
nonce?: number;
|
||||
}
|
||||
|
||||
export interface TxDataPayable extends TxData {
|
||||
value?: BigNumber;
|
||||
}
|
||||
|
||||
export interface TransactionReceipt {
|
||||
blockHash: string;
|
||||
blockNumber: number;
|
||||
|
@@ -1,2 +1,5 @@
|
||||
export {promisify} from './promisify';
|
||||
export {addressUtils} from './address_utils';
|
||||
export {classUtils} from './class_utils';
|
||||
export {intervalUtils} from './interval_utils';
|
||||
export {bigNumberConfigs} from './bignumber_config';
|
||||
|
Reference in New Issue
Block a user