Skip to content

Commit

Permalink
repair dar->eth records
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Apr 1, 2024
1 parent a6cf69d commit 265f475
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apollo/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ XTOKEN_DARWINIA_CRAB_BACKING=https://thegraph.darwinia.network/helix/subgraphs/n
XTOKEN_DARWINIA_CRAB_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-crab-issuing
XTOKEN_CRAB_DARWINIA_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-backing
XTOKEN_CRAB_DARWINIA_ISSUING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab-darwinia-issuing
XTOKEN_DARWINIA_ETHEREUM_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/build-darwinia-ethereum-backing
XTOKEN_DARWINIA_ETHEREUM_BACKING=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/darwinia-ethereum-backing
XTOKEN_DARWINIA_ETHEREUM_ISSUING=https://api.studio.thegraph.com/query/59403/xtoken-dar-ethereum-issuing/v1.0.0
XTOKEN_CRAB=https://thegraph.darwinia.network/helix/subgraphs/name/xtokentransfer/crab
XTOKEN_DISPATCH_DARWINIA=https://thegraph.darwinia.network/helix/subgraphs/name/xtokendispatch/darwinia
Expand Down
25 changes: 24 additions & 1 deletion apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,38 @@ export class xTokenService implements OnModuleInit {
return `${from}2${to}-${this.baseConfigure.name}(${direction})-${id}`;
}

findPartner(transfer: PartnerT2): PartnerT2 {
return (
this.transferService.transfers.find(
(target) =>
target.bridge === transfer.bridge && target.chainId !== transfer.chainId
) ?? null
);
}

async fetchRecords(transfer: PartnerT2, index: number) {
const partner = this.findPartner(transfer);
if (partner === null) {
this.logger.error(`xtoken can't find partner ${transfer.chainId}, ${transfer.bridge}`);
return;
}

// the nonce of cBridge message is not increased
let latestNonce = this.fetchCache[index].latestNonce;
try {
if (latestNonce === -1) {
const firstRecord = await this.aggregationService.queryHistoryRecordFirst(
{
fromChain: transfer.chain,
toChain: partner.chain,
bridge: 'xtoken-' + transfer.chain,
},
{ nonce: 'desc' }
);
latestNonce = firstRecord ? Number(firstRecord.nonce) : 0;
}

const query = `query { transferRecords(first: ${this.baseConfigure.fetchHistoryDataFirst}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, direction, remoteChainId, nonce, userNonce, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee, extData } }`;
const query = `query { transferRecords(where: {remoteChainId: ${partner.chainId}}, first: ${this.baseConfigure.fetchHistoryDataFirst}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, direction, remoteChainId, nonce, userNonce, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee, extData } }`;

const records = await axios
.post(transfer.url, {
Expand Down Expand Up @@ -193,13 +209,20 @@ export class xTokenService implements OnModuleInit {
}

async fetchStatus(transfer: PartnerT2, index: number) {
const partner = this.findPartner(transfer);
if (partner === null) {
this.logger.error(`xtoken can't find partner ${transfer.chainId}, ${transfer.bridge}`);
return;
}

try {
const uncheckedRecords = await this.aggregationService
.queryHistoryRecords({
skip: this.fetchCache[index].skip,
take: this.baseConfigure.takeEachTime,
where: {
fromChain: transfer.chain,
toChain: partner.chain,
bridge: `xtoken-${transfer.chain}`,
responseTxHash: '',
},
Expand Down

0 comments on commit 265f475

Please sign in to comment.