Skip to content

Commit

Permalink
Initialise transaction envelope in build (#1376)
Browse files Browse the repository at this point in the history
Instead of building the transaction envelope at the start of Sign we can do this at the end of build. This allows an unsigned envelope to be returned for signing offline/elsewhere

Fix for: #956
  • Loading branch information
OwenJacob authored and poliha committed Jun 20, 2019
1 parent 88133e0 commit 078fa57
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions txnbuild/transaction.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
Package txnbuild implements transactions and operations on the Stellar network.
This library provides an interface to the Stellar transaction model. It supports the building of Go applications on
top of the Stellar network (https://www.stellar.org/). Transactions constructed by this library may be submitted
to any Horizon instance for processing onto the ledger, using any Stellar SDK client. The recommended client for Go
programmers is horizonclient (https://github.com/stellar/go/tree/master/clients/horizonclient). Together, these two
libraries provide a complete Stellar SDK.
For more information and further examples, see https://www.stellar.org/developers/go/reference/index.html.
*/
package txnbuild
Expand Down Expand Up @@ -125,6 +123,12 @@ func (tx *Transaction) Build() error {
// Set a default fee, if it hasn't been set yet
tx.SetDefaultFee()

// Initialise transaction envelope
if tx.xdrEnvelope == nil {
tx.xdrEnvelope = &xdr.TransactionEnvelope{}
tx.xdrEnvelope.Tx = tx.xdrTransaction
}

return nil
}

Expand All @@ -133,11 +137,6 @@ func (tx *Transaction) Build() error {
func (tx *Transaction) Sign(kps ...*keypair.Full) error {
// TODO: Only sign if Transaction has been previously built
// TODO: Validate network set before sign
// Initialise transaction envelope
if tx.xdrEnvelope == nil {
tx.xdrEnvelope = &xdr.TransactionEnvelope{}
tx.xdrEnvelope.Tx = tx.xdrTransaction
}

// Hash the transaction
hash, err := tx.Hash()
Expand Down

0 comments on commit 078fa57

Please sign in to comment.