Skip to content

Commit

Permalink
Merge branch 'main' of github.com:aura-nw/horoscope-v2 into feat/api-…
Browse files Browse the repository at this point in the history
…health-check
  • Loading branch information
phamphong9981 committed Sep 22, 2023
2 parents 144d176 + 7aa36bc commit 4b5eeff
Show file tree
Hide file tree
Showing 26 changed files with 6,187 additions and 52 deletions.
18 changes: 17 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"sourceMaps": true,
"runtimeArgs": ["-r", "ts-node/register"],
"cwd": "${workspaceRoot}",
"args": ["--env", "src/services/**/*.service.ts"]
"args": [
"--env",
"src/services/**/*.service.ts",
"--config",
"src/moleculer.config.ts"
]
},
{
"type": "node",
Expand All @@ -26,6 +31,17 @@
"cwd": "${workspaceRoot}",
"runtimeArgs": ["--inspect-brk"]
},
{
"type": "node",
"request": "launch",
"name": "Jest current file",
"runtimeExecutable": "ts-node",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"args": [
"${fileBasename}"
],
"internalConsoleOptions": "neverOpen"
},
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
Expand Down
9 changes: 9 additions & 0 deletions ci/config.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,21 @@
"jobRedecodeTx": {
"limitRecordGet": 100
},
"jobReassignMsgIndexToEvent": {
"millisecondCrawl": 1000,
"blocksPerCall": 100
},
"crawlIbcTao": {
"key": "crawlIbcTao",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
},
"servicesManager": {
"healthCheckLimit": 100
},
"crawlIbcApp": {
"key": "crawlIbcApp",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
}
}
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,21 @@
"jobRedecodeTx": {
"limitRecordGet": 100
},
"jobReassignMsgIndexToEvent": {
"millisecondCrawl": 1000,
"blocksPerCall": 100
},
"crawlIbcTao": {
"key": "crawlIbcTao",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
},
"servicesManager": {
"healthCheckLimit": 100
},
"crawlIbcApp": {
"key": "crawlIbcApp",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
}
}
23 changes: 23 additions & 0 deletions migrations/20230810094108_create_ibc_tx_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('ibc_message', (table) => {
table.increments();
table.integer('transaction_message_id').index();
table.string('src_channel_id').notNullable().index();
table.string('src_port_id').notNullable().index();
table.string('dst_channel_id').notNullable().index();
table.string('dst_port_id').notNullable().index();
table.string('type').notNullable().index();
table.integer('sequence').notNullable().index();
table.string('sequence_key').notNullable().index();
table.jsonb('data');
table
.foreign('transaction_message_id')
.references('transaction_message.id');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists('ibc_message');
}
32 changes: 32 additions & 0 deletions migrations/20230912095510_smart_contract_add_label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Knex } from 'knex';
import { getHttpBatchClient } from '../src/common';
import { SmartContract } from '../src/models';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('smart_contract', (table) => {
table.string('label').defaultTo('');
});
await knex.transaction(async (trx) => {
const smartContracts = await SmartContract.query().transacting(trx);
if (smartContracts.length > 0) {
const contractsInfo = await SmartContract.getContractInfos(
smartContracts.map((smartContract) => smartContract.address),
getHttpBatchClient()
);
smartContracts.forEach((smartContract, index) => {
smartContract.label = contractsInfo[index]?.contractInfo?.label;
});
await SmartContract.query()
.transacting(trx)
.insert(smartContracts)
.onConflict('id')
.merge();
}
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('smart_contract', (table) => {
table.dropColumn('label');
});
}
10 changes: 10 additions & 0 deletions src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export const BULL_JOB_NAME = {
REINDEX_CW721_HISTORY: 'reindex:cw721-history',
HANDLE_MIGRATE_CONTRACT: 'handle:migrate-contract',
JOB_REDECODE_TX: 'job:redecode-tx',
JOB_REASSIGN_MSG_INDEX_TO_EVENT: 'job:reassign-msg-index-to-event',
CRAWL_IBC_TAO: 'crawl:ibc-tao',
CRAWL_GENESIS_IBC_TAO: 'crawl:genesis-ibc-tao',
CRAWL_IBC_APP: 'crawl:ibc-app',
REINDEX_CW20_CONTRACT: 'reindex:cw20-contract',
REINDEX_CW20_HISTORY: 'reindex:cw20-history',
};
Expand Down Expand Up @@ -231,11 +233,19 @@ export const SERVICE = {
key: 'ReDecodeTx',
path: 'v1.ReDecodeTx',
},
ReAssignMsgIndexToEvent: {
key: 'ReAssignMsgIndexToEvent',
path: 'v1.ReAssignMsgIndexToEvent',
},
},
CrawlIBCTaoService: {
key: 'CrawlIBCTaoService',
name: 'v1.CrawlIBCTaoService',
},
CrawlIBCAppService: {
key: 'CrawlIBCAppService',
name: 'v1.CrawlIBCAppService',
},
DailyStatisticsService: {
key: 'DailyStatisticsService',
name: 'v1.DailyStatisticsService',
Expand Down
5 changes: 3 additions & 2 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export class Event extends BaseModel {

tx_id!: number;

tx_msg_index: number | undefined;
tx_msg_index?: number | undefined;

type!: string;

block_height!: number | undefined;

source!: string;

attributes!: EventAttribute[];

static get tableName() {
return 'event';
}
Expand All @@ -30,7 +32,6 @@ export class Event extends BaseModel {
required: ['type'],
properties: {
tx_id: { type: 'number' },
tx_msg_index: { type: 'number' },
type: { type: 'string' },
block_height: { type: 'number' },
source: { type: 'string', enum: Object.values(this.SOURCE) },
Expand Down
6 changes: 6 additions & 0 deletions src/models/event_attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export class EventAttribute extends BaseModel {
PORT_ID: 'port_id',
COUNTERPARTY_PORT_ID: 'counterparty_port_id',
COUNTERPARTY_CHANNEL_ID: 'counterparty_channel_id',
DATA_HEX: 'packet_data_hex',
SEQUENCE: 'packet_sequence',
SRC_PORT: 'packet_src_port',
SRC_CHANNEL: 'packet_src_channel',
DST_PORT: 'packet_dst_port',
DST_CHANNEL: 'packet_dst_channel',
MINTER: 'minter',
FEE: 'fee',
FEE_PAYER: 'fee_payer',
Expand Down
93 changes: 93 additions & 0 deletions src/models/ibc_message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable import/no-cycle */
import { Model } from 'objection';
import BaseModel from './base';
import { IbcChannel } from './ibc_channel';
import { TransactionMessage } from './transaction_message';

export class IbcMessage extends BaseModel {
id!: number;

transaction_message_id!: number;

src_channel_id!: string;

src_port_id!: string;

dst_channel_id!: string;

dst_port_id!: string;

type!: string;

sequence!: number;

sequence_key!: string;

data!: any;

static get tableName() {
return 'ibc_message';
}

static get jsonSchema() {
return {
type: 'object',
required: [
'transaction_message_id',
'src_channel_id',
'src_port_id',
'dst_channel_id',
'dst_port_id',
'type',
'sequence',
'sequence_key',
],
properties: {
transaction_message_id: { type: 'number' },
src_channel_id: { type: 'string' },
src_port_id: { type: 'string' },
dst_channel_id: { type: 'string' },
dst_port_id: { type: 'string' },
type: { type: 'string' },
sequence: { type: 'number' },
sequence_key: { type: 'string' },
},
};
}

static get relationMappings() {
return {
message: {
relation: Model.BelongsToOneRelation,
modelClass: TransactionMessage,
join: {
from: 'ibc_message.transaction_message_id',
to: 'transaction_message.id',
},
},
src_channel: {
relation: Model.BelongsToOneRelation,
modelClass: IbcChannel,
join: {
from: 'ibc_message.src_channel_id',
to: 'ibc_channel.id',
},
},
dst_channel: {
relation: Model.BelongsToOneRelation,
modelClass: IbcChannel,
join: {
from: 'ibc_message.dst_channel_id',
to: 'ibc_channel.id',
},
},
};
}

static EVENT_TYPE = {
SEND_PACKET: 'send_packet',
RECV_PACKET: 'recv_packet',
ACKNOWLEDGE_PACKET: 'acknowledge_packet',
TIMEOUT_PACKET: 'timeout_packet',
};
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export * from './cw20_total_holder_stats';
export * from './ibc_client';
export * from './ibc_connection';
export * from './ibc_channel';
export * from './ibc_message';
3 changes: 3 additions & 0 deletions src/models/smart_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class SmartContract extends BaseModel {

status!: string;

label?: string;

instantiate_hash!: string;

instantiate_height!: number;
Expand Down Expand Up @@ -66,6 +68,7 @@ export class SmartContract extends BaseModel {
instantiate_hash: { type: 'string' },
instantiate_height: { type: 'number' },
version: { type: ['string', 'null'] },
label: { type: 'string' },
},
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/crawl-cosmwasm/crawl_smart_contract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default class CrawlSmartContractService extends BullableService {
instantiate_hash: instantiateEvent ? instantiateEvent.hash : '',
instantiate_height: instantiateEvent ? instantiateEvent.height : 0,
version: codeContract ? codeContract.version : '',
label: contract.label,
});

if (codeContract) newContracts.push(migrateContract);
Expand Down Expand Up @@ -320,7 +321,7 @@ export default class CrawlSmartContractService extends BullableService {
10
);
contract.creator = contractInfos[index]?.contractInfo?.creator || '';

contract.label = contractInfos[index]?.contractInfo?.label;
codeIds.push(
parseInt(
contractInfos[index]?.contractInfo?.codeId.toString() || '0',
Expand Down
Loading

0 comments on commit 4b5eeff

Please sign in to comment.