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

refactor: detect proxy api then handle erc721/20 types #899

Open
wants to merge 5 commits into
base: evm
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/services/evm/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export const SERVICE = {
CrawlEvmProxyHistory: {
key: 'CrawlEvmProxyHistory',
path: 'v1.CrawlEvmProxyHistory',
handleTypeProxyContracts: {
key: 'handleTypeProxyContracts',
path: 'v1.CrawlEvmProxyHistory.handleTypeProxyContracts',
},
},
JobService: {
CrawlEvmEvent: {
Expand Down
39 changes: 37 additions & 2 deletions src/services/evm/crawl_evm_proxy_history.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable @typescript-eslint/return-await */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { Service } from '@ourparentcenter/moleculer-decorators-extended';
import {
Action,
Service,
} from '@ourparentcenter/moleculer-decorators-extended';
import _, { Dictionary } from 'lodash';
import { ServiceBroker } from 'moleculer';
import { Context, ServiceBroker } from 'moleculer';
import {
PublicClient,
decodeAbiParameters,
Expand Down Expand Up @@ -235,6 +238,38 @@ export default class CrawlProxyContractEVMService extends BullableService {
await this.handleTypeProxyContracts(newProxyContracts);
}

@Action({
name: SERVICE.V1.CrawlEvmProxyHistory.handleTypeProxyContracts.key,
params: {
proxyHistoryIds: {
type: 'array',
items: 'number',
required: true,
},
},
})
public async actionHandleTypeProxyContracts(
ctx: Context<{ proxyHistoryIds: number[] }>
) {
const ids = ctx.params.proxyHistoryIds;
// handle erc20 proxies
await this.handleErc20ProxyContracts(
ids.map((id) =>
EvmProxyHistory.fromJson({
id,
})
)
);
// handle erc721 proxies
await this.handleErc721ProxyContracts(
ids.map((id) =>
EvmProxyHistory.fromJson({
id,
})
)
);
}

async handleTypeProxyContracts(proxyContracts: EvmProxyHistory[]) {
// handle erc20 proxies
await this.handleErc20ProxyContracts(proxyContracts);
Expand Down
6 changes: 6 additions & 0 deletions src/services/evm/evm_proxy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export default class EVMProxy extends BaseService {
})
.returning('*');
}
await this.broker.call(
SERVICE.V1.CrawlEvmProxyHistory.handleTypeProxyContracts.path,
{
proxyHistoryIds: [evmProxyHistory.id],
}
);
}

return evmProxyHistory;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/services/evm/evm_proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class EvmProxyServiceTest {
jest
.spyOn(ContractHelper.prototype, 'isContractProxy')
.mockResolvedValueOnce(proxyContractRPC);

jest.spyOn(this.evmProxyService.broker, 'call').mockImplementation();
const insertedSmartContract = await EVMSmartContract.query()
.insert({ address: ctx.params.contractAddress })
.returning('*');
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class EvmProxyServiceTest {
jest
.spyOn(this.evmProxyService.viemClient, 'getBlockNumber')
.mockResolvedValueOnce(Promise.resolve(BigInt(lastBlockHeight)));

jest.spyOn(this.evmProxyService.broker, 'call').mockImplementation();
await EVMSmartContract.query()
.insert({
address: ctx.params.contractAddress,
Expand Down
Loading