-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
b54cdb4
to
534ce8c
Compare
89158a5
to
5147932
Compare
b70740e
to
d92e50e
Compare
src/mappings/events/balances.ts
Outdated
logger.info(`Created new entry for address: ${address}`); | ||
} | ||
|
||
function validateBLDTransaction(amount: string | null): BLDTransaction { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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}`
);
aca9e3e
to
98ef89c
Compare
13b19f2
to
df83db2
Compare
for (let denom of supportedDenominations) { | ||
if (coin.endsWith(denom)) { | ||
result.isValidTransaction = true; | ||
result.coins.push({ amount: coin.slice(0, -denom.length), denom }); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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] }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
df83db2
to
d3bdefd
Compare
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
for (let denom of supportedDenominations) { | ||
if (coin.endsWith(denom)) { | ||
result.isValidTransaction = true; | ||
result.coins.push({ amount: coin.slice(0, -denom.length), denom }); | ||
} | ||
} |
There was a problem hiding this comment.
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
9636fec
to
1c35103
Compare
1c35103
to
c8eddf7
Compare
No description provided.