Merge pull request #239 from harmony-one/internal_txs_fallback

internal transactions fallback to rpc when older than 34000000
pull/242/head
Artem 2 years ago committed by GitHub
commit 53b8cabd33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/api/client.ts
  2. 18
      src/api/rpc.ts
  3. 7
      src/pages/TransactionPage/index.tsx

@ -16,6 +16,7 @@ import {
} from "./client.interface";
import { ApiCache } from "./ApiCache";
import { get4byteSignatureByHex } from "./3rdPartyApi";
import { eth_traceTransaction } from './rpc'
// import { ClientCache } from "./clientCache";
// const clientCache = new ClientCache({
@ -66,7 +67,35 @@ export function getStakingTransactionByField(params: [number, "hash", string]) {
) as Promise<RPCStakingTransactionHarmony>;
}
export function getInternalTransactionsByField(params: any[]) {
export function getInternalTransactionsByField(params: any[], blockNumber?: string) {
// fallback to rpc as we don't keep old records older than 34000000 any more in postgres
if (!blockNumber || +blockNumber < 34000000) {
const queryType = params[1]
if (queryType !== 'transaction_hash') {
console.error('use only transaction hash to get internal transactions')
return [] as InternalTransaction[]
}
const txHash = params[2]
// todo note check error field may not work properly
return eth_traceTransaction(txHash).then(txs => {
const mapTxs = txs.map((tx: any, i: number) => ({
type: tx.action.type || tx.type,
value: tx.value,
input: tx.action.input,
output: tx.result.output,
transactionHash: tx.transactionHash,
gasUsed: tx.result.gasUsed,
index: i,
to: tx.action.to,
from: tx.action.from,
error: tx.result.error,
gas: tx.action.gas
}))
return mapTxs as InternalTransaction[]
})
}
return transport("getInternalTransactionsByField", params) as Promise<
InternalTransaction[]
>;

@ -90,6 +90,24 @@ const defaultGetHistoryParams = {
order: RequestOrder.DESC
}
export const eth_traceTransaction = (hash: string) => {
return rpcAdapter<any>(API_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
method: "trace_transaction",
id: 1,
params: [hash],
}),
}).then(data => {
if (data.error) {
throw new Error(data.error.message)
}
return data.result
});
}
export const hmyv2_getTransactionsHistory = (params: IGetTxsHistoryParams[]) => {
return rpcAdapter<TRPCResponse<{ transactions: RPCTransactionHarmony[] }>>(API_URL, {
method: "POST",

@ -93,7 +93,7 @@ export const TransactionPage = () => {
trxInputSignature = await getTxInputSignature(trx)
}
}
setTx((trx || {}) as RPCTransactionHarmony);
setInputSignature(trxInputSignature)
};
@ -110,7 +110,10 @@ export const TransactionPage = () => {
0,
"transaction_hash",
tx.hash,
]);
],
// need to track fallback
tx.blockNumber
);
const methodSignatures = await Promise.all(
txs.map((tx) => {
return tx.input && tx.input.length > 10

Loading…
Cancel
Save