Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: moul <[email protected]>
  • Loading branch information
moul committed Jul 5, 2024
1 parent a65537b commit e8668f0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/gno.land/r/demo/foo20/foo20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ var (

func init() {
foo = grc20.NewAdminToken("Foo", "FOO", 4)
grc20reg.Register(foo.GRC20(), "")
pub := foo.GRC20()
proxy := grc20reg.Proxify(pub)
grc20reg.Register(proxy.GetName, "")
foo.Mint(admin, 1000000*10000) // @administrator (1M)
foo.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10000*10000) // @manfred (10k)
}
Expand Down
6 changes: 5 additions & 1 deletion examples/gno.land/r/demo/grc20reg/grc20reg.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import (

var registry = avl.NewTree() // pkg path -> IGRC20

// func Register(getName func() string, slug string) {

func Register(token grc20.IGRC20, slug string) {
// proxy := tmpproxy{getName: getName}
proxy := Proxify(token)
rlmPath := std.PrevRealm().PkgPath()
key := fqname.Construct(rlmPath, slug)
registry.Set(key, token)
registry.Set(key, proxy)
std.Emit(
registerEvent,
"pkgpath", rlmPath,
Expand Down
57 changes: 57 additions & 0 deletions examples/gno.land/r/demo/grc20reg/tmp_proxy.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package grc20reg

import (
"std"

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

// FIXME; delete this file.
// we currently have a gnovm limitation:
//
// panic: cannot modify external-realm or non-realm object
type tmpproxy struct {
getName func() string
getSymbol func() string
getDecimals func() uint
totalSupply func() uint64
balanceOf func(std.Address) (uint64, error)
transfer func(std.Address, uint64) error
allowance func(owner, spender std.Address) (uint64, error)
approve func(std.Address, uint64) error
transferFrom func(from, to std.Address, amount uint64) error
}

func Proxify(input grc20.IGRC20) *tmpproxy {
return &tmpproxy{
getName: input.GetName,
getSymbol: input.GetSymbol,
getDecimals: input.GetDecimals,
totalSupply: input.TotalSupply,
balanceOf: input.BalanceOf,
transfer: input.Transfer,
allowance: input.Allowance,
approve: input.Approve,
transferFrom: input.TransferFrom,
}
}

var _ grc20.IGRC20 = (*tmpproxy)(nil)

func (impl *tmpproxy) GetName() string { return impl.getName() }
func (impl *tmpproxy) GetSymbol() string { return impl.getSymbol() }
func (impl *tmpproxy) GetDecimals() uint { return impl.getDecimals() }
func (impl *tmpproxy) TotalSupply() uint64 { return impl.totalSupply() }
func (impl *tmpproxy) BalanceOf(account std.Address) (uint64, error) { return impl.balanceOf(account) }
func (impl *tmpproxy) Transfer(to std.Address, amount uint64) error { return impl.transfer(to, amount) }
func (impl *tmpproxy) Allowance(owner, spender std.Address) (uint64, error) {
return impl.allowance(owner, spender)
}

func (impl *tmpproxy) Approve(spender std.Address, amount uint64) error {
return impl.approve(spender, amount)
}

func (impl *tmpproxy) TransferFrom(from, to std.Address, amount uint64) error {
return impl.transferFrom(from, to, amount)
}
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/wugnot/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ 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/grc20reg v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
)
9 changes: 6 additions & 3 deletions examples/gno.land/r/demo/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

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

"gno.land/r/demo/users"

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

var (
Expand All @@ -19,6 +18,10 @@ var (
WUGNOT = wugnot.GRC20()
)

func init() {
grc20reg.Register(WUGNOT, "")
}

const (
ugnotMinDeposit uint64 = 1000
wugnotMinDeposit uint64 = 1
Expand Down

0 comments on commit e8668f0

Please sign in to comment.