Skip to content

Commit

Permalink
chore: switch to string instead of std.Address for input types on grc…
Browse files Browse the repository at this point in the history
…20 and foo20

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed May 6, 2022
1 parent 522464e commit 0c57267
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
54 changes: 27 additions & 27 deletions examples/gno.land/p/grc/grc20/impl/impl.gno
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,48 @@ func (t *Token) GetSymbol() string { return t.symbol }
func (t *Token) GetDecimals() uint { return t.decimals }
func (t *Token) TotalSupply() uint64 { return t.totalSupply }

func (t *Token) BalanceOf(address std.Address) uint64 {
address = users.GetUserByNameOrAddress(address.String()).Address()
return t.balanceOf(address)
func (t *Token) BalanceOf(owner string) uint64 {
ownerAddr := users.GetUserByNameOrAddress(owner).Address()
return t.balanceOf(ownerAddr)
}

func (t *Token) Transfer(owner, to std.Address, amount uint64) {
owner = users.GetUserByNameOrAddress(owner.String()).Address()
to = users.GetUserByNameOrAddress(to.String()).Address()
t.transfer(owner, to, amount)
func (t *Token) Transfer(owner, to string, amount uint64) {
ownerAddr := users.GetUserByNameOrAddress(owner).Address()
toAddr := users.GetUserByNameOrAddress(to).Address()
t.transfer(ownerAddr, toAddr, amount)
}

func (t *Token) Allowance(owner, spender std.Address) uint64 {
owner = users.GetUserByNameOrAddress(owner.String()).Address()
spender = users.GetUserByNameOrAddress(spender.String()).Address()
return t.allowance(owner, spender)
func (t *Token) Allowance(owner, spender string) uint64 {
ownerAddr := users.GetUserByNameOrAddress(owner).Address()
spenderAddr := users.GetUserByNameOrAddress(spender).Address()
return t.allowance(ownerAddr, spenderAddr)
}

func (t *Token) Approve(owner, spender std.Address, amount uint64) {
owner = users.GetUserByNameOrAddress(owner.String()).Address()
spender = users.GetUserByNameOrAddress(spender.String()).Address()
t.approve(owner, spender, amount)
func (t *Token) Approve(owner, spender string, amount uint64) {
ownerAddr := users.GetUserByNameOrAddress(owner).Address()
spenderAddr := users.GetUserByNameOrAddress(spender).Address()
t.approve(ownerAddr, spenderAddr, amount)
}

func (t *Token) TransferFrom(spender, from, to std.Address, amount uint64) {
spender = users.GetUserByNameOrAddress(spender.String()).Address()
from = users.GetUserByNameOrAddress(from.String()).Address()
to = users.GetUserByNameOrAddress(to.String()).Address()
t.spendAllowance(from, spender, amount)
t.transfer(from, to, amount)
func (t *Token) TransferFrom(spender, from, to string, amount uint64) {
spenderAddr := users.GetUserByNameOrAddress(spender).Address()
fromAddr := users.GetUserByNameOrAddress(from).Address()
toAddr := users.GetUserByNameOrAddress(to).Address()
t.spendAllowance(fromAddr, spenderAddr, amount)
t.transfer(fromAddr, toAddr, amount)
}

// Administration helpers implementation.
//

func (t *Token) Mint(address std.Address, amount uint64) {
address = users.GetUserByNameOrAddress(address.String()).Address()
t.mint(address, amount)
func (t *Token) Mint(to string, amount uint64) {
toAddr := users.GetUserByNameOrAddress(to).Address()
t.mint(toAddr, amount)
}

func (t *Token) Burn(address std.Address, amount uint64) {
address = users.GetUserByNameOrAddress(address.String()).Address()
t.burn(address, amount)
func (t *Token) Burn(from string, amount uint64) {
fromAddr := users.GetUserByNameOrAddress(from).Address()
t.burn(fromAddr, amount)
}

// private helpers
Expand Down
26 changes: 13 additions & 13 deletions examples/gno.land/r/foo20/foo.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ func init() {

// getters.

func TotalSupply() uint64 { return foo.TotalSupply() }
func BalanceOf(address std.Address) uint64 { return foo.BalanceOf(address) }
func Allowance(owner, spender std.Address) uint64 { return foo.Allowance(owner, spender) }
func TotalSupply() uint64 { return foo.TotalSupply() }
func BalanceOf(address string) uint64 { return foo.BalanceOf(address) }
func Allowance(owner, spender string) uint64 { return foo.Allowance(owner, spender) }

// setters.

func Transfer(to std.Address, amount uint64) {
caller := std.GetCallerAt(2)
func Transfer(to string, amount uint64) {
caller := std.GetCallerAt(2).String()
foo.Transfer(caller, to, amount)
}

func Approve(spender std.Address, amount uint64) {
caller := std.GetCallerAt(2)
func Approve(spender string, amount uint64) {
caller := std.GetCallerAt(2).String()
foo.Approve(caller, spender, amount)
}

func TransferFrom(from, to std.Address, amount uint64) {
caller := std.GetCallerAt(2)
func TransferFrom(from, to string, amount uint64) {
caller := std.GetCallerAt(2).String()
foo.TransferFrom(caller, from, to, amount)
}

// administration.

func Mint(address std.Address, amount uint64) {
func Mint(address string, amount uint64) {
caller := std.GetCallerAt(2)
assertIsAdmin(caller)
foo.Mint(address, amount)
}

func Burn(address std.Address, amount uint64) {
func Burn(address string, amount uint64) {
caller := std.GetCallerAt(2)
assertIsAdmin(caller)
foo.Burn(address, amount)
Expand All @@ -68,8 +68,8 @@ func Render(path string) string {
case path == "":
return foo.RenderHome()
case c == 2 && parts[0] == "balance":
addr := std.Address(parts[1])
balance := foo.BalanceOf(addr)
nameOrAddr := parts[1]
balance := foo.BalanceOf(nameOrAddr)
return ufmt.Sprintf("%d\n", balance)
default:
return "404\n"
Expand Down
3 changes: 2 additions & 1 deletion examples/gno.land/r/users/users.gno
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func GetUserByAddress(addr std.Address) *User {
}

func GetUserByNameOrAddress(input string) *User {
// TODO: if input matches an address, return it directly (to prevent someone registering someone else's address as its name)
// TODO: if input matches an address, return it directly.
// -> to prevent someone registering someone else's address as its name.

user := GetUserByName(input)
if user != nil {
Expand Down
6 changes: 3 additions & 3 deletions tests/files2/zrealm_foo200.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"gno.land/r/foo20"
)

var admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
var manfred = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")
var unknown = std.Address("g1u0000000000000000000000000000000000000")
var admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj").String()
var manfred = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq").String()
var unknown = std.Address("g1u0000000000000000000000000000000000000").String()

func main() {
// testing read-only public methods
Expand Down

0 comments on commit 0c57267

Please sign in to comment.