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

chore: use std.PrevRealm() in grc20 and grc721 #895

Merged
merged 2 commits into from
Jul 4, 2023
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
10 changes: 5 additions & 5 deletions examples/gno.land/p/demo/grc/grc20/user_token.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ func (t *userToken) BalanceOf(owner std.Address) (uint64, error) {
}

func (t *userToken) Transfer(to std.Address, amount uint64) error {
owner := std.GetOrigCaller()
return t.admin.transfer(owner, to, amount)
caller := std.PrevRealm().Addr()
return t.admin.transfer(caller, to, amount)
}

func (t *userToken) Allowance(owner, spender std.Address) (uint64, error) {
return t.admin.allowance(owner, spender)
}

func (t *userToken) Approve(spender std.Address, amount uint64) error {
owner := std.GetOrigCaller()
return t.admin.approve(owner, spender, amount)
caller := std.PrevRealm().Addr()
return t.admin.approve(caller, spender, amount)
}

func (t *userToken) TransferFrom(from, to std.Address, amount uint64) error {
spender := std.GetOrigCaller()
spender := std.PrevRealm().Addr()
if err := t.admin.spendAllowance(from, spender, amount); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestSetApprovalForAll(t *testing.T) {
t.Errorf("should not be nil")
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

isApprovedForAll := dummy.IsApprovedForAll(caller, addr.Resolve())
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestApprove(t *testing.T) {
t.Errorf("should not be nil")
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

dummy.mint(caller, TokenID("1"))
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestTransferFrom(t *testing.T) {
t.Errorf("should not be nil")
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

dummy.mint(caller, TokenID("1"))
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestSafeTransferFrom(t *testing.T) {
t.Errorf("should not be nil")
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
addr := users.AddressOrName("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

dummy.mint(caller, TokenID("1"))
Expand Down
12 changes: 6 additions & 6 deletions examples/gno.land/r/demo/foo20/foo20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func Allowance(owner, spender users.AddressOrName) uint64 {
// setters.

func Transfer(to users.AddressOrName, amount uint64) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
foo.Transfer(caller, to.Resolve(), amount)
}

func Approve(spender users.AddressOrName, amount uint64) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
foo.Approve(caller, spender.Resolve(), amount)
}

func TransferFrom(from, to users.AddressOrName, amount uint64) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
foo.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
}

Expand All @@ -67,20 +67,20 @@ func TransferFrom(from, to users.AddressOrName, amount uint64) {
func Faucet() {
// FIXME: add limits?
// FIXME: add payment in gnot?
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
foo.Mint(caller, 1000*10000) // 1k
}

// administration.

func Mint(address users.AddressOrName, amount uint64) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
foo.Mint(address.Resolve(), amount)
}

func Burn(address users.AddressOrName, amount uint64) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
foo.Burn(address.Resolve(), amount)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/foo721/foo721.gno
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) {
// Admin

func Mint(to users.AddressOrName, tid grc721.TokenID) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := foo.Mint(to.Resolve(), tid)
if err != nil {
Expand All @@ -94,7 +94,7 @@ func Mint(to users.AddressOrName, tid grc721.TokenID) {
}

func Burn(tid grc721.TokenID) {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := foo.Burn(tid)
if err != nil {
Expand Down