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: cw20 handle mint/transfer/burn/send #178

Merged
merged 13 commits into from
Jun 21, 2023
Merged

feat: cw20 handle mint/transfer/burn/send #178

merged 13 commits into from
Jun 21, 2023

Conversation

phamphong9981
Copy link
Collaborator

No description provided.

@phamphong9981 phamphong9981 changed the title feat: just support events whose cw20 contracts in DB feat: cw20 handle mint/transfer/burn/send Jun 15, 2023
@phamphong9981 phamphong9981 reopened this Jun 15, 2023
cw20BurnEvents.forEach((burnEvent) => {
if (burnEvent.amount) {
addAmount = (
BigInt(addAmount) + BigInt(`-${burnEvent.amount}`)
Copy link
Member

Choose a reason for hiding this comment

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

.

if (addBalanceHolders[event.from]) {
// sub balance for sender
addBalanceHolders[event.from].amount = (
BigInt(addBalanceHolders[event.from].amount) +
Copy link
Member

Choose a reason for hiding this comment

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

.

}
}

async _start(): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

ko làm gì thì thôi?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

addBalanceHolders[event.from].last_updated_height = event.height;
} else {
addBalanceHolders[event.from] = {
address: event.from,
Copy link
Member

Choose a reason for hiding this comment

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

cái này ko dùng

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

if (event.amount) {
// sender
if (event.from) {
if (addBalanceHolders[event.from]) {
Copy link
Member

@peara peara Jun 19, 2023

Choose a reason for hiding this comment

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

addBalanceHolders[event.from] = {
  amount: (addBalanceHolders[event.from]?.amount || BigInt(0)) + BigInt(event.amount),
  last_updated_height: event.height
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

// eslint-disable-next-line no-restricted-syntax
for (const cw20ContractId of ctx.params.cw20ContractIds) {
// eslint-disable-next-line no-await-in-loop
await this.createJob(
Copy link
Member

Choose a reason for hiding this comment

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

chỗ này đã unique theo contract id để ko bị lặp chưa?
nếu bị thì có sống ko?

},
})
async UpdateByContract(ctx: Context<IContextUpdateCw20>) {
let { startBlock } = ctx.params;
Copy link
Member

Choose a reason for hiding this comment

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

const { startBlock, endBlock } = ctx.params;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

const { endBlock } = ctx.params;
// eslint-disable-next-line no-restricted-syntax
for (const cw20Contract of ctx.params.cw20Contracts) {
if (startBlock < cw20Contract.last_updated_height) {
Copy link
Member

Choose a reason for hiding this comment

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

const startUpdateBlock = _.min(startBlock, cw20Contract.last_updated_height);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

endBlock: number,
trx: Knex.Transaction
) {
let addAmount = '0';
Copy link
Member

Choose a reason for hiding this comment

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

let addAmount = BigInt(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.

done

);
cw20MintEvents.forEach((mintEvent) => {
if (mintEvent.amount) {
addAmount = (BigInt(addAmount) + BigInt(mintEvent.amount)).toString();
Copy link
Member

Choose a reason for hiding this comment

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

addAmount = addAmount + BigInt(mintEvent.amount);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

});
if (Object.keys(addBalanceHolders).length > 0) {
const holders = _.keyBy(
await CW20Holder.query()
Copy link
Member

Choose a reason for hiding this comment

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

lấy luôn last_updated_height để check

@peara peara merged commit ab6c2f3 into main Jun 21, 2023
@peara peara deleted the feat/cw20 branch June 21, 2023 02:26
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.

2 participants