import { TxParams } from '@zilliqa-js/account' ; import { RPCResponse , TransactionError , TransactionObj , } from '@zilliqa-js/core' ; import { toChecksumAddress } from '@zilliqa-js/crypto' ; import { BN , Long } from '@zilliqa-js/util' ; export function toTxParams ( response ) { const { toAddr , senderPubKey , gasPrice , gasLimit , nonce , amount , receipt , version , code , data , ... rest } = < TransactionObj > response . result ; const msg = receipt . errors ? Object . keys ( receipt . errors ) . reduce ( ( acc , depth ) => { const errorMsgList = receipt . errors [ depth ] . map ( ( num ) => TransactionError [ num ] ) ; return { ... acc , [ depth ] : errorMsgList } ; } , { } ) : { } ; return { ... rest , version : parseInt ( version , 10 ) , toAddr : toChecksumAddress ( toAddr ) , pubKey : senderPubKey . replace ( '0x' , '' ) , gasPrice : new BN ( gasPrice ) , gasLimit : Long . fromString ( gasLimit , 10 ) , amount : new BN ( amount ) , nonce : parseInt ( nonce , 10 ) , code , data , receipt : { ... receipt , accepted : receipt . accepted , errors : msg , cumulative_gas : parseInt ( receipt . cumulative_gas , 10 ) , } , } ; }