func bundle(feeMeta, resultMeta string) (ret Bundle) { err := xdr.SafeUnmarshalBase64(feeMeta, &ret.FeeMeta) if err != nil { panic(err) } err = xdr.SafeUnmarshalBase64(resultMeta, &ret.TransactionMeta) if err != nil { panic(err) } return }
func main() { in = bufio.NewReader(os.Stdin) // read envelope env, err := readLine("Enter envelope (base64): ", false) if err != nil { log.Fatal(err) } // parse the envelope var txe xdr.TransactionEnvelope err = xdr.SafeUnmarshalBase64(env, &txe) if err != nil { log.Fatal(err) } fmt.Println("") fmt.Println("Transaction Summary:") fmt.Printf(" source: %s\n", txe.Tx.SourceAccount.Address()) fmt.Printf(" ops: %d\n", len(txe.Tx.Operations)) fmt.Printf(" sigs: %d\n", len(txe.Signatures)) fmt.Println("") // TODO: add operation details // read seed seed, err := readLine("Enter seed: ", true) if err != nil { log.Fatal(err) } // sign the transaction b := &build.TransactionEnvelopeBuilder{E: &txe} b.Init() b.MutateTX(build.PublicNetwork) b.Mutate(build.Sign{seed}) if b.Err != nil { log.Fatal(b.Err) } newEnv, err := xdr.MarshalBase64(b.E) if err != nil { log.Fatal(err) } fmt.Print("\n==== Result ====\n\n") fmt.Println(newEnv) }
func TestHashTransaction(t *testing.T) { var txe xdr.TransactionEnvelope err := xdr.SafeUnmarshalBase64("AAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3AAAACgAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAArqN6LeOagjxMaUP96Bzfs9e0corNZXzBWJkFoK7kvkwAAAAAO5rKAAAAAAAAAAABVvwF9wAAAEAKZ7IPj/46PuWU6ZOtyMosctNAkXRNX9WCAI5RnfRk+AyxDLoDZP/9l3NvsxQtWj9juQOuoBlFLnWu8intgxQA", &txe) require.NoError(t, err) expected := [32]byte{ 0xc4, 0x92, 0xd8, 0x7c, 0x46, 0x42, 0x81, 0x5d, 0xfb, 0x3c, 0x7d, 0xcc, 0xe0, 0x1a, 0xf4, 0xef, 0xfd, 0x16, 0x2b, 0x03, 0x10, 0x64, 0x09, 0x8a, 0x0d, 0x78, 0x6b, 0x6e, 0x0a, 0x00, 0xfd, 0x74, } actual, err := HashTransaction(&txe.Tx, TestNetworkPassphrase) if assert.NoError(t, err) { assert.Equal(t, expected, actual) } }
// Envelope extracts the transaction envelope that triggered this error from the // extra fields. func (herr *Error) Envelope() (*xdr.TransactionEnvelope, error) { raw, ok := herr.Problem.Extras["envelope_xdr"] if !ok { return nil, ErrEnvelopeNotPopulated } var b64 string var result xdr.TransactionEnvelope err := json.Unmarshal(raw, &b64) if err != nil { return nil, errors.Wrap(err, "json decode failed") } err = xdr.SafeUnmarshalBase64(b64, &result) if err != nil { return nil, errors.Wrap(err, "xdr decode failed") } return &result, nil }