aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-14 04:40:46 +0800
committerGitHub <noreply@github.com>2018-08-14 04:40:46 +0800
commit7340338626ea11bccd44eef1da277196b78a6a7d (patch)
tree1a99424e80ece948af73995378a5737c8985dd0e /packages/web3-wrapper
parent083319786fad31dfde16cb9e06e893bfeb23785d (diff)
parent9d3c287918389d07f884245bd1bc968955768b6f (diff)
downloaddexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar.gz
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar.bz2
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar.lz
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar.xz
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.tar.zst
dexon-sol-tools-7340338626ea11bccd44eef1da277196b78a6a7d.zip
Merge pull request #938 from 0xProject/sol-cov-fixes
Sol cov fixes
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.json13
-rw-r--r--packages/web3-wrapper/src/index.ts13
-rw-r--r--packages/web3-wrapper/src/marshaller.ts48
3 files changed, 73 insertions, 1 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json
index 7bf28dfa8..9224d89b0 100644
--- a/packages/web3-wrapper/CHANGELOG.json
+++ b/packages/web3-wrapper/CHANGELOG.json
@@ -1,5 +1,18 @@
[
{
+ "version": "1.2.0",
+ "changes": [
+ {
+ "note": "Export marshaller to convert between RPC and user-space data formats",
+ "pr": 938
+ },
+ {
+ "note": "Export RPC types",
+ "pr": 938
+ }
+ ]
+ },
+ {
"timestamp": 1532619515,
"version": "1.1.2",
"changes": [
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index 6787e0102..5d3d135e4 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -1,2 +1,13 @@
export { Web3Wrapper } from './web3_wrapper';
-export { Web3WrapperErrors, NodeType } from './types';
+export { marshaller } from './marshaller';
+export {
+ Web3WrapperErrors,
+ NodeType,
+ CallDataRPC,
+ CallTxDataBaseRPC,
+ AbstractBlockRPC,
+ BlockWithoutTransactionDataRPC,
+ BlockWithTransactionDataRPC,
+ TransactionRPC,
+ TxDataRPC,
+} from './types';
diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts
index fed197822..572a322d6 100644
--- a/packages/web3-wrapper/src/marshaller.ts
+++ b/packages/web3-wrapper/src/marshaller.ts
@@ -25,7 +25,15 @@ import {
TxDataRPC,
} from './types';
+/**
+ * Utils to convert ethereum structures from user-space format to RPC format. (marshall/unmarshall)
+ */
export const marshaller = {
+ /**
+ * Unmarshall block without transaction data
+ * @param blockWithHexValues block to unmarshall
+ * @return unmarshalled block without transaction data
+ */
unmarshalIntoBlockWithoutTransactionData(
blockWithHexValues: BlockWithoutTransactionDataRPC,
): BlockWithoutTransactionData {
@@ -41,6 +49,11 @@ export const marshaller = {
};
return block;
},
+ /**
+ * Unmarshall block with transaction data
+ * @param blockWithHexValues block to unmarshall
+ * @return unmarshalled block with transaction data
+ */
unmarshalIntoBlockWithTransactionData(blockWithHexValues: BlockWithTransactionDataRPC): BlockWithTransactionData {
const block = {
...blockWithHexValues,
@@ -59,6 +72,11 @@ export const marshaller = {
});
return block;
},
+ /**
+ * Unmarshall transaction
+ * @param txRpc transaction to unmarshall
+ * @return unmarshalled transaction
+ */
unmarshalTransaction(txRpc: TransactionRPC): Transaction {
const tx = {
...txRpc,
@@ -73,6 +91,11 @@ export const marshaller = {
};
return tx;
},
+ /**
+ * Unmarshall transaction data
+ * @param txDataRpc transaction data to unmarshall
+ * @return unmarshalled transaction data
+ */
unmarshalTxData(txDataRpc: TxDataRPC): TxData {
if (_.isUndefined(txDataRpc.from)) {
throw new Error(`txData must include valid 'from' value.`);
@@ -86,6 +109,11 @@ export const marshaller = {
};
return txData;
},
+ /**
+ * Marshall transaction data
+ * @param txData transaction data to marshall
+ * @return marshalled transaction data
+ */
marshalTxData(txData: Partial<TxData>): Partial<TxDataRPC> {
if (_.isUndefined(txData.from)) {
throw new Error(`txData must include valid 'from' value.`);
@@ -107,6 +135,11 @@ export const marshaller = {
});
return txDataRPC;
},
+ /**
+ * Marshall call data
+ * @param callData call data to marshall
+ * @return marshalled call data
+ */
marshalCallData(callData: Partial<CallData>): Partial<CallDataRPC> {
const callTxDataBase = {
...callData,
@@ -119,12 +152,22 @@ export const marshaller = {
};
return callDataRPC;
},
+ /**
+ * Marshall address
+ * @param address address to marshall
+ * @return marshalled address
+ */
marshalAddress(address: string): string {
if (addressUtils.isAddress(address)) {
return ethUtil.addHexPrefix(address);
}
throw new Error(`Invalid address encountered: ${address}`);
},
+ /**
+ * Marshall block param
+ * @param blockParam block param to marshall
+ * @return marshalled block param
+ */
marshalBlockParam(blockParam: BlockParam | string | number | undefined): string | undefined {
if (_.isUndefined(blockParam)) {
return BlockParamLiteral.Latest;
@@ -132,6 +175,11 @@ export const marshaller = {
const encodedBlockParam = _.isNumber(blockParam) ? utils.numberToHex(blockParam) : blockParam;
return encodedBlockParam;
},
+ /**
+ * Unmarshall log
+ * @param rawLog log to unmarshall
+ * @return unmarshalled log
+ */
unmarshalLog(rawLog: RawLogEntry): LogEntry {
const formattedLog = {
...rawLog,