@@ -27,7 +27,6 @@ import (
27
27
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
28
28
"github.com/cosmos/cosmos-sdk/codec"
29
29
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
30
- "github.com/cosmos/cosmos-sdk/std"
31
30
sdk "github.com/cosmos/cosmos-sdk/types"
32
31
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
33
32
"github.com/cosmos/cosmos-sdk/types/query"
@@ -117,12 +116,13 @@ func (t txServer[T]) GetBlockWithTxs(ctx context.Context, req *txtypes.GetBlockW
117
116
}
118
117
decodeTxAt := func (i uint64 ) error {
119
118
tx := blockTxs [i ]
120
- txb , err := t .clientCtx .TxConfig .TxDecoder ()(tx )
121
- fmt .Println ("TxDecoder" , txb , err )
119
+ txb , err := t .txCodec .Decode (tx )
122
120
if err != nil {
123
121
return err
124
122
}
125
- p , err := txb .(interface { AsTx () (* txtypes.Tx , error ) }).AsTx ()
123
+
124
+ // txServer works only with sdk.Tx
125
+ p , err := any (txb ).(interface { AsTx () (* txtypes.Tx , error ) }).AsTx ()
126
126
if err != nil {
127
127
return err
128
128
}
@@ -256,13 +256,19 @@ func (t txServer[T]) Simulate(ctx context.Context, req *txtypes.SimulateRequest)
256
256
msgResponses = append (msgResponses , anyMsg )
257
257
}
258
258
259
+ event , err := intoABCIEvents (txResult .Events , map [string ]struct {}{}, false )
260
+ if err != nil {
261
+ return nil , status .Errorf (codes .Unknown , "failed to convert events: %v" , err )
262
+ }
263
+
259
264
return & txtypes.SimulateResponse {
260
265
GasInfo : & sdk.GasInfo {
261
266
GasUsed : txResult .GasUsed ,
262
267
GasWanted : txResult .GasWanted ,
263
268
},
264
269
Result : & sdk.Result {
265
270
MsgResponses : msgResponses ,
271
+ Events : event ,
266
272
},
267
273
}, nil
268
274
}
@@ -273,15 +279,17 @@ func (t txServer[T]) TxDecode(ctx context.Context, req *txtypes.TxDecodeRequest)
273
279
return nil , status .Error (codes .InvalidArgument , "invalid empty tx bytes" )
274
280
}
275
281
276
- txb , err := t .clientCtx . TxConfig . TxDecoder () (req .TxBytes )
282
+ txb , err := t .txCodec . Decode (req .TxBytes )
277
283
if err != nil {
278
284
return nil , err
279
285
}
280
286
281
- tx , err := txb .(interface { AsTx () (* txtypes.Tx , error ) }).AsTx () // TODO: maybe we can break the Tx interface to add this also
287
+ // txServer works only with sdk.Tx
288
+ tx , err := any (txb ).(interface { AsTx () (* txtypes.Tx , error ) }).AsTx ()
282
289
if err != nil {
283
290
return nil , err
284
291
}
292
+
285
293
return & txtypes.TxDecodeResponse {
286
294
Tx : tx ,
287
295
}, nil
@@ -350,7 +358,7 @@ func (t txServer[T]) TxEncodeAmino(_ context.Context, req *txtypes.TxEncodeAmino
350
358
var stdTx legacytx.StdTx
351
359
err := t .clientCtx .LegacyAmino .UnmarshalJSON ([]byte (req .AminoJson ), & stdTx )
352
360
if err != nil {
353
- return nil , err
361
+ return nil , status . Error ( codes . InvalidArgument , fmt . Sprintf ( "invalid request %s" , err ))
354
362
}
355
363
356
364
encodedBytes , err := t .clientCtx .LegacyAmino .Marshal (stdTx )
@@ -466,7 +474,7 @@ func (c *consensus[T]) maybeHandleExternalServices(ctx context.Context, req *abc
466
474
if strings .HasPrefix (req .Path , "/cosmos.base.tendermint.v1beta1.Service" ) {
467
475
rpcClient , _ := rpchttp .New (c .cfg .ConfigTomlConfig .RPC .ListenAddress )
468
476
469
- cometQServer := cmtservice .NewQueryServer (rpcClient , c .Query , c .consensusAddressCodec )
477
+ cometQServer := cmtservice .NewQueryServer (rpcClient , c .Query , c .appCodecs . ConsensusAddressCodec )
470
478
paths := strings .Split (req .Path , "/" )
471
479
if len (paths ) <= 2 {
472
480
return nil , fmt .Errorf ("invalid request path: %s" , req .Path )
@@ -516,27 +524,18 @@ func (c *consensus[T]) maybeHandleExternalServices(ctx context.Context, req *abc
516
524
517
525
// Handle tx service
518
526
if strings .HasPrefix (req .Path , "/cosmos.tx.v1beta1.Service" ) {
519
- // init simple client context
520
- amino := codec .NewLegacyAmino ()
521
- std .RegisterLegacyAminoCodec (amino )
522
- txConfig := authtx .NewTxConfig (
523
- c .appCodec ,
524
- c .appCodec .InterfaceRegistry ().SigningContext ().AddressCodec (),
525
- c .appCodec .InterfaceRegistry ().SigningContext ().ValidatorAddressCodec (),
526
- authtx .DefaultSignModes ,
527
- )
528
527
rpcClient , _ := client .NewClientFromNode (c .cfg .AppTomlConfig .Address )
529
528
529
+ // init simple client context
530
530
clientCtx := client.Context {}.
531
- WithLegacyAmino (amino ).
532
- WithCodec (c .appCodec ).
533
- WithTxConfig (txConfig ).
531
+ WithLegacyAmino (c .appCodecs .LegacyAmino .(* codec.LegacyAmino )).
532
+ WithCodec (c .appCodecs .AppCodec ).
534
533
WithNodeURI (c .cfg .AppTomlConfig .Address ).
535
534
WithClient (rpcClient )
536
535
537
536
txService := txServer [T ]{
538
537
clientCtx : clientCtx ,
539
- txCodec : c .txCodec ,
538
+ txCodec : c .appCodecs . TxCodec ,
540
539
app : c .app ,
541
540
consensus : c ,
542
541
}
0 commit comments