Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(whale-api): skip null txid used by evmtx #2148

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/whale-api/src/module.indexer/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const NULL_TX_ID = '0000000000000000000000000000000000000000000000000000000000000000'
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'
import { NULL_TX_ID } from './constants'

function checkIfEvmTx (txn: blockchain.Transaction): boolean {
return txn.vin.length === 2 && txn.vin.every(vin => vin.txid === NULL_TX_ID)
}

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