Skip to content

Commit

Permalink
Fix the amount
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikiyer56 committed Nov 14, 2024
1 parent ce975a1 commit 410b29e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions ingest/offers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const (
EventTypeOfferClosed = "OfferClosed"
)

// Base struct with common fields for all offer events
// Base struct with common fields for all offer events.
type OfferEventData struct {
SellerId string
OfferID int64

BuyingAsset xdr.Asset
SellingAsset xdr.Asset

RemainingAmount int64
RemainingAmount int64 // Remaining amount that still needs to be filled for this offer
PriceN int32
PriceD int32

Expand Down Expand Up @@ -114,7 +114,7 @@ func populateOfferData(e *xdr.LedgerEntry) OfferEventData {
}
}

func ProcessOffer(change ingest.Change) *OfferEvent {
func ProcessOffer(change ingest.Change) OfferEvent {
if change.Type != xdr.LedgerEntryTypeOffer {
return nil
}
Expand All @@ -131,7 +131,6 @@ func ProcessOffer(change ingest.Change) *OfferEvent {
// Order Fill
o = populateOfferData(change.Post)
fillAmt := int64(change.Pre.Data.MustOffer().Amount - change.Post.Data.MustOffer().Amount)
o.RemainingAmount = fillAmt
event = OfferFillEvent{OfferEventData: o, FillAmount: fillAmt}
//TODO: populate MatchingOrders field in OfferFillEvent

Expand All @@ -142,6 +141,6 @@ func ProcessOffer(change ingest.Change) *OfferEvent {
event = OfferClosedEvent{OfferEventData: o}
//TODO: populate CloseReason field in OfferClosedEvent
}
return &event
return event

}
11 changes: 6 additions & 5 deletions services/horizon/internal/ingest/processors/offers_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ func (p *OffersProcessor) ProcessChange(ctx context.Context, change ingest.Chang
return nil
}

switch ev := (*event).(type) {
switch ev := event.(type) {
case offers.OfferCreatedEvent:
row := p.eventToRow(ev.OfferEventData)
row := p.offerEventToRow(ev.OfferEventData)
err := p.insertBatchBuilder.Add(row)
if err != nil {
return errors.New("Error adding to OffersBatchInsertBuilder")
}
case offers.OfferFillEvent:
row := p.eventToRow(ev.OfferEventData)
row := p.offerEventToRow(ev.OfferEventData)
p.batchUpdateOffers = append(p.batchUpdateOffers, row)
case offers.OfferClosedEvent:
row := p.eventToRow(ev.OfferEventData)
row := p.offerEventToRow(ev.OfferEventData)
row.Deleted = true
row.LastModifiedLedger = p.sequence
p.batchUpdateOffers = append(p.batchUpdateOffers, row)
Expand All @@ -70,7 +70,7 @@ func (p *OffersProcessor) ProcessChange(ctx context.Context, change ingest.Chang

}

func (p *OffersProcessor) eventToRow(event offers.OfferEventData) history.Offer {
func (p *OffersProcessor) offerEventToRow(event offers.OfferEventData) history.Offer {
flags := int32(0)
if event.IsPassive {
flags = 1
Expand All @@ -81,6 +81,7 @@ func (p *OffersProcessor) eventToRow(event offers.OfferEventData) history.Offer
OfferID: event.OfferID,
SellingAsset: event.SellingAsset,
BuyingAsset: event.BuyingAsset,
Amount: event.RemainingAmount,
Pricen: event.PriceN,
Priced: event.PriceD,
Price: float64(event.PriceN) / float64(event.PriceD),
Expand Down

0 comments on commit 410b29e

Please sign in to comment.