-
Notifications
You must be signed in to change notification settings - Fork 6
/
tx_decoding.go
47 lines (37 loc) · 962 Bytes
/
tx_decoding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cosmos
import (
"errors"
"log"
sign "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
auth2 "github.com/cosmos/cosmos-sdk/x/auth/tx"
)
var DecodeErr = errors.New("could not decode tx")
func decodeTx(codec *codec.ProtoCodec, tx types.Tx) (sdk.Tx, error) {
txInterface, err := auth2.DefaultTxDecoder(codec)(tx)
if err != nil {
log.Println(err)
return nil, DecodeErr
}
return txInterface, nil
}
// Decode accept tx bytes and transforms them to cosmos std tx
func toStdTx(tx sdk.Tx) (sdk.Tx, error) {
stdTx, ok := tx.(sdk.Tx)
//log.Println(stdTx)
if !ok {
return nil, DecodeErr
}
return stdTx, nil
}
// Decode accept tx bytes and transforms them to cosmos sign tx
func toSignTx(tx sdk.Tx) (sign.Tx, error) {
stdTx, ok := tx.(sign.Tx)
//log.Println(stdTx)
if !ok {
return nil, DecodeErr
}
return stdTx, nil
}