Skip to content

Commit db38bfa

Browse files
author
Pierre Gee
authored
fix(whale-api): skip null txid used by evmtx (#2148)
<!-- Thanks for sending a pull request! --> #### What this PR does / why we need it: - [x] If an EVM tx is found (2 exact vin - both null), skip it - [x] Check how it will impact data representation in DeFiScan (can be done in another PR), vin will be empty as expected #### Which issue(s) does this PR fixes?: <!-- (Optional) Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Fixes # #### Additional comments?: - Add tests on another PR, test all these change in Changi network concurrently
1 parent 0cc8c84 commit db38bfa

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { blockchain } from '@defichain/jellyfish-api-core'
2+
3+
function checkIfEvmTx (txn: blockchain.Transaction): boolean {
4+
// To identify that the transaction is evmtx, it has to have exactly 2 null transaction ids
5+
return txn.vin.length === 2 && txn.vin.every(vin => vin.txid === '0000000000000000000000000000000000000000000000000000000000000000')
6+
}
7+
8+
export {
9+
checkIfEvmTx
10+
}

apps/whale-api/src/module.indexer/model/script.activity.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder'
55
import { TransactionVout } from '../../module.model/transaction.vout'
66
import { VoutFinder } from './_vout_finder'
77
import { NotFoundIndexerError } from '../error'
8+
import { checkIfEvmTx } from '../helper'
89

910
@Injectable()
1011
export class ScriptActivityIndexer extends Indexer {
@@ -17,11 +18,12 @@ export class ScriptActivityIndexer extends Indexer {
1718

1819
async index (block: RawBlock): Promise<void> {
1920
for (const txn of block.tx) {
21+
const isEvmTx = checkIfEvmTx(txn)
22+
2023
for (const vin of txn.vin) {
21-
if (vin.coinbase !== undefined) {
24+
if (vin.coinbase !== undefined || isEvmTx) {
2225
continue
2326
}
24-
2527
const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout)
2628
if (vout === undefined) {
2729
throw new NotFoundIndexerError('index', 'TransactionVout', `${vin.txid} - ${vin.vout}`)
@@ -40,8 +42,10 @@ export class ScriptActivityIndexer extends Indexer {
4042

4143
async invalidate (block: RawBlock): Promise<void> {
4244
for (const txn of block.tx) {
45+
const isEvmTx = checkIfEvmTx(txn)
46+
4347
for (const vin of txn.vin) {
44-
if (vin.coinbase !== undefined) {
48+
if (vin.coinbase !== undefined || isEvmTx) {
4549
continue
4650
}
4751

apps/whale-api/src/module.indexer/model/script.aggregation.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { VoutFinder } from './_vout_finder'
55
import { HexEncoder } from '../../module.model/_hex.encoder'
66
import BigNumber from 'bignumber.js'
77
import { NotFoundIndexerError } from '../error'
8+
import { checkIfEvmTx } from '../helper'
89

910
@Injectable()
1011
export class ScriptAggregationIndexer extends Indexer {
@@ -27,8 +28,10 @@ export class ScriptAggregationIndexer extends Indexer {
2728
}
2829

2930
for (const txn of block.tx) {
31+
const isEvmTx = checkIfEvmTx(txn)
32+
3033
for (const vin of txn.vin) {
31-
if (vin.coinbase !== undefined) {
34+
if (vin.coinbase !== undefined || isEvmTx) {
3235
continue
3336
}
3437

@@ -76,8 +79,10 @@ export class ScriptAggregationIndexer extends Indexer {
7679
const hidList = new Set<string>()
7780

7881
for (const txn of block.tx) {
82+
const isEvmTx = checkIfEvmTx(txn)
83+
7984
for (const vin of txn.vin) {
80-
if (vin.coinbase !== undefined) {
85+
if (vin.coinbase !== undefined || isEvmTx) {
8186
continue
8287
}
8388

apps/whale-api/src/module.indexer/model/script.unspent.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder'
55
import { TransactionVout, TransactionVoutMapper } from '../../module.model/transaction.vout'
66
import { Transaction, TransactionMapper } from '../../module.model/transaction'
77
import { NotFoundIndexerError } from '../error'
8+
import { checkIfEvmTx } from '../helper'
89

910
@Injectable()
1011
export class ScriptUnspentIndexer extends Indexer {
@@ -18,8 +19,10 @@ export class ScriptUnspentIndexer extends Indexer {
1819

1920
async index (block: RawBlock): Promise<void> {
2021
for (const txn of block.tx) {
22+
const isEvmTx = checkIfEvmTx(txn)
23+
2124
for (const vin of txn.vin) {
22-
if (vin.coinbase !== undefined) {
25+
if (vin.coinbase !== undefined || isEvmTx) {
2326
continue
2427
}
2528
await this.unspentMapper.delete(vin.txid + HexEncoder.encodeVoutIndex(vin.vout))
@@ -33,8 +36,10 @@ export class ScriptUnspentIndexer extends Indexer {
3336

3437
async invalidate (block: RawBlock): Promise<void> {
3538
for (const txn of block.tx) {
39+
const isEvmTx = checkIfEvmTx(txn)
40+
3641
for (const vin of txn.vin) {
37-
if (vin.coinbase !== undefined) {
42+
if (vin.coinbase !== undefined || isEvmTx) {
3843
continue
3944
}
4045

apps/whale-api/src/module.indexer/model/transaction.vin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TransactionVout } from '../../module.model/transaction.vout'
55
import { HexEncoder } from '../../module.model/_hex.encoder'
66
import { VoutFinder } from './_vout_finder'
77
import { NotFoundIndexerError } from '../error'
8+
import { checkIfEvmTx } from '../helper'
89

910
@Injectable()
1011
export class TransactionVinIndexer extends Indexer {
@@ -17,8 +18,10 @@ export class TransactionVinIndexer extends Indexer {
1718

1819
async index (block: RawBlock): Promise<void> {
1920
for (const txn of block.tx) {
21+
const isEvmTx = checkIfEvmTx(txn)
22+
2023
for (const vin of txn.vin) {
21-
if (vin.coinbase !== undefined) {
24+
if (vin.coinbase !== undefined || isEvmTx) {
2225
await this.vinMapper.put(this.map(txn, vin, undefined))
2326
} else {
2427
const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout)

0 commit comments

Comments
 (0)