Skip to content

Commit

Permalink
txnbuild: Remove TxEnvelope() functions from txnbuild (#3377)
Browse files Browse the repository at this point in the history
Remove TxEnvelope() from Transaction and FeeBumpTransaction. Now ToXDR() is the only function which produces XDR transaction envelopes.
  • Loading branch information
tamirms authored Feb 1, 2021
1 parent e5817bb commit c56bd76
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 105 deletions.
6 changes: 6 additions & 0 deletions txnbuild/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Breaking changes

* Remove `TxEnvelope()` functions from `Transaction` and `FeeBumpTransaction` to simplify the API. `ToXDR()` should be used instead of `TxEnvelope()` ([#3377](https://github.com/stellar/go/pull/3377))

## [v5.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v5.0.0) - 2020-11-12

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion txnbuild/fee_bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func TestFeeBumpRoundTrip(t *testing.T) {
outerHash, err := feeBumpTx.HashHex(network.TestNetworkPassphrase)
assert.NoError(t, err)

env, err := feeBumpTx.TxEnvelope()
env := feeBumpTx.ToXDR()
assert.NoError(t, err)
assert.Equal(t, xdr.EnvelopeTypeEnvelopeTypeTxFeeBump, env.Type)
assert.Equal(t, xdr.MustAddress(kp1.Address()), env.FeeBumpAccount().ToAccountId())
Expand Down
2 changes: 2 additions & 0 deletions txnbuild/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func newSignedFeeBumpTransaction(
}

func convertToV0(tx *Transaction) {
signatures := tx.Signatures()
tx.envelope.V0 = &xdr.TransactionV0Envelope{
Tx: xdr.TransactionV0{
SourceAccountEd25519: *tx.envelope.SourceAccount().Ed25519,
Expand All @@ -112,6 +113,7 @@ func convertToV0(tx *Transaction) {
Memo: tx.envelope.Memo(),
Operations: tx.envelope.Operations(),
},
Signatures: signatures,
}
tx.envelope.V1 = nil
tx.envelope.Type = xdr.EnvelopeTypeEnvelopeTypeTxV0
Expand Down
2 changes: 1 addition & 1 deletion txnbuild/manage_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestManageDataRoundTrip(t *testing.T) {
)
assert.NoError(t, err)

envelope, err := tx.TxEnvelope()
envelope := tx.ToXDR()
assert.NoError(t, err)
assert.Len(t, envelope.Operations(), 1)
assert.Equal(t, xdr.String64(manageData.Name), envelope.Operations()[0].Body.ManageDataOp.DataName)
Expand Down
11 changes: 4 additions & 7 deletions txnbuild/signers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ type transactionCommon interface {
Signatures() []xdr.DecoratedSignature
Hash(networkStr string) ([32]byte, error)
Base64() (string, error)
TxEnvelope() (xdr.TransactionEnvelope, error)
ToXDR() xdr.TransactionEnvelope
}

Expand All @@ -459,16 +458,10 @@ func assertBase64(t *testing.T, tx transactionCommon) string {
base64, err := tx.Base64()
assert.NoError(t, err)

envCopy, err := tx.TxEnvelope()
assert.NoError(t, err)
envCopyBase64, err := xdr.MarshalBase64(envCopy)
assert.NoError(t, err)

envRef := tx.ToXDR()
envRefBase64, err := xdr.MarshalBase64(envRef)
assert.NoError(t, err)

assert.Equal(t, base64, envCopyBase64)
assert.Equal(t, base64, envRefBase64)

return base64
Expand All @@ -489,6 +482,7 @@ func TestSigningImmutability(t *testing.T) {
root, err = root.Sign(network.TestNetworkPassphrase, kp0)
assert.NoError(t, err)
rootB64 := assertBase64(t, root)
rootXDR := root.ToXDR()

left, err := root.Sign(network.TestNetworkPassphrase, kp1)
assert.NoError(t, err)
Expand Down Expand Up @@ -517,6 +511,9 @@ func TestSigningImmutability(t *testing.T) {
verifySignatures(t, left, kp0, kp1)
assert.Equal(t, expectedRightB64, rightB64)
verifySignatures(t, right, kp0, kp2)

rootXDRB64, err := xdr.MarshalBase64(rootXDR)
assert.Equal(t, expectedRootB64, rootXDRB64)
}

func TestFeeBumpSigningImmutability(t *testing.T) {
Expand Down
Loading

0 comments on commit c56bd76

Please sign in to comment.