Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txnbuild: Use strings to represent accounts in txnbuild operations #3393

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exp/services/recoverysigner/internal/serve/account_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ func (h accountSignHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
for _, op := range tx.Operations() {
opSourceAccount := op.GetSourceAccount()
if opSourceAccount == nil {
if opSourceAccount == "" {
continue
}

if op.GetSourceAccount().GetAccountID() != req.Address.Address() {
if op.GetSourceAccount() != req.Address.Address() {
var opHasAllowedAccount bool
for _, sa := range h.AllowedSourceAccounts {
if sa.Address() == op.GetSourceAccount().GetAccountID() {
if sa.Address() == op.GetSourceAccount() {
opHasAllowedAccount = true
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func TestAccountSign_signingAddressAccountAuthenticatedTxAndOpSourceAccountValid
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4"},
SourceAccount: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4",
Signer: &txnbuild.Signer{
Address: "GD7CGJSJ5OBOU5KOP2UQDH3MPY75UTEY27HVV5XPSL2X6DJ2VGTOSXEU",
Weight: 20,
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestAccountSign_signingAddressAccountAuthenticatedTxSourceAccountInvalid(t
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4"},
SourceAccount: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4",
Signer: &txnbuild.Signer{
Address: "GD7CGJSJ5OBOU5KOP2UQDH3MPY75UTEY27HVV5XPSL2X6DJ2VGTOSXEU",
Weight: 20,
Expand Down Expand Up @@ -666,7 +666,7 @@ func TestAccountSign_signingAddressAccountAuthenticatedOpSourceAccountInvalid(t
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GA47G3ZQBUR5NF2ZECG774O3QGKFMAW75XLXSCDICFDDV5GKGRFGFSOI"},
SourceAccount: "GA47G3ZQBUR5NF2ZECG774O3QGKFMAW75XLXSCDICFDDV5GKGRFGFSOI",
Signer: &txnbuild.Signer{
Address: "GD7CGJSJ5OBOU5KOP2UQDH3MPY75UTEY27HVV5XPSL2X6DJ2VGTOSXEU",
Weight: 20,
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestAccountSign_signingAddressAccountAuthenticatedTxAndOpSourceAccountInval
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
&txnbuild.SetOptions{
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GA47G3ZQBUR5NF2ZECG774O3QGKFMAW75XLXSCDICFDDV5GKGRFGFSOI"},
SourceAccount: "GA47G3ZQBUR5NF2ZECG774O3QGKFMAW75XLXSCDICFDDV5GKGRFGFSOI",
Signer: &txnbuild.Signer{
Address: "GD7CGJSJ5OBOU5KOP2UQDH3MPY75UTEY27HVV5XPSL2X6DJ2VGTOSXEU",
Weight: 20,
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func TestAccountSign_signingAddressEmailOwnerAuthenticatedOpSourceAccountIsAllow
Operations: []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SponsoredID: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4",
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GDR3RJVOHYR5A4RSLZ7D3GOSTPBGD2FY7KJD7ZB7363ROOQHWYDVVULS"},
SourceAccount: "GDR3RJVOHYR5A4RSLZ7D3GOSTPBGD2FY7KJD7ZB7363ROOQHWYDVVULS",
},
&txnbuild.SetOptions{
Signer: &txnbuild.Signer{
Expand Down Expand Up @@ -1098,7 +1098,7 @@ func TestAccountSign_signingAddressEmailOwnerAuthenticatedOpSourceAccountInvalid
Operations: []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SponsoredID: "GA6HNE7O2N2IXIOBZNZ4IPTS2P6DSAJJF5GD5PDLH5GYOZ6WMPSKCXD4",
SourceAccount: &txnbuild.SimpleAccount{AccountID: "GDR3RJVOHYR5A4RSLZ7D3GOSTPBGD2FY7KJD7ZB7363ROOQHWYDVVULS"},
SourceAccount: "GDR3RJVOHYR5A4RSLZ7D3GOSTPBGD2FY7KJD7ZB7363ROOQHWYDVVULS",
},
&txnbuild.SetOptions{
Signer: &txnbuild.Signer{
Expand Down
2 changes: 1 addition & 1 deletion services/friendbot/internal/minion.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (minion *Minion) checkHandleBadSequence(err *horizonclient.Error) {
func (minion *Minion) makeTx(destAddress string) (string, error) {
createAccountOp := txnbuild.CreateAccount{
Destination: destAddress,
SourceAccount: minion.BotAccount,
SourceAccount: minion.BotAccount.GetAccountID(),
Amount: minion.StartingBalance,
}
tx, err := txnbuild.NewTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ func TestSponsorships(t *testing.T) {
t.Logf("Revoking & replacing sponsorship")
ops = []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: newSponsor,
SourceAccount: newSponsor.GetAccountID(),
SponsoredID: sponsorPair.Address(),
},
&txnbuild.RevokeSponsorship{
SourceAccount: sponsor,
SourceAccount: sponsor.GetAccountID(),
SponsorshipType: txnbuild.RevokeSponsorshipTypeAccount,
Account: &newAccountID,
},
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestSponsorships(t *testing.T) {
signerKey := keypair.MustRandom().Address() // unspecified signer

ops := sponsorOperations(newAccountPair.Address(), &txnbuild.SetOptions{
SourceAccount: newAccount,
SourceAccount: newAccount.GetAccountID(),
Signer: &txnbuild.Signer{
Address: signerKey,
Weight: 1,
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestSponsorships(t *testing.T) {
newSponsorPair, newSponsor := keys[2], accounts[2]
ops = []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: newSponsor,
SourceAccount: newSponsor.GetAccountID(),
SponsoredID: sponsorPair.Address(),
},
&txnbuild.RevokeSponsorship{
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestSponsorships(t *testing.T) {
}
ops := sponsorOperations(newAccountPair.Address(),
&txnbuild.SetOptions{
SourceAccount: newAccount,
SourceAccount: newAccount.GetAccountID(),
Signer: &txnbuild.Signer{
Address: preAuthSignerKey.Address(),
Weight: 1,
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestSponsorships(t *testing.T) {
&txnbuild.ManageData{
Name: "SponsoredData",
Value: []byte("SponsoredValue"),
SourceAccount: newAccount,
SourceAccount: newAccount.GetAccountID(),
})

signers := []*keypair.Full{sponsorPair, newAccountPair}
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestSponsorships(t *testing.T) {
newSponsorPair, newSponsor := keys[2], accounts[2]
ops = []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: newSponsor,
SourceAccount: newSponsor.GetAccountID(),
SponsoredID: sponsorPair.Address(),
},
&txnbuild.RevokeSponsorship{
Expand Down Expand Up @@ -507,12 +507,12 @@ func TestSponsorships(t *testing.T) {

ops := sponsorOperations(newAccountPair.Address(),
&txnbuild.ChangeTrust{
SourceAccount: newAccount,
SourceAccount: newAccount.GetAccountID(),
Line: asset,
Limit: txnbuild.MaxTrustlineLimit,
},
&txnbuild.ManageSellOffer{
SourceAccount: newAccount,
SourceAccount: newAccount.GetAccountID(),
Selling: txnbuild.NativeAsset{},
Buying: asset,
Amount: "3",
Expand Down Expand Up @@ -572,7 +572,7 @@ func TestSponsorships(t *testing.T) {

ops = []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: newSponsor,
SourceAccount: newSponsor.GetAccountID(),
SponsoredID: sponsorPair.Address(),
},
&txnbuild.RevokeSponsorship{
Expand Down Expand Up @@ -653,11 +653,11 @@ func TestSponsorships(t *testing.T) {

ops := []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: sponsor,
SourceAccount: sponsor.GetAccountID(),
SponsoredID: sponsoreePair.Address(),
},
&txnbuild.CreateClaimableBalance{
SourceAccount: sponsoree,
SourceAccount: sponsoree.GetAccountID(),
Destinations: []txnbuild.Claimant{
txnbuild.NewClaimant(sponsorPair.Address(), nil),
txnbuild.NewClaimant(sponsoreePair.Address(), nil),
Expand Down Expand Up @@ -747,7 +747,7 @@ func sponsorOperations(account string, ops ...txnbuild.Operation) []txnbuild.Ope
},
ops...),
&txnbuild.EndSponsoringFutureReserves{
SourceAccount: &txnbuild.SimpleAccount{AccountID: account},
SourceAccount: account,
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ func TestProtocol14StateVerifier(t *testing.T) {
Amount: "100",
},
&txnbuild.ChangeTrust{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Line: txnbuild.CreditAsset{"ABCD", master.Address()},
Limit: txnbuild.MaxTrustlineLimit,
},
&txnbuild.ManageSellOffer{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Selling: txnbuild.NativeAsset{},
Buying: txnbuild.CreditAsset{"ABCD", master.Address()},
Amount: "3",
Price: "1",
},
&txnbuild.ManageData{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Name: "test",
Value: []byte("test"),
},
&txnbuild.CreateClaimableBalance{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Amount: "2",
Asset: txnbuild.NativeAsset{},
Destinations: []txnbuild.Claimant{
txnbuild.NewClaimant(keypair.MustRandom().Address(), nil),
},
},
&txnbuild.EndSponsoringFutureReserves{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
},
&txnbuild.SetOptions{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Signer: &txnbuild.Signer{
Address: signer1.Address(),
Weight: 3,
Expand All @@ -77,17 +77,17 @@ func TestProtocol14StateVerifier(t *testing.T) {
SponsoredID: sponsored.Address(),
},
&txnbuild.SetOptions{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Signer: &txnbuild.Signer{
Address: signer2.Address(),
Weight: 3,
},
},
&txnbuild.EndSponsoringFutureReserves{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
},
&txnbuild.SetOptions{
SourceAccount: sponsoredSource,
SourceAccount: sponsoredSource.AccountID,
Signer: &txnbuild.Signer{
Address: signer3.Address(),
Weight: 3,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/integration/protocol14_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestClaimableBalancePredicates(t *testing.T) {
t.Logf(" amount: %d, predicate: %+v", amount, predicate.Type)

createClaimOps[i] = &txnbuild.CreateClaimableBalance{
SourceAccount: accountA,
SourceAccount: accountA.GetAccountID(),
Destinations: []txnbuild.Claimant{claimant},
Amount: fmt.Sprintf("%d.0000000", amount),
Asset: txnbuild.NativeAsset{},
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (i *Test) CreateAccounts(count int, initialBalance string) ([]*keypair.Full
pairs[i] = pair

ops[i] = &txnbuild.CreateAccount{
SourceAccount: &masterAccount,
SourceAccount: masterAccount.AccountID,
Destination: pair.Address(),
Amount: initialBalance,
}
Expand Down
5 changes: 4 additions & 1 deletion txnbuild/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

* Fix bug in `ClaimableBalanceID()` ([#3393](https://github.com/stellar/go/pull/3393))

### 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))
* Use strings to represent accounts in Operation structs ([#3393](https://github.com/stellar/go/pull/3393))
* 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

Expand Down
6 changes: 3 additions & 3 deletions txnbuild/account_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type AccountMerge struct {
Destination string
SourceAccount Account
SourceAccount string
}

// BuildXDR for AccountMerge returns a fully configured XDR Operation.
Expand Down Expand Up @@ -56,8 +56,8 @@ func (am *AccountMerge) Validate() error {
return nil
}

// GetSourceAccount returns the source account of the operation, or nil if not
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (am *AccountMerge) GetSourceAccount() Account {
func (am *AccountMerge) GetSourceAccount() string {
return am.SourceAccount
}
6 changes: 3 additions & 3 deletions txnbuild/allow_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AllowTrust struct {
Type Asset
Authorize bool
AuthorizeToMaintainLiabilities bool
SourceAccount Account
SourceAccount string
}

// BuildXDR for AllowTrust returns a fully configured XDR Operation.
Expand Down Expand Up @@ -97,8 +97,8 @@ func (at *AllowTrust) Validate() error {
return nil
}

// GetSourceAccount returns the source account of the operation, or nil if not
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (at *AllowTrust) GetSourceAccount() Account {
func (at *AllowTrust) GetSourceAccount() string {
return at.SourceAccount
}
6 changes: 3 additions & 3 deletions txnbuild/begin_sponsoring_future_reserves.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type BeginSponsoringFutureReserves struct {
SponsoredID string
SourceAccount Account
SourceAccount string
}

// BuildXDR for BeginSponsoringFutureReserves returns a fully configured XDR Operation.
Expand Down Expand Up @@ -53,8 +53,8 @@ func (bs *BeginSponsoringFutureReserves) Validate() error {
return nil
}

// GetSourceAccount returns the source account of the operation, or nil if not
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (bs *BeginSponsoringFutureReserves) GetSourceAccount() Account {
func (bs *BeginSponsoringFutureReserves) GetSourceAccount() string {
return bs.SourceAccount
}
6 changes: 3 additions & 3 deletions txnbuild/bump_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type BumpSequence struct {
BumpTo int64
SourceAccount Account
SourceAccount string
}

// BuildXDR for BumpSequence returns a fully configured XDR Operation.
Expand Down Expand Up @@ -47,8 +47,8 @@ func (bs *BumpSequence) Validate() error {
return nil
}

// GetSourceAccount returns the source account of the operation, or nil if not
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (bs *BumpSequence) GetSourceAccount() Account {
func (bs *BumpSequence) GetSourceAccount() string {
return bs.SourceAccount
}
6 changes: 3 additions & 3 deletions txnbuild/change_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type ChangeTrust struct {
Line Asset
Limit string
SourceAccount Account
SourceAccount string
}

// MaxTrustlineLimit represents the maximum value that can be set as a trustline limit.
Expand Down Expand Up @@ -97,8 +97,8 @@ func (ct *ChangeTrust) Validate() error {
return nil
}

// GetSourceAccount returns the source account of the operation, or nil if not
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (ct *ChangeTrust) GetSourceAccount() Account {
func (ct *ChangeTrust) GetSourceAccount() string {
return ct.SourceAccount
}
Loading