PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/nt/treasury/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
nt / treasury
Files
14 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/nt/treasury/v0
gno
0.9

Files (14)

  • README.mdmarkdown
  • gnomod.tomltoml
  • banker_coins.gnogno
  • banker_grc20.gnogno
  • doc.gnogno
  • render.gnogno
  • treasury.gnogno
  • types.gnogno
  • banker_canonical_filetest.gnogno
  • banker_coins_filetest.gnogno
  • banker_coins_payment_canonical_filetest.gnogno
  • banker_coins_payment_copy_filetest.gnogno
  • banker_grc20_filetest.gnogno
  • treasury_filetest.gnogno
  • banker_grc20_filetest.gnogno
    1// PKGPATH: gno.land/r/treasury/main23package main45import (6	"chain"7	"strings"8

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    9 "gno.land/p/nt/grc20/v0"
    10 "gno.land/p/nt/seqid/v0"
    11 "gno.land/p/nt/treasury/v0"
    12)
    13
    14const amount = int64(1000)
    15
    16var nextTokenID seqid.ID
    17
    18func createToken(_ int, rlm realm, name string, toMint address) *grc20.Token {
    19 // Create the token.
    20 symbol := strings.ToUpper(name)
    21 token, ledger := grc20.NewToken(name, symbol, 0, nextTokenID.Next(), rlm)
    22
    23 // Mint the requested amount.
    24 ledger.Mint(toMint, amount)
    25
    26 return token
    27}
    28
    29func main(cur realm) {
    30 // Define addresses for the sender (owner) and destination.
    31 ownerAddr := chain.PackageAddress("gno.land/r/treasury/main")
    32 destAddr := chain.PackageAddress("gno.land/r/dest/main")
    33
    34 // Try to create a GRC20Banker using a nil lister.
    35 gbanker, err := treasury.NewGRC20BankerWithOwner(ownerAddr, nil)
    36 if err == nil {
    37 panic("expected error when creating GRC20Banker with nil lister")
    38 }
    39
    40 // Define a list of token and the associated lister.
    41 tokens := []*grc20.Token{
    42 createToken(0, cur, "TestToken0", ownerAddr),
    43 createToken(0, cur, "TestToken1", ownerAddr),
    44 createToken(0, cur, "TestToken2", ownerAddr),
    45 }
    46
    47 grc20Lister := func() map[string]*grc20.Token {
    48 tokensMap := make(map[string]*grc20.Token, len(tokens))
    49
    50 for _, token := range tokens {
    51 tokensMap[token.GetSymbol()] = token
    52 }
    53
    54 return tokensMap
    55 }
    56
    57 // Create a GRC20Banker.
    58 gbanker, err = treasury.NewGRC20BankerWithOwner(ownerAddr, grc20Lister)
    59 if err != nil {
    60 panic("failed to create GRC20Banker: " + err.Error())
    61 }
    62
    63 println("GRC20Banker ID:", gbanker.ID())
    64 println("GRC20Banker Address:", gbanker.Address())
    65
    66 // Check if the GRC20Banker address matches the owner address.
    67 if gbanker.Address() != ownerAddr.String() {
    68 panic("GRC20Banker address does not match current realm address")
    69 }
    70
    71 // Check the balances of the GRC20Banker.
    72 println("GRC20Banker Balances count:", len(gbanker.Balances()))
    73 for _, balance := range gbanker.Balances() {
    74 if balance.Amount != amount {
    75 panic("GRC20Banker balance does not match expected amount")
    76 }
    77 }
    78
    79 // Send a valid payment.
    80 token := tokens[len(tokens)-1]
    81 validPayment := treasury.NewGRC20Payment(
    82 token.GetSymbol(),
    83 100,
    84 destAddr,
    85 )
    86 err = gbanker.Send(0, cur, validPayment)
    87 println("Valid payment error:", err)
    88 if err != nil {
    89 panic("failed to send valid payment: " + err.Error())
    90 }
    91
    92 println("Owner balance:", token.BalanceOf(ownerAddr))
    93 println("Dest balance:", token.BalanceOf(destAddr))
    94
    95 // Send an unknown token payment.
    96 unknownPayment := treasury.NewGRC20Payment(
    97 "unknown",
    98 100,
    99 destAddr,
    100 )
    101 err = gbanker.Send(0, cur, unknownPayment)
    102 println("Unknown token payment error:", err)
    103 if err == nil {
    104 panic("expected error for unknown token, but got none")
    105 }
    106
    107 // Send an unsufficient funds payment.
    108 unsufficientPayment := treasury.NewGRC20Payment(
    109 tokens[0].GetSymbol(),
    110 amount+1,
    111 destAddr,
    112 )
    113 err = gbanker.Send(0, cur, unsufficientPayment)
    114 println("Unsufficient funds payment error:", err)
    115 if err == nil {
    116 panic("expected error for insufficient funds, but got none")
    117 }
    118
    119 // Send a payment with an invalid type.
    120 invalidPaymentType := treasury.NewCoinsPayment(chain.Coins{}, destAddr)
    121 err = gbanker.Send(0, cur, invalidPaymentType)
    122 println("Invalid payment type error:", err)
    123 if err == nil {
    124 panic("expected error for invalid payment type, but got none")
    125 }
    126}
    127
    128// Output:
    129// GRC20Banker ID: GRC20
    130// GRC20Banker Address: g1ynsdz5zaxhn9gnqtr6t40m5k4fueeutq7xy224
    131// GRC20Banker Balances count: 3
    132// Valid payment error: undefined
    133// Owner balance: 900
    134// Dest balance: 100
    135// Unknown token payment error: GRC20 token not found: unknown
    136// Unsufficient funds payment error: insufficient balance
    137// Invalid payment type error: invalid payment type
    138