From 94f3e247b37e4ed7546820fc1c7b3433ea660294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Th=C3=A0nh=20Phong?= <49814372+phamphong9981@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:48:19 +0700 Subject: [PATCH] fix: smart contract missing label ( develop ) (#367) * fix: cw721 activity missing from/to ( main ) (#294) * fix: cw721 activity missing from/to * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * refactor: code * fix: code * refactor: code --------- Co-authored-by: Vu Ngoc Quang * feat: crawl ibc tao ( main ) (#278) * feat: crawl ibc tao * feat: crawl genesis ibc tao * fix: code * fix: code * fix: smart contract missing label * fix: test * fix: test * fix: test * fix: test --------- Co-authored-by: Vu Ngoc Quang --- ...20230912095510_smart_contract_add_label.ts | 32 +++++++++++++++++++ src/models/event_attribute.ts | 2 +- src/models/smart_contract.ts | 3 ++ .../crawl_smart_contract.service.ts | 3 +- .../crawl_smart_contract.spec.ts | 2 ++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 migrations/20230912095510_smart_contract_add_label.ts diff --git a/migrations/20230912095510_smart_contract_add_label.ts b/migrations/20230912095510_smart_contract_add_label.ts new file mode 100644 index 000000000..a73aff94d --- /dev/null +++ b/migrations/20230912095510_smart_contract_add_label.ts @@ -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 { + 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 { + await knex.schema.alterTable('smart_contract', (table) => { + table.dropColumn('label'); + }); +} diff --git a/src/models/event_attribute.ts b/src/models/event_attribute.ts index f67aad3b2..2f450dbe8 100644 --- a/src/models/event_attribute.ts +++ b/src/models/event_attribute.ts @@ -96,6 +96,7 @@ export class EventAttribute extends BaseModel { GRANTER: 'granter', GRANTEE: 'grantee', FROM: 'from', + MINTER: 'minter', FEE: 'fee', FEE_PAYER: 'fee_payer', CLIENT_ID: 'client_id', @@ -107,7 +108,6 @@ export class EventAttribute extends BaseModel { PORT_ID: 'port_id', COUNTERPARTY_PORT_ID: 'counterparty_port_id', COUNTERPARTY_CHANNEL_ID: 'counterparty_channel_id', - MINTER: 'minter', DATA_HEX: 'packet_data_hex', SEQUENCE: 'packet_sequence', SRC_PORT: 'packet_src_port', diff --git a/src/models/smart_contract.ts b/src/models/smart_contract.ts index 10a33debf..b3ea35e05 100644 --- a/src/models/smart_contract.ts +++ b/src/models/smart_contract.ts @@ -30,6 +30,8 @@ export class SmartContract extends BaseModel { status!: string; + label?: string; + instantiate_hash!: string; instantiate_height!: number; @@ -66,6 +68,7 @@ export class SmartContract extends BaseModel { instantiate_hash: { type: 'string' }, instantiate_height: { type: 'number' }, version: { type: ['string', 'null'] }, + label: { type: 'string' }, }, }; } diff --git a/src/services/crawl-cosmwasm/crawl_smart_contract.service.ts b/src/services/crawl-cosmwasm/crawl_smart_contract.service.ts index dfe4e8faa..a35405ea6 100644 --- a/src/services/crawl-cosmwasm/crawl_smart_contract.service.ts +++ b/src/services/crawl-cosmwasm/crawl_smart_contract.service.ts @@ -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); @@ -321,7 +322,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', diff --git a/test/unit/services/crawl-cosmwasm/crawl_smart_contract.spec.ts b/test/unit/services/crawl-cosmwasm/crawl_smart_contract.spec.ts index 604c3b3ea..6b48cc95e 100644 --- a/test/unit/services/crawl-cosmwasm/crawl_smart_contract.spec.ts +++ b/test/unit/services/crawl-cosmwasm/crawl_smart_contract.spec.ts @@ -192,6 +192,7 @@ export default class CrawlSmartContractTest { '4A8B0DE950F563553A81360D4782F6EC451F6BEF7AC50E2459D1997FA168997E', instantiate_height: 3967530, version: '0.19.0', + label: '', }); expect( _.omit( @@ -211,6 +212,7 @@ export default class CrawlSmartContractTest { '4A8B0DE950F563553A81360D4782F6EC451F6BEF7AC50E2459D1997FA168997D', instantiate_height: 3967520, version: '0.16.0', + label: '', }); } }