From 4f6ca96975f6ae9e3dff0d35d9dcc36a40d1cf85 Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Wed, 2 Oct 2024 21:02:34 +0900 Subject: [PATCH] chore(p/grc20): Distinct Event Types for GRC20 Functions (#2749) # Description Currently, the event type for grc20 is uniformly set to `TrasferEvent` (execpt for `Approval` function), which necessitated making RPC calls to check every block. Therefore, I have modified it by adding event types for each function to distinguish them from one another. In this case, we can reduce the number of RPC calls by retrieving data only when the target event type occurs.
Contributors' checklist... - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
Co-authored-by: Morgan --- examples/gno.land/p/demo/grc/grc20/banker.gno | 8 +++----- examples/gno.land/p/demo/grc/grc20/types.gno | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gno.land/p/demo/grc/grc20/banker.gno b/examples/gno.land/p/demo/grc/grc20/banker.gno index f643d3e2635..7a3ebb18ef5 100644 --- a/examples/gno.land/p/demo/grc/grc20/banker.gno +++ b/examples/gno.land/p/demo/grc/grc20/banker.gno @@ -64,7 +64,7 @@ func (b *Banker) Mint(address std.Address, amount uint64) error { b.balances.Set(string(address), newBalance) std.Emit( - TransferEvent, + MintEvent, "from", "", "to", string(address), "value", strconv.Itoa(int(amount)), @@ -90,7 +90,7 @@ func (b *Banker) Burn(address std.Address, amount uint64) error { b.balances.Set(string(address), newBalance) std.Emit( - TransferEvent, + BurnEvent, "from", string(address), "to", "", "value", strconv.Itoa(int(amount)), @@ -146,9 +146,6 @@ func (b *Banker) Transfer(from, to std.Address, amount uint64) error { toBalance := b.BalanceOf(to) fromBalance := b.BalanceOf(from) - // debug. - // println("from", from, "to", to, "amount", amount, "fromBalance", fromBalance, "toBalance", toBalance) - if fromBalance < amount { return ErrInsufficientBalance } @@ -165,6 +162,7 @@ func (b *Banker) Transfer(from, to std.Address, amount uint64) error { "to", to.String(), "value", strconv.Itoa(int(amount)), ) + return nil } diff --git a/examples/gno.land/p/demo/grc/grc20/types.gno b/examples/gno.land/p/demo/grc/grc20/types.gno index fe3aef349d9..201c6638914 100644 --- a/examples/gno.land/p/demo/grc/grc20/types.gno +++ b/examples/gno.land/p/demo/grc/grc20/types.gno @@ -56,6 +56,8 @@ type Token interface { } const ( + MintEvent = "Mint" + BurnEvent = "Burn" TransferEvent = "Transfer" ApprovalEvent = "Approval" )