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: Enable Muxed accounts by default #4169

Merged
merged 5 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion clients/horizonclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Client) checkMemoRequired(transaction *txnbuild.Transaction) error {
for i, op := range transaction.Operations() {
var destination string

if err := op.Validate(true); err != nil {
if err := op.Validate(); err != nil {
return err
}

Expand Down
1 change: 0 additions & 1 deletion clients/horizonclient/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ func TestSubmitTransactionRequestMuxedAccounts(t *testing.T) {
Operations: []txnbuild.Operation{&payment},
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewTimebounds(0, 10),
EnableMuxedAccounts: true,
},
)
assert.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestNegativeSequenceTxSubmission(t *testing.T) {
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewInfiniteTimeout(),
IncrementSequenceNum: false,
EnableMuxedAccounts: true,
}
tx, err := txnbuild.NewTransaction(txParams)
tt.NoError(err)
Expand Down
1 change: 0 additions & 1 deletion services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ func (i *Test) CreateSignedTransaction(
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewInfiniteTimeout(),
IncrementSequenceNum: true,
EnableMuxedAccounts: true,
}

tx, err := txnbuild.NewTransaction(txParams)
Expand Down
10 changes: 9 additions & 1 deletion txnbuild/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased


* Enable Muxed Accounts ([SEP-23](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md)) by default:
* Remove `TransactionParams.EnableMuxedAccounts`
* Remove `TransactionFromXDROptionEnableMuxedAccounts`
* Remove `FeeBumpTransactionParams.EnableMuxedAccounts`
* Remove parameter `withMuxedAccounts bool` from all methods/functions.
* Remove `options ...TransactionFromXDROption` parameter from `TransactionFromXDR()`
* Rename `SetOpSourceMuxedAccount()` to (pre-existing) `SetOpSourceAccount()` which now accepts
both `G` and `M` (muxed) account strkeys.

## [8.0.0-beta.0](https://github.com/stellar/go/releases/tag/horizonclient-v8.0.0-beta.0) - 2021-10-04

**This release adds support for Protocol 18.**
Expand Down
34 changes: 8 additions & 26 deletions txnbuild/account_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ type AccountMerge struct {
}

// BuildXDR for AccountMerge returns a fully configured XDR Operation.
func (am *AccountMerge) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (am *AccountMerge) BuildXDR() (xdr.Operation, error) {
var xdrOp xdr.MuxedAccount
var err error
if withMuxedAccounts {
err = xdrOp.SetAddress(am.Destination)
} else {
err = xdrOp.SetEd25519Address(am.Destination)
}
err := xdrOp.SetAddress(am.Destination)
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to set destination address")
}
Expand All @@ -31,42 +26,29 @@ func (am *AccountMerge) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error)
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, am.SourceAccount)
} else {
SetOpSourceAccount(&op, am.SourceAccount)
}
SetOpSourceAccount(&op, am.SourceAccount)
return op, nil
}

// FromXDR for AccountMerge initialises the txnbuild struct from the corresponding xdr Operation.
func (am *AccountMerge) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (am *AccountMerge) FromXDR(xdrOp xdr.Operation) error {
if xdrOp.Body.Type != xdr.OperationTypeAccountMerge {
return errors.New("error parsing account_merge operation from xdr")
}

am.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
am.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
if xdrOp.Body.Destination != nil {
if withMuxedAccounts {
am.Destination = xdrOp.Body.Destination.Address()
} else {
aid := xdrOp.Body.Destination.ToAccountId()
am.Destination = aid.Address()
}
am.Destination = xdrOp.Body.Destination.Address()
}

return nil
}

// Validate for AccountMerge validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (am *AccountMerge) Validate(withMuxedAccounts bool) error {
func (am *AccountMerge) Validate() error {
var err error
if withMuxedAccounts {
_, err = xdr.AddressToMuxedAccount(am.Destination)
} else {
_, err = xdr.AddressToAccountId(am.Destination)
}
_, err = xdr.AddressToMuxedAccount(am.Destination)
if err != nil {
return NewValidationError("Destination", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion txnbuild/account_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccountMergeValidate(t *testing.T) {
},
)
if assert.Error(t, err) {
expected := "minimum valid length is 5"
expected := "invalid address length"
assert.Contains(t, err.Error(), expected)
}
}
Expand Down
14 changes: 5 additions & 9 deletions txnbuild/allow_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type AllowTrust struct {
}

// BuildXDR for AllowTrust returns a fully configured XDR Operation.
func (at *AllowTrust) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (at *AllowTrust) BuildXDR() (xdr.Operation, error) {
var xdrOp xdr.AllowTrustOp

// Set XDR address associated with the trustline
Expand Down Expand Up @@ -56,11 +56,7 @@ func (at *AllowTrust) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, at.SourceAccount)
} else {
SetOpSourceAccount(&op, at.SourceAccount)
}
SetOpSourceAccount(&op, at.SourceAccount)
return op, nil
}

Expand All @@ -79,13 +75,13 @@ func assetCodeToCreditAsset(assetCode xdr.AssetCode) (CreditAsset, error) {
}

// FromXDR for AllowTrust initialises the txnbuild struct from the corresponding xdr Operation.
func (at *AllowTrust) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (at *AllowTrust) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetAllowTrustOp()
if !ok {
return errors.New("error parsing allow_trust operation from xdr")
}

at.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
at.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
at.Trustor = result.Trustor.Address()
flag := xdr.TrustLineFlags(result.Authorize)
at.Authorize = flag.IsAuthorized()
Expand All @@ -101,7 +97,7 @@ func (at *AllowTrust) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error

// Validate for AllowTrust validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (at *AllowTrust) Validate(withMuxedAccounts bool) error {
func (at *AllowTrust) Validate() error {
err := validateStellarPublicKey(at.Trustor)
if err != nil {
return NewValidationError("Trustor", err.Error())
Expand Down
8 changes: 4 additions & 4 deletions txnbuild/begin_sponsoring_future_reserves.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type BeginSponsoringFutureReserves struct {
}

// BuildXDR for BeginSponsoringFutureReserves returns a fully configured XDR Operation.
func (bs *BeginSponsoringFutureReserves) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (bs *BeginSponsoringFutureReserves) BuildXDR() (xdr.Operation, error) {
xdrOp := xdr.BeginSponsoringFutureReservesOp{}
err := xdrOp.SponsoredId.SetAddress(bs.SponsoredID)
if err != nil {
Expand All @@ -32,20 +32,20 @@ func (bs *BeginSponsoringFutureReserves) BuildXDR(withMuxedAccounts bool) (xdr.O
}

// FromXDR for BeginSponsoringFutureReserves initializes the txnbuild struct from the corresponding xdr Operation.
func (bs *BeginSponsoringFutureReserves) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (bs *BeginSponsoringFutureReserves) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetBeginSponsoringFutureReservesOp()
if !ok {
return errors.New("error parsing begin_sponsoring_future_reserves operation from xdr")
}
bs.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
bs.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
bs.SponsoredID = result.SponsoredId.Address()

return nil
}

// Validate for BeginSponsoringFutureReserves validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (bs *BeginSponsoringFutureReserves) Validate(withMuxedAccounts bool) error {
func (bs *BeginSponsoringFutureReserves) Validate() error {
err := validateStellarPublicKey(bs.SponsoredID)
if err != nil {
return NewValidationError("SponsoredID", err.Error())
Expand Down
14 changes: 5 additions & 9 deletions txnbuild/bump_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,33 @@ type BumpSequence struct {
}

// BuildXDR for BumpSequence returns a fully configured XDR Operation.
func (bs *BumpSequence) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (bs *BumpSequence) BuildXDR() (xdr.Operation, error) {
opType := xdr.OperationTypeBumpSequence
xdrOp := xdr.BumpSequenceOp{BumpTo: xdr.SequenceNumber(bs.BumpTo)}
body, err := xdr.NewOperationBody(opType, xdrOp)
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, bs.SourceAccount)
} else {
SetOpSourceAccount(&op, bs.SourceAccount)
}
SetOpSourceAccount(&op, bs.SourceAccount)
return op, nil
}

// FromXDR for BumpSequence initialises the txnbuild struct from the corresponding xdr Operation.
func (bs *BumpSequence) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (bs *BumpSequence) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetBumpSequenceOp()
if !ok {
return errors.New("error parsing bump_sequence operation from xdr")
}

bs.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
bs.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
bs.BumpTo = int64(result.BumpTo)
return nil
}

// Validate for BumpSequence validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (bs *BumpSequence) Validate(withMuxedAccounts bool) error {
func (bs *BumpSequence) Validate() error {
err := validateAmount(bs.BumpTo)
if err != nil {
return NewValidationError("BumpTo", err.Error())
Expand Down
14 changes: 5 additions & 9 deletions txnbuild/change_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RemoveTrustlineOp(issuedAsset ChangeTrustAsset) ChangeTrust {
}

// BuildXDR for ChangeTrust returns a fully configured XDR Operation.
func (ct *ChangeTrust) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (ct *ChangeTrust) BuildXDR() (xdr.Operation, error) {
if ct.Line.IsNative() {
return xdr.Operation{}, errors.New("trustline cannot be extended to a native (XLM) asset")
}
Expand Down Expand Up @@ -58,22 +58,18 @@ func (ct *ChangeTrust) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, ct.SourceAccount)
} else {
SetOpSourceAccount(&op, ct.SourceAccount)
}
SetOpSourceAccount(&op, ct.SourceAccount)
return op, nil
}

// FromXDR for ChangeTrust initialises the txnbuild struct from the corresponding xdr Operation.
func (ct *ChangeTrust) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (ct *ChangeTrust) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetChangeTrustOp()
if !ok {
return errors.New("error parsing change_trust operation from xdr")
}

ct.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
ct.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
ct.Limit = amount.String(result.Limit)
asset, err := assetFromChangeTrustAssetXDR(result.Line)
if err != nil {
Expand All @@ -85,7 +81,7 @@ func (ct *ChangeTrust) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) erro

// Validate for ChangeTrust validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (ct *ChangeTrust) Validate(withMuxedAccounts bool) error {
func (ct *ChangeTrust) Validate() error {
// only validate limit if it has a value. Empty limit is set to the max trustline limit.
if ct.Limit != "" {
err := validateAmount(ct.Limit)
Expand Down
15 changes: 6 additions & 9 deletions txnbuild/claim_claimable_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ClaimClaimableBalance struct {
}

// BuildXDR for ClaimClaimableBalance returns a fully configured XDR Operation.
func (cb *ClaimClaimableBalance) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (cb *ClaimClaimableBalance) BuildXDR() (xdr.Operation, error) {
var xdrBalanceID xdr.ClaimableBalanceId
err := xdr.SafeUnmarshalHex(cb.BalanceID, &xdrBalanceID)
if err != nil {
Expand All @@ -31,22 +31,19 @@ func (cb *ClaimClaimableBalance) BuildXDR(withMuxedAccounts bool) (xdr.Operation
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, cb.SourceAccount)
} else {
SetOpSourceAccount(&op, cb.SourceAccount)
}
SetOpSourceAccount(&op, cb.SourceAccount)

return op, nil
}

// FromXDR for ClaimClaimableBalance initializes the txnbuild struct from the corresponding xdr Operation.
func (cb *ClaimClaimableBalance) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (cb *ClaimClaimableBalance) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetClaimClaimableBalanceOp()
if !ok {
return errors.New("error parsing claim_claimable_balance operation from xdr")
}

cb.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
cb.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
balanceID, err := xdr.MarshalHex(result.BalanceId)
if err != nil {
return errors.New("error parsing BalanceID in claim_claimable_balance operation from xdr")
Expand All @@ -58,7 +55,7 @@ func (cb *ClaimClaimableBalance) FromXDR(xdrOp xdr.Operation, withMuxedAccounts

// Validate for ClaimClaimableBalance validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (cb *ClaimClaimableBalance) Validate(withMuxedAccounts bool) error {
func (cb *ClaimClaimableBalance) Validate() error {
var xdrBalanceID xdr.ClaimableBalanceId
err := xdr.SafeUnmarshalHex(cb.BalanceID, &xdrBalanceID)
if err != nil {
Expand Down
31 changes: 10 additions & 21 deletions txnbuild/clawback.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ type Clawback struct {
}

// BuildXDR for Clawback returns a fully configured XDR Operation.
func (cb *Clawback) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
func (cb *Clawback) BuildXDR() (xdr.Operation, error) {
var fromMuxedAccount xdr.MuxedAccount
var err error
if withMuxedAccounts {
err = fromMuxedAccount.SetAddress(cb.From)
} else {
err = fromMuxedAccount.SetEd25519Address(cb.From)
}
err := fromMuxedAccount.SetAddress(cb.From)

if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to set from address")
}
Expand Down Expand Up @@ -58,23 +54,19 @@ func (cb *Clawback) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR Operation")
}
op := xdr.Operation{Body: body}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, cb.SourceAccount)
} else {
SetOpSourceAccount(&op, cb.SourceAccount)
}
SetOpSourceAccount(&op, cb.SourceAccount)
return op, nil
}

// FromXDR for Clawback initialises the txnbuild struct from the corresponding xdr Operation.
func (cb *Clawback) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {
func (cb *Clawback) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetClawbackOp()
if !ok {
return errors.New("error parsing clawback operation from xdr")
}

cb.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
cb.From = accountFromXDR(&result.From, withMuxedAccounts)
cb.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
cb.From = accountFromXDR(&result.From)
cb.Amount = amount.String(result.Amount)
asset, err := assetFromXDR(result.Asset)
if err != nil {
Expand All @@ -87,13 +79,10 @@ func (cb *Clawback) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error {

// Validate for Clawback validates the required struct fields. It returns an error if any
// of the fields are invalid. Otherwise, it returns nil.
func (cb *Clawback) Validate(withMuxedAccounts bool) error {
func (cb *Clawback) Validate() error {
var err error
if withMuxedAccounts {
_, err = xdr.AddressToMuxedAccount(cb.From)
} else {
_, err = xdr.AddressToAccountId(cb.From)
}
_, err = xdr.AddressToMuxedAccount(cb.From)

if err != nil {
return NewValidationError("From", err.Error())
}
Expand Down
Loading