From 6ef676830a67b1ea9a4ce555414b392771fba7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaza=C3=AF?= <149690535+kazai777@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:46:02 +0100 Subject: [PATCH] docs: Update creating-grc20.md add missing imports and modified the call to `AddressOrName()` by adding an alias `pusers` to access the `users` package functions. And modified calls to `Resolve()` by adding the prefix `users`. --- docs/how-to-guides/creating-grc20.md | 46 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/docs/how-to-guides/creating-grc20.md b/docs/how-to-guides/creating-grc20.md index d00fd8c349e..1b278479708 100644 --- a/docs/how-to-guides/creating-grc20.md +++ b/docs/how-to-guides/creating-grc20.md @@ -56,65 +56,79 @@ In this code preview, we have: The following section will be about introducing Public functions to expose functionality imported from the [grc20 package](https://github.com/gnolang/gno/tree/master/examples/gno.land/p/demo/grc/grc20). +Add this imports : + +```go +import ( + .... + "strings" + + "gno.land/p/demo/ufmt" + "gno.land/r/demo/users" + + pusers "gno.land/p/demo/users" +) +``` + [embedmd]:# (../assets/how-to-guides/creating-grc20/mytoken-2.gno go) ```go func TotalSupply() uint64 { return mytoken.TotalSupply() } -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := mytoken.BalanceOf(owner.Resolve()) +func BalanceOf(owner pusers.AddressOrName) uint64 { + balance, err := mytoken.BalanceOf(users.Resolve(owner)) if err != nil { panic(err) } return balance } -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := mytoken.Allowance(owner.Resolve(), spender.Resolve()) +func Allowance(owner, spender pusers.AddressOrName) uint64 { + allowance, err := mytoken.Allowance(users.Resolve(owner), users.Resolve(spender)) if err != nil { panic(err) } return allowance } -func Transfer(to users.AddressOrName, amount uint64) { +func Transfer(to pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := mytoken.Transfer(caller, to.Resolve(), amount) + err := mytoken.Transfer(caller, users.Resolve(to), amount) if err != nil { panic(err) } } -func Approve(spender users.AddressOrName, amount uint64) { +func Approve(spender pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := mytoken.Approve(caller, spender.Resolve(), amount) + err := mytoken.Approve(caller, users.Resolve(spender), amount) if err != nil { panic(err) } } -func TransferFrom(from, to users.AddressOrName, amount uint64) { +func TransferFrom(from, to pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() - err := mytoken.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) + err := mytoken.TransferFrom(caller, users.Resolve(from), users.Resolve(to), amount) if err != nil { panic(err) } } -func Mint(address users.AddressOrName, amount uint64) { +func Mint(address pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() assertIsAdmin(caller) - err := mytoken.Mint(address.Resolve(), amount) + err := mytoken.Mint(users.Resolve(address), amount) if err != nil { panic(err) } } -func Burn(address users.AddressOrName, amount uint64) { +func Burn(address pusers.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() assertIsAdmin(caller) - err := mytoken.Burn(address.Resolve(), amount) + err := mytoken.Burn(users.Resolve(address), amount) if err != nil { panic(err) } @@ -128,8 +142,8 @@ func Render(path string) string { case path == "": return mytoken.RenderHome() case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := mytoken.BalanceOf(owner.Resolve()) + owner := pusers.AddressOrName(parts[1]) + balance, _ := mytoken.BalanceOf(users.Resolve(owner)) return ufmt.Sprintf("%d\n", balance) default: return "404\n"