Skip to content

Commit

Permalink
Protocol v11 XDR files (#1164)
Browse files Browse the repository at this point in the history
This commit updates XDR files to be up to date with stellar-core v11.
Changes affecting this repository:

* Operation type names changes:
  * `manage_offer` -> `manage_sell_offer`,
  * `create_passive_offer` -> `create_passive_sell_offer`.
* New `manage_buy_offer` operation.
* Offer IDs are now of `int64` type.

For backward compatibility, `manage_offer` and `create_passive_offer`
type names have not been changed in Horizon. This will be a breaking
change in Horizon 0.18.0.
  • Loading branch information
bartekn authored Apr 24, 2019
1 parent 43c62a5 commit 686ff67
Show file tree
Hide file tree
Showing 29 changed files with 1,340 additions and 455 deletions.
16 changes: 8 additions & 8 deletions build/manage_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type ManageOfferMutator interface {
type ManageOfferBuilder struct {
PassiveOffer bool
O xdr.Operation
MO xdr.ManageOfferOp
PO xdr.CreatePassiveOfferOp
MO xdr.ManageSellOfferOp
PO xdr.CreatePassiveSellOfferOp
Err error
}

Expand Down Expand Up @@ -79,9 +79,9 @@ func (m Amount) MutateManageOffer(o interface{}) (err error) {
switch o := o.(type) {
default:
err = errors.New("Unexpected operation type")
case *xdr.ManageOfferOp:
case *xdr.ManageSellOfferOp:
o.Amount, err = amount.Parse(string(m))
case *xdr.CreatePassiveOfferOp:
case *xdr.CreatePassiveSellOfferOp:
o.Amount, err = amount.Parse(string(m))
}
return
Expand All @@ -92,8 +92,8 @@ func (m OfferID) MutateManageOffer(o interface{}) (err error) {
switch o := o.(type) {
default:
err = errors.New("Unexpected operation type")
case *xdr.ManageOfferOp:
o.OfferId = xdr.Uint64(m)
case *xdr.ManageSellOfferOp:
o.OfferId = xdr.Int64(m)
}
return
}
Expand All @@ -103,7 +103,7 @@ func (m Rate) MutateManageOffer(o interface{}) (err error) {
switch o := o.(type) {
default:
err = errors.New("Unexpected operation type")
case *xdr.ManageOfferOp:
case *xdr.ManageSellOfferOp:
o.Selling, err = m.Selling.ToXDR()
if err != nil {
return
Expand All @@ -115,7 +115,7 @@ func (m Rate) MutateManageOffer(o interface{}) (err error) {
}

o.Price, err = price.Parse(string(m.Price))
case *xdr.CreatePassiveOfferOp:
case *xdr.CreatePassiveSellOfferOp:
o.Selling, err = m.Selling.ToXDR()
if err != nil {
return
Expand Down
6 changes: 3 additions & 3 deletions build/manage_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("ManageOffer", func() {
Expect(builder.MO.Price.N).To(Equal(xdr.Int32(8253)))
Expect(builder.MO.Price.D).To(Equal(xdr.Int32(200)))

Expect(builder.MO.OfferId).To(Equal(xdr.Uint64(0)))
Expect(builder.MO.OfferId).To(Equal(xdr.Int64(0)))
})
})
})
Expand All @@ -75,7 +75,7 @@ var _ = Describe("ManageOffer", func() {
Expect(builder.MO.Price.N).To(Equal(xdr.Int32(8253)))
Expect(builder.MO.Price.D).To(Equal(xdr.Int32(200)))

Expect(builder.MO.OfferId).To(Equal(xdr.Uint64(5)))
Expect(builder.MO.OfferId).To(Equal(xdr.Int64(5)))
})
})
})
Expand All @@ -101,7 +101,7 @@ var _ = Describe("ManageOffer", func() {
Expect(builder.MO.Price.N).To(Equal(xdr.Int32(8253)))
Expect(builder.MO.Price.D).To(Equal(xdr.Int32(200)))

Expect(builder.MO.OfferId).To(Equal(xdr.Uint64(10)))
Expect(builder.MO.OfferId).To(Equal(xdr.Int64(10)))
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions build/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ func (m ManageOfferBuilder) MutateTransaction(o *TransactionBuilder) error {
}

if m.PassiveOffer {
m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreatePassiveOffer, m.PO)
m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreatePassiveSellOffer, m.PO)
o.TX.Operations = append(o.TX.Operations, m.O)
} else {
m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageOffer, m.MO)
m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageSellOffer, m.MO)
o.TX.Operations = append(o.TX.Operations, m.O)
}
return m.Err
Expand Down Expand Up @@ -283,7 +283,7 @@ func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) {
}

func (m Timebounds) MutateTransaction(o *TransactionBuilder) error {
o.TX.TimeBounds = &xdr.TimeBounds{MinTime: xdr.Uint64(m.MinTime), MaxTime: xdr.Uint64(m.MaxTime)}
o.TX.TimeBounds = &xdr.TimeBounds{MinTime: xdr.TimePoint(m.MinTime), MaxTime: xdr.TimePoint(m.MaxTime)}
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions build/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ var _ = Describe("Transaction Mutators:", func() {
BeforeEach(func() { mut = Timebounds{1521056118, 1521056298} })
It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) })
It("sets an minimum and maximum timebound on the transaction", func() {
Expect(subject.TX.TimeBounds.MinTime).To(Equal(xdr.Uint64(1521056118)))
Expect(subject.TX.TimeBounds.MaxTime).To(Equal(xdr.Uint64(1521056298)))
Expect(subject.TX.TimeBounds.MinTime).To(Equal(xdr.TimePoint(1521056118)))
Expect(subject.TX.TimeBounds.MaxTime).To(Equal(xdr.TimePoint(1521056298)))
})
})

Expand Down
2 changes: 1 addition & 1 deletion exp/clients/horizon/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func TestOperationsRequest(t *testing.T) {
mangageOfferOp := ops.Embedded.Records[1]
createAccountOp := ops.Embedded.Records[2]
assert.IsType(t, paymentOp, operations.Payment{})
assert.IsType(t, mangageOfferOp, operations.ManageOffer{})
assert.IsType(t, mangageOfferOp, operations.ManageSellOffer{})
assert.IsType(t, createAccountOp, operations.CreateAccount{})

c, ok := createAccountOp.(operations.CreateAccount)
Expand Down
6 changes: 3 additions & 3 deletions exp/txnbuild/cmd/txnbuild_examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func exampleCreatePassiveOffer(client *horizon.Client, mock bool) horizon.Transa
sellAmount := "10"
price := "1.0"

createPassiveOffer := txnbuild.CreatePassiveOffer{
createPassiveOffer := txnbuild.CreatePassiveSellOffer{
Selling: selling,
Buying: &buying,
Amount: sellAmount,
Expand Down Expand Up @@ -207,7 +207,7 @@ func exampleManageOfferUpdateOffer(client *horizon.Client, mock bool) horizon.Tr
}
sellAmount := "50"
price := "0.02"
offerID := uint64(2497628)
offerID := int64(2497628)

updateOffer := txnbuild.UpdateOfferOp(selling, &buying, sellAmount, price, offerID)

Expand All @@ -229,7 +229,7 @@ func exampleManageOfferDeleteOffer(client *horizon.Client, mock bool) horizon.Tr
dieIfError("loadaccount", err)
sourceAccount := mapAccounts(horizonSourceAccount)

offerID := uint64(4326054)
offerID := int64(4326054)

deleteOffer := txnbuild.DeleteOfferOp(offerID)

Expand Down
12 changes: 6 additions & 6 deletions exp/txnbuild/create_passive_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"github.com/stellar/go/xdr"
)

// CreatePassiveOffer represents the Stellar create passive offer operation. See
// CreatePassiveSellOffer represents the Stellar create passive offer operation. See
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type CreatePassiveOffer struct {
type CreatePassiveSellOffer struct {
Selling Asset
Buying Asset
Amount string
Price string // TODO: Extend to include number, and n/d fraction. See package 'amount'
}

// BuildXDR for CreatePassiveOffer returns a fully configured XDR Operation.
func (cpo *CreatePassiveOffer) BuildXDR() (xdr.Operation, error) {
// BuildXDR for CreatePassiveSellOffer returns a fully configured XDR Operation.
func (cpo *CreatePassiveSellOffer) BuildXDR() (xdr.Operation, error) {
xdrSelling, err := cpo.Selling.ToXDR()
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to set XDR 'Selling' field")
Expand All @@ -38,14 +38,14 @@ func (cpo *CreatePassiveOffer) BuildXDR() (xdr.Operation, error) {
return xdr.Operation{}, errors.Wrap(err, "failed to parse 'Price'")
}

xdrOp := xdr.CreatePassiveOfferOp{
xdrOp := xdr.CreatePassiveSellOfferOp{
Selling: xdrSelling,
Buying: xdrBuying,
Amount: xdrAmount,
Price: xdrPrice,
}

opType := xdr.OperationTypeCreatePassiveOffer
opType := xdr.OperationTypeCreatePassiveSellOffer
body, err := xdr.NewOperationBody(opType, xdrOp)

return xdr.Operation{Body: body}, errors.Wrap(err, "failed to build XDR OperationBody")
Expand Down
36 changes: 18 additions & 18 deletions exp/txnbuild/manage_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/stellar/go/xdr"
)

//CreateOfferOp returns a ManageOffer operation to create a new offer, by
//CreateOfferOp returns a ManageSellOffer operation to create a new offer, by
// setting the OfferID to "0".
func CreateOfferOp(selling, buying Asset, amount, price string) ManageOffer {
return ManageOffer{
func CreateOfferOp(selling, buying Asset, amount, price string) ManageSellOffer {
return ManageSellOffer{
Selling: selling,
Buying: buying,
Amount: amount,
Expand All @@ -19,9 +19,9 @@ func CreateOfferOp(selling, buying Asset, amount, price string) ManageOffer {
}
}

//UpdateOfferOp returns a ManageOffer operation to update an offer.
func UpdateOfferOp(selling, buying Asset, amount, price string, offerID uint64) ManageOffer {
return ManageOffer{
//UpdateOfferOp returns a ManageSellOffer operation to update an offer.
func UpdateOfferOp(selling, buying Asset, amount, price string, offerID int64) ManageSellOffer {
return ManageSellOffer{
Selling: selling,
Buying: buying,
Amount: amount,
Expand All @@ -30,14 +30,14 @@ func UpdateOfferOp(selling, buying Asset, amount, price string, offerID uint64)
}
}

//DeleteOfferOp returns a ManageOffer operation to delete an offer, by
//DeleteOfferOp returns a ManageSellOffer operation to delete an offer, by
// setting the Amount to "0".
func DeleteOfferOp(offerID uint64) ManageOffer {
func DeleteOfferOp(offerID int64) ManageSellOffer {
// It turns out Stellar core doesn't care about any of these fields except the amount.
// However, Horizon will reject ManageOffer if it is missing fields.
// However, Horizon will reject ManageSellOffer if it is missing fields.
// Horizon will also reject if Buying == Selling.
// Therefore unfortunately we have to make up some dummy values here.
return ManageOffer{
return ManageSellOffer{
Selling: NativeAsset{},
Buying: CreditAsset{Code: "FAKE", Issuer: "GBAQPADEYSKYMYXTMASBUIS5JI3LMOAWSTM2CHGDBJ3QDDPNCSO3DVAA"},
Amount: "0",
Expand All @@ -46,18 +46,18 @@ func DeleteOfferOp(offerID uint64) ManageOffer {
}
}

// ManageOffer represents the Stellar manage offer operation. See
// ManageSellOffer represents the Stellar manage offer operation. See
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type ManageOffer struct {
type ManageSellOffer struct {
Selling Asset
Buying Asset
Amount string
Price string // TODO: Extend to include number, and n/d fraction. See package 'amount'
OfferID uint64
OfferID int64
}

// BuildXDR for ManageOffer returns a fully configured XDR Operation.
func (mo *ManageOffer) BuildXDR() (xdr.Operation, error) {
// BuildXDR for ManageSellOffer returns a fully configured XDR Operation.
func (mo *ManageSellOffer) BuildXDR() (xdr.Operation, error) {
xdrSelling, err := mo.Selling.ToXDR()
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to set XDR 'Selling' field")
Expand All @@ -78,13 +78,13 @@ func (mo *ManageOffer) BuildXDR() (xdr.Operation, error) {
return xdr.Operation{}, errors.Wrap(err, "failed to parse 'Price'")
}

opType := xdr.OperationTypeManageOffer
xdrOp := xdr.ManageOfferOp{
opType := xdr.OperationTypeManageSellOffer
xdrOp := xdr.ManageSellOfferOp{
Selling: xdrSelling,
Buying: xdrBuying,
Amount: xdrAmount,
Price: xdrPrice,
OfferId: xdr.Uint64(mo.OfferID),
OfferId: xdr.Int64(mo.OfferID),
}
body, err := xdr.NewOperationBody(opType, xdrOp)

Expand Down
4 changes: 2 additions & 2 deletions exp/txnbuild/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (tx *Transaction) Build() error {
if err != nil {
return err
}
tx.xdrTransaction.TimeBounds = &xdr.TimeBounds{MinTime: xdr.Uint64(tx.Timebounds.MinTime),
MaxTime: xdr.Uint64(tx.Timebounds.MaxTime)}
tx.xdrTransaction.TimeBounds = &xdr.TimeBounds{MinTime: xdr.TimePoint(tx.Timebounds.MinTime),
MaxTime: xdr.TimePoint(tx.Timebounds.MaxTime)}

// Handle the memo, if one is present
if tx.Memo != nil {
Expand Down
6 changes: 3 additions & 3 deletions exp/txnbuild/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func TestManageOfferDeleteOffer(t *testing.T) {
kp1 := newKeypair1()
sourceAccount := makeTestAccount(kp1, "41137196761105")

offerID := uint64(2921622)
offerID := int64(2921622)
deleteOffer := DeleteOfferOp(offerID)

tx := Transaction{
Expand All @@ -506,7 +506,7 @@ func TestManageOfferUpdateOffer(t *testing.T) {
buying := CreditAsset{"ABCD", kp0.Address()}
sellAmount := "50"
price := "0.02"
offerID := uint64(2497628)
offerID := int64(2497628)
updateOffer := UpdateOfferOp(selling, buying, sellAmount, price, offerID)

tx := Transaction{
Expand All @@ -526,7 +526,7 @@ func TestCreatePassiveOffer(t *testing.T) {
kp1 := newKeypair1()
sourceAccount := makeTestAccount(kp1, "41137196761100")

createPassiveOffer := CreatePassiveOffer{
createPassiveOffer := CreatePassiveSellOffer{
Selling: NativeAsset{},
Buying: CreditAsset{"ABCD", kp0.Address()},
Amount: "10",
Expand Down
Loading

0 comments on commit 686ff67

Please sign in to comment.