Skip to content

Commit

Permalink
Merge pull request #3087 from tamirms/fix-txnbuild
Browse files Browse the repository at this point in the history
txnbuild: Fix bug in parsing transactions with Protocol 14 operations
  • Loading branch information
tamirms authored Oct 2, 2020
2 parents 5c62e03 + bbc57f7 commit 10d1362
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 18 deletions.
25 changes: 21 additions & 4 deletions clients/horizonclient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
## [v4.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v4.0.0) - 2020-09-29

Added new client methods and effects supporting [Protocol 14](https://github.com/stellar/go/issues/3035).

* New client methods
* `ClaimableBalances(req ClaimableBalanceRequest)` - returns details about available claimable balances, possibly filtered to a specific sponsor or other parameters.
* `ClaimableBalance(balanceID string)` - returns details about a *specific*, unique claimable balance.
* New effects:
* `ClaimableBalance{Created,Updated,Removed}`
* `ClaimabeBalanceSponsorship{Created,Updated,Removed}`
* `AccountSponsorship{Created,Updated,Removed}`
* `TrustlineSponsorship{Created,Updated,Removed}`
* `Data{Created,Updated,Removed}`
* `DataSponsorship{Created,Updated,Removed}`
* `SignerSponsorship{Created,Updated,Removed}`
* Removed JSON variant of `GET /metrics`, both in the server and client code. It's using Prometheus format by default now.
* Added `NextAccountsPage`.
* Fixed `Fund` function that consistently errored.
* Added support for Go 1.15.

### Breaking changes

* Remove JSON variant of `GET /metrics`, both in the server and client code. It's using Prometheus format by default now.
* Add `NextAccountsPage`.
* Fix `Fund` function that consistently errored.
* Dropped support for Go 1.13.

## [v3.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v3.0.0) - 2020-04-28
Expand Down
25 changes: 13 additions & 12 deletions txnbuild/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
Updated to support [Protocol 14](https://github.com/stellar/go/issues/3035) operations. There are now ways to:
## [v4.0.1](https://github.com/stellar/go/releases/tag/horizonclient-v4.0.1) - 2020-10-02

* Fixed bug in `TransactionFromXDR()` which occurs when parsing transaction XDR envelopes which contain Protocol 14 operations.

## [v4.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v4.0.0) - 2020-09-29

Added support for the new operations in [Protocol 14](https://github.com/stellar/go/issues/3035). Now it is possible to:
* Create and claim claimable balance operations (see [CAP-23](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0023.md)) with the `[Create|Claim]ClaimableBalance` structures and their associated helpers
* Begin/end sponsoring future reserves for other accounts (see [CAP-33](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0033.md)) with the `[Begin|End]SponsoringFutureReserves` operations
* Revoke sponsorships of various objects with the `RevokeSponsorship` operation
* Dropped support for Go 1.13.

## [v4.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v4.0.0) - 2020-08-31
* Revoke sponsorships of various objects with the `RevokeSponsorship` operation (see [CAP-33](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0033.md)).

Also:
* Added support for Go 1.15.
### Breaking changes

* Replace `BuildChallengeTx()`'s `anchorName string` parameter with `homeDomain string`
* Add `homeDomain string` parameter to `ReadChallengeTx()`, `VerifyChallengeTxThreshold()`, and `VerifyChallengeTxSigners()`

SEP-10 now requires clients to verify the `SIGNING_KEY` included in the TOML file of the service requiring authentication is used to sign the challenge and that the challenge's Manage Data operation key includes the requested service's home domain. These checks ensure the challenge cannot be used in a relay attack.

The breaking changes described above support the added SEP-10 2.0 requirements for both servers and clients.
* Dropped support for Go 1.13.
* Add support for SEP-10 v2.0.0.
* Replace `BuildChallengeTx`'s `anchorName` parameter with `homeDomain`.
* Add `homeDomain` parameter to `ReadChallengeTx`, `VerifyChallengeTxThreshold`, and `VerifyChallengeTxSigners`.

## [v3.2.0](https://github.com/stellar/go/releases/tag/horizonclient-v3.2.0) - 2020-06-18

Expand Down
44 changes: 44 additions & 0 deletions txnbuild/begin_sponsoring_future_reserves_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package txnbuild

import (
"github.com/stretchr/testify/assert"
"testing"
)

func roundTrip(t *testing.T, operations []Operation) {
kp1 := newKeypair1()
sourceAccount := NewSimpleAccount(kp1.Address(), int64(9606132444168199))

tx, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
Operations: operations,
Timebounds: NewInfiniteTimeout(),
BaseFee: MinBaseFee,
},
)
assert.NoError(t, err)

var b64 string
b64, err = tx.Base64()
assert.NoError(t, err)

var parsedTx *GenericTransaction
parsedTx, err = TransactionFromXDR(b64)
assert.NoError(t, err)
var ok bool
tx, ok = parsedTx.Transaction()
assert.True(t, ok)

for i := 0; i < len(operations); i++ {
assert.Equal(t, operations[i], tx.Operations()[i])
}
}

func TestBeginSponsoringFutureReservesRoundTrip(t *testing.T) {
beginSponsoring := &BeginSponsoringFutureReserves{
SponsoredID: newKeypair1().Address(),
}

roundTrip(t, []Operation{beginSponsoring})
}
13 changes: 13 additions & 0 deletions txnbuild/claim_claimable_balance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package txnbuild

import (
"testing"
)

func TestClaimClaimableBalanceRoundTrip(t *testing.T) {
claimClaimableBalance := &ClaimClaimableBalance{
BalanceID: "00000000929b20b72e5890ab51c24f1cc46fa01c4f318d8d33367d24dd614cfdf5491072",
}

roundTrip(t, []Operation{claimClaimableBalance})
}
4 changes: 2 additions & 2 deletions txnbuild/create_claimable_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func NotPredicate(pred xdr.ClaimPredicate) xdr.ClaimPredicate {
// This predicate will be fulfilled if the closing time of the ledger that
// includes the CreateClaimableBalance operation is less than this (absolute)
// Unix timestamp.
func BeforeAbsoluteTimePredicate(secondsBefore int64) xdr.ClaimPredicate {
absBefore := xdr.Int64(secondsBefore)
func BeforeAbsoluteTimePredicate(epochSeconds int64) xdr.ClaimPredicate {
absBefore := xdr.Int64(epochSeconds)
return xdr.ClaimPredicate{
Type: xdr.ClaimPredicateTypeClaimPredicateBeforeAbsoluteTime,
AbsBefore: &absBefore,
Expand Down
33 changes: 33 additions & 0 deletions txnbuild/create_claimable_balance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package txnbuild

import (
"testing"
)

func TestCreateClaimableBalanceRoundTrip(t *testing.T) {
and := AndPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10))
createNativeBalance := &CreateClaimableBalance{
Amount: "1234.0000000",
Asset: NativeAsset{},
Destinations: []Claimant{
NewClaimant(newKeypair1().Address(), &UnconditionalPredicate),
NewClaimant(newKeypair1().Address(), &and),
},
}

not := NotPredicate(UnconditionalPredicate)
or := OrPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10))
createAssetBalance := &CreateClaimableBalance{
Amount: "99.0000000",
Asset: CreditAsset{
Code: "COP",
Issuer: "GB56OJGSA6VHEUFZDX6AL2YDVG2TS5JDZYQJHDYHBDH7PCD5NIQKLSDO",
},
Destinations: []Claimant{
NewClaimant(newKeypair1().Address(), &not),
NewClaimant(newKeypair1().Address(), &or),
},
}

roundTrip(t, []Operation{createNativeBalance, createAssetBalance})
}
7 changes: 7 additions & 0 deletions txnbuild/end_sponsoring_future_reserves_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package txnbuild

import "testing"

func TestEndSponsoringFutureReservesRoundTrip(t *testing.T) {
roundTrip(t, []Operation{&EndSponsoringFutureReserves{}})
}
10 changes: 10 additions & 0 deletions txnbuild/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ func operationFromXDR(xdrOp xdr.Operation) (Operation, error) {
newOp = &ManageBuyOffer{}
case xdr.OperationTypePathPaymentStrictSend:
newOp = &PathPaymentStrictSend{}
case xdr.OperationTypeBeginSponsoringFutureReserves:
newOp = &BeginSponsoringFutureReserves{}
case xdr.OperationTypeEndSponsoringFutureReserves:
newOp = &EndSponsoringFutureReserves{}
case xdr.OperationTypeCreateClaimableBalance:
newOp = &CreateClaimableBalance{}
case xdr.OperationTypeClaimClaimableBalance:
newOp = &ClaimClaimableBalance{}
case xdr.OperationTypeRevokeSponsorship:
newOp = &RevokeSponsorship{}
}

err := newOp.FromXDR(xdrOp)
Expand Down
1 change: 1 addition & 0 deletions txnbuild/revoke_sponsorship_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestRevokeSponsorship(t *testing.T) {
var op2 RevokeSponsorship
assert.NoError(t, op2.FromXDR(xdrOp2))
assert.Equal(t, op, op2)
roundTrip(t, []Operation{&testcase.op})
})
}
}

0 comments on commit 10d1362

Please sign in to comment.