diff --git a/src/clients/mdw-http-client.model.ts b/src/clients/mdw-http-client.model.ts index 95398cc4..ee7ba673 100644 --- a/src/clients/mdw-http-client.model.ts +++ b/src/clients/mdw-http-client.model.ts @@ -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; diff --git a/src/clients/mdw-http-client.service.ts b/src/clients/mdw-http-client.service.ts index 0951a8b4..831f1ba5 100644 --- a/src/clients/mdw-http-client.service.ts +++ b/src/clients/mdw-http-client.service.ts @@ -8,6 +8,9 @@ import { ContractLog, MdwMicroBlock, MdwPaginatedResponse, + PayingForTx, + PayingForTxType, + Transaction, TransactionWithContext, } from '@/clients/mdw-http-client.model'; import { @@ -91,7 +94,10 @@ export class MdwHttpClientService { async getSenderAccountForTransaction(txHash: TxHash): Promise { 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)!; } @@ -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), + ); }); } @@ -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; + } + } }