From bb4d15005a3b9f71a4be2cd265d46ec5b9bf41f2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 3 Aug 2018 16:45:26 +0200 Subject: Add comments --- packages/web3-wrapper/src/marshaller.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'packages') 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): Partial { 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): Partial { 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, -- cgit v1.2.3