Skip to content

Commit

Permalink
Update to v11 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-wasp committed Jun 3, 2019
1 parent d96759e commit 009a375
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
23 changes: 17 additions & 6 deletions es/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ func NewOperation(t *Transaction, o *xdr.Operation, n byte) *Operation {
newPayment(o.Body.MustPaymentOp(), op)
case xdr.OperationTypePathPayment:
newPathPayment(o.Body.MustPathPaymentOp(), op)
case xdr.OperationTypeManageOffer:
newManageOffer(o.Body.MustManageOfferOp(), op)
case xdr.OperationTypeCreatePassiveOffer:
newCreatePassiveOffer(o.Body.MustCreatePassiveOfferOp(), op)
case xdr.OperationTypeManageSellOffer:
newManageSellOffer(o.Body.MustManageSellOfferOp(), op)
case xdr.OperationTypeManageBuyOffer:
newManageBuyOffer(o.Body.MustManageBuyOfferOp(), op)
case xdr.OperationTypeCreatePassiveSellOffer:
newCreatePassiveSellOffer(o.Body.MustCreatePassiveSellOfferOp(), op)
case xdr.OperationTypeSetOptions:
newSetOptions(o.Body.MustSetOptionsOp(), op)
case xdr.OperationTypeChangeTrust:
Expand Down Expand Up @@ -188,7 +190,7 @@ func newPathPayment(o xdr.PathPaymentOp, op *Operation) {
}
}

func newManageOffer(o xdr.ManageOfferOp, op *Operation) {
func newManageSellOffer(o xdr.ManageSellOfferOp, op *Operation) {
op.SourceAmount = amount.String(o.Amount)
op.SourceAsset = NewAsset(&o.Buying)
op.OfferID = int(o.OfferId)
Expand All @@ -197,7 +199,16 @@ func newManageOffer(o xdr.ManageOfferOp, op *Operation) {
op.DestinationAsset = NewAsset(&o.Selling)
}

func newCreatePassiveOffer(o xdr.CreatePassiveOfferOp, op *Operation) {
func newManageBuyOffer(o xdr.ManageBuyOfferOp, op *Operation) {
op.SourceAmount = amount.String(o.BuyAmount)
op.SourceAsset = NewAsset(&o.Selling)
op.DestinationAsset = NewAsset(&o.Buying)
op.OfferID = int(o.OfferId)
op.OfferPrice, _ = big.NewRat(int64(o.Price.N), int64(o.Price.D)).Float64()
op.OfferPriceND = &Price{int(o.Price.N), int(o.Price.D)}
}

func newCreatePassiveSellOffer(o xdr.CreatePassiveSellOfferOp, op *Operation) {
op.SourceAmount = amount.String(o.Amount)
op.SourceAsset = NewAsset(&o.Buying)
op.OfferPrice, _ = big.NewRat(int64(o.Price.N), int64(o.Price.D)).Float64()
Expand Down
57 changes: 36 additions & 21 deletions es/operation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ func AppendResult(op *Operation, r *xdr.OperationResult) {
newPaymentResult(r.Tr.MustPaymentResult(), op)
case xdr.OperationTypePathPayment:
newPathPaymentResult(r.Tr.MustPathPaymentResult(), op)
case xdr.OperationTypeManageOffer:
newManageOfferResult(r.Tr.MustManageOfferResult(), op)
case xdr.OperationTypeCreatePassiveOffer:
newManageOfferResult(r.Tr.MustCreatePassiveOfferResult(), op)
case xdr.OperationTypeManageSellOffer:
newManageSellOfferResult(r.Tr.MustManageSellOfferResult(), op)
case xdr.OperationTypeManageBuyOffer:
newManageBuyOfferResult(r.Tr.MustManageBuyOfferResult(), op)
case xdr.OperationTypeCreatePassiveSellOffer:
newManageSellOfferResult(r.Tr.MustCreatePassiveSellOfferResult(), op)
case xdr.OperationTypeSetOptions:
newSetOptionsResult(r.Tr.MustSetOptionsResult(), op)
case xdr.OperationTypeChangeTrust:
Expand Down Expand Up @@ -73,28 +75,41 @@ func newPathPaymentResult(r xdr.PathPaymentResult, op *Operation) {
}
}

func newManageOfferResult(r xdr.ManageOfferResult, op *Operation) {
func newManageSellOfferResult(r xdr.ManageSellOfferResult, op *Operation) {
op.InnerResultCode = int(r.Code)
op.Succesful = r.Code == xdr.ManageOfferResultCodeManageOfferSuccess
op.Succesful = r.Code == xdr.ManageSellOfferResultCodeManageSellOfferSuccess

if s, ok := r.GetSuccess(); ok {
op.ResultOffersClaimed = appendOffersClaimed(s.OffersClaimed)

if o, ok := s.Offer.GetOffer(); ok {
p, _ := big.NewRat(int64(o.Price.N), int64(o.Price.D)).Float64()

op.ResultOffer = &Offer{
Amount: amount.String(o.Amount),
Price: p,
PriceND: Price{int(o.Price.N), int(o.Price.D)},
Buying: *NewAsset(&o.Buying),
Selling: *NewAsset(&o.Selling),
OfferID: int64(o.OfferId),
SellerID: o.SellerId.Address(),
}
newManageOfferResult(s, op)
}
}

func newManageBuyOfferResult(r xdr.ManageBuyOfferResult, op *Operation) {
op.InnerResultCode = int(r.Code)
op.Succesful = r.Code == xdr.ManageBuyOfferResultCodeManageBuyOfferSuccess

if s, ok := r.GetSuccess(); ok {
newManageOfferResult(s, op)
}
}

op.ResultOfferEffect = s.Offer.Effect.String()
func newManageOfferResult(s xdr.ManageOfferSuccessResult, op *Operation) {
op.ResultOffersClaimed = appendOffersClaimed(s.OffersClaimed)

if o, ok := s.Offer.GetOffer(); ok {
p, _ := big.NewRat(int64(o.Price.N), int64(o.Price.D)).Float64()

op.ResultOffer = &Offer{
Amount: amount.String(o.Amount),
Price: p,
PriceND: Price{int(o.Price.N), int(o.Price.D)},
Buying: *NewAsset(&o.Buying),
Selling: *NewAsset(&o.Selling),
OfferID: int64(o.OfferId),
SellerID: o.SellerId.Address(),
}

op.ResultOfferEffect = s.Offer.Effect.String()
}
}

Expand Down

0 comments on commit 009a375

Please sign in to comment.