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

fix: make r/demo/wugnot compatible with r/demo/users #1782

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/gno.land/r/demo/wugnot/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ module gno.land/r/demo/wugnot
require (
gno.land/p/demo/grc/grc20 v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
)
24 changes: 14 additions & 10 deletions examples/gno.land/r/demo/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (

"gno.land/p/demo/grc/grc20"
"gno.land/p/demo/ufmt"

"gno.land/r/demo/users"

pusers "gno.land/p/demo/users"
)

var (
Expand Down Expand Up @@ -82,16 +86,16 @@ func TotalSupply() uint64 {
return wugnot.TotalSupply()
}

func BalanceOf(owner std.Address) uint64 {
balance, err := wugnot.BalanceOf(owner)
func BalanceOf(owner pusers.AddressOrName) uint64 {
balance, err := wugnot.BalanceOf(users.Resolve(owner))
if err != nil {
panic(err)
}
return balance
}

func Allowance(owner, spender std.Address) uint64 {
allowance, err := wugnot.Allowance(owner, spender)
func Allowance(owner, spender pusers.AddressOrName) uint64 {
allowance, err := wugnot.Allowance(users.Resolve(owner), users.Resolve(spender))
if err != nil {
panic(err)
}
Expand All @@ -101,25 +105,25 @@ func Allowance(owner, spender std.Address) uint64 {
// setters.
//

func Transfer(to std.Address, amount uint64) {
func Transfer(to pusers.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.Transfer(caller, to, amount)
err := wugnot.Transfer(caller, users.Resolve(to), amount)
if err != nil {
panic(err)
}
}

func Approve(spender std.Address, amount uint64) {
func Approve(spender pusers.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.Approve(caller, spender, amount)
err := wugnot.Approve(caller, users.Resolve(spender), amount)
if err != nil {
panic(err)
}
}

func TransferFrom(from, to std.Address, amount uint64) {
func TransferFrom(from, to pusers.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := wugnot.TransferFrom(caller, from, to, amount)
err := wugnot.TransferFrom(caller, users.Resolve(from), users.Resolve(to), amount)
if err != nil {
panic(err)
}
Expand Down
4 changes: 3 additions & 1 deletion examples/gno.land/r/demo/wugnot/z0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"gno.land/p/demo/testutils"
"gno.land/r/demo/wugnot"

pusers "gno.land/p/demo/users"
)

var (
Expand Down Expand Up @@ -37,7 +39,7 @@ func main() {

func printBalances() {
printSingleBalance := func(name string, addr std.Address) {
wugnotBal := wugnot.BalanceOf(addr)
wugnotBal := wugnot.BalanceOf(pusers.AddressOrName(addr))
std.TestSetOrigCaller(addr)
abanker := std.GetBanker(std.BankerTypeOrigSend)
acoins := abanker.GetCoins(addr).AmountOf("ugnot")
Expand Down
7 changes: 4 additions & 3 deletions gno.land/cmd/gnoland/testdata/issue-1786.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"gno.land/r/demo/wugnot"

"gno.land/p/demo/ufmt"
pusers "gno.land/p/demo/users"
)

func ProxyWrap() {
Expand All @@ -65,17 +66,17 @@ func ProxyWrap() {
wugnot.Deposit() // `proxywugnot` has ugnot

// SEND WUGNOT: PROXY_WUGNOT -> USER
wugnot.Transfer(std.GetOrigCaller(), ugnotSent)
wugnot.Transfer(pusers.AddressOrName(std.GetOrigCaller()), ugnotSent)
}

func ProxyUnwrap(wugnotAmount uint64) {
if wugnotAmount == 0 {
return
}
userOldWugnot := wugnot.BalanceOf(std.GetOrigCaller())
userOldWugnot := wugnot.BalanceOf(pusers.AddressOrName(std.GetOrigCaller()))

// SEND WUGNOT: USER -> PROXY_WUGNOT
wugnot.TransferFrom(std.GetOrigCaller(), std.CurrentRealm().Addr(), wugnotAmount)
wugnot.TransferFrom(pusers.AddressOrName(std.GetOrigCaller()), pusers.AddressOrName(std.CurrentRealm().Addr()), wugnotAmount)

// UNWRAP IT
wugnot.Withdraw(wugnotAmount)
Expand Down
Loading