diff --git a/build/manage_offer.go b/build/manage_offer.go index 3b68df7181..8b33dcf90c 100644 --- a/build/manage_offer.go +++ b/build/manage_offer.go @@ -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 } @@ -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 @@ -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 } @@ -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 @@ -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 diff --git a/build/manage_offer_test.go b/build/manage_offer_test.go index cc14b1a307..76ca697090 100644 --- a/build/manage_offer_test.go +++ b/build/manage_offer_test.go @@ -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))) }) }) }) @@ -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))) }) }) }) @@ -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))) }) }) }) diff --git a/build/transaction.go b/build/transaction.go index 0d7e27455a..14e0ceddba 100644 --- a/build/transaction.go +++ b/build/transaction.go @@ -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 @@ -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 } diff --git a/build/transaction_test.go b/build/transaction_test.go index f574262ee1..148c143229 100644 --- a/build/transaction_test.go +++ b/build/transaction_test.go @@ -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))) }) }) diff --git a/exp/clients/horizon/main_test.go b/exp/clients/horizon/main_test.go index f4e0f8c600..1fb3df783f 100644 --- a/exp/clients/horizon/main_test.go +++ b/exp/clients/horizon/main_test.go @@ -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) diff --git a/exp/txnbuild/cmd/txnbuild_examples/main.go b/exp/txnbuild/cmd/txnbuild_examples/main.go index 74e9b70054..1ba285e4c4 100644 --- a/exp/txnbuild/cmd/txnbuild_examples/main.go +++ b/exp/txnbuild/cmd/txnbuild_examples/main.go @@ -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, @@ -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) @@ -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) diff --git a/exp/txnbuild/create_passive_offer.go b/exp/txnbuild/create_passive_offer.go index 84fbf1e33f..176569458f 100644 --- a/exp/txnbuild/create_passive_offer.go +++ b/exp/txnbuild/create_passive_offer.go @@ -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") @@ -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") diff --git a/exp/txnbuild/manage_offer.go b/exp/txnbuild/manage_offer.go index d1bfc31c8d..cf9ffa48c3 100644 --- a/exp/txnbuild/manage_offer.go +++ b/exp/txnbuild/manage_offer.go @@ -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, @@ -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, @@ -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", @@ -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") @@ -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) diff --git a/exp/txnbuild/transaction.go b/exp/txnbuild/transaction.go index 2767adc89d..849d74a012 100644 --- a/exp/txnbuild/transaction.go +++ b/exp/txnbuild/transaction.go @@ -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 { diff --git a/exp/txnbuild/transaction_test.go b/exp/txnbuild/transaction_test.go index d0c72bc062..41263ad88f 100644 --- a/exp/txnbuild/transaction_test.go +++ b/exp/txnbuild/transaction_test.go @@ -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{ @@ -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{ @@ -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", diff --git a/protocols/horizon/operations/main.go b/protocols/horizon/operations/main.go index d69aa133cf..c24e0920ce 100644 --- a/protocols/horizon/operations/main.go +++ b/protocols/horizon/operations/main.go @@ -13,18 +13,23 @@ import ( // OperationTypeNames maps from operation type to the string used to represent that type // in horizon's JSON responses var TypeNames = map[xdr.OperationType]string{ - xdr.OperationTypeCreateAccount: "create_account", - xdr.OperationTypePayment: "payment", - xdr.OperationTypePathPayment: "path_payment", - xdr.OperationTypeManageOffer: "manage_offer", - xdr.OperationTypeCreatePassiveOffer: "create_passive_offer", - xdr.OperationTypeSetOptions: "set_options", - xdr.OperationTypeChangeTrust: "change_trust", - xdr.OperationTypeAllowTrust: "allow_trust", - xdr.OperationTypeAccountMerge: "account_merge", - xdr.OperationTypeInflation: "inflation", - xdr.OperationTypeManageData: "manage_data", - xdr.OperationTypeBumpSequence: "bump_sequence", + xdr.OperationTypeCreateAccount: "create_account", + xdr.OperationTypePayment: "payment", + xdr.OperationTypePathPayment: "path_payment", + // Deprecated - remove in: horizon-v0.18.0 + // Change name to `manage_sell_offer` + xdr.OperationTypeManageSellOffer: "manage_offer", + // Deprecated - remove in: horizon-v0.18.0 + // Change name to `create_passive_sell_offer` + xdr.OperationTypeCreatePassiveSellOffer: "create_passive_offer", + xdr.OperationTypeSetOptions: "set_options", + xdr.OperationTypeChangeTrust: "change_trust", + xdr.OperationTypeAllowTrust: "allow_trust", + xdr.OperationTypeAccountMerge: "account_merge", + xdr.OperationTypeInflation: "inflation", + xdr.OperationTypeManageData: "manage_data", + xdr.OperationTypeBumpSequence: "bump_sequence", + xdr.OperationTypeManageBuyOffer: "manage_buy_offer", } // Base represents the common attributes of an operation resource @@ -100,9 +105,8 @@ type ManageData struct { Value string `json:"value"` } -// CreatePassiveOffer is the json resource representing a single operation whose -// type is CreatePassiveOffer. -type CreatePassiveOffer struct { +// Offer is an embedded resource used in offer type operations. +type Offer struct { Base Amount string `json:"amount"` Price string `json:"price"` @@ -115,10 +119,23 @@ type CreatePassiveOffer struct { SellingAssetIssuer string `json:"selling_asset_issuer,omitempty"` } -// ManageOffer is the json resource representing a single operation whose type -// is ManageOffer. -type ManageOffer struct { - CreatePassiveOffer +// CreatePassiveSellOffer is the json resource representing a single operation whose +// type is CreatePassiveSellOffer. +type CreatePassiveSellOffer struct { + Offer +} + +// ManageSellOffer is the json resource representing a single operation whose type +// is ManageSellOffer. +type ManageSellOffer struct { + Offer + OfferID int64 `json:"offer_id"` +} + +// ManageBuyOffer is the json resource representing a single operation whose type +// is ManageBuyOffer. +type ManageBuyOffer struct { + Offer OfferID int64 `json:"offer_id"` } @@ -267,14 +284,14 @@ func UnmarshalOperation(operationType string, dataString []byte) (ops Operation, return } ops = op - case TypeNames[xdr.OperationTypeManageOffer]: - var op ManageOffer + case TypeNames[xdr.OperationTypeManageSellOffer]: + var op ManageSellOffer if err = json.Unmarshal(dataString, &op); err != nil { return } ops = op - case TypeNames[xdr.OperationTypeCreatePassiveOffer]: - var op CreatePassiveOffer + case TypeNames[xdr.OperationTypeCreatePassiveSellOffer]: + var op CreatePassiveSellOffer if err = json.Unmarshal(dataString, &op); err != nil { return } @@ -321,6 +338,12 @@ func UnmarshalOperation(operationType string, dataString []byte) (ops Operation, return } ops = op + case TypeNames[xdr.OperationTypeManageBuyOffer]: + var op ManageBuyOffer + if err = json.Unmarshal(dataString, &op); err != nil { + return + } + ops = op default: err = errors.New("Invalid operation format, unable to unmarshal json response") } diff --git a/protocols/stellarcore/tx_response.go b/protocols/stellarcore/tx_response.go index cd263b3b50..ee8556adc3 100644 --- a/protocols/stellarcore/tx_response.go +++ b/protocols/stellarcore/tx_response.go @@ -12,6 +12,11 @@ const ( // TXStatusDuplicate represents the status value returned by stellar-core when a submitted // transaction is a duplicate TXStatusDuplicate = "DUPLICATE" + + // TXStatusTryAgainLater represents the status value returned by stellar-core when a submitted + // transaction was not included in the previous 4 ledgers and get banned for being added in the + // next few ledgers. + TXStatusTryAgainLater = "TRY_AGAIN_LATER" ) // TXResponse represents the response returned from a submission request sent to stellar-core's /tx diff --git a/services/horizon/internal/actions_operation_test.go b/services/horizon/internal/actions_operation_test.go index e5de71bafb..1d38a09b0a 100644 --- a/services/horizon/internal/actions_operation_test.go +++ b/services/horizon/internal/actions_operation_test.go @@ -219,7 +219,7 @@ func TestOperationActions_Regressions(t *testing.T) { test.LoadScenario("trades") w = ht.Get("/operations/25769807873") if ht.Assert.Equal(200, w.Code) { - var result operations.ManageOffer + var result operations.ManageSellOffer err := json.Unmarshal(w.Body.Bytes(), &result) ht.Require.NoError(err, "failed to parse body") ht.Assert.Equal("1.0000000", result.Price) diff --git a/services/horizon/internal/codes/main.go b/services/horizon/internal/codes/main.go index eaf072a9cc..96685568ed 100644 --- a/services/horizon/internal/codes/main.go +++ b/services/horizon/internal/codes/main.go @@ -74,6 +74,10 @@ func String(code interface{}) (string, error) { return "op_no_source_account", nil case xdr.OperationResultCodeOpNotSupported: return "op_not_supported", nil + case xdr.OperationResultCodeOpTooManySubentries: + return "op_too_many_subentries", nil + case xdr.OperationResultCodeOpExceededWorkLimit: + return "op_exceeded_work_limit", nil } case xdr.CreateAccountResultCode: switch code { @@ -140,33 +144,62 @@ func String(code interface{}) (string, error) { case xdr.PathPaymentResultCodePathPaymentOverSendmax: return "op_over_source_max", nil } - case xdr.ManageOfferResultCode: + case xdr.ManageBuyOfferResultCode: switch code { - case xdr.ManageOfferResultCodeManageOfferSuccess: + case xdr.ManageBuyOfferResultCodeManageBuyOfferSuccess: return OpSuccess, nil - case xdr.ManageOfferResultCodeManageOfferMalformed: + case xdr.ManageBuyOfferResultCodeManageBuyOfferMalformed: return OpMalformed, nil - case xdr.ManageOfferResultCodeManageOfferSellNoTrust: + case xdr.ManageBuyOfferResultCodeManageBuyOfferSellNoTrust: return "op_sell_no_trust", nil - case xdr.ManageOfferResultCodeManageOfferBuyNoTrust: + case xdr.ManageBuyOfferResultCodeManageBuyOfferBuyNoTrust: return "op_buy_no_trust", nil - case xdr.ManageOfferResultCodeManageOfferSellNotAuthorized: + case xdr.ManageBuyOfferResultCodeManageBuyOfferSellNotAuthorized: return "sell_not_authorized", nil - case xdr.ManageOfferResultCodeManageOfferBuyNotAuthorized: + case xdr.ManageBuyOfferResultCodeManageBuyOfferBuyNotAuthorized: return "buy_not_authorized", nil - case xdr.ManageOfferResultCodeManageOfferLineFull: + case xdr.ManageBuyOfferResultCodeManageBuyOfferLineFull: return OpLineFull, nil - case xdr.ManageOfferResultCodeManageOfferUnderfunded: + case xdr.ManageBuyOfferResultCodeManageBuyOfferUnderfunded: return OpUnderfunded, nil - case xdr.ManageOfferResultCodeManageOfferCrossSelf: + case xdr.ManageBuyOfferResultCodeManageBuyOfferCrossSelf: return "op_cross_self", nil - case xdr.ManageOfferResultCodeManageOfferSellNoIssuer: + case xdr.ManageBuyOfferResultCodeManageBuyOfferSellNoIssuer: return "op_sell_no_issuer", nil - case xdr.ManageOfferResultCodeManageOfferBuyNoIssuer: + case xdr.ManageBuyOfferResultCodeManageBuyOfferBuyNoIssuer: return "buy_no_issuer", nil - case xdr.ManageOfferResultCodeManageOfferNotFound: + case xdr.ManageBuyOfferResultCodeManageBuyOfferNotFound: return "op_offer_not_found", nil - case xdr.ManageOfferResultCodeManageOfferLowReserve: + case xdr.ManageBuyOfferResultCodeManageBuyOfferLowReserve: + return OpLowReserve, nil + } + case xdr.ManageSellOfferResultCode: + switch code { + case xdr.ManageSellOfferResultCodeManageSellOfferSuccess: + return OpSuccess, nil + case xdr.ManageSellOfferResultCodeManageSellOfferMalformed: + return OpMalformed, nil + case xdr.ManageSellOfferResultCodeManageSellOfferSellNoTrust: + return "op_sell_no_trust", nil + case xdr.ManageSellOfferResultCodeManageSellOfferBuyNoTrust: + return "op_buy_no_trust", nil + case xdr.ManageSellOfferResultCodeManageSellOfferSellNotAuthorized: + return "sell_not_authorized", nil + case xdr.ManageSellOfferResultCodeManageSellOfferBuyNotAuthorized: + return "buy_not_authorized", nil + case xdr.ManageSellOfferResultCodeManageSellOfferLineFull: + return OpLineFull, nil + case xdr.ManageSellOfferResultCodeManageSellOfferUnderfunded: + return OpUnderfunded, nil + case xdr.ManageSellOfferResultCodeManageSellOfferCrossSelf: + return "op_cross_self", nil + case xdr.ManageSellOfferResultCodeManageSellOfferSellNoIssuer: + return "op_sell_no_issuer", nil + case xdr.ManageSellOfferResultCodeManageSellOfferBuyNoIssuer: + return "buy_no_issuer", nil + case xdr.ManageSellOfferResultCodeManageSellOfferNotFound: + return "op_offer_not_found", nil + case xdr.ManageSellOfferResultCodeManageSellOfferLowReserve: return OpLowReserve, nil } case xdr.SetOptionsResultCode: @@ -286,10 +319,12 @@ func ForOperationResult(opr xdr.OperationResult) (string, error) { ic = ir.MustPaymentResult().Code case xdr.OperationTypePathPayment: ic = ir.MustPathPaymentResult().Code - case xdr.OperationTypeManageOffer: - ic = ir.MustManageOfferResult().Code - case xdr.OperationTypeCreatePassiveOffer: - ic = ir.MustCreatePassiveOfferResult().Code + case xdr.OperationTypeManageBuyOffer: + ic = ir.MustManageBuyOfferResult().Code + case xdr.OperationTypeManageSellOffer: + ic = ir.MustManageSellOfferResult().Code + case xdr.OperationTypeCreatePassiveSellOffer: + ic = ir.MustCreatePassiveSellOfferResult().Code case xdr.OperationTypeSetOptions: ic = ir.MustSetOptionsResult().Code case xdr.OperationTypeChangeTrust: diff --git a/services/horizon/internal/docs/reference/resources/account.md b/services/horizon/internal/docs/reference/resources/account.md index 9a15d83142..8772a4852f 100644 --- a/services/horizon/internal/docs/reference/resources/account.md +++ b/services/horizon/internal/docs/reference/resources/account.md @@ -59,7 +59,7 @@ When horizon returns information about an account it uses the following format: | Attribute | Type | | |---------------|------------------|------------------------------------------------------------------------------------------------------------------------| | low_threshold | number | The weight required for a valid transaction including the [Allow Trust][allow_trust] and [Bump Sequence][bump_seq] operations. | -| med_threshold | number | The weight required for a valid transaction including the [Create Account][create_acc], [Payment][payment], [Path Payment][path_payment], [Manage Offer][manage_offer], [Create Passive Offer][passive_offer], [Change Trust][change_trust], [Inflation][inflation], and [Manage Data][manage_data] operations. | +| med_threshold | number | The weight required for a valid transaction including the [Create Account][create_acc], [Payment][payment], [Path Payment][path_payment], [Manage Buy Offer][manage_buy_offer], [Manage Sell Offer][manage_sell_offer], [Create Passive Sell Offer][passive_sell_offer], [Change Trust][change_trust], [Inflation][inflation], and [Manage Data][manage_data] operations. | | high_threshold | number | The weight required for a valid transaction including the [Account Merge][account_merge] and [Set Options]() operations. | [account_merge]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#account-merge @@ -69,8 +69,9 @@ When horizon returns information about an account it uses the following format: [create_acc]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#create-account [inflation]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#inflation [manage_data]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#manage-data -[manage_offer]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#manage-offer -[passive_offer]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#create-passive-offer +[manage_buy_offer]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#manage-buy-offer +[manage_sell_offer]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#manage-sell-offer +[passive_sell_offer]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#create-passive-sell-offer [path_payment]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#path-payment [payment]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#payment [set_options]: https://www.stellar.org/developers/guides/concepts/list-of-operations.html#set-options diff --git a/services/horizon/internal/docs/reference/resources/effect.md b/services/horizon/internal/docs/reference/resources/effect.md index 888a876822..d7c95c21d6 100644 --- a/services/horizon/internal/docs/reference/resources/effect.md +++ b/services/horizon/internal/docs/reference/resources/effect.md @@ -51,10 +51,10 @@ We can distinguish 6 effect groups: | Type | Operation | | --- | --- | -| Offer Created | manage_offer, create_passive_offer | -| Offer Removed | manage_offer, create_passive_offer, path_payment | -| Offer Updated | manage_offer, create_passive_offer, path_payment | -| Trade | manage_offer, create_passive_offer, path_payment | +| Offer Created | manage_buy_offer, manage_offer (manage_sell_offer from v0.18.0), create_passive_offer (create_passive_sell_offer from v0.18.0) | +| Offer Removed | manage_buy_offer, manage_offer (manage_sell_offer from v0.18.0), create_passive_offer (create_passive_sell_offer from v0.18.0), path_payment | +| Offer Updated | manage_buy_offer, manage_offer (manage_sell_offer from v0.18.0), create_passive_offer (create_passive_sell_offer from v0.18.0), path_payment | +| Trade | manage_buy_offer, manage_offer (manage_sell_offer from v0.18.0), create_passive_offer (create_passive_sell_offer from v0.18.0), path_payment | ### Data effects diff --git a/services/horizon/internal/docs/reference/resources/operation.md b/services/horizon/internal/docs/reference/resources/operation.md index be603bc1a8..86109251f1 100644 --- a/services/horizon/internal/docs/reference/resources/operation.md +++ b/services/horizon/internal/docs/reference/resources/operation.md @@ -12,18 +12,20 @@ To learn more about the concept of operations in the Stellar network, take a loo | type | type_i | description | |-----------------------------------------------|--------|------------------------------------------------------------------------------------------------------------| -| [CREATE_ACCOUNT](#create-account) | 0 | Creates a new account in Stellar network. -| [PAYMENT](#payment) | 1 | Sends a simple payment between two accounts in Stellar network. -| [PATH_PAYMENT](#path-payment) | 2 | Sends a path payment between two accounts in the Stellar network. -| [MANAGE_OFFER](#manage-offer) | 3 | Creates, updates or deletes an offer in the Stellar network. -| [CREATE_PASSIVE_OFFER](#create-passive-offer) | 4 | Creates an offer that won't consume a counter offer that exactly matches this offer. -| [SET_OPTIONS](#set-options) | 5 | Sets account options (inflation destination, adding signers, etc.) -| [CHANGE_TRUST](#change-trust) | 6 | Creates, updates or deletes a trust line. -| [ALLOW_TRUST](#allow-trust) | 7 | Updates the "authorized" flag of an existing trust line this is called by the issuer of the related asset. -| [ACCOUNT_MERGE](#account-merge) | 8 | Deletes account and transfers remaining balance to destination account. -| [INFLATION](#inflation) | 9 | Runs inflation. -| [MANAGE_DATA](#manage-data) | 10 | Set, modify or delete a Data Entry (name/value pair) for an account. -| [BUMP_SEQUENCE](#bump-sequence) | 11 | Bumps forward the sequence number of an account. +| [CREATE_ACCOUNT](#create-account) | 0 | Creates a new account in Stellar network. +| [PAYMENT](#payment) | 1 | Sends a simple payment between two accounts in Stellar network. +| [PATH_PAYMENT](#path-payment) | 2 | Sends a path payment between two accounts in the Stellar network. +| [MANAGE_SELL_OFFER](#manage-sell-offer) | 3 | Creates, updates or deletes a sell offer in the Stellar network. +| [MANAGE_BUY_OFFER](#manage-buy-offer) | 12 | Creates, updates or deletes a buy offer in the Stellar network. +| [CREATE_PASSIVE_SELL_OFFER](#create-passive-sell-offer) | 4 | Creates an offer that won't consume a counter offer that exactly matches this offer. +| [SET_OPTIONS](#set-options) | 5 | Sets account options (inflation destination, adding signers, etc.) +| [CHANGE_TRUST](#change-trust) | 6 | Creates, updates or deletes a trust line. +| [ALLOW_TRUST](#allow-trust) | 7 | Updates the "authorized" flag of an existing trust line this is called by the issuer of the related asset. +| [ACCOUNT_MERGE](#account-merge) | 8 | Deletes account and transfers remaining balance to destination account. +| [INFLATION](#inflation) | 9 | Runs inflation. +| [MANAGE_DATA](#manage-data) | 10 | Set, modify or delete a Data Entry (name/value pair) for an account. +| [BUMP_SEQUENCE](#bump-sequence) | 11 | Bumps forward the sequence number of an account. + Every operation type shares a set of common attributes and links, some operations also contain @@ -221,10 +223,10 @@ A path payment operation represents a payment from one account to another throug } ``` - -### Manage Offer + +### Manage Sell Offer -A "Manage Offer" operation can create, update or delete an +A "Manage Sell Offer" operation can create, update or delete a sell offer to trade assets in the Stellar network. It specifies an issuer, a price and amount of a given asset to buy or sell. @@ -236,6 +238,14 @@ In the event that there are not enough crossing orders to fill the order complet a new "Offer" object will be created in the ledger. As other accounts make offers or payments, this offer can potentially be filled. +#### Sell Offer vs. Buy Offer + +A [sell offer](#manage-sell-offer) specifies a certain amount of the `selling` asset that should be sold in exchange for the maximum quantity of the `buying` asset. It additionally only crosses offers where the price is higher than `price`. + +A [buy offer](#manage-buy-offer) specifies a certain amount of the `buying` asset that should be bought in exchange for the minimum quantity of the `selling` asset. It additionally only crosses offers where the price is lower than `price`. + +Both will fill only partially (or not at all) if there are few (or no) offers that cross them. + #### Attributes | Field | Type | Description | @@ -245,7 +255,7 @@ offers or payments, this offer can potentially be filled. | buying_asset_code | string | The code of asset to buy. | | buying_asset_issuer | string | The issuer of asset to buy. | | buying_asset_type | string | Type of asset to buy (native / alphanum4 / alphanum12) | -| price | string | Price to buy a buying_asset | +| price | string | Price of selling_asset in units of buying_asset | | price_r | Object | n: price numerator, d: price denominator | | selling_asset_code | string | The code of asset to sell. | | selling_asset_issuer | string | The issuer of asset to sell. | @@ -290,18 +300,91 @@ offers or payments, this offer can potentially be filled. "selling_asset_type": "credit_alphanum4", "transaction_successful": true, "type_i": 3, - "type": "manage_offer" + "type": "manage_offer" // `manage_sell_offer` from v0.18.0 +} +``` + + +### Manage Buy Offer + +A "Manage Buy Offer" operation can create, update or delete a buy +offer to trade assets in the Stellar network. +It specifies an issuer, a price and amount of a given asset to +buy or sell. + +When this operation is applied to the ledger, trades can potentially be executed if +this offer crosses others that already exist in the ledger. + +In the event that there are not enough crossing orders to fill the order completely +a new "Offer" object will be created in the ledger. As other accounts make +offers or payments, this offer can potentially be filled. + +#### Attributes + +| Field | Type | Description | +| --------------- | ------ | ----------------- | +| offer_id | number | Offer ID. | +| buy_amount | string | Amount of asset to be bought. | +| buying_asset_code | string | The code of asset to buy. | +| buying_asset_issuer | string | The issuer of asset to buy. | +| buying_asset_type | string | Type of asset to buy (native / alphanum4 / alphanum12) | +| price | string | Price of thing being bought in terms of what you are selling. | +| price_r | Object | n: price numerator, d: price denominator | +| selling_asset_code | string | The code of asset to sell. | +| selling_asset_issuer | string | The issuer of asset to sell. | +| selling_asset_type | string | Type of asset to sell (native / alphanum4 / alphanum12) | + +#### Example + +```json +{ + "_links": { + "effects": { + "href": "/operations/592323234762753/effects{?cursor,limit,order}", + "templated": true + }, + "precedes": { + "href": "/operations?cursor=592323234762753\u0026order=asc" + }, + "self": { + "href": "/operations/592323234762753" + }, + "succeeds": { + "href": "/operations?cursor=592323234762753\u0026order=desc" + }, + "transaction": { + "href": "/transactions/592323234762752" + } + }, + "amount": "100.0", + "buying_asset_code": "CHP", + "buying_asset_issuer": "GAC2ZUXVI5266NMMGDPBMXHH4BTZKJ7MMTGXRZGX2R5YLMFRYLJ7U5EA", + "buying_asset_type": "credit_alphanum4", + "id": 592323234762753, + "offer_id": 8, + "paging_token": "592323234762753", + "price": "2.0", + "price_r": { + "d": 1, + "n": 2 + }, + "selling_asset_code": "YEN", + "selling_asset_issuer": "GDVXG2FMFFSUMMMBIUEMWPZAIU2FNCH7QNGJMWRXRD6K5FZK5KJS4DDR", + "selling_asset_type": "credit_alphanum4", + "transaction_successful": true, + "type_i": 12, + "type": "manage_buy_offer" } ``` - -### Create Passive Offer + +### Create Passive Sell Offer -“Create Passive Offer” operation creates an offer that won't consume a counter offer that exactly matches this offer. This is useful for offers just used as 1:1 exchanges for path payments. Use Manage Offer to manage this offer after using this operation to create it. +“Create Passive Sell Offer” operation creates an offer that won't consume a counter offer that exactly matches this offer. This is useful for offers just used as 1:1 exchanges for path payments. Use Manage Sell Offer to manage this offer after using this operation to create it. #### Attributes -As in [Manage Offer](#manage-offer) operation. +As in [Manage Sell Offer](#manage-sell-offer) operation. #### Example @@ -340,7 +423,7 @@ As in [Manage Offer](#manage-offer) operation. "selling_asset_type": "native", "transaction_successful": true, "type_i": 4, - "type": "create_passive_offer" + "type": "create_passive_offer" // `create_passive_sell_offer` from v0.18.0 } ``` diff --git a/services/horizon/internal/ingest/asset_stat.go b/services/horizon/internal/ingest/asset_stat.go index 1d5143b138..34860232fb 100644 --- a/services/horizon/internal/ingest/asset_stat.go +++ b/services/horizon/internal/ingest/asset_stat.go @@ -84,14 +84,18 @@ func (assetStats *AssetStats) IngestOperation(op *xdr.Operation, source *xdr.Acc for _, asset := range body.PathPaymentOp.Path { assetStats.add(asset) } - case xdr.OperationTypeManageOffer: + case xdr.OperationTypeManageBuyOffer: // if this gets expensive then we can limit it to only include those assets that includes the issuer - assetStats.add(body.ManageOfferOp.Buying) - assetStats.add(body.ManageOfferOp.Selling) - case xdr.OperationTypeCreatePassiveOffer: + assetStats.add(body.ManageBuyOfferOp.Buying) + assetStats.add(body.ManageBuyOfferOp.Selling) + case xdr.OperationTypeManageSellOffer: // if this gets expensive then we can limit it to only include those assets that includes the issuer - assetStats.add(body.CreatePassiveOfferOp.Buying) - assetStats.add(body.CreatePassiveOfferOp.Selling) + assetStats.add(body.ManageSellOfferOp.Buying) + assetStats.add(body.ManageSellOfferOp.Selling) + case xdr.OperationTypeCreatePassiveSellOffer: + // if this gets expensive then we can limit it to only include those assets that includes the issuer + assetStats.add(body.CreatePassiveSellOfferOp.Buying) + assetStats.add(body.CreatePassiveSellOfferOp.Selling) case xdr.OperationTypeChangeTrust: assetStats.add(body.ChangeTrustOp.Line) case xdr.OperationTypeAllowTrust: diff --git a/services/horizon/internal/ingest/asset_stat_test.go b/services/horizon/internal/ingest/asset_stat_test.go index 69bb2c2a36..a7a1dc2280 100644 --- a/services/horizon/internal/ingest/asset_stat_test.go +++ b/services/horizon/internal/ingest/asset_stat_test.go @@ -229,7 +229,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCFZWN3AOVFQM2BZTZX7P47WSI4QMGJC62LILPKODTNDLVKZZNA5BQJ3", // issuerUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeManageOffer, xdr.ManageOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeManageSellOffer, xdr.ManageSellOfferOp{ Selling: sourceUSD, Buying: anotherUSD, Amount: 1000000, @@ -241,7 +241,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCYLTPOU7IVYHHA3XKQF4YB4W4ZWHFERMOQ7K47IWANKNBFBNJJNEOG5", // sourceUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeManageOffer, xdr.ManageOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeManageSellOffer, xdr.ManageSellOfferOp{ Selling: issuerUSD, Buying: sourceUSD, Amount: 1000000, @@ -253,7 +253,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCYLTPOU7IVYHHA3XKQF4YB4W4ZWHFERMOQ7K47IWANKNBFBNJJNEOG5", // sourceUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeManageOffer, xdr.ManageOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeManageSellOffer, xdr.ManageSellOfferOp{ Selling: issuerUSD, Buying: anotherUSD, Amount: 1000000, @@ -265,7 +265,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCFZWN3AOVFQM2BZTZX7P47WSI4QMGJC62LILPKODTNDLVKZZNA5BQJ3", // issuerUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeCreatePassiveOffer, xdr.CreatePassiveOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeCreatePassiveSellOffer, xdr.CreatePassiveSellOfferOp{ Selling: sourceUSD, Buying: anotherUSD, Amount: 1000000, @@ -276,7 +276,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCYLTPOU7IVYHHA3XKQF4YB4W4ZWHFERMOQ7K47IWANKNBFBNJJNEOG5", // sourceUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeCreatePassiveOffer, xdr.CreatePassiveOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeCreatePassiveSellOffer, xdr.CreatePassiveSellOfferOp{ Selling: issuerUSD, Buying: sourceUSD, Amount: 1000000, @@ -287,7 +287,7 @@ func TestAssetModified(t *testing.T) { "credit_alphanum4/USD/GCYLTPOU7IVYHHA3XKQF4YB4W4ZWHFERMOQ7K47IWANKNBFBNJJNEOG5", // sourceUSD }, }, { - opBody: makeOperationBody(xdr.OperationTypeCreatePassiveOffer, xdr.CreatePassiveOfferOp{ + opBody: makeOperationBody(xdr.OperationTypeCreatePassiveSellOffer, xdr.CreatePassiveSellOfferOp{ Selling: issuerUSD, Buying: anotherUSD, Amount: 1000000, diff --git a/services/horizon/internal/ingest/ingestion_test.go b/services/horizon/internal/ingest/ingestion_test.go index 0bcfe9ac80..213ff74308 100644 --- a/services/horizon/internal/ingest/ingestion_test.go +++ b/services/horizon/internal/ingest/ingestion_test.go @@ -76,8 +76,8 @@ func TestTimeBoundsMaxBig(t *testing.T) { "", sqx.StringArray([]string{}), ingestion.formatTimeBounds(&xdr.TimeBounds{ - MinTime: xdr.Uint64(0), - MaxTime: xdr.Uint64(9999999999999999999), + MinTime: xdr.TimePoint(0), + MaxTime: xdr.TimePoint(9999999999999999999), }), "id", "111", diff --git a/services/horizon/internal/ingest/participants/main.go b/services/horizon/internal/ingest/participants/main.go index 0b1b540d88..8ba0ff2a07 100644 --- a/services/horizon/internal/ingest/participants/main.go +++ b/services/horizon/internal/ingest/participants/main.go @@ -28,9 +28,11 @@ func ForOperation( result = append(result, op.Body.MustPaymentOp().Destination) case xdr.OperationTypePathPayment: result = append(result, op.Body.MustPathPaymentOp().Destination) - case xdr.OperationTypeManageOffer: + case xdr.OperationTypeManageBuyOffer: // the only direct participant is the source_account - case xdr.OperationTypeCreatePassiveOffer: + case xdr.OperationTypeManageSellOffer: + // the only direct participant is the source_account + case xdr.OperationTypeCreatePassiveSellOffer: // the only direct participant is the source_account case xdr.OperationTypeSetOptions: // the only direct participant is the source_account diff --git a/services/horizon/internal/ingest/session.go b/services/horizon/internal/ingest/session.go index e2e2296d56..3744bf0950 100644 --- a/services/horizon/internal/ingest/session.go +++ b/services/horizon/internal/ingest/session.go @@ -197,19 +197,22 @@ func (is *Session) ingestEffects() { effects.Add(source, history.EffectAccountDebited, dets) is.ingestTradeEffects(effects, source, resultSuccess.Offers) - case xdr.OperationTypeManageOffer: - result := is.Cursor.OperationResult().MustManageOfferResult().MustSuccess() + case xdr.OperationTypeManageBuyOffer: + result := is.Cursor.OperationResult().MustManageBuyOfferResult().MustSuccess() is.ingestTradeEffects(effects, source, result.OffersClaimed) - case xdr.OperationTypeCreatePassiveOffer: + case xdr.OperationTypeManageSellOffer: + result := is.Cursor.OperationResult().MustManageSellOfferResult().MustSuccess() + is.ingestTradeEffects(effects, source, result.OffersClaimed) + case xdr.OperationTypeCreatePassiveSellOffer: claims := []xdr.ClaimOfferAtom{} result := is.Cursor.OperationResult() // KNOWN ISSUE: stellar-core creates results for CreatePassiveOffer operations // with the wrong result arm set. - if result.Type == xdr.OperationTypeManageOffer { - claims = result.MustManageOfferResult().MustSuccess().OffersClaimed + if result.Type == xdr.OperationTypeManageSellOffer { + claims = result.MustManageSellOfferResult().MustSuccess().OffersClaimed } else { - claims = result.MustCreatePassiveOfferResult().MustSuccess().OffersClaimed + claims = result.MustCreatePassiveSellOfferResult().MustSuccess().OffersClaimed } is.ingestTradeEffects(effects, source, claims) @@ -539,22 +542,27 @@ func (is *Session) ingestTrades() { MustSuccess(). Offers - case xdr.OperationTypeManageOffer: - manageOfferResult := cursor.OperationResult().MustManageOfferResult().MustSuccess() + case xdr.OperationTypeManageBuyOffer: + manageOfferResult := cursor.OperationResult().MustManageBuyOfferResult().MustSuccess() + trades = manageOfferResult.OffersClaimed + buyOffer, buyOfferExists = manageOfferResult.Offer.GetOffer() + + case xdr.OperationTypeManageSellOffer: + manageOfferResult := cursor.OperationResult().MustManageSellOfferResult().MustSuccess() trades = manageOfferResult.OffersClaimed buyOffer, buyOfferExists = manageOfferResult.Offer.GetOffer() - case xdr.OperationTypeCreatePassiveOffer: + case xdr.OperationTypeCreatePassiveSellOffer: result := cursor.OperationResult() // KNOWN ISSUE: stellar-core creates results for CreatePassiveOffer operations // with the wrong result arm set. - if result.Type == xdr.OperationTypeManageOffer { - manageOfferResult := result.MustManageOfferResult().MustSuccess() + if result.Type == xdr.OperationTypeManageSellOffer { + manageOfferResult := result.MustManageSellOfferResult().MustSuccess() trades = manageOfferResult.OffersClaimed buyOffer, buyOfferExists = manageOfferResult.Offer.GetOffer() } else { - passiveOfferResult := result.MustCreatePassiveOfferResult().MustSuccess() + passiveOfferResult := result.MustCreatePassiveSellOfferResult().MustSuccess() trades = passiveOfferResult.OffersClaimed buyOffer, buyOfferExists = passiveOfferResult.Offer.GetOffer() } @@ -748,8 +756,19 @@ func (is *Session) operationDetails() map[string]interface{} { is.assetDetails(path[i], op.Path[i], "") } details["path"] = path - case xdr.OperationTypeManageOffer: - op := c.Operation().Body.MustManageOfferOp() + case xdr.OperationTypeManageBuyOffer: + op := c.Operation().Body.MustManageBuyOfferOp() + details["offer_id"] = op.OfferId + details["amount"] = amount.String(op.BuyAmount) + details["price"] = op.Price.String() + details["price_r"] = map[string]interface{}{ + "n": op.Price.N, + "d": op.Price.D, + } + is.assetDetails(details, op.Buying, "buying_") + is.assetDetails(details, op.Selling, "selling_") + case xdr.OperationTypeManageSellOffer: + op := c.Operation().Body.MustManageSellOfferOp() details["offer_id"] = op.OfferId details["amount"] = amount.String(op.Amount) details["price"] = op.Price.String() @@ -759,9 +778,8 @@ func (is *Session) operationDetails() map[string]interface{} { } is.assetDetails(details, op.Buying, "buying_") is.assetDetails(details, op.Selling, "selling_") - - case xdr.OperationTypeCreatePassiveOffer: - op := c.Operation().Body.MustCreatePassiveOfferOp() + case xdr.OperationTypeCreatePassiveSellOffer: + op := c.Operation().Body.MustCreatePassiveSellOfferOp() details["amount"] = amount.String(op.Amount) details["price"] = op.Price.String() details["price_r"] = map[string]interface{}{ diff --git a/services/horizon/internal/resourceadapter/operations.go b/services/horizon/internal/resourceadapter/operations.go index b1dfc29ddd..5663c83185 100644 --- a/services/horizon/internal/resourceadapter/operations.go +++ b/services/horizon/internal/resourceadapter/operations.go @@ -40,13 +40,19 @@ func NewOperation( e.Payment.Base = base err = row.UnmarshalDetails(&e) result = e - case xdr.OperationTypeManageOffer: - e := operations.ManageOffer{} - e.CreatePassiveOffer.Base = base + case xdr.OperationTypeManageBuyOffer: + e := operations.ManageBuyOffer{} + e.Offer.Base = base err = row.UnmarshalDetails(&e) result = e - case xdr.OperationTypeCreatePassiveOffer: - e := operations.CreatePassiveOffer{Base: base} + case xdr.OperationTypeManageSellOffer: + e := operations.ManageSellOffer{} + e.Offer.Base = base + err = row.UnmarshalDetails(&e) + result = e + case xdr.OperationTypeCreatePassiveSellOffer: + e := operations.CreatePassiveSellOffer{} + e.Offer.Base = base err = row.UnmarshalDetails(&e) result = e case xdr.OperationTypeSetOptions: diff --git a/services/horizon/internal/txsub/submitter.go b/services/horizon/internal/txsub/submitter.go index f7ac291b43..511d843025 100644 --- a/services/horizon/internal/txsub/submitter.go +++ b/services/horizon/internal/txsub/submitter.go @@ -59,7 +59,7 @@ func (sub *submitter) Submit(ctx context.Context, env string) (result Submission switch cresp.Status { case proto.TXStatusError: result.Err = &FailedTransactionError{cresp.Error} - case proto.TXStatusPending, proto.TXStatusDuplicate: + case proto.TXStatusPending, proto.TXStatusDuplicate, proto.TXStatusTryAgainLater: //noop. A nil Err indicates success default: result.Err = errors.Errorf("Unrecognized stellar-core status response: %s", cresp.Status) diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index ed7b09adee..200e11a67e 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -12,6 +12,7 @@ typedef opaque Thresholds[4]; typedef string string32<32>; typedef string string64<64>; typedef int64 SequenceNumber; +typedef uint64 TimePoint; typedef opaque DataValue<64>; enum AssetType @@ -105,7 +106,6 @@ const MASK_ACCOUNT_FLAGS = 0x7; Other ledger entries created require an account. */ - struct AccountEntry { AccountID accountID; // master public key for this account @@ -210,7 +210,7 @@ const MASK_OFFERENTRY_FLAGS = 1; struct OfferEntry { AccountID sellerID; - uint64 offerID; + int64 offerID; Asset selling; // A Asset buying; // B int64 amount; // amount of A @@ -283,6 +283,7 @@ enum EnvelopeType { ENVELOPE_TYPE_SCP = 1, ENVELOPE_TYPE_TX = 2, - ENVELOPE_TYPE_AUTH = 3 + ENVELOPE_TYPE_AUTH = 3, + ENVELOPE_TYPE_SCPVALUE = 4 }; } diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index 5021112c8a..9e5f77bf3e 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -10,12 +10,24 @@ namespace stellar typedef opaque UpgradeType<128>; +enum StellarValueType +{ + STELLAR_VALUE_BASIC = 0, + STELLAR_VALUE_SIGNED = 1 +}; + +struct LedgerCloseValueSignature +{ + NodeID nodeID; // which node introduced the value + Signature signature; // nodeID's signature +}; + /* StellarValue is the value used by SCP to reach consensus on a given ledger -*/ + */ struct StellarValue { - Hash txSetHash; // transaction set to apply to previous ledger - uint64 closeTime; // network close time + Hash txSetHash; // transaction set to apply to previous ledger + TimePoint closeTime; // network close time // upgrades to apply to the previous ledger (usually empty) // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop @@ -27,15 +39,17 @@ struct StellarValue // reserved for future use union switch (int v) { - case 0: + case STELLAR_VALUE_BASIC: void; + case STELLAR_VALUE_SIGNED: + LedgerCloseValueSignature lcValueSignature; } ext; }; /* The LedgerHeader is the highest level structure representing the * state of a ledger, cryptographically linked to previous ledgers. -*/ + */ struct LedgerHeader { uint32 ledgerVersion; // the protocol version of the ledger @@ -120,7 +134,7 @@ case OFFER: struct { AccountID sellerID; - uint64 offerID; + int64 offerID; } offer; case DATA: @@ -133,17 +147,38 @@ case DATA: enum BucketEntryType { - LIVEENTRY = 0, - DEADENTRY = 1 + METAENTRY = + -1, // At-and-after protocol 11: bucket metadata, should come first. + LIVEENTRY = 0, // Before protocol 11: created-or-updated; + // At-and-after protocol 11: only updated. + DEADENTRY = 1, + INITENTRY = 2 // At-and-after protocol 11: only created. +}; + +struct BucketMetadata +{ + // Indicates the protocol version used to create / merge this bucket. + uint32 ledgerVersion; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; }; union BucketEntry switch (BucketEntryType type) { case LIVEENTRY: +case INITENTRY: LedgerEntry liveEntry; case DEADENTRY: LedgerKey deadEntry; +case METAENTRY: + BucketMetadata metaEntry; }; // Transaction sets are the unit used by SCP to decide on transitions @@ -268,7 +303,7 @@ struct OperationMeta struct TransactionMetaV1 { LedgerEntryChanges txChanges; // tx level changes if any - OperationMeta operations<>; // meta for each operation + OperationMeta operations<>; // meta for each operation }; // this is the meta produced when applying transactions diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index 22c3a6139e..cf6dce07fb 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -18,15 +18,16 @@ enum OperationType CREATE_ACCOUNT = 0, PAYMENT = 1, PATH_PAYMENT = 2, - MANAGE_OFFER = 3, - CREATE_PASSIVE_OFFER = 4, + MANAGE_SELL_OFFER = 3, + CREATE_PASSIVE_SELL_OFFER = 4, SET_OPTIONS = 5, CHANGE_TRUST = 6, ALLOW_TRUST = 7, ACCOUNT_MERGE = 8, INFLATION = 9, MANAGE_DATA = 10, - BUMP_SEQUENCE = 11 + BUMP_SEQUENCE = 11, + MANAGE_BUY_OFFER = 12 }; /* CreateAccount @@ -37,7 +38,6 @@ Threshold: med Result: CreateAccountResult */ - struct CreateAccountOp { AccountID destination; // account to create @@ -88,10 +88,10 @@ struct PathPaymentOp Threshold: med -Result: ManageOfferResult +Result: ManageSellOfferResult */ -struct ManageOfferOp +struct ManageSellOfferOp { Asset selling; Asset buying; @@ -99,17 +99,36 @@ struct ManageOfferOp Price price; // price of thing being sold in terms of what you are buying // 0=create a new offer, otherwise edit an existing offer - uint64 offerID; + int64 offerID; +}; + +/* Creates, updates or deletes an offer with amount in terms of buying asset + +Threshold: med + +Result: ManageBuyOfferResult + +*/ +struct ManageBuyOfferOp +{ + Asset selling; + Asset buying; + int64 buyAmount; // amount being bought. if set to 0, delete the offer + Price price; // price of thing being bought in terms of what you are + // selling + + // 0=create a new offer, otherwise edit an existing offer + int64 offerID; }; /* Creates an offer that doesn't take offers of the same price Threshold: med -Result: CreatePassiveOfferResult +Result: CreatePassiveSellOfferResult */ -struct CreatePassiveOfferOp +struct CreatePassiveSellOfferOp { Asset selling; // A Asset buying; // B @@ -126,7 +145,6 @@ struct CreatePassiveOfferOp Result: SetOptionsResult */ - struct SetOptionsOp { AccountID* inflationDest; // sets the inflation destination @@ -215,7 +233,6 @@ Result: InflationResult Result: ManageDataResult */ - struct ManageDataOp { string64 dataName; @@ -226,9 +243,10 @@ struct ManageDataOp increases the sequence to a given level + Threshold: low + Result: BumpSequenceResult */ - struct BumpSequenceOp { SequenceNumber bumpTo; @@ -250,10 +268,10 @@ struct Operation PaymentOp paymentOp; case PATH_PAYMENT: PathPaymentOp pathPaymentOp; - case MANAGE_OFFER: - ManageOfferOp manageOfferOp; - case CREATE_PASSIVE_OFFER: - CreatePassiveOfferOp createPassiveOfferOp; + case MANAGE_SELL_OFFER: + ManageSellOfferOp manageSellOfferOp; + case CREATE_PASSIVE_SELL_OFFER: + CreatePassiveSellOfferOp createPassiveSellOfferOp; case SET_OPTIONS: SetOptionsOp setOptionsOp; case CHANGE_TRUST: @@ -268,6 +286,8 @@ struct Operation ManageDataOp manageDataOp; case BUMP_SEQUENCE: BumpSequenceOp bumpSequenceOp; + case MANAGE_BUY_OFFER: + ManageBuyOfferOp manageBuyOfferOp; } body; }; @@ -297,10 +317,13 @@ case MEMO_RETURN: struct TimeBounds { - uint64 minTime; - uint64 maxTime; // 0 here means no maxTime + TimePoint minTime; + TimePoint maxTime; // 0 here means no maxTime }; +// maximum number of operations per transaction +const MAX_OPS_PER_TX = 100; + /* a transaction is a container for a set of operations - is executed by an account - fees are collected from the account @@ -308,7 +331,6 @@ struct TimeBounds either all operations are applied or none are if any returns a failing code */ - struct Transaction { // account used to run the transaction @@ -325,7 +347,7 @@ struct Transaction Memo memo; - Operation operations<100>; + Operation operations; // reserved for future use union switch (int v) @@ -364,7 +386,7 @@ struct ClaimOfferAtom { // emitted to identify the offer AccountID sellerID; // Account that owns the offer - uint64 offerID; + int64 offerID; // amount and asset taken from the owner Asset assetSold; @@ -468,29 +490,29 @@ default: void; }; -/******* ManageOffer Result ********/ +/******* ManageSellOffer Result ********/ -enum ManageOfferResultCode +enum ManageSellOfferResultCode { // codes considered as "success" for the operation - MANAGE_OFFER_SUCCESS = 0, + MANAGE_SELL_OFFER_SUCCESS = 0, // codes considered as "failure" for the operation - MANAGE_OFFER_MALFORMED = -1, // generated offer would be invalid - MANAGE_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling - MANAGE_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying - MANAGE_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell - MANAGE_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy - MANAGE_OFFER_LINE_FULL = -6, // can't receive more of what it's buying - MANAGE_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell - MANAGE_OFFER_CROSS_SELF = -8, // would cross an offer from the same user - MANAGE_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling - MANAGE_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying + MANAGE_SELL_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_SELL_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling + MANAGE_SELL_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_SELL_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_SELL_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_SELL_OFFER_CROSS_SELF = -8, // would cross an offer from the same user + MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_SELL_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying // update errors - MANAGE_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer + MANAGE_SELL_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer - MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer + MANAGE_SELL_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer }; enum ManageOfferEffect @@ -516,9 +538,42 @@ struct ManageOfferSuccessResult offer; }; -union ManageOfferResult switch (ManageOfferResultCode code) +union ManageSellOfferResult switch (ManageSellOfferResultCode code) +{ +case MANAGE_SELL_OFFER_SUCCESS: + ManageOfferSuccessResult success; +default: + void; +}; + +/******* ManageBuyOffer Result ********/ + +enum ManageBuyOfferResultCode +{ + // codes considered as "success" for the operation + MANAGE_BUY_OFFER_SUCCESS = 0, + + // codes considered as "failure" for the operation + MANAGE_BUY_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling + MANAGE_BUY_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_BUY_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user + MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying + + // update errors + MANAGE_BUY_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer + + MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +}; + +union ManageBuyOfferResult switch (ManageBuyOfferResultCode code) { -case MANAGE_OFFER_SUCCESS: +case MANAGE_BUY_OFFER_SUCCESS: ManageOfferSuccessResult success; default: void; @@ -563,7 +618,7 @@ enum ChangeTrustResultCode // cannot create with a limit of 0 CHANGE_TRUST_LOW_RESERVE = -4, // not enough funds to create a new trust line, - CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed + CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed }; union ChangeTrustResult switch (ChangeTrustResultCode code) @@ -693,7 +748,9 @@ enum OperationResultCode opBAD_AUTH = -1, // too few valid signatures / wrong network opNO_ACCOUNT = -2, // source account was not found - opNOT_SUPPORTED = -3 // operation not supported at this time + opNOT_SUPPORTED = -3, // operation not supported at this time + opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached + opEXCEEDED_WORK_LIMIT = -5 // operation did too much work }; union OperationResult switch (OperationResultCode code) @@ -707,10 +764,10 @@ case opINNER: PaymentResult paymentResult; case PATH_PAYMENT: PathPaymentResult pathPaymentResult; - case MANAGE_OFFER: - ManageOfferResult manageOfferResult; - case CREATE_PASSIVE_OFFER: - ManageOfferResult createPassiveOfferResult; + case MANAGE_SELL_OFFER: + ManageSellOfferResult manageSellOfferResult; + case CREATE_PASSIVE_SELL_OFFER: + ManageSellOfferResult createPassiveSellOfferResult; case SET_OPTIONS: SetOptionsResult setOptionsResult; case CHANGE_TRUST: @@ -725,6 +782,8 @@ case opINNER: ManageDataResult manageDataResult; case BUMP_SEQUENCE: BumpSequenceResult bumpSeqResult; + case MANAGE_BUY_OFFER: + ManageBuyOfferResult manageBuyOfferResult; } tr; default: diff --git a/xdr/ledger_key.go b/xdr/ledger_key.go index 734100ece2..ff4cd7f5c9 100644 --- a/xdr/ledger_key.go +++ b/xdr/ledger_key.go @@ -63,7 +63,7 @@ func (key *LedgerKey) SetData(account AccountId, name string) error { // SetOffer mutates `key` such that it represents the identity of the // data entry owned by `account` and for offer `id`. func (key *LedgerKey) SetOffer(account AccountId, id uint64) error { - data := LedgerKeyOffer{account, Uint64(id)} + data := LedgerKeyOffer{account, Int64(id)} nkey, err := NewLedgerKey(LedgerEntryTypeOffer, data) if err != nil { return err diff --git a/xdr/xdr_generated.go b/xdr/xdr_generated.go index 8dfaae8ff8..29aaa19b90 100644 --- a/xdr/xdr_generated.go +++ b/xdr/xdr_generated.go @@ -798,6 +798,30 @@ var ( _ encoding.BinaryUnmarshaler = (*SequenceNumber)(nil) ) +// TimePoint is an XDR Typedef defines as: +// +// typedef uint64 TimePoint; +// +type TimePoint Uint64 + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s TimePoint) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *TimePoint) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*TimePoint)(nil) + _ encoding.BinaryUnmarshaler = (*TimePoint)(nil) +) + // DataValue is an XDR Typedef defines as: // // typedef opaque DataValue<64>; @@ -2054,7 +2078,7 @@ var ( // struct OfferEntry // { // AccountID sellerID; -// uint64 offerID; +// int64 offerID; // Asset selling; // A // Asset buying; // B // int64 amount; // amount of A @@ -2078,7 +2102,7 @@ var ( // type OfferEntry struct { SellerId AccountId - OfferId Uint64 + OfferId Int64 Selling Asset Buying Asset Amount Int64 @@ -2515,21 +2539,24 @@ var ( // { // ENVELOPE_TYPE_SCP = 1, // ENVELOPE_TYPE_TX = 2, -// ENVELOPE_TYPE_AUTH = 3 +// ENVELOPE_TYPE_AUTH = 3, +// ENVELOPE_TYPE_SCPVALUE = 4 // }; // type EnvelopeType int32 const ( - EnvelopeTypeEnvelopeTypeScp EnvelopeType = 1 - EnvelopeTypeEnvelopeTypeTx EnvelopeType = 2 - EnvelopeTypeEnvelopeTypeAuth EnvelopeType = 3 + EnvelopeTypeEnvelopeTypeScp EnvelopeType = 1 + EnvelopeTypeEnvelopeTypeTx EnvelopeType = 2 + EnvelopeTypeEnvelopeTypeAuth EnvelopeType = 3 + EnvelopeTypeEnvelopeTypeScpvalue EnvelopeType = 4 ) var envelopeTypeMap = map[int32]string{ 1: "EnvelopeTypeEnvelopeTypeScp", 2: "EnvelopeTypeEnvelopeTypeTx", 3: "EnvelopeTypeEnvelopeTypeAuth", + 4: "EnvelopeTypeEnvelopeTypeScpvalue", } // ValidEnum validates a proposed value for this enum. Implements @@ -2592,16 +2619,101 @@ var ( _ encoding.BinaryUnmarshaler = (*UpgradeType)(nil) ) +// StellarValueType is an XDR Enum defines as: +// +// enum StellarValueType +// { +// STELLAR_VALUE_BASIC = 0, +// STELLAR_VALUE_SIGNED = 1 +// }; +// +type StellarValueType int32 + +const ( + StellarValueTypeStellarValueBasic StellarValueType = 0 + StellarValueTypeStellarValueSigned StellarValueType = 1 +) + +var stellarValueTypeMap = map[int32]string{ + 0: "StellarValueTypeStellarValueBasic", + 1: "StellarValueTypeStellarValueSigned", +} + +// ValidEnum validates a proposed value for this enum. Implements +// the Enum interface for StellarValueType +func (e StellarValueType) ValidEnum(v int32) bool { + _, ok := stellarValueTypeMap[v] + return ok +} + +// String returns the name of `e` +func (e StellarValueType) String() string { + name, _ := stellarValueTypeMap[int32(e)] + return name +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s StellarValueType) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *StellarValueType) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*StellarValueType)(nil) + _ encoding.BinaryUnmarshaler = (*StellarValueType)(nil) +) + +// LedgerCloseValueSignature is an XDR Struct defines as: +// +// struct LedgerCloseValueSignature +// { +// NodeID nodeID; // which node introduced the value +// Signature signature; // nodeID's signature +// }; +// +type LedgerCloseValueSignature struct { + NodeId NodeId + Signature Signature +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s LedgerCloseValueSignature) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *LedgerCloseValueSignature) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*LedgerCloseValueSignature)(nil) + _ encoding.BinaryUnmarshaler = (*LedgerCloseValueSignature)(nil) +) + // StellarValueExt is an XDR NestedUnion defines as: // // union switch (int v) // { -// case 0: +// case STELLAR_VALUE_BASIC: // void; +// case STELLAR_VALUE_SIGNED: +// LedgerCloseValueSignature lcValueSignature; // } // type StellarValueExt struct { - V int32 + V int32 + LcValueSignature *LedgerCloseValueSignature } // SwitchFieldName returns the field name in which this union's @@ -2614,8 +2726,10 @@ func (u StellarValueExt) SwitchFieldName() string { // the value for an instance of StellarValueExt func (u StellarValueExt) ArmForSwitch(sw int32) (string, bool) { switch int32(sw) { - case 0: + case int32(StellarValueTypeStellarValueBasic): return "", true + case int32(StellarValueTypeStellarValueSigned): + return "LcValueSignature", true } return "-", false } @@ -2624,12 +2738,44 @@ func (u StellarValueExt) ArmForSwitch(sw int32) (string, bool) { func NewStellarValueExt(v int32, value interface{}) (result StellarValueExt, err error) { result.V = v switch int32(v) { - case 0: + case int32(StellarValueTypeStellarValueBasic): // void + case int32(StellarValueTypeStellarValueSigned): + tv, ok := value.(LedgerCloseValueSignature) + if !ok { + err = fmt.Errorf("invalid value, must be LedgerCloseValueSignature") + return + } + result.LcValueSignature = &tv } return } +// MustLcValueSignature retrieves the LcValueSignature value from the union, +// panicing if the value is not set. +func (u StellarValueExt) MustLcValueSignature() LedgerCloseValueSignature { + val, ok := u.GetLcValueSignature() + + if !ok { + panic("arm LcValueSignature is not set") + } + + return val +} + +// GetLcValueSignature retrieves the LcValueSignature value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u StellarValueExt) GetLcValueSignature() (result LedgerCloseValueSignature, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.V)) + + if armName == "LcValueSignature" { + result = *u.LcValueSignature + ok = true + } + + return +} + // MarshalBinary implements encoding.BinaryMarshaler. func (s StellarValueExt) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) @@ -2652,8 +2798,8 @@ var ( // // struct StellarValue // { -// Hash txSetHash; // transaction set to apply to previous ledger -// uint64 closeTime; // network close time +// Hash txSetHash; // transaction set to apply to previous ledger +// TimePoint closeTime; // network close time // // // upgrades to apply to the previous ledger (usually empty) // // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop @@ -2665,15 +2811,17 @@ var ( // // reserved for future use // union switch (int v) // { -// case 0: +// case STELLAR_VALUE_BASIC: // void; +// case STELLAR_VALUE_SIGNED: +// LedgerCloseValueSignature lcValueSignature; // } // ext; // }; // type StellarValue struct { TxSetHash Hash - CloseTime Uint64 + CloseTime TimePoint Upgrades []UpgradeType `xdrmaxsize:"6"` Ext StellarValueExt } @@ -3148,12 +3296,12 @@ var ( // struct // { // AccountID sellerID; -// uint64 offerID; +// int64 offerID; // } // type LedgerKeyOffer struct { SellerId AccountId - OfferId Uint64 + OfferId Int64 } // MarshalBinary implements encoding.BinaryMarshaler. @@ -3226,7 +3374,7 @@ var ( // struct // { // AccountID sellerID; -// uint64 offerID; +// int64 offerID; // } offer; // // case DATA: @@ -3425,20 +3573,28 @@ var ( // // enum BucketEntryType // { -// LIVEENTRY = 0, -// DEADENTRY = 1 +// METAENTRY = +// -1, // At-and-after protocol 11: bucket metadata, should come first. +// LIVEENTRY = 0, // Before protocol 11: created-or-updated; +// // At-and-after protocol 11: only updated. +// DEADENTRY = 1, +// INITENTRY = 2 // At-and-after protocol 11: only created. // }; // type BucketEntryType int32 const ( + BucketEntryTypeMetaentry BucketEntryType = -1 BucketEntryTypeLiveentry BucketEntryType = 0 BucketEntryTypeDeadentry BucketEntryType = 1 + BucketEntryTypeInitentry BucketEntryType = 2 ) var bucketEntryTypeMap = map[int32]string{ - 0: "BucketEntryTypeLiveentry", - 1: "BucketEntryTypeDeadentry", + -1: "BucketEntryTypeMetaentry", + 0: "BucketEntryTypeLiveentry", + 1: "BucketEntryTypeDeadentry", + 2: "BucketEntryTypeInitentry", } // ValidEnum validates a proposed value for this enum. Implements @@ -3472,21 +3628,120 @@ var ( _ encoding.BinaryUnmarshaler = (*BucketEntryType)(nil) ) +// BucketMetadataExt is an XDR NestedUnion defines as: +// +// union switch (int v) +// { +// case 0: +// void; +// } +// +type BucketMetadataExt struct { + V int32 +} + +// SwitchFieldName returns the field name in which this union's +// discriminant is stored +func (u BucketMetadataExt) SwitchFieldName() string { + return "V" +} + +// ArmForSwitch returns which field name should be used for storing +// the value for an instance of BucketMetadataExt +func (u BucketMetadataExt) ArmForSwitch(sw int32) (string, bool) { + switch int32(sw) { + case 0: + return "", true + } + return "-", false +} + +// NewBucketMetadataExt creates a new BucketMetadataExt. +func NewBucketMetadataExt(v int32, value interface{}) (result BucketMetadataExt, err error) { + result.V = v + switch int32(v) { + case 0: + // void + } + return +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s BucketMetadataExt) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *BucketMetadataExt) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*BucketMetadataExt)(nil) + _ encoding.BinaryUnmarshaler = (*BucketMetadataExt)(nil) +) + +// BucketMetadata is an XDR Struct defines as: +// +// struct BucketMetadata +// { +// // Indicates the protocol version used to create / merge this bucket. +// uint32 ledgerVersion; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// }; +// +type BucketMetadata struct { + LedgerVersion Uint32 + Ext BucketMetadataExt +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s BucketMetadata) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *BucketMetadata) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*BucketMetadata)(nil) + _ encoding.BinaryUnmarshaler = (*BucketMetadata)(nil) +) + // BucketEntry is an XDR Union defines as: // // union BucketEntry switch (BucketEntryType type) // { // case LIVEENTRY: +// case INITENTRY: // LedgerEntry liveEntry; // // case DEADENTRY: // LedgerKey deadEntry; +// case METAENTRY: +// BucketMetadata metaEntry; // }; // type BucketEntry struct { Type BucketEntryType LiveEntry *LedgerEntry DeadEntry *LedgerKey + MetaEntry *BucketMetadata } // SwitchFieldName returns the field name in which this union's @@ -3501,8 +3756,12 @@ func (u BucketEntry) ArmForSwitch(sw int32) (string, bool) { switch BucketEntryType(sw) { case BucketEntryTypeLiveentry: return "LiveEntry", true + case BucketEntryTypeInitentry: + return "LiveEntry", true case BucketEntryTypeDeadentry: return "DeadEntry", true + case BucketEntryTypeMetaentry: + return "MetaEntry", true } return "-", false } @@ -3518,6 +3777,13 @@ func NewBucketEntry(aType BucketEntryType, value interface{}) (result BucketEntr return } result.LiveEntry = &tv + case BucketEntryTypeInitentry: + tv, ok := value.(LedgerEntry) + if !ok { + err = fmt.Errorf("invalid value, must be LedgerEntry") + return + } + result.LiveEntry = &tv case BucketEntryTypeDeadentry: tv, ok := value.(LedgerKey) if !ok { @@ -3525,6 +3791,13 @@ func NewBucketEntry(aType BucketEntryType, value interface{}) (result BucketEntr return } result.DeadEntry = &tv + case BucketEntryTypeMetaentry: + tv, ok := value.(BucketMetadata) + if !ok { + err = fmt.Errorf("invalid value, must be BucketMetadata") + return + } + result.MetaEntry = &tv } return } @@ -3579,6 +3852,31 @@ func (u BucketEntry) GetDeadEntry() (result LedgerKey, ok bool) { return } +// MustMetaEntry retrieves the MetaEntry value from the union, +// panicing if the value is not set. +func (u BucketEntry) MustMetaEntry() BucketMetadata { + val, ok := u.GetMetaEntry() + + if !ok { + panic("arm MetaEntry is not set") + } + + return val +} + +// GetMetaEntry retrieves the MetaEntry value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u BucketEntry) GetMetaEntry() (result BucketMetadata, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "MetaEntry" { + result = *u.MetaEntry + ok = true + } + + return +} + // MarshalBinary implements encoding.BinaryMarshaler. func (s BucketEntry) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) @@ -4438,7 +4736,7 @@ var ( // struct TransactionMetaV1 // { // LedgerEntryChanges txChanges; // tx level changes if any -// OperationMeta operations<>; // meta for each operation +// OperationMeta operations<>; // meta for each operation // }; // type TransactionMetaV1 struct { @@ -5792,40 +6090,42 @@ var ( // CREATE_ACCOUNT = 0, // PAYMENT = 1, // PATH_PAYMENT = 2, -// MANAGE_OFFER = 3, -// CREATE_PASSIVE_OFFER = 4, +// MANAGE_SELL_OFFER = 3, +// CREATE_PASSIVE_SELL_OFFER = 4, // SET_OPTIONS = 5, // CHANGE_TRUST = 6, // ALLOW_TRUST = 7, // ACCOUNT_MERGE = 8, // INFLATION = 9, // MANAGE_DATA = 10, -// BUMP_SEQUENCE = 11 +// BUMP_SEQUENCE = 11, +// MANAGE_BUY_OFFER = 12 // }; // type OperationType int32 const ( - OperationTypeCreateAccount OperationType = 0 - OperationTypePayment OperationType = 1 - OperationTypePathPayment OperationType = 2 - OperationTypeManageOffer OperationType = 3 - OperationTypeCreatePassiveOffer OperationType = 4 - OperationTypeSetOptions OperationType = 5 - OperationTypeChangeTrust OperationType = 6 - OperationTypeAllowTrust OperationType = 7 - OperationTypeAccountMerge OperationType = 8 - OperationTypeInflation OperationType = 9 - OperationTypeManageData OperationType = 10 - OperationTypeBumpSequence OperationType = 11 + OperationTypeCreateAccount OperationType = 0 + OperationTypePayment OperationType = 1 + OperationTypePathPayment OperationType = 2 + OperationTypeManageSellOffer OperationType = 3 + OperationTypeCreatePassiveSellOffer OperationType = 4 + OperationTypeSetOptions OperationType = 5 + OperationTypeChangeTrust OperationType = 6 + OperationTypeAllowTrust OperationType = 7 + OperationTypeAccountMerge OperationType = 8 + OperationTypeInflation OperationType = 9 + OperationTypeManageData OperationType = 10 + OperationTypeBumpSequence OperationType = 11 + OperationTypeManageBuyOffer OperationType = 12 ) var operationTypeMap = map[int32]string{ 0: "OperationTypeCreateAccount", 1: "OperationTypePayment", 2: "OperationTypePathPayment", - 3: "OperationTypeManageOffer", - 4: "OperationTypeCreatePassiveOffer", + 3: "OperationTypeManageSellOffer", + 4: "OperationTypeCreatePassiveSellOffer", 5: "OperationTypeSetOptions", 6: "OperationTypeChangeTrust", 7: "OperationTypeAllowTrust", @@ -5833,6 +6133,7 @@ var operationTypeMap = map[int32]string{ 9: "OperationTypeInflation", 10: "OperationTypeManageData", 11: "OperationTypeBumpSequence", + 12: "OperationTypeManageBuyOffer", } // ValidEnum validates a proposed value for this enum. Implements @@ -5973,9 +6274,9 @@ var ( _ encoding.BinaryUnmarshaler = (*PathPaymentOp)(nil) ) -// ManageOfferOp is an XDR Struct defines as: +// ManageSellOfferOp is an XDR Struct defines as: // -// struct ManageOfferOp +// struct ManageSellOfferOp // { // Asset selling; // Asset buying; @@ -5983,38 +6284,78 @@ var ( // Price price; // price of thing being sold in terms of what you are buying // // // 0=create a new offer, otherwise edit an existing offer -// uint64 offerID; +// int64 offerID; // }; // -type ManageOfferOp struct { +type ManageSellOfferOp struct { Selling Asset Buying Asset Amount Int64 Price Price - OfferId Uint64 + OfferId Int64 } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ManageOfferOp) MarshalBinary() ([]byte, error) { +func (s ManageSellOfferOp) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) _, err := Marshal(b, s) return b.Bytes(), err } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ManageOfferOp) UnmarshalBinary(inp []byte) error { +func (s *ManageSellOfferOp) UnmarshalBinary(inp []byte) error { _, err := Unmarshal(bytes.NewReader(inp), s) return err } var ( - _ encoding.BinaryMarshaler = (*ManageOfferOp)(nil) - _ encoding.BinaryUnmarshaler = (*ManageOfferOp)(nil) + _ encoding.BinaryMarshaler = (*ManageSellOfferOp)(nil) + _ encoding.BinaryUnmarshaler = (*ManageSellOfferOp)(nil) ) -// CreatePassiveOfferOp is an XDR Struct defines as: +// ManageBuyOfferOp is an XDR Struct defines as: // -// struct CreatePassiveOfferOp +// struct ManageBuyOfferOp +// { +// Asset selling; +// Asset buying; +// int64 buyAmount; // amount being bought. if set to 0, delete the offer +// Price price; // price of thing being bought in terms of what you are +// // selling +// +// // 0=create a new offer, otherwise edit an existing offer +// int64 offerID; +// }; +// +type ManageBuyOfferOp struct { + Selling Asset + Buying Asset + BuyAmount Int64 + Price Price + OfferId Int64 +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s ManageBuyOfferOp) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *ManageBuyOfferOp) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*ManageBuyOfferOp)(nil) + _ encoding.BinaryUnmarshaler = (*ManageBuyOfferOp)(nil) +) + +// CreatePassiveSellOfferOp is an XDR Struct defines as: +// +// struct CreatePassiveSellOfferOp // { // Asset selling; // A // Asset buying; // B @@ -6022,7 +6363,7 @@ var ( // Price price; // cost of A in terms of B // }; // -type CreatePassiveOfferOp struct { +type CreatePassiveSellOfferOp struct { Selling Asset Buying Asset Amount Int64 @@ -6030,21 +6371,21 @@ type CreatePassiveOfferOp struct { } // MarshalBinary implements encoding.BinaryMarshaler. -func (s CreatePassiveOfferOp) MarshalBinary() ([]byte, error) { +func (s CreatePassiveSellOfferOp) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) _, err := Marshal(b, s) return b.Bytes(), err } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *CreatePassiveOfferOp) UnmarshalBinary(inp []byte) error { +func (s *CreatePassiveSellOfferOp) UnmarshalBinary(inp []byte) error { _, err := Unmarshal(bytes.NewReader(inp), s) return err } var ( - _ encoding.BinaryMarshaler = (*CreatePassiveOfferOp)(nil) - _ encoding.BinaryUnmarshaler = (*CreatePassiveOfferOp)(nil) + _ encoding.BinaryMarshaler = (*CreatePassiveSellOfferOp)(nil) + _ encoding.BinaryUnmarshaler = (*CreatePassiveSellOfferOp)(nil) ) // SetOptionsOp is an XDR Struct defines as: @@ -6375,10 +6716,10 @@ var ( // PaymentOp paymentOp; // case PATH_PAYMENT: // PathPaymentOp pathPaymentOp; -// case MANAGE_OFFER: -// ManageOfferOp manageOfferOp; -// case CREATE_PASSIVE_OFFER: -// CreatePassiveOfferOp createPassiveOfferOp; +// case MANAGE_SELL_OFFER: +// ManageSellOfferOp manageSellOfferOp; +// case CREATE_PASSIVE_SELL_OFFER: +// CreatePassiveSellOfferOp createPassiveSellOfferOp; // case SET_OPTIONS: // SetOptionsOp setOptionsOp; // case CHANGE_TRUST: @@ -6393,21 +6734,24 @@ var ( // ManageDataOp manageDataOp; // case BUMP_SEQUENCE: // BumpSequenceOp bumpSequenceOp; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferOp manageBuyOfferOp; // } // type OperationBody struct { - Type OperationType - CreateAccountOp *CreateAccountOp - PaymentOp *PaymentOp - PathPaymentOp *PathPaymentOp - ManageOfferOp *ManageOfferOp - CreatePassiveOfferOp *CreatePassiveOfferOp - SetOptionsOp *SetOptionsOp - ChangeTrustOp *ChangeTrustOp - AllowTrustOp *AllowTrustOp - Destination *AccountId - ManageDataOp *ManageDataOp - BumpSequenceOp *BumpSequenceOp + Type OperationType + CreateAccountOp *CreateAccountOp + PaymentOp *PaymentOp + PathPaymentOp *PathPaymentOp + ManageSellOfferOp *ManageSellOfferOp + CreatePassiveSellOfferOp *CreatePassiveSellOfferOp + SetOptionsOp *SetOptionsOp + ChangeTrustOp *ChangeTrustOp + AllowTrustOp *AllowTrustOp + Destination *AccountId + ManageDataOp *ManageDataOp + BumpSequenceOp *BumpSequenceOp + ManageBuyOfferOp *ManageBuyOfferOp } // SwitchFieldName returns the field name in which this union's @@ -6426,10 +6770,10 @@ func (u OperationBody) ArmForSwitch(sw int32) (string, bool) { return "PaymentOp", true case OperationTypePathPayment: return "PathPaymentOp", true - case OperationTypeManageOffer: - return "ManageOfferOp", true - case OperationTypeCreatePassiveOffer: - return "CreatePassiveOfferOp", true + case OperationTypeManageSellOffer: + return "ManageSellOfferOp", true + case OperationTypeCreatePassiveSellOffer: + return "CreatePassiveSellOfferOp", true case OperationTypeSetOptions: return "SetOptionsOp", true case OperationTypeChangeTrust: @@ -6444,6 +6788,8 @@ func (u OperationBody) ArmForSwitch(sw int32) (string, bool) { return "ManageDataOp", true case OperationTypeBumpSequence: return "BumpSequenceOp", true + case OperationTypeManageBuyOffer: + return "ManageBuyOfferOp", true } return "-", false } @@ -6473,20 +6819,20 @@ func NewOperationBody(aType OperationType, value interface{}) (result OperationB return } result.PathPaymentOp = &tv - case OperationTypeManageOffer: - tv, ok := value.(ManageOfferOp) + case OperationTypeManageSellOffer: + tv, ok := value.(ManageSellOfferOp) if !ok { - err = fmt.Errorf("invalid value, must be ManageOfferOp") + err = fmt.Errorf("invalid value, must be ManageSellOfferOp") return } - result.ManageOfferOp = &tv - case OperationTypeCreatePassiveOffer: - tv, ok := value.(CreatePassiveOfferOp) + result.ManageSellOfferOp = &tv + case OperationTypeCreatePassiveSellOffer: + tv, ok := value.(CreatePassiveSellOfferOp) if !ok { - err = fmt.Errorf("invalid value, must be CreatePassiveOfferOp") + err = fmt.Errorf("invalid value, must be CreatePassiveSellOfferOp") return } - result.CreatePassiveOfferOp = &tv + result.CreatePassiveSellOfferOp = &tv case OperationTypeSetOptions: tv, ok := value.(SetOptionsOp) if !ok { @@ -6531,6 +6877,13 @@ func NewOperationBody(aType OperationType, value interface{}) (result OperationB return } result.BumpSequenceOp = &tv + case OperationTypeManageBuyOffer: + tv, ok := value.(ManageBuyOfferOp) + if !ok { + err = fmt.Errorf("invalid value, must be ManageBuyOfferOp") + return + } + result.ManageBuyOfferOp = &tv } return } @@ -6610,50 +6963,50 @@ func (u OperationBody) GetPathPaymentOp() (result PathPaymentOp, ok bool) { return } -// MustManageOfferOp retrieves the ManageOfferOp value from the union, +// MustManageSellOfferOp retrieves the ManageSellOfferOp value from the union, // panicing if the value is not set. -func (u OperationBody) MustManageOfferOp() ManageOfferOp { - val, ok := u.GetManageOfferOp() +func (u OperationBody) MustManageSellOfferOp() ManageSellOfferOp { + val, ok := u.GetManageSellOfferOp() if !ok { - panic("arm ManageOfferOp is not set") + panic("arm ManageSellOfferOp is not set") } return val } -// GetManageOfferOp retrieves the ManageOfferOp value from the union, +// GetManageSellOfferOp retrieves the ManageSellOfferOp value from the union, // returning ok if the union's switch indicated the value is valid. -func (u OperationBody) GetManageOfferOp() (result ManageOfferOp, ok bool) { +func (u OperationBody) GetManageSellOfferOp() (result ManageSellOfferOp, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "ManageOfferOp" { - result = *u.ManageOfferOp + if armName == "ManageSellOfferOp" { + result = *u.ManageSellOfferOp ok = true } return } -// MustCreatePassiveOfferOp retrieves the CreatePassiveOfferOp value from the union, +// MustCreatePassiveSellOfferOp retrieves the CreatePassiveSellOfferOp value from the union, // panicing if the value is not set. -func (u OperationBody) MustCreatePassiveOfferOp() CreatePassiveOfferOp { - val, ok := u.GetCreatePassiveOfferOp() +func (u OperationBody) MustCreatePassiveSellOfferOp() CreatePassiveSellOfferOp { + val, ok := u.GetCreatePassiveSellOfferOp() if !ok { - panic("arm CreatePassiveOfferOp is not set") + panic("arm CreatePassiveSellOfferOp is not set") } return val } -// GetCreatePassiveOfferOp retrieves the CreatePassiveOfferOp value from the union, +// GetCreatePassiveSellOfferOp retrieves the CreatePassiveSellOfferOp value from the union, // returning ok if the union's switch indicated the value is valid. -func (u OperationBody) GetCreatePassiveOfferOp() (result CreatePassiveOfferOp, ok bool) { +func (u OperationBody) GetCreatePassiveSellOfferOp() (result CreatePassiveSellOfferOp, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "CreatePassiveOfferOp" { - result = *u.CreatePassiveOfferOp + if armName == "CreatePassiveSellOfferOp" { + result = *u.CreatePassiveSellOfferOp ok = true } @@ -6810,6 +7163,31 @@ func (u OperationBody) GetBumpSequenceOp() (result BumpSequenceOp, ok bool) { return } +// MustManageBuyOfferOp retrieves the ManageBuyOfferOp value from the union, +// panicing if the value is not set. +func (u OperationBody) MustManageBuyOfferOp() ManageBuyOfferOp { + val, ok := u.GetManageBuyOfferOp() + + if !ok { + panic("arm ManageBuyOfferOp is not set") + } + + return val +} + +// GetManageBuyOfferOp retrieves the ManageBuyOfferOp value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u OperationBody) GetManageBuyOfferOp() (result ManageBuyOfferOp, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "ManageBuyOfferOp" { + result = *u.ManageBuyOfferOp + ok = true + } + + return +} + // MarshalBinary implements encoding.BinaryMarshaler. func (s OperationBody) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) @@ -6845,10 +7223,10 @@ var ( // PaymentOp paymentOp; // case PATH_PAYMENT: // PathPaymentOp pathPaymentOp; -// case MANAGE_OFFER: -// ManageOfferOp manageOfferOp; -// case CREATE_PASSIVE_OFFER: -// CreatePassiveOfferOp createPassiveOfferOp; +// case MANAGE_SELL_OFFER: +// ManageSellOfferOp manageSellOfferOp; +// case CREATE_PASSIVE_SELL_OFFER: +// CreatePassiveSellOfferOp createPassiveSellOfferOp; // case SET_OPTIONS: // SetOptionsOp setOptionsOp; // case CHANGE_TRUST: @@ -6863,6 +7241,8 @@ var ( // ManageDataOp manageDataOp; // case BUMP_SEQUENCE: // BumpSequenceOp bumpSequenceOp; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferOp manageBuyOfferOp; // } // body; // }; @@ -7158,13 +7538,13 @@ var ( // // struct TimeBounds // { -// uint64 minTime; -// uint64 maxTime; // 0 here means no maxTime +// TimePoint minTime; +// TimePoint maxTime; // 0 here means no maxTime // }; // type TimeBounds struct { - MinTime Uint64 - MaxTime Uint64 + MinTime TimePoint + MaxTime TimePoint } // MarshalBinary implements encoding.BinaryMarshaler. @@ -7185,6 +7565,12 @@ var ( _ encoding.BinaryUnmarshaler = (*TimeBounds)(nil) ) +// MaxOpsPerTx is an XDR Const defines as: +// +// const MAX_OPS_PER_TX = 100; +// +const MaxOpsPerTx = 100 + // TransactionExt is an XDR NestedUnion defines as: // // union switch (int v) @@ -7259,7 +7645,7 @@ var ( // // Memo memo; // -// Operation operations<100>; +// Operation operations; // // // reserved for future use // union switch (int v) @@ -7462,7 +7848,7 @@ var ( // { // // emitted to identify the offer // AccountID sellerID; // Account that owns the offer -// uint64 offerID; +// int64 offerID; // // // amount and asset taken from the owner // Asset assetSold; @@ -7475,7 +7861,7 @@ var ( // type ClaimOfferAtom struct { SellerId AccountId - OfferId Uint64 + OfferId Int64 AssetSold Asset AmountSold Int64 AssetBought Asset @@ -8048,94 +8434,94 @@ var ( _ encoding.BinaryUnmarshaler = (*PathPaymentResult)(nil) ) -// ManageOfferResultCode is an XDR Enum defines as: +// ManageSellOfferResultCode is an XDR Enum defines as: // -// enum ManageOfferResultCode +// enum ManageSellOfferResultCode // { // // codes considered as "success" for the operation -// MANAGE_OFFER_SUCCESS = 0, +// MANAGE_SELL_OFFER_SUCCESS = 0, // // // codes considered as "failure" for the operation -// MANAGE_OFFER_MALFORMED = -1, // generated offer would be invalid -// MANAGE_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling -// MANAGE_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying -// MANAGE_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell -// MANAGE_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy -// MANAGE_OFFER_LINE_FULL = -6, // can't receive more of what it's buying -// MANAGE_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell -// MANAGE_OFFER_CROSS_SELF = -8, // would cross an offer from the same user -// MANAGE_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling -// MANAGE_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying +// MANAGE_SELL_OFFER_MALFORMED = -1, // generated offer would be invalid +// MANAGE_SELL_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling +// MANAGE_SELL_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying +// MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell +// MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy +// MANAGE_SELL_OFFER_LINE_FULL = -6, // can't receive more of what it's buying +// MANAGE_SELL_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell +// MANAGE_SELL_OFFER_CROSS_SELF = -8, // would cross an offer from the same user +// MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling +// MANAGE_SELL_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying // // // update errors -// MANAGE_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer +// MANAGE_SELL_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer // -// MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +// MANAGE_SELL_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer // }; // -type ManageOfferResultCode int32 +type ManageSellOfferResultCode int32 const ( - ManageOfferResultCodeManageOfferSuccess ManageOfferResultCode = 0 - ManageOfferResultCodeManageOfferMalformed ManageOfferResultCode = -1 - ManageOfferResultCodeManageOfferSellNoTrust ManageOfferResultCode = -2 - ManageOfferResultCodeManageOfferBuyNoTrust ManageOfferResultCode = -3 - ManageOfferResultCodeManageOfferSellNotAuthorized ManageOfferResultCode = -4 - ManageOfferResultCodeManageOfferBuyNotAuthorized ManageOfferResultCode = -5 - ManageOfferResultCodeManageOfferLineFull ManageOfferResultCode = -6 - ManageOfferResultCodeManageOfferUnderfunded ManageOfferResultCode = -7 - ManageOfferResultCodeManageOfferCrossSelf ManageOfferResultCode = -8 - ManageOfferResultCodeManageOfferSellNoIssuer ManageOfferResultCode = -9 - ManageOfferResultCodeManageOfferBuyNoIssuer ManageOfferResultCode = -10 - ManageOfferResultCodeManageOfferNotFound ManageOfferResultCode = -11 - ManageOfferResultCodeManageOfferLowReserve ManageOfferResultCode = -12 -) - -var manageOfferResultCodeMap = map[int32]string{ - 0: "ManageOfferResultCodeManageOfferSuccess", - -1: "ManageOfferResultCodeManageOfferMalformed", - -2: "ManageOfferResultCodeManageOfferSellNoTrust", - -3: "ManageOfferResultCodeManageOfferBuyNoTrust", - -4: "ManageOfferResultCodeManageOfferSellNotAuthorized", - -5: "ManageOfferResultCodeManageOfferBuyNotAuthorized", - -6: "ManageOfferResultCodeManageOfferLineFull", - -7: "ManageOfferResultCodeManageOfferUnderfunded", - -8: "ManageOfferResultCodeManageOfferCrossSelf", - -9: "ManageOfferResultCodeManageOfferSellNoIssuer", - -10: "ManageOfferResultCodeManageOfferBuyNoIssuer", - -11: "ManageOfferResultCodeManageOfferNotFound", - -12: "ManageOfferResultCodeManageOfferLowReserve", + ManageSellOfferResultCodeManageSellOfferSuccess ManageSellOfferResultCode = 0 + ManageSellOfferResultCodeManageSellOfferMalformed ManageSellOfferResultCode = -1 + ManageSellOfferResultCodeManageSellOfferSellNoTrust ManageSellOfferResultCode = -2 + ManageSellOfferResultCodeManageSellOfferBuyNoTrust ManageSellOfferResultCode = -3 + ManageSellOfferResultCodeManageSellOfferSellNotAuthorized ManageSellOfferResultCode = -4 + ManageSellOfferResultCodeManageSellOfferBuyNotAuthorized ManageSellOfferResultCode = -5 + ManageSellOfferResultCodeManageSellOfferLineFull ManageSellOfferResultCode = -6 + ManageSellOfferResultCodeManageSellOfferUnderfunded ManageSellOfferResultCode = -7 + ManageSellOfferResultCodeManageSellOfferCrossSelf ManageSellOfferResultCode = -8 + ManageSellOfferResultCodeManageSellOfferSellNoIssuer ManageSellOfferResultCode = -9 + ManageSellOfferResultCodeManageSellOfferBuyNoIssuer ManageSellOfferResultCode = -10 + ManageSellOfferResultCodeManageSellOfferNotFound ManageSellOfferResultCode = -11 + ManageSellOfferResultCodeManageSellOfferLowReserve ManageSellOfferResultCode = -12 +) + +var manageSellOfferResultCodeMap = map[int32]string{ + 0: "ManageSellOfferResultCodeManageSellOfferSuccess", + -1: "ManageSellOfferResultCodeManageSellOfferMalformed", + -2: "ManageSellOfferResultCodeManageSellOfferSellNoTrust", + -3: "ManageSellOfferResultCodeManageSellOfferBuyNoTrust", + -4: "ManageSellOfferResultCodeManageSellOfferSellNotAuthorized", + -5: "ManageSellOfferResultCodeManageSellOfferBuyNotAuthorized", + -6: "ManageSellOfferResultCodeManageSellOfferLineFull", + -7: "ManageSellOfferResultCodeManageSellOfferUnderfunded", + -8: "ManageSellOfferResultCodeManageSellOfferCrossSelf", + -9: "ManageSellOfferResultCodeManageSellOfferSellNoIssuer", + -10: "ManageSellOfferResultCodeManageSellOfferBuyNoIssuer", + -11: "ManageSellOfferResultCodeManageSellOfferNotFound", + -12: "ManageSellOfferResultCodeManageSellOfferLowReserve", } // ValidEnum validates a proposed value for this enum. Implements -// the Enum interface for ManageOfferResultCode -func (e ManageOfferResultCode) ValidEnum(v int32) bool { - _, ok := manageOfferResultCodeMap[v] +// the Enum interface for ManageSellOfferResultCode +func (e ManageSellOfferResultCode) ValidEnum(v int32) bool { + _, ok := manageSellOfferResultCodeMap[v] return ok } // String returns the name of `e` -func (e ManageOfferResultCode) String() string { - name, _ := manageOfferResultCodeMap[int32(e)] +func (e ManageSellOfferResultCode) String() string { + name, _ := manageSellOfferResultCodeMap[int32(e)] return name } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ManageOfferResultCode) MarshalBinary() ([]byte, error) { +func (s ManageSellOfferResultCode) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) _, err := Marshal(b, s) return b.Bytes(), err } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ManageOfferResultCode) UnmarshalBinary(inp []byte) error { +func (s *ManageSellOfferResultCode) UnmarshalBinary(inp []byte) error { _, err := Unmarshal(bytes.NewReader(inp), s) return err } var ( - _ encoding.BinaryMarshaler = (*ManageOfferResultCode)(nil) - _ encoding.BinaryUnmarshaler = (*ManageOfferResultCode)(nil) + _ encoding.BinaryMarshaler = (*ManageSellOfferResultCode)(nil) + _ encoding.BinaryUnmarshaler = (*ManageSellOfferResultCode)(nil) ) // ManageOfferEffect is an XDR Enum defines as: @@ -8335,43 +8721,43 @@ var ( _ encoding.BinaryUnmarshaler = (*ManageOfferSuccessResult)(nil) ) -// ManageOfferResult is an XDR Union defines as: +// ManageSellOfferResult is an XDR Union defines as: // -// union ManageOfferResult switch (ManageOfferResultCode code) +// union ManageSellOfferResult switch (ManageSellOfferResultCode code) // { -// case MANAGE_OFFER_SUCCESS: +// case MANAGE_SELL_OFFER_SUCCESS: // ManageOfferSuccessResult success; // default: // void; // }; // -type ManageOfferResult struct { - Code ManageOfferResultCode +type ManageSellOfferResult struct { + Code ManageSellOfferResultCode Success *ManageOfferSuccessResult } // SwitchFieldName returns the field name in which this union's // discriminant is stored -func (u ManageOfferResult) SwitchFieldName() string { +func (u ManageSellOfferResult) SwitchFieldName() string { return "Code" } // ArmForSwitch returns which field name should be used for storing -// the value for an instance of ManageOfferResult -func (u ManageOfferResult) ArmForSwitch(sw int32) (string, bool) { - switch ManageOfferResultCode(sw) { - case ManageOfferResultCodeManageOfferSuccess: +// the value for an instance of ManageSellOfferResult +func (u ManageSellOfferResult) ArmForSwitch(sw int32) (string, bool) { + switch ManageSellOfferResultCode(sw) { + case ManageSellOfferResultCodeManageSellOfferSuccess: return "Success", true default: return "", true } } -// NewManageOfferResult creates a new ManageOfferResult. -func NewManageOfferResult(code ManageOfferResultCode, value interface{}) (result ManageOfferResult, err error) { +// NewManageSellOfferResult creates a new ManageSellOfferResult. +func NewManageSellOfferResult(code ManageSellOfferResultCode, value interface{}) (result ManageSellOfferResult, err error) { result.Code = code - switch ManageOfferResultCode(code) { - case ManageOfferResultCodeManageOfferSuccess: + switch ManageSellOfferResultCode(code) { + case ManageSellOfferResultCodeManageSellOfferSuccess: tv, ok := value.(ManageOfferSuccessResult) if !ok { err = fmt.Errorf("invalid value, must be ManageOfferSuccessResult") @@ -8386,7 +8772,7 @@ func NewManageOfferResult(code ManageOfferResultCode, value interface{}) (result // MustSuccess retrieves the Success value from the union, // panicing if the value is not set. -func (u ManageOfferResult) MustSuccess() ManageOfferSuccessResult { +func (u ManageSellOfferResult) MustSuccess() ManageOfferSuccessResult { val, ok := u.GetSuccess() if !ok { @@ -8398,7 +8784,7 @@ func (u ManageOfferResult) MustSuccess() ManageOfferSuccessResult { // GetSuccess retrieves the Success value from the union, // returning ok if the union's switch indicated the value is valid. -func (u ManageOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok bool) { +func (u ManageSellOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Code)) if armName == "Success" { @@ -8410,21 +8796,203 @@ func (u ManageOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok boo } // MarshalBinary implements encoding.BinaryMarshaler. -func (s ManageOfferResult) MarshalBinary() ([]byte, error) { +func (s ManageSellOfferResult) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *ManageSellOfferResult) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*ManageSellOfferResult)(nil) + _ encoding.BinaryUnmarshaler = (*ManageSellOfferResult)(nil) +) + +// ManageBuyOfferResultCode is an XDR Enum defines as: +// +// enum ManageBuyOfferResultCode +// { +// // codes considered as "success" for the operation +// MANAGE_BUY_OFFER_SUCCESS = 0, +// +// // codes considered as "failure" for the operation +// MANAGE_BUY_OFFER_MALFORMED = -1, // generated offer would be invalid +// MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling +// MANAGE_BUY_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying +// MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell +// MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy +// MANAGE_BUY_OFFER_LINE_FULL = -6, // can't receive more of what it's buying +// MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell +// MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user +// MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling +// MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying +// +// // update errors +// MANAGE_BUY_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer +// +// MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +// }; +// +type ManageBuyOfferResultCode int32 + +const ( + ManageBuyOfferResultCodeManageBuyOfferSuccess ManageBuyOfferResultCode = 0 + ManageBuyOfferResultCodeManageBuyOfferMalformed ManageBuyOfferResultCode = -1 + ManageBuyOfferResultCodeManageBuyOfferSellNoTrust ManageBuyOfferResultCode = -2 + ManageBuyOfferResultCodeManageBuyOfferBuyNoTrust ManageBuyOfferResultCode = -3 + ManageBuyOfferResultCodeManageBuyOfferSellNotAuthorized ManageBuyOfferResultCode = -4 + ManageBuyOfferResultCodeManageBuyOfferBuyNotAuthorized ManageBuyOfferResultCode = -5 + ManageBuyOfferResultCodeManageBuyOfferLineFull ManageBuyOfferResultCode = -6 + ManageBuyOfferResultCodeManageBuyOfferUnderfunded ManageBuyOfferResultCode = -7 + ManageBuyOfferResultCodeManageBuyOfferCrossSelf ManageBuyOfferResultCode = -8 + ManageBuyOfferResultCodeManageBuyOfferSellNoIssuer ManageBuyOfferResultCode = -9 + ManageBuyOfferResultCodeManageBuyOfferBuyNoIssuer ManageBuyOfferResultCode = -10 + ManageBuyOfferResultCodeManageBuyOfferNotFound ManageBuyOfferResultCode = -11 + ManageBuyOfferResultCodeManageBuyOfferLowReserve ManageBuyOfferResultCode = -12 +) + +var manageBuyOfferResultCodeMap = map[int32]string{ + 0: "ManageBuyOfferResultCodeManageBuyOfferSuccess", + -1: "ManageBuyOfferResultCodeManageBuyOfferMalformed", + -2: "ManageBuyOfferResultCodeManageBuyOfferSellNoTrust", + -3: "ManageBuyOfferResultCodeManageBuyOfferBuyNoTrust", + -4: "ManageBuyOfferResultCodeManageBuyOfferSellNotAuthorized", + -5: "ManageBuyOfferResultCodeManageBuyOfferBuyNotAuthorized", + -6: "ManageBuyOfferResultCodeManageBuyOfferLineFull", + -7: "ManageBuyOfferResultCodeManageBuyOfferUnderfunded", + -8: "ManageBuyOfferResultCodeManageBuyOfferCrossSelf", + -9: "ManageBuyOfferResultCodeManageBuyOfferSellNoIssuer", + -10: "ManageBuyOfferResultCodeManageBuyOfferBuyNoIssuer", + -11: "ManageBuyOfferResultCodeManageBuyOfferNotFound", + -12: "ManageBuyOfferResultCodeManageBuyOfferLowReserve", +} + +// ValidEnum validates a proposed value for this enum. Implements +// the Enum interface for ManageBuyOfferResultCode +func (e ManageBuyOfferResultCode) ValidEnum(v int32) bool { + _, ok := manageBuyOfferResultCodeMap[v] + return ok +} + +// String returns the name of `e` +func (e ManageBuyOfferResultCode) String() string { + name, _ := manageBuyOfferResultCodeMap[int32(e)] + return name +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s ManageBuyOfferResultCode) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) _, err := Marshal(b, s) return b.Bytes(), err } // UnmarshalBinary implements encoding.BinaryUnmarshaler. -func (s *ManageOfferResult) UnmarshalBinary(inp []byte) error { +func (s *ManageBuyOfferResultCode) UnmarshalBinary(inp []byte) error { _, err := Unmarshal(bytes.NewReader(inp), s) return err } var ( - _ encoding.BinaryMarshaler = (*ManageOfferResult)(nil) - _ encoding.BinaryUnmarshaler = (*ManageOfferResult)(nil) + _ encoding.BinaryMarshaler = (*ManageBuyOfferResultCode)(nil) + _ encoding.BinaryUnmarshaler = (*ManageBuyOfferResultCode)(nil) +) + +// ManageBuyOfferResult is an XDR Union defines as: +// +// union ManageBuyOfferResult switch (ManageBuyOfferResultCode code) +// { +// case MANAGE_BUY_OFFER_SUCCESS: +// ManageOfferSuccessResult success; +// default: +// void; +// }; +// +type ManageBuyOfferResult struct { + Code ManageBuyOfferResultCode + Success *ManageOfferSuccessResult +} + +// SwitchFieldName returns the field name in which this union's +// discriminant is stored +func (u ManageBuyOfferResult) SwitchFieldName() string { + return "Code" +} + +// ArmForSwitch returns which field name should be used for storing +// the value for an instance of ManageBuyOfferResult +func (u ManageBuyOfferResult) ArmForSwitch(sw int32) (string, bool) { + switch ManageBuyOfferResultCode(sw) { + case ManageBuyOfferResultCodeManageBuyOfferSuccess: + return "Success", true + default: + return "", true + } +} + +// NewManageBuyOfferResult creates a new ManageBuyOfferResult. +func NewManageBuyOfferResult(code ManageBuyOfferResultCode, value interface{}) (result ManageBuyOfferResult, err error) { + result.Code = code + switch ManageBuyOfferResultCode(code) { + case ManageBuyOfferResultCodeManageBuyOfferSuccess: + tv, ok := value.(ManageOfferSuccessResult) + if !ok { + err = fmt.Errorf("invalid value, must be ManageOfferSuccessResult") + return + } + result.Success = &tv + default: + // void + } + return +} + +// MustSuccess retrieves the Success value from the union, +// panicing if the value is not set. +func (u ManageBuyOfferResult) MustSuccess() ManageOfferSuccessResult { + val, ok := u.GetSuccess() + + if !ok { + panic("arm Success is not set") + } + + return val +} + +// GetSuccess retrieves the Success value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u ManageBuyOfferResult) GetSuccess() (result ManageOfferSuccessResult, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Code)) + + if armName == "Success" { + result = *u.Success + ok = true + } + + return +} + +// MarshalBinary implements encoding.BinaryMarshaler. +func (s ManageBuyOfferResult) MarshalBinary() ([]byte, error) { + b := new(bytes.Buffer) + _, err := Marshal(b, s) + return b.Bytes(), err +} + +// UnmarshalBinary implements encoding.BinaryUnmarshaler. +func (s *ManageBuyOfferResult) UnmarshalBinary(inp []byte) error { + _, err := Unmarshal(bytes.NewReader(inp), s) + return err +} + +var ( + _ encoding.BinaryMarshaler = (*ManageBuyOfferResult)(nil) + _ encoding.BinaryUnmarshaler = (*ManageBuyOfferResult)(nil) ) // SetOptionsResultCode is an XDR Enum defines as: @@ -8578,7 +9146,7 @@ var ( // // cannot create with a limit of 0 // CHANGE_TRUST_LOW_RESERVE = // -4, // not enough funds to create a new trust line, -// CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed +// CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed // }; // type ChangeTrustResultCode int32 @@ -9404,16 +9972,20 @@ var ( // // opBAD_AUTH = -1, // too few valid signatures / wrong network // opNO_ACCOUNT = -2, // source account was not found -// opNOT_SUPPORTED = -3 // operation not supported at this time +// opNOT_SUPPORTED = -3, // operation not supported at this time +// opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached +// opEXCEEDED_WORK_LIMIT = -5 // operation did too much work // }; // type OperationResultCode int32 const ( - OperationResultCodeOpInner OperationResultCode = 0 - OperationResultCodeOpBadAuth OperationResultCode = -1 - OperationResultCodeOpNoAccount OperationResultCode = -2 - OperationResultCodeOpNotSupported OperationResultCode = -3 + OperationResultCodeOpInner OperationResultCode = 0 + OperationResultCodeOpBadAuth OperationResultCode = -1 + OperationResultCodeOpNoAccount OperationResultCode = -2 + OperationResultCodeOpNotSupported OperationResultCode = -3 + OperationResultCodeOpTooManySubentries OperationResultCode = -4 + OperationResultCodeOpExceededWorkLimit OperationResultCode = -5 ) var operationResultCodeMap = map[int32]string{ @@ -9421,6 +9993,8 @@ var operationResultCodeMap = map[int32]string{ -1: "OperationResultCodeOpBadAuth", -2: "OperationResultCodeOpNoAccount", -3: "OperationResultCodeOpNotSupported", + -4: "OperationResultCodeOpTooManySubentries", + -5: "OperationResultCodeOpExceededWorkLimit", } // ValidEnum validates a proposed value for this enum. Implements @@ -9464,10 +10038,10 @@ var ( // PaymentResult paymentResult; // case PATH_PAYMENT: // PathPaymentResult pathPaymentResult; -// case MANAGE_OFFER: -// ManageOfferResult manageOfferResult; -// case CREATE_PASSIVE_OFFER: -// ManageOfferResult createPassiveOfferResult; +// case MANAGE_SELL_OFFER: +// ManageSellOfferResult manageSellOfferResult; +// case CREATE_PASSIVE_SELL_OFFER: +// ManageSellOfferResult createPassiveSellOfferResult; // case SET_OPTIONS: // SetOptionsResult setOptionsResult; // case CHANGE_TRUST: @@ -9482,22 +10056,25 @@ var ( // ManageDataResult manageDataResult; // case BUMP_SEQUENCE: // BumpSequenceResult bumpSeqResult; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferResult manageBuyOfferResult; // } // type OperationResultTr struct { - Type OperationType - CreateAccountResult *CreateAccountResult - PaymentResult *PaymentResult - PathPaymentResult *PathPaymentResult - ManageOfferResult *ManageOfferResult - CreatePassiveOfferResult *ManageOfferResult - SetOptionsResult *SetOptionsResult - ChangeTrustResult *ChangeTrustResult - AllowTrustResult *AllowTrustResult - AccountMergeResult *AccountMergeResult - InflationResult *InflationResult - ManageDataResult *ManageDataResult - BumpSeqResult *BumpSequenceResult + Type OperationType + CreateAccountResult *CreateAccountResult + PaymentResult *PaymentResult + PathPaymentResult *PathPaymentResult + ManageSellOfferResult *ManageSellOfferResult + CreatePassiveSellOfferResult *ManageSellOfferResult + SetOptionsResult *SetOptionsResult + ChangeTrustResult *ChangeTrustResult + AllowTrustResult *AllowTrustResult + AccountMergeResult *AccountMergeResult + InflationResult *InflationResult + ManageDataResult *ManageDataResult + BumpSeqResult *BumpSequenceResult + ManageBuyOfferResult *ManageBuyOfferResult } // SwitchFieldName returns the field name in which this union's @@ -9516,10 +10093,10 @@ func (u OperationResultTr) ArmForSwitch(sw int32) (string, bool) { return "PaymentResult", true case OperationTypePathPayment: return "PathPaymentResult", true - case OperationTypeManageOffer: - return "ManageOfferResult", true - case OperationTypeCreatePassiveOffer: - return "CreatePassiveOfferResult", true + case OperationTypeManageSellOffer: + return "ManageSellOfferResult", true + case OperationTypeCreatePassiveSellOffer: + return "CreatePassiveSellOfferResult", true case OperationTypeSetOptions: return "SetOptionsResult", true case OperationTypeChangeTrust: @@ -9534,6 +10111,8 @@ func (u OperationResultTr) ArmForSwitch(sw int32) (string, bool) { return "ManageDataResult", true case OperationTypeBumpSequence: return "BumpSeqResult", true + case OperationTypeManageBuyOffer: + return "ManageBuyOfferResult", true } return "-", false } @@ -9563,20 +10142,20 @@ func NewOperationResultTr(aType OperationType, value interface{}) (result Operat return } result.PathPaymentResult = &tv - case OperationTypeManageOffer: - tv, ok := value.(ManageOfferResult) + case OperationTypeManageSellOffer: + tv, ok := value.(ManageSellOfferResult) if !ok { - err = fmt.Errorf("invalid value, must be ManageOfferResult") + err = fmt.Errorf("invalid value, must be ManageSellOfferResult") return } - result.ManageOfferResult = &tv - case OperationTypeCreatePassiveOffer: - tv, ok := value.(ManageOfferResult) + result.ManageSellOfferResult = &tv + case OperationTypeCreatePassiveSellOffer: + tv, ok := value.(ManageSellOfferResult) if !ok { - err = fmt.Errorf("invalid value, must be ManageOfferResult") + err = fmt.Errorf("invalid value, must be ManageSellOfferResult") return } - result.CreatePassiveOfferResult = &tv + result.CreatePassiveSellOfferResult = &tv case OperationTypeSetOptions: tv, ok := value.(SetOptionsResult) if !ok { @@ -9626,6 +10205,13 @@ func NewOperationResultTr(aType OperationType, value interface{}) (result Operat return } result.BumpSeqResult = &tv + case OperationTypeManageBuyOffer: + tv, ok := value.(ManageBuyOfferResult) + if !ok { + err = fmt.Errorf("invalid value, must be ManageBuyOfferResult") + return + } + result.ManageBuyOfferResult = &tv } return } @@ -9705,50 +10291,50 @@ func (u OperationResultTr) GetPathPaymentResult() (result PathPaymentResult, ok return } -// MustManageOfferResult retrieves the ManageOfferResult value from the union, +// MustManageSellOfferResult retrieves the ManageSellOfferResult value from the union, // panicing if the value is not set. -func (u OperationResultTr) MustManageOfferResult() ManageOfferResult { - val, ok := u.GetManageOfferResult() +func (u OperationResultTr) MustManageSellOfferResult() ManageSellOfferResult { + val, ok := u.GetManageSellOfferResult() if !ok { - panic("arm ManageOfferResult is not set") + panic("arm ManageSellOfferResult is not set") } return val } -// GetManageOfferResult retrieves the ManageOfferResult value from the union, +// GetManageSellOfferResult retrieves the ManageSellOfferResult value from the union, // returning ok if the union's switch indicated the value is valid. -func (u OperationResultTr) GetManageOfferResult() (result ManageOfferResult, ok bool) { +func (u OperationResultTr) GetManageSellOfferResult() (result ManageSellOfferResult, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "ManageOfferResult" { - result = *u.ManageOfferResult + if armName == "ManageSellOfferResult" { + result = *u.ManageSellOfferResult ok = true } return } -// MustCreatePassiveOfferResult retrieves the CreatePassiveOfferResult value from the union, +// MustCreatePassiveSellOfferResult retrieves the CreatePassiveSellOfferResult value from the union, // panicing if the value is not set. -func (u OperationResultTr) MustCreatePassiveOfferResult() ManageOfferResult { - val, ok := u.GetCreatePassiveOfferResult() +func (u OperationResultTr) MustCreatePassiveSellOfferResult() ManageSellOfferResult { + val, ok := u.GetCreatePassiveSellOfferResult() if !ok { - panic("arm CreatePassiveOfferResult is not set") + panic("arm CreatePassiveSellOfferResult is not set") } return val } -// GetCreatePassiveOfferResult retrieves the CreatePassiveOfferResult value from the union, +// GetCreatePassiveSellOfferResult retrieves the CreatePassiveSellOfferResult value from the union, // returning ok if the union's switch indicated the value is valid. -func (u OperationResultTr) GetCreatePassiveOfferResult() (result ManageOfferResult, ok bool) { +func (u OperationResultTr) GetCreatePassiveSellOfferResult() (result ManageSellOfferResult, ok bool) { armName, _ := u.ArmForSwitch(int32(u.Type)) - if armName == "CreatePassiveOfferResult" { - result = *u.CreatePassiveOfferResult + if armName == "CreatePassiveSellOfferResult" { + result = *u.CreatePassiveSellOfferResult ok = true } @@ -9930,6 +10516,31 @@ func (u OperationResultTr) GetBumpSeqResult() (result BumpSequenceResult, ok boo return } +// MustManageBuyOfferResult retrieves the ManageBuyOfferResult value from the union, +// panicing if the value is not set. +func (u OperationResultTr) MustManageBuyOfferResult() ManageBuyOfferResult { + val, ok := u.GetManageBuyOfferResult() + + if !ok { + panic("arm ManageBuyOfferResult is not set") + } + + return val +} + +// GetManageBuyOfferResult retrieves the ManageBuyOfferResult value from the union, +// returning ok if the union's switch indicated the value is valid. +func (u OperationResultTr) GetManageBuyOfferResult() (result ManageBuyOfferResult, ok bool) { + armName, _ := u.ArmForSwitch(int32(u.Type)) + + if armName == "ManageBuyOfferResult" { + result = *u.ManageBuyOfferResult + ok = true + } + + return +} + // MarshalBinary implements encoding.BinaryMarshaler. func (s OperationResultTr) MarshalBinary() ([]byte, error) { b := new(bytes.Buffer) @@ -9961,10 +10572,10 @@ var ( // PaymentResult paymentResult; // case PATH_PAYMENT: // PathPaymentResult pathPaymentResult; -// case MANAGE_OFFER: -// ManageOfferResult manageOfferResult; -// case CREATE_PASSIVE_OFFER: -// ManageOfferResult createPassiveOfferResult; +// case MANAGE_SELL_OFFER: +// ManageSellOfferResult manageSellOfferResult; +// case CREATE_PASSIVE_SELL_OFFER: +// ManageSellOfferResult createPassiveSellOfferResult; // case SET_OPTIONS: // SetOptionsResult setOptionsResult; // case CHANGE_TRUST: @@ -9979,6 +10590,8 @@ var ( // ManageDataResult manageDataResult; // case BUMP_SEQUENCE: // BumpSequenceResult bumpSeqResult; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferResult manageBuyOfferResult; // } // tr; // default: