Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/merge erc20 from develop to evm #878

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions migrations/evm/20240702013020_add_col_to_save_cosmos_erc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Knex } from 'knex';
import { Erc20Activity } from '../../src/models';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable(Erc20Activity.tableName, (table) => {
table.bigint('cosmos_event_id').index();
table.integer('cosmos_tx_id').index();
table.setNullable('evm_event_id');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable(Erc20Activity.tableName, (table) => {
table.dropColumn('cosmos_event_id');
table.dropColumn('cosmos_tx_id');
table.dropNullable('evm_event_id');
});
}
2 changes: 2 additions & 0 deletions src/models/account_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import BaseModel from './base';
import { Account } from './account';

export class AccountBalance extends BaseModel {
static softDelete = false;

account!: Account;

id!: number;
Expand Down
8 changes: 7 additions & 1 deletion src/models/erc20_activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ export class Erc20Activity extends BaseModel {

evm_tx_id!: number;

cosmos_tx_id!: number;

cosmos_event_id!: string;

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

static get jsonSchema() {
return {
type: 'object',
required: ['evm_event_id', 'erc20_contract_address', 'height'],
required: ['erc20_contract_address', 'height'],
properties: {
evm_event_id: { type: 'number' },
erc20_contract_address: { type: 'string' },
Expand All @@ -48,6 +52,8 @@ export class Erc20Activity extends BaseModel {
action: { type: 'string' },
from: { type: 'string' },
sender: { type: 'string' },
cosmos_tx_id: { type: 'number' },
cosmos_event_id: { type: 'string' },
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@ export class Event extends BaseModel {
CHANNEL_CLOSE_CONFIRM: 'channel_close_confirm',
CHANNEL_CLOSE: 'channel_close',
BLOCK_BLOOM: 'block_bloom',
CONVERT_COIN: 'convert_coin',
CONVERT_ERC20: 'convert_erc20',
};
}
1 change: 1 addition & 0 deletions src/models/event_attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class EventAttribute extends BaseModel {
REFUND_AMOUNT: 'refund_amount',
MEMO: 'memo',
BLOOM: 'bloom',
ERC20_TOKEN: 'erc20_token',
};

static ATTRIBUTE_COMPOSITE_KEY = {
Expand Down
1 change: 1 addition & 0 deletions src/services/api-gateways/api_gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import config from '../../../config.json' assert { type: 'json' };
'v1.job.insert-verify-by-codehash',
'v1.erc721-admin.*',
'v2.evm-statistics.syncPrevDateStatsByChainId',
'v1.erc20-admin.*',
],
},
{
Expand Down
49 changes: 49 additions & 0 deletions src/services/api-gateways/erc20_admin.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Post, Service } from '@ourparentcenter/moleculer-decorators-extended';
import { Context, ServiceBroker } from 'moleculer';
import networks from '../../../network.json' assert { type: 'json' };
import BaseService from '../../base/base.service';

@Service({
name: 'erc20-admin',
version: 1,
})
export default class Erc20AdminService extends BaseService {
public constructor(public broker: ServiceBroker) {
super(broker);
}

@Post('/erc20-reindexing', {
name: 'erc20Reindexing',
params: {
chainid: {
type: 'string',
optional: false,
enum: networks.map((network) => network.chainId),
},
addresses: {
type: 'array',
optional: false,
items: 'string',
},
},
})
async erc20Reindexing(
ctx: Context<
{
chainid: string;
addresses: string[];
},
Record<string, unknown>
>
) {
const selectedChain = networks.find(
(network) => network.chainId === ctx.params.chainid
);
return this.broker.call(
`v1.Erc20.reindexing@${selectedChain?.moleculerNamespace}`,
{
addresses: ctx.params.addresses,
}
);
}
}
5 changes: 5 additions & 0 deletions src/services/evm/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export const SERVICE = {
key: 'insertNewErc20Contracts',
path: 'v1.Erc20.insertNewErc20Contracts',
},
reindexing: {
key: 'reindexing',
path: 'v1.Erc20.reindexing',
},
},
Erc721: {
key: 'Erc721',
Expand Down Expand Up @@ -288,6 +292,7 @@ export const BULL_JOB_NAME = {
UPDATE_OPTIMISM_WITHDRAWAL_STATUS: 'handle:update-optimism-withdrawal-status',
INSERT_VERIFY_BY_CODEHASH: 'job:insert-verify-by-codehash',
HANDLE_SELF_DESTRUCT: 'handle:self-destruct',
REINDEX_ERC20: 'reindex:erc20',
};

export const MSG_TYPE = {
Expand Down
Loading
Loading