Created
June 25, 2019 09:05
-
-
Save crossle/be7f76a88ee838c70f87e937e59849b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"github.com/cosmos/cosmos-sdk/codec" | |
sdk "github.com/cosmos/cosmos-sdk/types" | |
"github.com/cosmos/cosmos-sdk/x/auth" | |
) | |
func main() { | |
tx := "ygHwYl3uCkSoo2GaChQxrczb/flZmTC8mDh3uKwKyZCnpRIUHKZpC3Ql+uFfYxDL3cCs3/DCKaMaEgoFdWF0b20SCTg3ODMzNjAwMBISCgwKBXVhdG9tEgM3NTAQwJoMGmoKJuta6YchAyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrEEkDZtTnvilzE4n+7B2N2oeHi7X9nAssjSU72VgMEwOE5wSHIpHCaVb6GobgZxN9Kv/zr1kWX14QspXwBcUdW05n0" | |
decoded, err := base64.StdEncoding.DecodeString(tx) | |
if err != nil { | |
fmt.Println("decode error:", err) | |
return | |
} | |
fmt.Println(decoded) | |
p := fmt.Sprintf("Tx{%X}", []byte(decoded)) | |
fmt.Println(p) | |
c := MakeCodec() | |
t, err := parseTx(c, decoded) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
fmt.Println(t) | |
} | |
func MakeCodec() *codec.Codec { | |
var cdc = codec.New() | |
auth.RegisterCodec(cdc) | |
sdk.RegisterCodec(cdc) | |
codec.RegisterCrypto(cdc) | |
return cdc | |
} | |
func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { | |
var tx auth.StdTx | |
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) | |
if err != nil { | |
return nil, err | |
} | |
return tx, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment