aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-08-03 22:45:26 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-08-03 22:45:26 +0800
commitbb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2 (patch)
tree6dff8d8024eeb713f87f80e2acba4c7b2a1778ac /packages/web3-wrapper/src
parent477c3dc4f6a0db036b803f77347c0515d617ca61 (diff)
downloaddexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar.gz
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar.bz2
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar.lz
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar.xz
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.tar.zst
dexon-sol-tools-bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2.zip
Add comments
Diffstat (limited to 'packages/web3-wrapper/src')
-rw-r--r--packages/web3-wrapper/src/marshaller.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/web3-wrapper/src/marshaller.ts b/packages/web3-wrapper/src/marshaller.ts
index fed197822..7d254b49e 100644
--- a/packages/web3-wrapper/src/marshaller.ts
+++ b/packages/web3-wrapper/src/marshaller.ts
@@ -25,7 +25,14 @@ 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
+ */
unmarshalIntoBlockWithoutTransactionData(
blockWithHexValues: BlockWithoutTransactionDataRPC,
): BlockWithoutTransactionData {
@@ -41,6 +48,10 @@ export const marshaller = {
};
return block;
},
+ /**
+ * Unmarshall block with transaction data
+ * @param blockWithHexValues block to unmarshall
+ */
unmarshalIntoBlockWithTransactionData(blockWithHexValues: BlockWithTransactionDataRPC): BlockWithTransactionData {
const block = {
...blockWithHexValues,
@@ -59,6 +70,10 @@ export const marshaller = {
});
return block;
},
+ /**
+ * Unmarshall transaction
+ * @param txRpc transaction to unmarshall
+ */
unmarshalTransaction(txRpc: TransactionRPC): Transaction {
const tx = {
...txRpc,
@@ -73,6 +88,10 @@ export const marshaller = {
};
return tx;
},
+ /**
+ * Unmarshall transaction data
+ * @param txDataRpc transaction data to unmarshall
+ */
unmarshalTxData(txDataRpc: TxDataRPC): TxData {
if (_.isUndefined(txDataRpc.from)) {
throw new Error(`txData must include valid 'from' value.`);
@@ -86,6 +105,10 @@ export const marshaller = {
};
return txData;
},
+ /**
+ * Marshall transaction data
+ * @param txData transaction data to marshall
+ */
marshalTxData(txData: Partial<TxData>): Partial<TxDataRPC> {
if (_.isUndefined(txData.from)) {
throw new Error(`txData must include valid 'from' value.`);
@@ -107,6 +130,10 @@ export const marshaller = {
});
return txDataRPC;
},
+ /**
+ * Marshall call data
+ * @param callData call data to marshall
+ */
marshalCallData(callData: Partial<CallData>): Partial<CallDataRPC> {
const callTxDataBase = {
...callData,
@@ -119,12 +146,20 @@ export const marshaller = {
};
return callDataRPC;
},
+ /**
+ * Marshall address
+ * @param address address to marshall
+ */
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
+ */
marshalBlockParam(blockParam: BlockParam | string | number | undefined): string | undefined {
if (_.isUndefined(blockParam)) {
return BlockParamLiteral.Latest;
@@ -132,6 +167,10 @@ export const marshaller = {
const encodedBlockParam = _.isNumber(blockParam) ? utils.numberToHex(blockParam) : blockParam;
return encodedBlockParam;
},
+ /**
+ * Unmarshall log
+ * @param rawLog log to unmarshall
+ */
unmarshalLog(rawLog: RawLogEntry): LogEntry {
const formattedLog = {
...rawLog,