aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.json32
-rw-r--r--packages/web3-wrapper/CHANGELOG.md13
-rw-r--r--packages/web3-wrapper/package.json15
-rw-r--r--packages/web3-wrapper/src/utils.ts4
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts79
5 files changed, 100 insertions, 43 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json
index b1ea2fe2e..7261dd474 100644
--- a/packages/web3-wrapper/CHANGELOG.json
+++ b/packages/web3-wrapper/CHANGELOG.json
@@ -1,11 +1,43 @@
[
{
+ "timestamp": 1538475601,
+ "version": "3.0.3",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1538157789,
+ "version": "3.0.2",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1537907159,
+ "version": "3.0.1",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"version": "3.0.0",
"changes": [
{
"note":
"Rename `getBlockAsync` to `getBlockIfExistsAsync` and rather then throw if the requested block wasn't found, return undefined.",
"pr": 1082
+ },
+ {
+ "note":
+ "Expose `sendRawPayloadAsync` so one can easily extend `Web3Wrapper` with their own custom JSON RPC calls",
+ "pr": 1080
}
],
"timestamp": 1537875740
diff --git a/packages/web3-wrapper/CHANGELOG.md b/packages/web3-wrapper/CHANGELOG.md
index cafbe1340..05e6a998b 100644
--- a/packages/web3-wrapper/CHANGELOG.md
+++ b/packages/web3-wrapper/CHANGELOG.md
@@ -5,9 +5,22 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v3.0.3 - _October 2, 2018_
+
+ * Dependencies updated
+
+## v3.0.2 - _September 28, 2018_
+
+ * Dependencies updated
+
+## v3.0.1 - _September 25, 2018_
+
+ * Dependencies updated
+
## v3.0.0 - _September 25, 2018_
* Rename `getBlockAsync` to `getBlockIfExistsAsync` and rather then throw if the requested block wasn't found, return undefined. (#1082)
+ * Expose `sendRawPayloadAsync` so one can easily extend `Web3Wrapper` with their own custom JSON RPC calls (#1080)
## v2.0.3 - _September 21, 2018_
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index f895296e9..5b5c0ec5b 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/web3-wrapper",
- "version": "3.0.0",
+ "version": "3.0.2",
"engines": {
"node": ">=6.12"
},
@@ -9,6 +9,7 @@
"types": "lib/src/index.d.ts",
"scripts": {
"build": "tsc -b",
+ "build:ci": "yarn build",
"clean": "shx rm -rf lib generated_docs",
"lint": "tslint --project .",
"test": "yarn run_mocha",
@@ -53,13 +54,13 @@
"typescript": "3.0.1"
},
"dependencies": {
- "@0xproject/assert": "^1.0.10",
- "@0xproject/json-schemas": "^1.0.3",
- "@0xproject/typescript-typings": "^2.0.1",
- "@0xproject/utils": "^1.0.10",
- "ethereum-types": "^1.0.7",
+ "@0xproject/assert": "^1.0.12",
+ "@0xproject/json-schemas": "^1.0.5",
+ "@0xproject/typescript-typings": "^3.0.0",
+ "@0xproject/utils": "^2.0.0",
+ "ethereum-types": "^1.0.9",
"ethereumjs-util": "^5.1.1",
- "ethers": "3.0.22",
+ "ethers": "4.0.0-beta.14",
"lodash": "^4.17.5"
},
"publishConfig": {
diff --git a/packages/web3-wrapper/src/utils.ts b/packages/web3-wrapper/src/utils.ts
index 01605dc9a..0b568aac5 100644
--- a/packages/web3-wrapper/src/utils.ts
+++ b/packages/web3-wrapper/src/utils.ts
@@ -37,7 +37,7 @@ export const utils = {
const hexBase = 16;
const valueHex = valueBigNumber.toString(hexBase);
- return valueBigNumber.lessThan(0) ? '-0x' + valueHex.substr(1) : '0x' + valueHex;
+ return valueBigNumber.lessThan(0) ? `-0x${valueHex.substr(1)}` : `0x${valueHex}`;
},
numberToHex(value: number): string {
if (!isFinite(value) && !utils.isHexStrict(value)) {
@@ -48,7 +48,7 @@ export const utils = {
const hexBase = 16;
const result = valueBigNumber.toString(hexBase);
- return valueBigNumber.lt(0) ? '-0x' + result.substr(1) : '0x' + result;
+ return valueBigNumber.lt(0) ? `-0x${result.substr(1)}` : `0x${result}`;
},
isHexStrict(hex: string | number): boolean {
return (
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts
index dc634a57f..d52c1cb6e 100644
--- a/packages/web3-wrapper/src/web3_wrapper.ts
+++ b/packages/web3-wrapper/src/web3_wrapper.ts
@@ -193,7 +193,7 @@ export class Web3Wrapper {
* @returns Ethereum node's version string
*/
public async getNodeVersionAsync(): Promise<string> {
- const nodeVersion = await this._sendRawPayloadAsync<string>({ method: 'web3_clientVersion' });
+ const nodeVersion = await this.sendRawPayloadAsync<string>({ method: 'web3_clientVersion' });
return nodeVersion;
}
/**
@@ -201,7 +201,7 @@ export class Web3Wrapper {
* @returns The network id
*/
public async getNetworkIdAsync(): Promise<number> {
- const networkIdStr = await this._sendRawPayloadAsync<string>({ method: 'net_version' });
+ const networkIdStr = await this.sendRawPayloadAsync<string>({ method: 'net_version' });
const networkId = _.parseInt(networkIdStr);
return networkId;
}
@@ -212,7 +212,7 @@ export class Web3Wrapper {
*/
public async getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt> {
assert.isHexString('txHash', txHash);
- const transactionReceipt = await this._sendRawPayloadAsync<TransactionReceipt>({
+ const transactionReceipt = await this.sendRawPayloadAsync<TransactionReceipt>({
method: 'eth_getTransactionReceipt',
params: [txHash],
});
@@ -228,7 +228,7 @@ export class Web3Wrapper {
*/
public async getTransactionByHashAsync(txHash: string): Promise<Transaction> {
assert.isHexString('txHash', txHash);
- const transaction = await this._sendRawPayloadAsync<Transaction>({
+ const transaction = await this.sendRawPayloadAsync<Transaction>({
method: 'eth_getTransactionByHash',
params: [txHash],
});
@@ -247,7 +247,7 @@ export class Web3Wrapper {
}
const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
const encodedOwner = marshaller.marshalAddress(owner);
- const balanceInWei = await this._sendRawPayloadAsync<string>({
+ const balanceInWei = await this.sendRawPayloadAsync<string>({
method: 'eth_getBalance',
params: [encodedOwner, marshalledDefaultBlock],
});
@@ -279,7 +279,7 @@ export class Web3Wrapper {
}
const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
const encodedAddress = marshaller.marshalAddress(address);
- const code = await this._sendRawPayloadAsync<string>({
+ const code = await this.sendRawPayloadAsync<string>({
method: 'eth_getCode',
params: [encodedAddress, marshalledDefaultBlock],
});
@@ -293,7 +293,7 @@ export class Web3Wrapper {
*/
public async getTransactionTraceAsync(txHash: string, traceParams: TraceParams): Promise<TransactionTrace> {
assert.isHexString('txHash', txHash);
- const trace = await this._sendRawPayloadAsync<TransactionTrace>({
+ const trace = await this.sendRawPayloadAsync<TransactionTrace>({
method: 'debug_traceTransaction',
params: [txHash, traceParams],
});
@@ -308,7 +308,7 @@ export class Web3Wrapper {
public async signMessageAsync(address: string, message: string): Promise<string> {
assert.isETHAddressHex('address', address);
assert.isString('message', message); // TODO: Should this be stricter? Hex string?
- const signData = await this._sendRawPayloadAsync<string>({
+ const signData = await this.sendRawPayloadAsync<string>({
method: 'eth_sign',
params: [address, message],
});
@@ -319,7 +319,7 @@ export class Web3Wrapper {
* @returns Block number
*/
public async getBlockNumberAsync(): Promise<number> {
- const blockNumberHex = await this._sendRawPayloadAsync<string>({
+ const blockNumberHex = await this.sendRawPayloadAsync<string>({
method: 'eth_blockNumber',
params: [],
});
@@ -339,7 +339,7 @@ export class Web3Wrapper {
const encodedBlockParam = marshaller.marshalBlockParam(blockParam);
const method = utils.isHexStrict(blockParam) ? 'eth_getBlockByHash' : 'eth_getBlockByNumber';
const shouldIncludeTransactionData = false;
- const blockWithoutTransactionDataWithHexValuesOrNull = await this._sendRawPayloadAsync<
+ const blockWithoutTransactionDataWithHexValuesOrNull = await this.sendRawPayloadAsync<
BlockWithoutTransactionDataRPC
>({
method,
@@ -366,7 +366,7 @@ export class Web3Wrapper {
}
const method = utils.isHexStrict(blockParam) ? 'eth_getBlockByHash' : 'eth_getBlockByNumber';
const shouldIncludeTransactionData = true;
- const blockWithTransactionDataWithHexValues = await this._sendRawPayloadAsync<BlockWithTransactionDataRPC>({
+ const blockWithTransactionDataWithHexValues = await this.sendRawPayloadAsync<BlockWithTransactionDataRPC>({
method,
params: [encodedBlockParam, shouldIncludeTransactionData],
});
@@ -393,7 +393,7 @@ export class Web3Wrapper {
* @returns Available user addresses
*/
public async getAvailableAddressesAsync(): Promise<string[]> {
- const addresses = await this._sendRawPayloadAsync<string>({
+ const addresses = await this.sendRawPayloadAsync<string>({
method: 'eth_accounts',
params: [],
});
@@ -405,7 +405,7 @@ export class Web3Wrapper {
* @returns The snapshot id. This can be used to revert to this snapshot
*/
public async takeSnapshotAsync(): Promise<number> {
- const snapshotId = Number(await this._sendRawPayloadAsync<string>({ method: 'evm_snapshot', params: [] }));
+ const snapshotId = Number(await this.sendRawPayloadAsync<string>({ method: 'evm_snapshot', params: [] }));
return snapshotId;
}
/**
@@ -415,14 +415,14 @@ export class Web3Wrapper {
*/
public async revertSnapshotAsync(snapshotId: number): Promise<boolean> {
assert.isNumber('snapshotId', snapshotId);
- const didRevert = await this._sendRawPayloadAsync<boolean>({ method: 'evm_revert', params: [snapshotId] });
+ const didRevert = await this.sendRawPayloadAsync<boolean>({ method: 'evm_revert', params: [snapshotId] });
return didRevert;
}
/**
* Mine a block on a TestRPC/Ganache local node
*/
public async mineBlockAsync(): Promise<void> {
- await this._sendRawPayloadAsync<string>({ method: 'evm_mine', params: [] });
+ await this.sendRawPayloadAsync<string>({ method: 'evm_mine', params: [] });
}
/**
* Increase the next blocks timestamp on TestRPC/Ganache or Geth local node.
@@ -434,9 +434,9 @@ export class Web3Wrapper {
// Detect Geth vs. Ganache and use appropriate endpoint.
const version = await this.getNodeVersionAsync();
if (_.includes(version, uniqueVersionIds.geth)) {
- return this._sendRawPayloadAsync<number>({ method: 'debug_increaseTime', params: [timeDelta] });
+ return this.sendRawPayloadAsync<number>({ method: 'debug_increaseTime', params: [timeDelta] });
} else if (_.includes(version, uniqueVersionIds.ganache)) {
- return this._sendRawPayloadAsync<number>({ method: 'evm_increaseTime', params: [timeDelta] });
+ return this.sendRawPayloadAsync<number>({ method: 'evm_increaseTime', params: [timeDelta] });
} else {
throw new Error(`Unknown client version: ${version}`);
}
@@ -447,6 +447,12 @@ export class Web3Wrapper {
* @returns The corresponding log entries
*/
public async getLogsAsync(filter: FilterObject): Promise<LogEntry[]> {
+ if (!_.isUndefined(filter.blockHash) && (!_.isUndefined(filter.fromBlock) || !_.isUndefined(filter.toBlock))) {
+ throw new Error(
+ `Cannot specify 'blockHash' as well as 'fromBlock'/'toBlock' in the filter supplied to 'getLogsAsync'`,
+ );
+ }
+
let fromBlock = filter.fromBlock;
if (_.isNumber(fromBlock)) {
fromBlock = utils.numberToHex(fromBlock);
@@ -464,7 +470,7 @@ export class Web3Wrapper {
method: 'eth_getLogs',
params: [serializedFilter],
};
- const rawLogs = await this._sendRawPayloadAsync<RawLogEntry[]>(payload);
+ const rawLogs = await this.sendRawPayloadAsync<RawLogEntry[]>(payload);
const formattedLogs = _.map(rawLogs, marshaller.unmarshalLog.bind(marshaller));
return formattedLogs;
}
@@ -480,7 +486,7 @@ export class Web3Wrapper {
schemas.jsNumber,
]);
const txDataHex = marshaller.marshalTxData(txData);
- const gasHex = await this._sendRawPayloadAsync<string>({ method: 'eth_estimateGas', params: [txDataHex] });
+ const gasHex = await this.sendRawPayloadAsync<string>({ method: 'eth_estimateGas', params: [txDataHex] });
const gas = utils.convertHexToNumber(gasHex);
return gas;
}
@@ -501,7 +507,7 @@ export class Web3Wrapper {
}
const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
const callDataHex = marshaller.marshalCallData(callData);
- const rawCallResult = await this._sendRawPayloadAsync<string>({
+ const rawCallResult = await this.sendRawPayloadAsync<string>({
method: 'eth_call',
params: [callDataHex, marshalledDefaultBlock],
});
@@ -522,7 +528,7 @@ export class Web3Wrapper {
schemas.jsNumber,
]);
const txDataHex = marshaller.marshalTxData(txData);
- const txHash = await this._sendRawPayloadAsync<string>({ method: 'eth_sendTransaction', params: [txDataHex] });
+ const txHash = await this.sendRawPayloadAsync<string>({ method: 'eth_sendTransaction', params: [txDataHex] });
return txHash;
}
/**
@@ -632,7 +638,24 @@ export class Web3Wrapper {
*/
public async setHeadAsync(blockNumber: number): Promise<void> {
assert.isNumber('blockNumber', blockNumber);
- await this._sendRawPayloadAsync<void>({ method: 'debug_setHead', params: [utils.numberToHex(blockNumber)] });
+ await this.sendRawPayloadAsync<void>({ method: 'debug_setHead', params: [utils.numberToHex(blockNumber)] });
+ }
+ /**
+ * Sends a raw Ethereum JSON RPC payload and returns the response's `result` key
+ * @param payload A partial JSON RPC payload. No need to include version, id, params (if none needed)
+ * @return The contents nested under the result key of the response body
+ */
+ public async sendRawPayloadAsync<A>(payload: Partial<JSONRPCRequestPayload>): Promise<A> {
+ const sendAsync = this._provider.sendAsync.bind(this._provider);
+ const payloadWithDefaults = {
+ id: this._jsonRpcRequestId++,
+ params: [],
+ jsonrpc: '2.0',
+ ...payload,
+ };
+ const response = await promisify<JSONRPCResponsePayload>(sendAsync)(payloadWithDefaults);
+ const result = response.result;
+ return result;
}
/**
* Returns either NodeType.Geth or NodeType.Ganache depending on the type of
@@ -648,16 +671,4 @@ export class Web3Wrapper {
throw new Error(`Unknown client version: ${version}`);
}
}
- private async _sendRawPayloadAsync<A>(payload: Partial<JSONRPCRequestPayload>): Promise<A> {
- const sendAsync = this._provider.sendAsync.bind(this._provider);
- const payloadWithDefaults = {
- id: this._jsonRpcRequestId++,
- params: [],
- jsonrpc: '2.0',
- ...payload,
- };
- const response = await promisify<JSONRPCResponsePayload>(sendAsync)(payloadWithDefaults);
- const result = response.result;
- return result;
- }
} // tslint:disable-line:max-file-line-count