|  | 
| 1 | 1 | import { | 
| 2 | 2 |   IApiToken, ITokenWithBalance, InternalTransaction, | 
| 3 |  | -  Token, TokenTransferApi, TransactionServerResponse | 
|  | 3 | +  Token, TokenTransferApi, TransactionResponse | 
| 4 | 4 | } from './types' | 
| 5 | 5 | import tokens from '@rsksmart/rsk-contract-metadata' | 
| 6 | 6 | import { toChecksumAddress } from '@rsksmart/rsk-utils' | 
| @@ -126,68 +126,70 @@ export const fromApiToTEvents = (tokenTransfer:TokenTransferApi): IEvent => | 
| 126 | 126 |     txStatus: '0x1' | 
| 127 | 127 |   }) | 
| 128 | 128 | 
 | 
| 129 |  | -export const fromApiToTransaction = (transaction: TransactionServerResponse): ITransaction => | 
| 130 |  | -  ({ | 
|  | 129 | +export const fromApiToTransaction = (transaction: TransactionResponse): ITransaction => { | 
|  | 130 | +  const txType = transaction.input === '0x' ? 'normal' : 'contract call' | 
|  | 131 | +  return ({ | 
| 131 | 132 |     _id: '', | 
| 132 | 133 |     hash: transaction.hash, | 
| 133 |  | -    nonce: transaction.nonce, | 
| 134 |  | -    blockHash: '', | 
| 135 |  | -    blockNumber: transaction.block, | 
|  | 134 | +    nonce: Number(transaction.nonce), | 
|  | 135 | +    blockHash: transaction.blockHash, | 
|  | 136 | +    blockNumber: Number(transaction.blockNumber), | 
| 136 | 137 |     transactionIndex: 0, | 
| 137 |  | -    from: transaction.from.hash, | 
| 138 |  | -    to: transaction.to.hash, | 
| 139 |  | -    gas: Number(transaction.gas_used), | 
| 140 |  | -    gasPrice: transaction.gas_price, | 
|  | 138 | +    from: transaction.from, | 
|  | 139 | +    to: transaction.to, | 
|  | 140 | +    gas: Number(transaction.gas), | 
|  | 141 | +    gasPrice: transaction.gasPrice, | 
| 141 | 142 |     value: transaction.value, | 
| 142 |  | -    input: transaction.raw_input, | 
|  | 143 | +    input: transaction.input, | 
| 143 | 144 |     v: '', | 
| 144 | 145 |     r: '', | 
| 145 | 146 |     s: '', | 
| 146 |  | -    type: String(transaction.type), | 
| 147 |  | -    timestamp: Date.parse(transaction.timestamp) / 1000, | 
|  | 147 | +    type: String(), | 
|  | 148 | +    timestamp: Number(transaction.timeStamp), | 
| 148 | 149 |     receipt: { | 
| 149 | 150 |       transactionHash: transaction.hash, | 
| 150 | 151 |       transactionIndex: 0, | 
| 151 | 152 |       blockHash: '', | 
| 152 |  | -      blockNumber: transaction.block, | 
| 153 |  | -      cumulativeGasUsed: Number(transaction.gas_limit), | 
| 154 |  | -      gasUsed: Number(transaction.gas_used), | 
|  | 153 | +      blockNumber: Number(transaction.blockNumber), | 
|  | 154 | +      cumulativeGasUsed: Number(transaction.gasUsed), | 
|  | 155 | +      gasUsed: Number(transaction.gasUsed), | 
| 155 | 156 |       contractAddress: null, | 
| 156 | 157 |       logs: [], | 
| 157 |  | -      from: transaction.from.hash, | 
| 158 |  | -      to: transaction.to.hash, | 
| 159 |  | -      status: transaction.status === 'ok' ? '0x1' : '0x0', | 
|  | 158 | +      from: transaction.from, | 
|  | 159 | +      to: transaction.to, | 
|  | 160 | +      status: transaction.txreceipt_status === '1' ? '0x1' : '0x0', | 
| 160 | 161 |       logsBloom: '', | 
| 161 |  | -      type: String(transaction.type) | 
|  | 162 | +      type: txType | 
| 162 | 163 |     }, | 
| 163 |  | -    txType: transaction.tx_types[0], | 
|  | 164 | +    txType, | 
| 164 | 165 |     txId: '' | 
| 165 | 166 |   }) | 
|  | 167 | +} | 
| 166 | 168 | 
 | 
| 167 | 169 | export const fromApiToInternalTransaction = (internalTransaction: InternalTransaction): IInternalTransaction => | 
| 168 | 170 |   ({ | 
| 169 | 171 |     _id: '', | 
| 170 | 172 |     action: { | 
| 171 | 173 |       callType: internalTransaction.type, | 
| 172 |  | -      from: internalTransaction.from.hash, | 
| 173 |  | -      to: internalTransaction.to.hash, | 
|  | 174 | +      from: internalTransaction.from, | 
|  | 175 | +      to: internalTransaction.to, | 
| 174 | 176 |       value: internalTransaction.value, | 
| 175 |  | -      gas: internalTransaction.gas_limit, | 
|  | 177 | +      gas: internalTransaction.gas, | 
| 176 | 178 |       input: '0x' | 
| 177 | 179 |     }, | 
| 178 | 180 |     blockHash: '', | 
| 179 |  | -    blockNumber: internalTransaction.block, | 
| 180 |  | -    transactionHash: internalTransaction.transaction_hash, | 
| 181 |  | -    transactionPosition: internalTransaction.index, | 
|  | 181 | +    blockNumber: Number(internalTransaction.blockNumber), | 
|  | 182 | +    transactionHash: internalTransaction.transactionHash, | 
|  | 183 | +    transactionPosition: Number(internalTransaction.index), | 
| 182 | 184 |     type: internalTransaction.type, | 
| 183 | 185 |     subtraces: 0, | 
| 184 | 186 |     traceAddress: [], | 
| 185 | 187 |     result: { | 
| 186 |  | -      gasUsed: internalTransaction.gas_limit, | 
|  | 188 | +      gasUsed: internalTransaction.gasUsed, | 
| 187 | 189 |       output: '0x' | 
| 188 | 190 |     }, | 
| 189 |  | -    _index: internalTransaction.index, | 
| 190 |  | -    timestamp: Date.parse(internalTransaction.timestamp) / 1000, | 
|  | 191 | +    _index: Number(internalTransaction.index), | 
|  | 192 | +    timestamp: Date.parse(internalTransaction.timeStamp) / 1000, | 
| 191 | 193 |     internalTxId: '' | 
| 192 | 194 |   }) | 
| 193 | 195 | 
 | 
|  | 
0 commit comments