55 "io"
66 "net/http"
77 "os"
8+ "time"
89 "path/filepath"
910
1011 "github.com/scrtlabs/SecretNetwork/app/keepers"
@@ -85,10 +86,11 @@ import (
8586 tmlog "github.com/tendermint/tendermint/libs/log"
8687 tmos "github.com/tendermint/tendermint/libs/os"
8788 dbm "github.com/tendermint/tm-db"
88- authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
89- sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
89+ // authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
90+ // sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
9091 // unnamed import of statik for swagger UI support
9192 _ "github.com/scrtlabs/SecretNetwork/client/docs/statik"
93+ tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
9294)
9395
9496const appName = "secret"
@@ -145,6 +147,7 @@ type SecretNetworkApp struct {
145147 sm * module.SimulationManager
146148
147149 configurator module.Configurator
150+ // chainID String
148151}
149152
150153func (app * SecretNetworkApp ) GetBaseApp () * baseapp.BaseApp {
@@ -179,8 +182,7 @@ func (app *SecretNetworkApp) RegisterTendermintService(clientCtx client.Context)
179182 tmservice .RegisterTendermintService (app .BaseApp .GRPCQueryRouter (), clientCtx , app .interfaceRegistry )
180183}
181184
182- func (app * SecretNetworkApp ) DeliverTx (req abci.RequestDeliverTx ) (res abci.ResponseDeliverTx ) {
183- fmt .Printf ("nerla app/app.go DeliverTx tx %x\n " , req .Tx )
185+ func (app * SecretNetworkApp ) CheckTx (req abci.RequestCheckTx ) (res abci.ResponseCheckTx ) {
184186 dTx , err := app .GetTxConfig ().TxDecoder ()(req .Tx )
185187 if err != nil {
186188 fmt .Println ( "nerla app/app.go error TxDecoder" )
@@ -190,48 +192,81 @@ func (app *SecretNetworkApp) DeliverTx(req abci.RequestDeliverTx) (res abci.Resp
190192 for _ , m := range msgs {
191193 mSecret := m .(compute.SecretNetworkMsg )
192194 if mSecret .Type () == "call_delivertx" || mSecret .Type () == "snapshot" {
193- fmt .Printf ("nerla app/app.go m.Type() %s calling Simulate\n " , mSecret .Type ())
194- ctx := app .BaseApp .GetContextForDeliverTx (req .Tx )
195- sigTx , ok := dTx .(authsigning.SigVerifiableTx )
196- if ! ok {
197- fmt .Println ("nerla app/app.go invalid transaction type" )
198- panic (sdkerrors .ErrTxDecode )
195+ fmt .Printf ("nerla app/app.go m.Type() %s calling Simulate\n " , mSecret .Type ())
196+ fmt .Printf ("nerla app/app.go CheckTx actually calling DeliverTx tx %x\n " , req .Tx )
197+ app .BaseApp .SetDeliverState (tmproto.Header {Time : time .Now (), ChainID : os .Getenv ("CHAINID" ), Height : 1 })
198+ gasInfo , response , err := app .BaseApp .Simulate (req .Tx )
199+ fmt .Printf ("nerla app/app.go Simulate response %v err %v\n " , response , err )
200+ app .BaseApp .FakeCommit ()
201+
202+
203+ // resp := app.DeliverTx(abci.RequestDeliverTx{Tx: req.Tx})
204+ return abci.ResponseCheckTx {
205+ Code : abci .CodeTypeOK ,
206+ GasWanted : int64 (gasInfo .GasWanted ),
207+ GasUsed : int64 (gasInfo .GasUsed ),
199208 }
200-
201- sigs , err := sigTx .GetSignaturesV2 ()
202- if err != nil {
203- fmt .Println ("nerla app/app.go GetSignaturesV2 err" )
204- panic (err )
205- }
206- signerAddrs := sigTx .GetSigners ()
207-
208- for i , sig := range sigs {
209- addr := signerAddrs [i ]
210- acc := app .AppKeepers .AccountKeeper .GetAccount (ctx , addr )
211- fmt .Printf ("nerla app/app.go before addr %s acc.seq %d sig.seq %d\n " , addr .String (), acc .GetSequence (), sig .Sequence + 1 )
212- if err := acc .SetSequence (sig .Sequence + 1 ); err != nil {
213- panic (err )
214- }
215- app .AppKeepers .AccountKeeper .SetAccount (ctx , acc )
216- acc2 := app .AppKeepers .AccountKeeper .GetAccount (ctx , addr )
217- fmt .Printf ("nerla app/app.go after addr %s acc.seq %d\n " , addr .String (), acc2 .GetSequence ())
218- }
219-
220- gasInfo , resp , err := app .BaseApp .Simulate (req .Tx )
221- fmt .Printf ("nerla app/app.go Simulate gasInfo %d res %v err %v\n " , gasInfo , resp , err )
222- return abci.ResponseDeliverTx {Code : abci .CodeTypeOK }
223209 }
224210 }
225-
226- // if compute.GetFakeDeliver() {
227- // fmt.Printf("nerla app/app.go DeliverTx FAKE_DELIVER is true\n", )
228- // return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
229- // }
230- resp := app .BaseApp .DeliverTx (req )
231- fmt .Printf ("nerla app/app.go DeliverTx res %v\n " , resp )
211+ fmt .Printf ("nerla app/app.go CheckTx tx %x\n " , req .Tx )
212+ resp := app .BaseApp .CheckTx (req )
213+ fmt .Printf ("nerla app/app.go CheckTx resp %v\n " , resp )
232214 return resp
233215}
234216
217+ // func (app *SecretNetworkApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
218+ // fmt.Printf("nerla app/app.go DeliverTx tx %x\n", req.Tx)
219+ // dTx, err := app.GetTxConfig().TxDecoder()(req.Tx)
220+ // if err != nil {
221+ // fmt.Println( "nerla app/app.go error TxDecoder")
222+ // panic(err)
223+ // }
224+ // msgs := dTx.GetMsgs()
225+ // for _, m := range msgs {
226+ // mSecret := m.(compute.SecretNetworkMsg)
227+ // if mSecret.Type() == "call_delivertx" || mSecret.Type() == "snapshot" {
228+ // fmt.Printf("nerla app/app.go m.Type() %s calling Simulate\n", mSecret.Type())
229+ // // ctx := app.BaseApp.GetContextForDeliverTx(req.Tx)
230+ // // sigTx, ok := dTx.(authsigning.SigVerifiableTx)
231+ // // if !ok {
232+ // // fmt.Println("nerla app/app.go invalid transaction type")
233+ // // panic(sdkerrors.ErrTxDecode)
234+ // // }
235+
236+ // // sigs, err := sigTx.GetSignaturesV2()
237+ // // if err != nil {
238+ // // fmt.Println("nerla app/app.go GetSignaturesV2 err")
239+ // // panic(err)
240+ // // }
241+ // // signerAddrs := sigTx.GetSigners()
242+
243+ // // for i, sig := range sigs {
244+ // // addr := signerAddrs[i]
245+ // // acc := app.AppKeepers.AccountKeeper.GetAccount(ctx, addr)
246+ // // fmt.Printf("nerla app/app.go before addr %s acc.seq %d sig.seq %d\n", addr.String(), acc.GetSequence(), sig.Sequence+1)
247+ // // if err := acc.SetSequence(sig.Sequence+1); err != nil {
248+ // // panic(err)
249+ // // }
250+ // // app.AppKeepers.AccountKeeper.SetAccount(ctx, acc)
251+ // // acc2 := app.AppKeepers.AccountKeeper.GetAccount(ctx, addr)
252+ // // fmt.Printf("nerla app/app.go after addr %s acc.seq %d\n", addr.String(), acc2.GetSequence())
253+ // // }
254+
255+ // gasInfo, resp, err := app.BaseApp.Simulate(req.Tx)
256+ // fmt.Printf("nerla app/app.go Simulate gasInfo %d res %v err %v\n", gasInfo, resp, err)
257+ // return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
258+ // }
259+ // }
260+
261+ // // if compute.GetFakeDeliver() {
262+ // // fmt.Printf("nerla app/app.go DeliverTx FAKE_DELIVER is true\n", )
263+ // // return abci.ResponseDeliverTx{Code: abci.CodeTypeOK}
264+ // // }
265+ // resp := app.BaseApp.DeliverTx(req)
266+ // fmt.Printf("nerla app/app.go DeliverTx res %v\n", resp)
267+ // return resp
268+ // }
269+
235270// WasmWrapper allows us to use namespacing in the config file
236271// This is only used for parsing in the app, x/compute expects WasmConfig
237272type WasmWrapper struct {
@@ -273,6 +308,7 @@ func NewSecretNetworkApp(
273308 interfaceRegistry : interfaceRegistry ,
274309 invCheckPeriod : invCheckPeriod ,
275310 bootstrap : bootstrap ,
311+ // chainID: appOpts.Get(server.Blockchain),
276312 }
277313
278314 app .AppKeepers .InitKeys ()
@@ -473,6 +509,7 @@ func (app *SecretNetworkApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBloc
473509
474510// InitChainer application update at chain initialization
475511func (app * SecretNetworkApp ) InitChainer (ctx sdk.Context , req abci.RequestInitChain ) abci.ResponseInitChain {
512+ fmt .Println ("nerla app/app.go InitChainer" )
476513 var genesisState simapp.GenesisState
477514 if err := tmjson .Unmarshal (req .AppStateBytes , & genesisState ); err != nil {
478515 panic (err )
0 commit comments