-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
189 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
module gno.land/r/x/grc20_dynamic_call/registry | ||
|
||
require ( | ||
gno.land/p/demo/ufmt v0.0.0-latest | ||
gno.land/r/demo/users v0.0.0-latest | ||
gno.land/r/x/grc20_dynamic_call/bar v0.0.0-latest | ||
gno.land/r/x/grc20_dynamic_call/baz v0.0.0-latest | ||
gno.land/r/x/grc20_dynamic_call/foo v0.0.0-latest | ||
gno.land/r/x/grc20_dynamic_call/wrapper v0.0.0-latest | ||
) |
87 changes: 87 additions & 0 deletions
87
examples/gno.land/r/x/grc20_dynamic_call/registry/z_0_transfer_filetest.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// PKGPATH: gno.land/r/x/grc20_dynamic_call/registries_test | ||
package registries_test | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/testutils" | ||
|
||
"gno.land/r/x/grc20_dynamic_call/registry" | ||
|
||
"gno.land/r/x/grc20_dynamic_call/bar" | ||
"gno.land/r/x/grc20_dynamic_call/foo" | ||
|
||
"gno.land/r/demo/users" | ||
) | ||
|
||
var ( | ||
actualRealmAddr std.Address | ||
transferTo std.Address | ||
) | ||
|
||
// FOO | ||
type FooStruct struct{} | ||
|
||
func (FooStruct) Transfer() func(to users.AddressOrName, amount uint64) { | ||
return foo.Transfer | ||
} | ||
func (FooStruct) TransferFrom() func(from, to users.AddressOrName, amount uint64) { | ||
return foo.TransferFrom | ||
} | ||
func (FooStruct) BalanceOf() func(owner users.AddressOrName) uint64 { | ||
return foo.BalanceOf | ||
} | ||
|
||
// BAR | ||
type BarStruct struct{} | ||
|
||
func (BarStruct) Transfer() func(to users.AddressOrName, amount uint64) { | ||
return bar.Transfer | ||
} | ||
func (BarStruct) TransferFrom() func(from, to users.AddressOrName, amount uint64) { | ||
return bar.TransferFrom | ||
} | ||
func (BarStruct) BalanceOf() func(owner users.AddressOrName) uint64 { | ||
return bar.BalanceOf | ||
} | ||
|
||
func init() { | ||
registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/foo", FooStruct{}) | ||
registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/bar", BarStruct{}) | ||
|
||
actualRealmAddr = std.DerivePkgAddr("gno.land/r/x/grc20_dynamic_call/registry") | ||
|
||
transferTo = testutils.TestAddress("transferTo") | ||
} | ||
|
||
func main() { | ||
// FOO | ||
fooBalanceRealm := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", actualRealmAddr) | ||
println(fooBalanceRealm) | ||
|
||
fooBalanceTo := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", transferTo) | ||
println(fooBalanceTo) | ||
|
||
registry.TransferByInterface("gno.land/r/x/grc20_dynamic_call/foo", transferTo, 12345) | ||
fooBalanceTo = registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", transferTo) | ||
println(fooBalanceTo) | ||
|
||
// BAR | ||
barBalanceRealm := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/bar", actualRealmAddr) | ||
println(barBalanceRealm) | ||
|
||
barBalanceTo := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/bar", transferTo) | ||
println(barBalanceTo) | ||
|
||
registry.TransferByInterface("gno.land/r/x/grc20_dynamic_call/bar", transferTo, 54321) | ||
barBalanceTo = registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/bar", transferTo) | ||
println(barBalanceTo) | ||
} | ||
|
||
// Output: | ||
// 10000000 | ||
// 0 | ||
// 12345 | ||
// 10000000 | ||
// 0 | ||
// 54321 |
79 changes: 79 additions & 0 deletions
79
examples/gno.land/r/x/grc20_dynamic_call/registry/z_1_transferfrom_filetest.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/testutils" | ||
|
||
"gno.land/r/x/grc20_dynamic_call/registry" | ||
|
||
"gno.land/r/x/grc20_dynamic_call/bar" | ||
"gno.land/r/x/grc20_dynamic_call/foo" | ||
|
||
"gno.land/r/demo/users" | ||
) | ||
|
||
var ( | ||
actualRealmAddr std.Address | ||
|
||
transferFromFrom std.Address = testutils.TestAddress("transferFromFrom") | ||
transferFromTo std.Address = testutils.TestAddress("transferFromTo") | ||
) | ||
|
||
// FOO | ||
type FooStruct struct{} | ||
|
||
func (FooStruct) Transfer() func(to users.AddressOrName, amount uint64) { | ||
return foo.Transfer | ||
} | ||
func (FooStruct) TransferFrom() func(from, to users.AddressOrName, amount uint64) { | ||
return foo.TransferFrom | ||
} | ||
func (FooStruct) BalanceOf() func(owner users.AddressOrName) uint64 { | ||
return foo.BalanceOf | ||
} | ||
|
||
// BAR | ||
type BarStruct struct{} | ||
|
||
func (BarStruct) Transfer() func(to users.AddressOrName, amount uint64) { | ||
return bar.Transfer | ||
} | ||
func (BarStruct) TransferFrom() func(from, to users.AddressOrName, amount uint64) { | ||
return bar.TransferFrom | ||
} | ||
func (BarStruct) BalanceOf() func(owner users.AddressOrName) uint64 { | ||
return bar.BalanceOf | ||
} | ||
|
||
func init() { | ||
registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/foo", FooStruct{}) | ||
registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/bar", BarStruct{}) | ||
|
||
actualRealmAddr = std.DerivePkgAddr("gno.land/r/x/grc20_dynamic_call/registry") | ||
} | ||
|
||
func main() { | ||
foo.Faucet() | ||
foo.Approve(users.AddressOrName(std.DerivePkgAddr("gno.land/r/x/grc20_dynamic_call/registry")), 1000*10000) | ||
|
||
fooBalanceOrigCaller := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", std.GetOrigCaller()) | ||
println(fooBalanceOrigCaller) | ||
|
||
fooBalanceTo := registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", transferFromTo) | ||
println(fooBalanceTo) | ||
|
||
registry.TransferFromByInterface("gno.land/r/x/grc20_dynamic_call/foo", std.GetOrigCaller(), transferFromTo, 54321) | ||
|
||
fooBalanceOrigCaller = registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", std.GetOrigCaller()) | ||
println(fooBalanceOrigCaller) | ||
|
||
fooBalanceTo = registry.BalanceOfByInterface("gno.land/r/x/grc20_dynamic_call/foo", transferFromTo) | ||
println(fooBalanceTo) | ||
} | ||
|
||
// Output: | ||
// 10000000 | ||
// 0 | ||
// 9945679 | ||
// 54321 |