Skip to content

Commit

Permalink
Feat/ibc tao ( staging ) (#308)
Browse files Browse the repository at this point in the history
* fix: hotfix

* fix: hotfix

* feat: crawl ibc tao

* feat: crawl genesis ibc tao

* fix: code

* fix: code
  • Loading branch information
phamphong9981 authored Aug 15, 2023
1 parent 5fe2bcd commit e7fc664
Show file tree
Hide file tree
Showing 13 changed files with 1,029 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ci/config.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,10 @@
},
"jobRedecodeTx": {
"limitRecordGet": 100
},
"crawlIbcTao": {
"key": "crawlIbcTao",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
}
}
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,10 @@
},
"jobRedecodeTx": {
"limitRecordGet": 100
},
"crawlIbcTao": {
"key": "crawlIbcTao",
"millisecondRepeatJob": 2000,
"blocksPerCall": 100
}
}
36 changes: 36 additions & 0 deletions migrations/20230802071931_ibc_tao_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('ibc_client', (table) => {
table.increments();
table.string('client_id').notNullable().unique();
table.string('counterparty_chain_id').notNullable();
table.jsonb('client_state').notNullable();
table.jsonb('consensus_state').notNullable();
table.string('client_type').notNullable();
});
await knex.schema.createTable('ibc_connection', (table) => {
table.increments();
table.integer('ibc_client_id').index();
table.string('connection_id').notNullable().unique();
table.string('counterparty_client_id').notNullable();
table.string('counterparty_connection_id').notNullable();
table.foreign('ibc_client_id').references('ibc_client.id');
});
await knex.schema.createTable('ibc_channel', (table) => {
table.increments();
table.integer('ibc_connection_id').index();
table.string('channel_id').notNullable().unique();
table.string('port_id').notNullable().index();
table.string('counterparty_port_id').notNullable();
table.string('counterparty_channel_id').notNullable();
table.string('state').notNullable();
table.foreign('ibc_connection_id').references('ibc_connection.id');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists('ibc_client');
await knex.schema.dropTableIfExists('ibc_connection');
await knex.schema.dropTableIfExists('ibc_channel');
}
6 changes: 6 additions & 0 deletions src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const BULL_JOB_NAME = {
REINDEX_CW721_HISTORY: 'reindex:cw721-history',
HANDLE_MIGRATE_CONTRACT: 'handle:migrate-contract',
JOB_REDECODE_TX: 'job:redecode-tx',
CRAWL_IBC_TAO: 'crawl:ibc-tao',
CRAWL_GENESIS_IBC_TAO: 'crawl:genesis-ibc-tao',
};

export const SERVICE = {
Expand Down Expand Up @@ -248,6 +250,10 @@ export const SERVICE = {
key: 'DailyStatsJobsService',
name: 'v1.DailyStatsJobsService',
},
CrawlIBCTaoService: {
key: 'CrawlIBCTaoService',
name: 'v1.CrawlIBCTaoService',
},
},
};

Expand Down
10 changes: 9 additions & 1 deletion src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EventAttribute } from './event_attribute';
import { TransactionMessage } from './transaction_message';

export class Event extends BaseModel {
[relation: string]: any;
[relation: string]: any | any[];

id!: string;

Expand Down Expand Up @@ -94,5 +94,13 @@ export class Event extends BaseModel {
TX: 'tx',
TRANSFER: 'transfer',
MIGRATE: 'migrate',
CREATE_CLIENT: 'create_client',
CONNECTION_OPEN_ACK: 'connection_open_ack',
CONNECTION_OPEN_CONFIRM: 'connection_open_confirm',
CHANNEL_OPEN_ACK: 'channel_open_ack',
CHANNEL_OPEN_CONFIRM: 'channel_open_confirm',
CHANNEL_CLOSE_INIT: 'channel_close_init',
CHANNEL_CLOSE_CONFIRM: 'channel_close_confirm',
CHANNEL_CLOSE: 'channel_close',
};
}
9 changes: 9 additions & 0 deletions src/models/event_attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export class EventAttribute extends BaseModel {
FROM: 'from',
FEE: 'fee',
FEE_PAYER: 'fee_payer',
CLIENT_ID: 'client_id',
CLIENT_TYPE: 'client_type',
CONNECTION_ID: 'connection_id',
COUNTERPARTY_CLIENT_ID: 'counterparty_client_id',
COUNTERPARTY_CONNECTION_ID: 'counterparty_connection_id',
CHANNEL_ID: 'channel_id',
PORT_ID: 'port_id',
COUNTERPARTY_PORT_ID: 'counterparty_port_id',
COUNTERPARTY_CHANNEL_ID: 'counterparty_channel_id',
MINTER: 'minter',
};

Expand Down
64 changes: 64 additions & 0 deletions src/models/ibc_channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable import/no-cycle */
import { Model } from 'objection';
import BaseModel from './base';
import { IbcConnection } from './ibc_connection';

export class IbcChannel extends BaseModel {
id!: number;

ibc_connection_id!: number;

channel_id!: string;

port_id!: string;

counterparty_port_id!: string;

counterparty_channel_id!: string;

state!: string;

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

static get jsonSchema() {
return {
type: 'object',
required: [
'ibc_connection_id',
'channel_id',
'port_id',
'counterparty_port_id',
'counterparty_channel_id',
'state',
],
properties: {
ibc_connection_id: { type: 'number' },
channel_id: { type: 'string' },
port_id: { type: 'string' },
counterparty_port_id: { type: 'string' },
counterparty_channel_id: { type: 'string' },
state: { type: 'string' },
},
};
}

static get relationMappings() {
return {
ibc_connection: {
relation: Model.BelongsToOneRelation,
modelClass: IbcConnection,
join: {
from: 'ibc_channel.ibc_connection_id',
to: 'ibc_connection.id',
},
},
};
}

static STATUS = {
OPEN: 'OPEN',
CLOSE: 'CLOSE',
};
}
40 changes: 40 additions & 0 deletions src/models/ibc_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable import/no-cycle */
import BaseModel from './base';

export class IbcClient extends BaseModel {
id!: number;

client_id!: string;

counterparty_chain_id!: string;

client_state!: any;

consensus_state!: any;

client_type!: string;

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

static get jsonSchema() {
return {
type: 'object',
required: [
'client_id',
'counterparty_chain_id',
'client_state',
'consensus_state',
'client_type',
],
properties: {
client_id: { type: 'string' },
counterparty_chain_id: { type: 'string' },
client_state: { type: 'object' },
consensus_state: { type: 'object' },
client_type: { type: 'string' },
},
};
}
}
51 changes: 51 additions & 0 deletions src/models/ibc_connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable import/no-cycle */
import { Model } from 'objection';
import BaseModel from './base';
import { IbcClient } from './ibc_client';

export class IbcConnection extends BaseModel {
id!: number;

ibc_client_id!: number;

connection_id!: string;

counterparty_client_id!: string;

counterparty_connection_id!: string;

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

static get jsonSchema() {
return {
type: 'object',
required: [
'ibc_client_id',
'connection_id',
'counterparty_client_id',
'counterparty_connection_id',
],
properties: {
ibc_client_id: { type: 'number' },
connection_id: { type: 'string' },
counterparty_client_id: { type: 'string' },
counterparty_connection_id: { type: 'string' },
},
};
}

static get relationMappings() {
return {
ibc_client: {
relation: Model.BelongsToOneRelation,
modelClass: IbcClient,
join: {
from: 'ibc_connection.ibc_client_id',
to: 'ibc_client.id',
},
},
};
}
}
3 changes: 3 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ export * from './feegrant_history';
export * from './daily_statistics';
export * from './account_statistics';
export * from './cw20_total_holder_stats';
export * from './ibc_client';
export * from './ibc_connection';
export * from './ibc_channel';
Loading

0 comments on commit e7fc664

Please sign in to comment.