Skip to content

Commit

Permalink
fix(whale-api): skip null txid used by evmtx (#2148)
Browse files Browse the repository at this point in the history
<!--  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
  • Loading branch information
Pierre Gee authored Sep 19, 2023
1 parent 0cc8c84 commit db38bfa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
10 changes: 10 additions & 0 deletions apps/whale-api/src/module.indexer/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { blockchain } from '@defichain/jellyfish-api-core'

function checkIfEvmTx (txn: blockchain.Transaction): boolean {
// To identify that the transaction is evmtx, it has to have exactly 2 null transaction ids
return txn.vin.length === 2 && txn.vin.every(vin => vin.txid === '0000000000000000000000000000000000000000000000000000000000000000')
}

export {
checkIfEvmTx
}
10 changes: 7 additions & 3 deletions apps/whale-api/src/module.indexer/model/script.activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder'
import { TransactionVout } from '../../module.model/transaction.vout'
import { VoutFinder } from './_vout_finder'
import { NotFoundIndexerError } from '../error'
import { checkIfEvmTx } from '../helper'

@Injectable()
export class ScriptActivityIndexer extends Indexer {
Expand All @@ -17,11 +18,12 @@ export class ScriptActivityIndexer extends Indexer {

async index (block: RawBlock): Promise<void> {
for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}

const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout)
if (vout === undefined) {
throw new NotFoundIndexerError('index', 'TransactionVout', `${vin.txid} - ${vin.vout}`)
Expand All @@ -40,8 +42,10 @@ export class ScriptActivityIndexer extends Indexer {

async invalidate (block: RawBlock): Promise<void> {
for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}

Expand Down
9 changes: 7 additions & 2 deletions apps/whale-api/src/module.indexer/model/script.aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { VoutFinder } from './_vout_finder'
import { HexEncoder } from '../../module.model/_hex.encoder'
import BigNumber from 'bignumber.js'
import { NotFoundIndexerError } from '../error'
import { checkIfEvmTx } from '../helper'

@Injectable()
export class ScriptAggregationIndexer extends Indexer {
Expand All @@ -27,8 +28,10 @@ export class ScriptAggregationIndexer extends Indexer {
}

for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}

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

for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}

Expand Down
9 changes: 7 additions & 2 deletions apps/whale-api/src/module.indexer/model/script.unspent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HexEncoder } from '../../module.model/_hex.encoder'
import { TransactionVout, TransactionVoutMapper } from '../../module.model/transaction.vout'
import { Transaction, TransactionMapper } from '../../module.model/transaction'
import { NotFoundIndexerError } from '../error'
import { checkIfEvmTx } from '../helper'

@Injectable()
export class ScriptUnspentIndexer extends Indexer {
Expand All @@ -18,8 +19,10 @@ export class ScriptUnspentIndexer extends Indexer {

async index (block: RawBlock): Promise<void> {
for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}
await this.unspentMapper.delete(vin.txid + HexEncoder.encodeVoutIndex(vin.vout))
Expand All @@ -33,8 +36,10 @@ export class ScriptUnspentIndexer extends Indexer {

async invalidate (block: RawBlock): Promise<void> {
for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
continue
}

Expand Down
5 changes: 4 additions & 1 deletion apps/whale-api/src/module.indexer/model/transaction.vin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TransactionVout } from '../../module.model/transaction.vout'
import { HexEncoder } from '../../module.model/_hex.encoder'
import { VoutFinder } from './_vout_finder'
import { NotFoundIndexerError } from '../error'
import { checkIfEvmTx } from '../helper'

@Injectable()
export class TransactionVinIndexer extends Indexer {
Expand All @@ -17,8 +18,10 @@ export class TransactionVinIndexer extends Indexer {

async index (block: RawBlock): Promise<void> {
for (const txn of block.tx) {
const isEvmTx = checkIfEvmTx(txn)

for (const vin of txn.vin) {
if (vin.coinbase !== undefined) {
if (vin.coinbase !== undefined || isEvmTx) {
await this.vinMapper.put(this.map(txn, vin, undefined))
} else {
const vout = await this.voutFinder.findVout(block, vin.txid, vin.vout)
Expand Down

0 comments on commit db38bfa

Please sign in to comment.