Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed May 17, 2024
1 parent b7b58cf commit ddedaa3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
29 changes: 29 additions & 0 deletions gno.land/cmd/gnoland/testdata/improved-coins.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
loadpkg gno.land/r/demo/wugnot

gnoland start

gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/coins -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

gnokey maketx call -pkgpath gno.land/r/demo/coins -func "MakeNewCoins" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

-- coins.gno --
package coins

import "std"

func MakeNewCoins() std.Coins {
coin1 := std.NewCoin("ugnot", 123)
coin2 := std.NewCoin("example", 321)

return std.NewCoins(coin1, coin2)
}

func MakeNewCoinsRaw() std.Coins {
return std.NewCoinsFromVal("ugnot", 123, "example", 321)
}






30 changes: 15 additions & 15 deletions gnovm/stdlibs/std/coins.gno
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ func NewCoins(coins ...Coin) Coins {

// NewCoinsFromVal is a type-unsafe way to make a Coins struct
// Usage is not recommended
func NewCoinsFromVal(val ...interface{}) (Coins, error) {
if len(val)%2 != 0 {
panic("invalid number of arguments")
}

cz := Coins{}
for i := 0; i < len(val)-1; i++ {
denom := val[i].(string)
amt := val[i+1].(int64)

cz = append(cz, NewCoin(denom, amt))
}

return cz, nil
}
//func NewCoinsFromVal(val ...interface{}) (Coins, error) {
// if len(val)%2 != 0 {
// panic("invalid number of arguments")
// }
//
// cz := Coins{}
// for i := 0; i < len(val)-1; i++ {
// denom := val[i].(string)
// amt := val[i+1].(int64)
//
// cz = append(cz, NewCoin(denom, amt))
// }
//
// return cz, nil
//}

func (cz Coins) String() string {
if len(cz) == 0 {
Expand Down

0 comments on commit ddedaa3

Please sign in to comment.