Skip to content

Commit

Permalink
fix: correctly extract sender account from paying for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt authored and kenodressel committed Nov 19, 2024
1 parent b501bd6 commit 6830daf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/clients/mdw-http-client.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,20 @@ export type TransactionWithContext = {
micro_index: string;
micro_time: string;
signatures: string[];
tx: Transaction;
tx: Transaction | PayingForTx;
};

export type PayingForTx = {
type: PayingForTxType;
tx: {
tx: Transaction;
};
};

export enum PayingForTxType {
PayingForTx = 'PayingForTx',
}

export type Transaction = {
abi_version: string;
aexn_type: string | null;
Expand Down
23 changes: 21 additions & 2 deletions src/clients/mdw-http-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
ContractLog,
MdwMicroBlock,
MdwPaginatedResponse,
PayingForTx,
PayingForTxType,
Transaction,
TransactionWithContext,
} from '@/clients/mdw-http-client.model';
import {
Expand Down Expand Up @@ -91,7 +94,10 @@ export class MdwHttpClientService {
async getSenderAccountForTransaction(txHash: TxHash): Promise<string> {
if (!this.transactionSenderMapping.has(txHash)) {
const tx = await this.getTransaction(txHash);
this.transactionSenderMapping.set(txHash, tx.tx.caller_id);
this.transactionSenderMapping.set(
txHash,
this.getSenderFromTransaction(tx),
);
}
return this.transactionSenderMapping.get(txHash)!;
}
Expand All @@ -105,7 +111,10 @@ export class MdwHttpClientService {
`/v3/transactions?contract_id=${process.env.ROUTER_ADDRESS}&${this.defaultParams}`,
);
transactions.forEach((tx) => {
this.transactionSenderMapping.set(tx.hash, tx.tx.caller_id);
this.transactionSenderMapping.set(
tx.hash,
this.getSenderFromTransaction(tx),
);
});
}

Expand Down Expand Up @@ -140,4 +149,14 @@ export class MdwHttpClientService {

return result.data;
}

private getSenderFromTransaction(
transactionWithContext: TransactionWithContext,
): string {
if (transactionWithContext.tx.type === PayingForTxType.PayingForTx) {
return (transactionWithContext.tx as PayingForTx).tx.tx.caller_id;
} else {
return (transactionWithContext.tx as Transaction).caller_id;
}
}
}

0 comments on commit 6830daf

Please sign in to comment.