Skip to content

Commit

Permalink
add support for events topics (#1131)
Browse files Browse the repository at this point in the history
* first iteration

* interpret transferValueOnly events when topics count is 2

* Revert "first iteration"

This reverts commit 8d1b307.

---------

Co-authored-by: tanghel <tanghel@live.com>
  • Loading branch information
cfaur09 and tanghel authored Oct 26, 2023
1 parent cbdb4c0 commit cce7598
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/endpoints/tokens/token.transfer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,21 @@ export class TokenTransferService {

private getTransactionTransferValueOperation(txHash: string, log: TransactionLog, event: TransactionLogEvent, action: TransactionOperationAction): TransactionOperation | undefined {
try {
const sender = BinaryUtils.base64ToAddress(event.topics[0]);
const receiver = BinaryUtils.base64ToAddress(event.topics[1]);
const value = BinaryUtils.base64ToBigInt(event.topics[2]).toString();
let sender: string;
let receiver: string;
let value: string;

if (event.topics.length === 2) {
sender = event.address;
receiver = BinaryUtils.base64ToAddress(event.topics[1]);
value = BinaryUtils.base64ToBigInt(event.topics[0]).toString();
} else if (event.topics.length === 3) {
sender = BinaryUtils.base64ToAddress(event.topics[0]);
receiver = BinaryUtils.base64ToAddress(event.topics[1]);
value = BinaryUtils.base64ToBigInt(event.topics[2]).toString();
} else {
throw new Error(`Unrecognized topic count when interpreting transferValue event`);
}

const operation = new TransactionOperation();
operation.id = log.id ?? '';
Expand Down

0 comments on commit cce7598

Please sign in to comment.