diff --git a/gno.land/pkg/gnoland/app.go b/gno.land/pkg/gnoland/app.go index 2380658c6e9..625254eef3c 100644 --- a/gno.land/pkg/gnoland/app.go +++ b/gno.land/pkg/gnoland/app.go @@ -12,6 +12,7 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" "github.com/gnolang/gno/tm2/pkg/bft/config" + bft "github.com/gnolang/gno/tm2/pkg/bft/types" "github.com/gnolang/gno/tm2/pkg/crypto" dbm "github.com/gnolang/gno/tm2/pkg/db" "github.com/gnolang/gno/tm2/pkg/events" @@ -287,6 +288,37 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci return nil, fmt.Errorf("invalid AppState of type %T", appState) } + // TODO move to the initchainer implementation + superBeginTxHook := cfg.baseApp.BeginTxHook() + beginTxHook := func(ctx sdk.Context) sdk.Context { + retCtx := ctx + + if superBeginTxHook != nil { + // Run the initially-set hook first + retCtx = superBeginTxHook(ctx) + } + + if true { // TODO change to check if there is a genesis context + return retCtx + } + + // TODO Modify the beginTx hook to give you the transaction, + // so metadata will be extracted + + // Create a copy of the header, in + // which only the timestamp information is modified + header := retCtx.BlockHeader().(*bft.Header).Copy() + header.Time = time.Now().Add(time.Hour * 72) // TODO modify based on tx metadata + + // Save the modified header + return retCtx.WithBlockHeader(header) + } + + cfg.baseApp.SetBeginTxHook(beginTxHook) + + // Restore the original beginTx hook + defer cfg.baseApp.SetBeginTxHook(superBeginTxHook) + // Parse and set genesis state balances for _, bal := range state.Balances { acc := cfg.acctKpr.NewAccountWithAddress(ctx, bal.Address) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index d8065f04e6e..202a2a76170 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -8,7 +8,6 @@ import ( "sort" "strings" "syscall" - "time" "github.com/gnolang/gno/tm2/pkg/amino" abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" @@ -337,39 +336,8 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC app.deliverState.ctx = app.deliverState.ctx. WithBlockGasMeter(store.NewInfiniteGasMeter()) - // Inject a custom - superBeginTxHook := app.beginTxHook - app.beginTxHook = func(ctx Context) Context { - retCtx := ctx - - if superBeginTxHook != nil { - // Run the initially-set hook first - retCtx = superBeginTxHook(ctx) - } - - if true { // TODO change to check if there is a genesis context - return retCtx - } - - // TODO Modify the beginTx hook to give you the transaction, - // so metadata will be extracted - - // Create a copy of the header, in - // which only the timestamp information is modified - header := initHeader.Copy() - header.Time = time.Now().Add(time.Hour * 72) // TODO modify based on tx metadata - - // Save the modified header - retCtx.header = header - - return retCtx - } - res = app.initChainer(app.deliverState.ctx, req) - // Restore the original beginTx hook - app.beginTxHook = superBeginTxHook - // sanity check if len(req.Validators) > 0 { if len(req.Validators) != len(res.Validators) { @@ -979,6 +947,10 @@ func (app *BaseApp) Close() error { return nil // XXX } +func (app *BaseApp) BeginTxHook() BeginTxHook { + return app.beginTxHook +} + // ---------------------------------------------------------------------------- // State