Skip to content

Commit

Permalink
user nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Dec 25, 2023
1 parent e46f259 commit d9b2955
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export class xTokenService implements OnModuleInit {
);
}

private toMessageNonce(messageId: string, nonce: string): string {
return `${nonce}-${messageId}`;
}

private toMessageId(messageNonce: string): string {
return last(messageNonce.split('-'));
}

private getToken(chain: PartnerT2, symbolOrAddress: string): PartnerSymbol | null {
return (
chain.symbols.find(
Expand Down Expand Up @@ -106,7 +114,7 @@ export class xTokenService implements OnModuleInit {
latestNonce = firstRecord ? Number(firstRecord.nonce) : 0;
}

const query = `query { transferRecords(first: ${this.baseConfigure.fetchHistoryDataFirst}, orderBy: nonce, orderDirection: asc, skip: ${latestNonce}) { id, direction, remoteChainId, nonce, messageId, sender, receiver, token, amount, timestamp, transactionHash, fee } }`;
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 } }`;

const records = await axios
.post(transfer.url, {
Expand Down Expand Up @@ -143,7 +151,7 @@ export class xTokenService implements OnModuleInit {
fromChain: transfer.chain,
toChain: toChain.chain,
bridge: 'xtoken-' + transfer.chain,
messageNonce: record.messageId,
messageNonce: this.toMessageNonce(record.messageId, record.userNonce),
nonce: latestNonce + 1,
requestTxHash: record.transactionHash,
sender: record.sender,
Expand Down Expand Up @@ -198,7 +206,7 @@ export class xTokenService implements OnModuleInit {

for (const uncheckedRecord of uncheckedRecords) {
const sourceId = this.nodeIdToTransferId(uncheckedRecord.id);
const messageId = uncheckedRecord.messageNonce;
const messageId = this.toMessageId(uncheckedRecord.messageNonce);
const node = await axios
.post(this.transferService.dispatchEndPoints[uncheckedRecord.toChain], {
query: `query { messageDispatchedResult (id: \"${messageId}\") { id, token, transactionHash, result, timestamp }}`,
Expand Down
1 change: 1 addition & 0 deletions subgraph/xtoken/transfer/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type TransferRecord @entity {
timestamp: BigInt!
transactionHash: Bytes!
fee: BigInt
userNonce: String!
}

type RefundTransferRecord @entity {
Expand Down
1 change: 1 addition & 0 deletions subgraph/xtoken/transfer/src/xTokenBacking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function handleTokenLocked(event: TokenLocked): void {
entity.transactionHash = event.transaction.hash;
entity.timestamp = event.block.timestamp;
entity.fee = event.params.fee;
entity.userNonce = event.params.nonce.toHexString();

var messageId: string;
// find the messageId
Expand Down
1 change: 1 addition & 0 deletions subgraph/xtoken/transfer/src/xTokenIssuing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function handleBurnAndRemoteUnlocked(event: BurnAndRemoteUnlocked): void
entity.transactionHash = event.transaction.hash;
entity.timestamp = event.block.timestamp;
entity.fee = event.params.fee;
entity.userNonce = event.params.nonce.toHexString();

var messageId: string;
// find the messageId
Expand Down

0 comments on commit d9b2955

Please sign in to comment.