Skip to content

Commit

Permalink
Merge branch 'evm' of github.com:aura-nw/horoscope-v2 into refactor/d…
Browse files Browse the repository at this point in the history
…etect-proxy-api
  • Loading branch information
phamphong9981 committed Sep 10, 2024
2 parents aa59d78 + e9a06f5 commit d98a378
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ci/config.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@
},
"transport": {
"batchSize": 10,
"waitMilisecond": 1000
"waitMilisecond": 1000,
"timeout": 10000
}
},
"crawlEvmAccount": {
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@
},
"transport": {
"batchSize": 10,
"waitMilisecond": 1000
"waitMilisecond": 1000,
"timeout": 10000
}
},
"crawlEvmAccount": {
Expand Down
15 changes: 15 additions & 0 deletions migrations/20240909092417_create_index_validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('validator', (table) => {
table.index('tokens');
table.index('status');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('validator', (table) => {
table.dropIndex('tokens');
table.dropIndex('status');
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Knex } from 'knex';
import { EvmInternalTransaction } from '../src/models/evm_internal_transaction';
import { EvmInternalTransaction } from '../../src/models/evm_internal_transaction';

export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable(EvmInternalTransaction.tableName, (table) => {
Expand Down
13 changes: 13 additions & 0 deletions migrations/evm/20240909092542_create_index_miner_in_evm_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('evm_block', (table) => {
table.index('miner');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('evm_block', (table) => {
table.dropIndex('miner');
});
}
1 change: 1 addition & 0 deletions src/common/utils/etherjs_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function getViemClient(chainId?: string): PublicClient {
batchSize: config.viemConfig.transport.batchSize,
wait: config.viemConfig.transport.waitMilisecond,
},
timeout: config.viemConfig.transport.timeout,
}),
}).extend(publicActionsL1());
viemClientMapping.set(chainId ?? config.chainId, viemClient);
Expand Down
3 changes: 1 addition & 2 deletions src/models/evm_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ export class EVMTransaction extends BaseModel {
static get jsonSchema() {
return {
type: 'object',
required: ['hash', 'height'],
required: ['height'],
properties: {
hash: { type: 'string' },
height: { type: 'number' },
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/evm/crawl_evm_account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class CrawlEvmAccountService extends BullableService {
BULL_JOB_NAME.CRAWL_EVM_TRANSACTION,
BULL_JOB_NAME.EVM_CRAWL_INTERNAL_TX,
],
config.evmCrawlInternalTx.key
config.crawlEvmAccount.key
);
this.logger.info(
`Crawl evm_account from block ${startBlock} to ${endBlock}`
Expand Down
5 changes: 3 additions & 2 deletions src/services/evm/crawl_evm_proxy_history.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default class CrawlProxyContractEVMService extends BullableService {
.where('block_height', '>', startBlock)
.andWhere('block_height', '<=', endBlock)
.select('address', 'topic0', 'topic1', 'block_height', 'tx_hash');
const distictAddresses = _.uniq(evmEvents.map((e) => e.address));
const proxyContractDb = await EVMSmartContract.query()
.whereIn('type', [
EVMSmartContract.TYPES.PROXY_EIP_1967,
Expand All @@ -86,8 +87,8 @@ export default class CrawlProxyContractEVMService extends BullableService {
EVMSmartContract.TYPES.PROXY_EIP_1167,
EVMSmartContract.TYPES.PROXY_EIP_1967_BEACON,
])
.andWhere('address', 'in', distictAddresses)
.select('address');
const distictAddresses = _.uniq(evmEvents.map((e) => e.address));
const batchReqs: any[] = [];
distictAddresses.forEach((address) => {
batchReqs.push(
Expand Down Expand Up @@ -190,7 +191,7 @@ export default class CrawlProxyContractEVMService extends BullableService {
) {
newProxyContractsToSave.push(proxyHistory);
} else {
this.logger.warn(
this.logger.debug(
`This contract address ${proxyHistory.proxy_contract} is not proxy, at tx hash ${proxyHistory.tx_hash}`
);
}
Expand Down
14 changes: 8 additions & 6 deletions test/unit/services/erc721/erc721_handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BeforeAll, Describe, Test } from '@jest-decorated/core';
import { ServiceBroker } from 'moleculer';
import { bytesToHex, hexToBytes } from 'viem';
import config from '../../../../config.json' assert { type: 'json' };
import knex from '../../../../src/common/utils/db_connection';
import {
Expand Down Expand Up @@ -42,11 +43,12 @@ export default class Erc721HandlerTest {

evmTx = EVMTransaction.fromJson({
id: 11111,
hash: '',
hash: hexToBytes(
'0x3faac2ed3ca031892c04598177f7c36e9fdcdf2fb3b6c4a13c520590facb82ef'
),
height: 111,
tx_msg_id: 222,
tx_id: 223,
contract_address: '',
index: 1,
});

Expand Down Expand Up @@ -100,7 +102,7 @@ export default class Erc721HandlerTest {
address: this.evmSmartContract.address,
evm_tx_id: this.evmTx.id,
tx_id: 1234,
tx_hash: this.evmTx.hash,
tx_hash: bytesToHex(this.evmTx.hash),
tx_index: 1,
}),
EvmEvent.fromJson({
Expand All @@ -119,7 +121,7 @@ export default class Erc721HandlerTest {
address: this.evmSmartContract.address,
evm_tx_id: this.evmTx.id,
tx_id: 1234,
tx_hash: this.evmTx.hash,
tx_hash: bytesToHex(this.evmTx.hash),
tx_index: 1,
}),
EvmEvent.fromJson({
Expand All @@ -138,7 +140,7 @@ export default class Erc721HandlerTest {
address: this.evmSmartContract2.address,
evm_tx_id: this.evmTx.id,
tx_id: 1234,
tx_hash: this.evmTx.hash,
tx_hash: bytesToHex(this.evmTx.hash),
tx_index: 1,
}),
EvmEvent.fromJson({
Expand All @@ -157,7 +159,7 @@ export default class Erc721HandlerTest {
address: this.evmSmartContract.address,
evm_tx_id: this.evmTx.id,
tx_id: 1234,
tx_hash: this.evmTx.hash,
tx_hash: bytesToHex(this.evmTx.hash),
tx_index: 1,
}),
];
Expand Down
6 changes: 4 additions & 2 deletions test/unit/services/evm/erc20_handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AfterAll, BeforeAll, Describe, Test } from '@jest-decorated/core';
import _ from 'lodash';
import { ServiceBroker } from 'moleculer';
import { decodeAbiParameters, toHex } from 'viem';
import { decodeAbiParameters, hexToBytes, toHex } from 'viem';
import knex from '../../../../src/common/utils/db_connection';
import { getViemClient } from '../../../../src/common/utils/etherjs_client';
import {
Expand Down Expand Up @@ -111,7 +111,9 @@ const erc20Contract = Erc20Contract.fromJson({
});
const evmTransaction = EVMTransaction.fromJson({
id: 2931,
hash: '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d',
hash: hexToBytes(
'0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d'
),
height: 1,
tx_id: 1612438,
tx_msg_id: 4752908,
Expand Down
6 changes: 4 additions & 2 deletions test/unit/services/evm/erc20_reindex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AfterAll, BeforeAll, Describe, Test } from '@jest-decorated/core';
import _ from 'lodash';
import { ServiceBroker } from 'moleculer';
import { decodeAbiParameters, toHex } from 'viem';
import { decodeAbiParameters, hexToBytes, toHex } from 'viem';
import knex from '../../../../src/common/utils/db_connection';
import { getViemClient } from '../../../../src/common/utils/etherjs_client';
import {
Expand Down Expand Up @@ -111,7 +111,9 @@ const erc20Contract = Erc20Contract.fromJson({
});
const evmTransaction = EVMTransaction.fromJson({
id: 2931,
hash: '0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d',
hash: hexToBytes(
'0xf15467ec2a25eeef95798d93c2fe9ed8e7c891578b8e1bcc3284105849656c9d'
),
height: 1,
tx_id: 1612438,
tx_msg_id: 4752908,
Expand Down

0 comments on commit d98a378

Please sign in to comment.