Skip to content

Instantly share code, notes, and snippets.

@liamsi
Last active March 20, 2019 12:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamsi/62228b744796166882aa566da15d1845 to your computer and use it in GitHub Desktop.
Save liamsi/62228b744796166882aa566da15d1845 to your computer and use it in GitHub Desktop.
Unmarshal TX
package main
import (
"encoding/base64"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/tendermint/go-amino"
)
func main() {
encoded := "lwHwYl3uChrk9x1PChQeAqKCNwtVXU9A7b0v8BkNWPfrDRIJCgMSATAQwJoMGmoKJuta6YchAmbZ4oUx+GWVQDUo2z+NB0YzOpj9g4Px/n8H3EbId7aCEkDUcLJcPiQaeDOxeDt9VHyIllWiAlqyOCHxL6VV+HHvXDs0c/AhACQwXA/yKv8IGhXb77Ndc9Td3W+6P+94/OtN"
res, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
panic(err)
}
fmt.Println(fmt.Sprintf("%X", res))
fmt.Println(res)
cdc := amino.NewCodec()
bank.RegisterCodec(cdc)
stake.RegisterCodec(cdc)
distr.RegisterCodec(cdc)
slashing.RegisterCodec(cdc)
gov.RegisterCodec(cdc)
auth.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
var tx auth.StdTx
err = cdc.UnmarshalBinaryLengthPrefixed(res, &tx)
if err != nil {
panic(err)
}
fmt.Println(fmt.Sprintf("%#v", tx))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment