Skip to content

Commit

Permalink
Merge branch 'fixGetEffects' of github.com:kajoseph/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Nov 7, 2024
2 parents fe3f462 + efcc6f9 commit 73cf4fd
Show file tree
Hide file tree
Showing 4 changed files with 18,459 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,52 +396,54 @@ export class EVMTransactionModel extends BaseTransaction<IEVMTransaction> {
getEffects(tx: IEVMTransactionInProcess): Effect[] {
const effects = [] as Effect[];
try {
// Top level tx effects
if (tx.abiType) {
// Handle Abi related effects
const effect = this._getEffectForAbiType(tx.abiType, tx.to, tx.from, '');
if (effect) {
effects.push(effect);
}
}
// Internal tx effects
if (tx.internal && tx.internal.length) {
for (let internalTx of tx.internal) {
if (internalTx.action.value && BigInt(internalTx.action.value) > 0) {
if (tx.calls?.length) { // Geth trace calls[]
for (let call of tx.calls) {
if (call.value && BigInt(call.value) > 0) {
// Handle native asset transfer
const effect = this._getEffectForNativeTransfer(BigInt(internalTx.action.value).toString(), internalTx.action.to, internalTx.action.from || tx.from, internalTx.traceAddress.join('_'));
const effect = this._getEffectForNativeTransfer(BigInt(call.value).toString(), call.to, call.from, call.depth);
effects.push(effect);
}
// We used to ignore delegated calls because we thought they were redundant in ERC20 transfers via proxy contract
// Maybe something changed with the EVM, but they seem to be necessary now to get ERC20 transfers to show up.
// TODO: Revisit this logic to reduce duplicates
if (internalTx.abiType) { // && internalTx.type != 'delegatecall') {
if (call.abiType) { // If there was a known ABI (ERC20, Invoice) transfer within the tx execution
// Handle Abi related effects
const effect = this._getEffectForAbiType(internalTx.abiType, internalTx.action.to, internalTx.action.from || tx.from, internalTx.traceAddress.join('_'));
let effect: Effect | undefined;
if (call.type === 'DELEGATECALL') { // Delegate calls are proxy calls within a smart contract
// find parent call that's one level up. E.g. if depth = '0_1_2', then find '0_1'
const parent = tx.calls.find(c => c.depth === call.depth.split('_').slice(0, -1).join('_')) || { to: tx.to, from: tx.from, input: null }; // Fallback to tx.to and tx.from if no parent found
if (parent?.to === call.from && parent?.input === call.input) {
// If parent is the same as the current call, then it's just a proxy call
continue;
}
effect = this._getEffectForAbiType(call.abiType, parent.to, parent.from, call.depth);
} else {
effect = this._getEffectForAbiType(call.abiType, call.to, call.from, call.depth);
}
if (effect) {
effects.push(effect);
}
}
}
} else if (tx.calls && tx.calls.length) {
for (let internalTx of tx.calls) {
if (internalTx.value && BigInt(internalTx.value) > 0) {
} else if (tx.internal?.length) { // LEGACY: Used for converting old OpenEthereum/Parity db entries with internal[]
for (let internalTx of tx.internal) {
if (internalTx.action.value && BigInt(internalTx.action.value) > 0) {
// Handle native asset transfer
const effect = this._getEffectForNativeTransfer(BigInt(internalTx.value).toString(), internalTx.to, internalTx.from, internalTx.depth);
const effect = this._getEffectForNativeTransfer(BigInt(internalTx.action.value).toString(), internalTx.action.to, internalTx.action.from || tx.from, internalTx.traceAddress.join('_'));
effects.push(effect);
}
// We used to ignore delegated calls because we thought they were redundant in ERC20 transfers via proxy contract
// Maybe something changed with the EVM, but they seem to be necessary now to get ERC20 transfers to show up.
// TODO: Revisit this logic to reduce duplicates
if (internalTx.abiType) { // && internalTx.type != 'DELEGATECALL') {
if (internalTx.abiType) {
// Handle Abi related effects
const effect = this._getEffectForAbiType(internalTx.abiType, internalTx.to, internalTx.from, internalTx.depth);
const effect = this._getEffectForAbiType(internalTx.abiType, internalTx.action.to, internalTx.action.from || tx.from, internalTx.traceAddress.join('_'));
if (effect) {
effects.push(effect);
}
}
}
}
} else if (tx.abiType) { // We recognized upstream that this is a known ABI tx
// Handle Abi related effects
const effect = this._getEffectForAbiType(tx.abiType, tx.to, tx.from, '');
if (effect) {
effects.push(effect);
}
}
} catch (err) {
logger.error('Error Getting Effects For TxId: %o ::%o', tx.txid, err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ interface IGethTxTraceBase {
gas: string;
gasUsed: string;
input: string;
output: string;
output?: string;
to: string;
type: 'CALL' | 'STATICCALL' | 'DELEGATECALL' | 'CREATE' | 'CREATE2';
value: string;
value?: string;
abiType?: IAbiDecodedData;
}

Expand Down
18,219 changes: 18,219 additions & 0 deletions packages/bitcore-node/test/data/ETH/gethTxs.ts

Large diffs are not rendered by default.

Loading

0 comments on commit 73cf4fd

Please sign in to comment.