Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contribs/gnodev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ FLAGS
-chain-domain gno.land set node ChainDomain
-chain-id dev set node ChainID
-deploy-key g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 default key name or Bech32 address for deploying packages
-empty-blocks=false enable creation of empty blocks (default: ~1s interval)
-empty-blocks-interval 1s set the interval for creating empty blocks
-genesis ... load the given genesis file
-interactive=false enable gnodev interactive mode
-lazy-loader=true enable lazy loader
Expand Down Expand Up @@ -154,6 +156,8 @@ FLAGS
-chain-domain gno.land set node ChainDomain
-chain-id dev set node ChainID
-deploy-key g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 default key name or Bech32 address for deploying packages
-empty-blocks=false enable creation of empty blocks (default: ~1s interval)
-empty-blocks-interval 0s set the interval for creating empty blocks
-genesis ... load the given genesis file
-interactive=false enable gnodev interactive mode
-lazy-loader=false enable lazy loader
Expand Down
43 changes: 31 additions & 12 deletions contribs/gnodev/app_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "flag"
import (
"flag"
"time"
)

type AppConfig struct {
// Listeners
Expand Down Expand Up @@ -31,17 +34,19 @@ type AppConfig struct {
resolvers varResolver

// Node Configuration
logFormat string
lazyLoader bool
verbose bool
noWatch bool
noReplay bool
maxGas int64
chainId string
chainDomain string
unsafeAPI bool
interactive bool
paths string
logFormat string
lazyLoader bool
verbose bool
noWatch bool
noReplay bool
maxGas int64
chainId string
chainDomain string
unsafeAPI bool
interactive bool
paths string
emptyBlocks bool
emptyBlocksInterval time.Duration
}

func (c *AppConfig) RegisterFlagsWith(fs *flag.FlagSet, defaultCfg AppConfig) {
Expand Down Expand Up @@ -220,6 +225,20 @@ func (c *AppConfig) RegisterFlagsWith(fs *flag.FlagSet, defaultCfg AppConfig) {
`additional paths to preload in the form of "gno.land/r/my/realm", separated by commas; glob is supported`,
)

fs.BoolVar(
&c.emptyBlocks,
"empty-blocks",
defaultCfg.emptyBlocks,
"enable creation of empty blocks (default: ~1s interval)",
)

fs.DurationVar(
&c.emptyBlocksInterval,
"empty-blocks-interval",
defaultCfg.emptyBlocksInterval,
"set the interval for creating empty blocks",
)

fs.BoolVar(
&c.verbose,
"v",
Expand Down
3 changes: 3 additions & 0 deletions contribs/gnodev/command_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/gnolang/gno/contribs/gnodev/pkg/packages"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
Expand Down Expand Up @@ -38,6 +39,8 @@ var defaultLocalAppConfig = AppConfig{
interactive: isatty.IsTerminal(os.Stdout.Fd()),
unsafeAPI: true,
lazyLoader: true,
emptyBlocks: false,
emptyBlocksInterval: time.Second * 1,

// As we have no reason to configure this yet, set this to random port
// to avoid potential conflict with other app
Expand Down
2 changes: 2 additions & 0 deletions contribs/gnodev/setup_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func setupDevNodeConfig(
config.NoReplay = cfg.noReplay
config.MaxGasPerBlock = cfg.maxGas
config.ChainID = cfg.chainId
config.TMConfig.Consensus.CreateEmptyBlocks = cfg.emptyBlocks
config.TMConfig.Consensus.CreateEmptyBlocksInterval = cfg.emptyBlocksInterval

// other listeners
config.TMConfig.P2P.ListenAddress = defaultLocalAppConfig.nodeP2PListenerAddr
Expand Down
7 changes: 2 additions & 5 deletions gno.land/pkg/gnoland/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *mockParamsKeeper) GetString(ctx sdk.Context, key string, ptr *string)
func (m *mockParamsKeeper) GetInt64(ctx sdk.Context, key string, ptr *int64) {}
func (m *mockParamsKeeper) GetUint64(ctx sdk.Context, key string, ptr *uint64) {}
func (m *mockParamsKeeper) GetBool(ctx sdk.Context, key string, ptr *bool) {}
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {}
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte { return nil }
func (m *mockParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {}

func (m *mockParamsKeeper) SetString(ctx sdk.Context, key string, value string) {}
Expand All @@ -181,10 +181,7 @@ func (m *mockParamsKeeper) SetBool(ctx sdk.Context, key string, value bool)
func (m *mockParamsKeeper) SetBytes(ctx sdk.Context, key string, value []byte) {}
func (m *mockParamsKeeper) SetStrings(ctx sdk.Context, key string, value []string) {}

func (m *mockParamsKeeper) Has(ctx sdk.Context, key string) bool { return false }
func (m *mockParamsKeeper) GetRaw(ctx sdk.Context, key string) []byte { return nil }
func (m *mockParamsKeeper) SetRaw(ctx sdk.Context, key string, value []byte) {}

func (m *mockParamsKeeper) Has(ctx sdk.Context, key string) bool { return false }
func (m *mockParamsKeeper) GetStruct(ctx sdk.Context, key string, strctPtr any) {}
func (m *mockParamsKeeper) SetStruct(ctx sdk.Context, key string, strct any) {}

Expand Down
36 changes: 36 additions & 0 deletions gno.land/pkg/integration/testdata/maketx_call_send.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# load the package
loadpkg gno.land/r/foo/call_realm $WORK/realm

# start a new node
gnoland start

## user balance before realm send
gnokey query auth/accounts/$test1_user_addr
stdout '"coins": "9999998810000ugnot"'

## realm balance before realm send
gnokey query auth/accounts/g1x4ykzcqksj2hc5qpvr8kd9zaffkd82rvmzqup7
stdout '"coins": ""'

# call to realm with -send
gnokey maketx call -send 42ugnot -pkgpath gno.land/r/foo/call_realm -func GimmeMoney -gas-fee 1000000ugnot -gas-wanted 3000000 -broadcast -chainid=tendermint_test test1
stdout '("send: 42ugnot")'

## user balance after realm send
# reduced by -gas-fee AND -send
gnokey query auth/accounts/$test1_user_addr
stdout '"coins": "9999997809958ugnot"'

## realm balance after realm send
gnokey query auth/accounts/g1x4ykzcqksj2hc5qpvr8kd9zaffkd82rvmzqup7
stdout '"coins": "42ugnot"'


-- realm/realm.gno --
package call_realm

import "chain/banker"

func GimmeMoney(cur realm) string {
return "send: " + banker.OriginSend().String()
}
76 changes: 76 additions & 0 deletions gno.land/pkg/integration/testdata/maketx_run_send.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## start a new node
gnoland start

## user balance before realm send
gnokey query auth/accounts/$test1_user_addr
stdout '"coins": "10000000000000ugnot"'

## run script/print_originsend.gno with send flag
gnokey maketx run -send 42ugnot -gas-fee 1000000ugnot -gas-wanted 20000000 -broadcast -chainid=tendermint_test test1 $WORK/script/print_originsend.gno
stdout 'send: 42ugnot'

## user balance after realm send
# only reduced by -gas-fee, -send does not affect balance since no transfer
# occurred and the run script shares the same address as the user.
gnokey query auth/accounts/$test1_user_addr
stdout '"coins": "9999999000000ugnot"'

## run script/newbanker_realmissue.gno with send flag
# must fail because this banker type is not allowed in ephemerals.
! gnokey maketx run -send 42ugnot -gas-fee 1000000ugnot -gas-wanted 20000000 -broadcast -chainid=tendermint_test test1 $WORK/script/newbanker_realmissue.gno
stderr 'invalid banker type 3 for ephemeral'

## run script/newbanker_realmsend.gno with send flag
# must fail because this banker type is not allowed in ephemerals.
! gnokey maketx run -send 42ugnot -gas-fee 1000000ugnot -gas-wanted 20000000 -broadcast -chainid=tendermint_test test1 $WORK/script/newbanker_realmsend.gno
stderr 'invalid banker type 2 for ephemeral'

## run script/newbanker_originsend.gno with send flag
gnokey maketx run -send 42ugnot -gas-fee 1000000ugnot -gas-wanted 20000000 -broadcast -chainid=tendermint_test test1 $WORK/script/newbanker_originsend.gno
stdout 'OK!'

## user balance after coin transfer in newbanker_originsend
# reduced by -gas-fee and -send
gnokey query auth/accounts/$test1_user_addr
stdout '"coins": "9999997999958ugnot"'

-- script/print_originsend.gno --
package main

import "chain/banker"

func main() {
println("send:", banker.OriginSend())
}
-- script/newbanker_realmissue.gno --
package main

import "chain/banker"

func main() {
banker.NewBanker(banker.BankerTypeRealmIssue)
}
-- script/newbanker_realmsend.gno --
package main

import "chain/banker"

func main() {
banker.NewBanker(banker.BankerTypeRealmSend)
}
-- script/newbanker_originsend.gno --
package main

import (
"chain"
"chain/banker"
"chain/runtime"
)

func main() {
to := chain.PackageAddress("gno.land/r/gimmemoney")
banker.NewBanker(banker.BankerTypeOriginSend).SendCoins(
runtime.CurrentRealm().Address(), to,
chain.Coins{{"ugnot", 42}},
)
}
16 changes: 15 additions & 1 deletion gno.land/pkg/keyscli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type MakeRunCfg struct {
RootCfg *client.MakeTxCfg
Send string
MaxDeposit string
}

Expand All @@ -42,6 +43,12 @@ func NewMakeRunCmd(rootCfg *client.MakeTxCfg, cmdio commands.IO) *commands.Comma
}

func (c *MakeRunCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.Send,
"send",
"",
"send amount",
)
fs.StringVar(
&c.MaxDeposit,
"max-deposit",
Expand Down Expand Up @@ -75,7 +82,13 @@ func execMakeRun(cfg *MakeRunCfg, args []string, cmdio commands.IO) error {
}
caller := info.GetAddress()

// Parase deposit amount
// Parse send amount.
send, err := std.ParseCoins(cfg.Send)
if err != nil {
return errors.Wrap(err, "parsing send coins")
}

// Parse deposit amount
deposit, err := std.ParseCoins(cfg.MaxDeposit)
if err != nil {
return errors.Wrap(err, "parsing storage deposit coins")
Expand Down Expand Up @@ -133,6 +146,7 @@ func execMakeRun(cfg *MakeRunCfg, args []string, cmdio commands.IO) error {
msg := vm.MsgRun{
Caller: caller,
Package: memPkg,
Send: send,
MaxDeposit: deposit,
}
tx := std.Tx{
Expand Down
4 changes: 2 additions & 2 deletions gnovm/stdlibs/chain/banker/banker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (b BankerType) String() string {
// NewBanker returns a new Banker, with its capabilities matching the given
// [BankerType].
func NewBanker(bt BankerType) Banker {
assertCallerIsRealm()
assertCallerIsRealmOrEphemeral(uint8(bt))
if bt >= maxBanker {
panic("invalid banker type")
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func OriginSend() chain.Coins {
return coins
}

func assertCallerIsRealm()
func assertCallerIsRealmOrEphemeral(bt uint8)
func originSend() (denoms []string, amounts []int64)

// expandNative expands coins for usage within natively bound functions.
Expand Down
25 changes: 22 additions & 3 deletions gnovm/stdlibs/chain/banker/banker.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,30 @@ func CompactCoins(denoms []string, amounts []int64) std.Coins {
return coins
}

func X_assertCallerIsRealm(m *gno.Machine) {
func X_assertCallerIsRealmOrEphemeral(m *gno.Machine, bt uint8) {
frame := m.Frames[m.NumFrames()-2]
if path := frame.LastPackage.PkgPath; !gno.IsRealmPath(path) {
m.PanicString("caller is not a realm")
path := frame.LastPackage.PkgPath
if gno.IsRealmPath(path) {
return
}
if gno.IsEphemeralPath(path) {
switch bt {
case btOriginSend, btReadonly:
return
default:
// Other bankType than OriginSend and ReadOnly are forbidden for an
// ephemeral.
// The reason is that a malicious script could easily drain users' funds
// if they didn't carefully check the code. Restricting the banker type
// to OriginSend ensures that the amount spent cannot exceed what the
// user put in the 'send' field.
// Some complex smart contracts require ephemeral script to be used, and
// we expect those scripts to be generated by Dapps and not by user,
// hence we need to put some safeguards.
panic(fmt.Sprintf("invalid banker type %d for ephemeral", bt))
}
}
m.PanicString("caller is not a realm or an ephemeral")
}

func X_originSend(m *gno.Machine) (denoms []string, amounts []int64) {
Expand Down
20 changes: 16 additions & 4 deletions gnovm/stdlibs/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tm2/pkg/sdk/params/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (bh paramsHandler) Query(ctx sdk.Context, req abci.RequestQuery) (res abci.
std.ErrUnknownRequest(fmt.Sprintf("module not registered: %q", module)))
return
}
val := bh.params.GetRaw(ctx, rest)
val := bh.params.GetBytes(ctx, rest)
res.Data = val
return

Expand Down
Loading
Loading