Skip to content

Commit

Permalink
fix: smart contract missing label ( develop ) (#367)
Browse files Browse the repository at this point in the history
* 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 <quang.vn@outlook.com>

* 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 <quang.vn@outlook.com>
  • Loading branch information
phamphong9981 and peara authored Sep 15, 2023
1 parent 58ffa5f commit 94f3e24
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
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');
});
}
2 changes: 1 addition & 1 deletion src/models/event_attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
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 @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export default class CrawlSmartContractTest {
'4A8B0DE950F563553A81360D4782F6EC451F6BEF7AC50E2459D1997FA168997E',
instantiate_height: 3967530,
version: '0.19.0',
label: '',
});
expect(
_.omit(
Expand All @@ -211,6 +212,7 @@ export default class CrawlSmartContractTest {
'4A8B0DE950F563553A81360D4782F6EC451F6BEF7AC50E2459D1997FA168997D',
instantiate_height: 3967520,
version: '0.16.0',
label: '',
});
}
}

0 comments on commit 94f3e24

Please sign in to comment.