-
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.
feat(gnovm): add
Coin
constructor and more functionality (#2104)
<!-- please provide a detailed description of the changes made in this pull request. --> ## Description This PR ports more functionality from [coin.go](https://github.com/gnolang/gno/blob/master/tm2/pkg/std/coin.go?rgh-link-date=2024-02-27T11%3A01%3A45Z), into Gno (std & stdshim). It will also update the concept & reference docs for Coins. Superseding #1696 <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
- Loading branch information
Showing
14 changed files
with
502 additions
and
37 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
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
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
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,86 @@ | ||
loadpkg gno.land/r/demo/coins $WORK | ||
|
||
gnoland start | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "MakeNewCoins" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(300 int64)' | ||
stdout '(321 int64)' | ||
stdout '("ugnot" string)' | ||
stdout '("example" string)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "AddCoin" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(300 int64)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "SubCoin" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(123 int64)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "StringZeroCoin" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '("0ugnot" string)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "IsZero" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(true bool)' | ||
stdout '(false bool)' | ||
stdout '(false bool)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "IsPositive" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(false bool)' | ||
stdout '(false bool)' | ||
stdout '(true bool)' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/demo/coins -func "IsNegative" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(true bool)' | ||
stdout '(false bool)' | ||
stdout '(false bool)' | ||
|
||
-- coins.gno -- | ||
package coins | ||
|
||
import "std" | ||
|
||
func MakeNewCoins() std.Coins { | ||
coin1 := std.NewCoin("ugnot", 123) | ||
coin2 := std.NewCoin("example", 321) | ||
coin3 := std.NewCoin("ugnot", 177) | ||
|
||
|
||
return std.NewCoins(coin1, coin2, coin3) | ||
} | ||
|
||
func AddCoin() std.Coin { | ||
coin1 := std.NewCoin("ugnot", 123) | ||
coin2 := std.NewCoin("ugnot", 177) | ||
return coin1.Add(coin2) | ||
} | ||
|
||
func SubCoin() std.Coin { | ||
coin1 := std.NewCoin("ugnot", 300) | ||
coin2 := std.NewCoin("ugnot", 177) | ||
return coin1.Sub(coin2) | ||
} | ||
|
||
func StringZeroCoin() string { | ||
coin1 := std.NewCoin("ugnot", 0) | ||
return coin1.String() | ||
} | ||
|
||
func IsZero() (bool, bool, bool) { | ||
coin1 := std.NewCoin("ugnot", 0) | ||
coin2 := std.NewCoin("ugnot", 123) | ||
coin3 := std.NewCoin("ugnot", -123) | ||
return coin1.IsZero(), coin2.IsZero(), coin3.IsZero() | ||
} | ||
|
||
func IsPositive() (bool, bool, bool) { | ||
coin1 := std.NewCoin("ugnot", -123) | ||
coin2 := std.NewCoin("ugnot", 0) | ||
coin3 := std.NewCoin("ugnot", 123) | ||
return coin1.IsPositive(), coin2.IsPositive(), coin3.IsPositive() | ||
} | ||
|
||
func IsNegative() (bool, bool, bool) { | ||
coin1 := std.NewCoin("ugnot", -123) | ||
coin2 := std.NewCoin("ugnot", 0) | ||
coin3 := std.NewCoin("ugnot", 123) | ||
return coin1.IsNegative(), coin2.IsNegative(), coin3.IsNegative() | ||
} | ||
|
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
Oops, something went wrong.