Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: index balance events #9

Closed
wants to merge 13 commits into from
Closed

Conversation

rabi-siddique
Copy link
Collaborator

No description provided.

@rabi-siddique rabi-siddique marked this pull request as draft April 30, 2024 10:46
@rabi-siddique rabi-siddique force-pushed the rs-index-transter-events branch 2 times, most recently from 89158a5 to 5147932 Compare April 30, 2024 13:18
@rabi-siddique rabi-siddique changed the title feat: index transfer events feat: index balance events Apr 30, 2024
@rabi-siddique rabi-siddique force-pushed the rs-index-transter-events branch 5 times, most recently from b70740e to d92e50e Compare May 2, 2024 11:47
logger.info(`Created new entry for address: ${address}`);
}

function validateBLDTransaction(amount: string | null): BLDTransaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not limit just to BLD, and instead let any token balance be indexed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can do that. We'll need to discuss the schema design for that.
With the current schema, we'll be updating the same amount field for each token.

const currentBalance = balance.balance ?? BigInt(0);
let newBalance: bigint;

if (operation === Operation.Increment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend removing the if condition and replacing it with lambda operation like below. Also suggesting two log statements that works for both scenarios.

      newBalance = operation(currentBalance, amount);

      if (newBalance < 0) {
        logger.error(
          `Attempt to update ${amount} would result in a negative balance. Current balance: ${currentBalance}.`
        );
        return;
      }
      balance.balance = newBalance;
      logger.info(
        `Updated balance for ${address} by ${amount}. New balance: ${balance.balance}`
      );

src/mappings/mappingHandlers.ts Outdated Show resolved Hide resolved
@rabi-siddique rabi-siddique force-pushed the rs-index-transter-events branch 6 times, most recently from aca9e3e to 98ef89c Compare May 3, 2024 15:52
Comment on lines +122 to +127
for (let denom of supportedDenominations) {
if (coin.endsWith(denom)) {
result.isValidTransaction = true;
result.coins.push({ amount: coin.slice(0, -denom.length), denom });
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (let denom of supportedDenominations) {
if (coin.endsWith(denom)) {
result.isValidTransaction = true;
result.coins.push({ amount: coin.slice(0, -denom.length), denom });
}
}
result.isValidTransaction = true;
result.coins.push({ amount: (coin.match(/^\d+/) || [""])[0] , denom: (coin.match(/[a-zA-Z]+.*$/) || [""])[0] });

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is convenient. Should we add this snippet now? It will index another token with the denomination ibc/someHugeNumber that I've seen in the logs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibc/someHugeNumber is a fungible token created when a token is recieved from another chain through an IBC transaction.
the number after it might mess with the regex that @toliaqat has suggested

Comment on lines +35 to +48
function getData(cosmosEvent: CosmosEvent) {
let dataAlreadyDecoded = true;
const value = getAttributeValue(cosmosEvent.event, BALANCE_FIELDS.amount);

if (!value) {
dataAlreadyDecoded = false;
}

const data = dataAlreadyDecoded
? cosmosEvent.event
: decodeEvent(cosmosEvent);

return data;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this function assume the value isnt decoded?
an encoded event might look like this:

{
    type: 'foo',
    attributes: [
        {
            key: "asdjkhasd",
            value: "nasjdh23",
    ]
}

the value here will be b64 encoded but it will still be truthy, so shouldnt this function return a false negative?

Copy link
Collaborator Author

@rabi-siddique rabi-siddique May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks whether the key has the value amount. If it does, the data is decoded. If it doesn't, the data is encoded. You will need to look getAttributeValue for more details. We're tracking events that must have an amount present in the object

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I skimmed your PR for IBC on Friday........Maybe I'll reuse your code for decoding/encoding.

Comment on lines +122 to +127
for (let denom of supportedDenominations) {
if (coin.endsWith(denom)) {
result.isValidTransaction = true;
result.coins.push({ amount: coin.slice(0, -denom.length), denom });
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibc/someHugeNumber is a fungible token created when a token is recieved from another chain through an IBC transaction.
the number after it might mess with the regex that @toliaqat has suggested

@rabi-siddique rabi-siddique marked this pull request as ready for review May 6, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants