Skip to content

Commit

Permalink
Merge pull request #33 from helix-bridge/xiaoch05-lnv2-previousTransf…
Browse files Browse the repository at this point in the history
…erId

get lnv2 previous transfer id
  • Loading branch information
xiaoch05 authored Jul 22, 2024
2 parents 76bbfd2 + 3c22d79 commit 80333ec
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/dataworker/dataworker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class DataworkerService implements OnModuleInit {
token: \"${token.toLowerCase()}\",
order: "${firstPendingOrderBy}",
notsubmited: true
) {id, startTime, sendTokenAddress, recvToken, sender, relayer, recipient, sendAmount, recvAmount, fromChain, toChain, reason, fee, requestTxHash, confirmedBlocks, messageNonce}}`;
) {id, startTime, sendTokenAddress, recvToken, sender, relayer, recipient, sendAmount, recvAmount, fromChain, toChain, reason, fee, requestTxHash, confirmedBlocks, messageNonce, nonce}}`;
const pendingRecord = await axios
.post(url, {
query,
Expand All @@ -114,30 +114,28 @@ export class DataworkerService implements OnModuleInit {
};
}

// query the first successed record
// query the previous transfer record
query = `query {
firstHistoryRecord(
fromChain: \"${fromChain}\",
toChain: \"${toChain}\",
bridge: \"${bridgeType}\",
results: [${this.statusSuccess}, ${this.statusRefund}, ${
this.pendingToConfirmRefund
}],
relayer: \"${relayer.toLowerCase()}\",
token: \"${token.toLowerCase()}\",
order: "${lastSuccessOrderBy}"
) {id}}`;
const lastRecord = await axios
previousHistoryRecord(
fromChain: \"${fromChain}\",
toChain: \"${toChain}\",
bridge: \"${bridgeType}\",
relayer: \"${relayer.toLowerCase()}\",
token: \"${token.toLowerCase()}\",
nonce: ${Number(pendingRecord.nonce)}
) {id}}`;

const previousRecord = await axios
.post(url, {
query,
variables: null,
})
.then((res) => res.data.data.firstHistoryRecord);
.then((res) => res.data.data.previousHistoryRecord);

const lastTransferId =
lastRecord === null ? zeroTransferId : last(lastRecord.id.split("-"));
const previousTransferId =
previousRecord === null ? zeroTransferId : last(previousRecord.id.split("-"));
return {
lastTransferId: lastTransferId,
lastTransferId: previousTransferId,
record: pendingRecord,
};
}
Expand Down

0 comments on commit 80333ec

Please sign in to comment.