Add comments

This commit is contained in:
Leonid Logvinov
2018-08-03 16:45:26 +02:00
parent 477c3dc4f6
commit bb4d15005a

View File

@@ -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,