Skip to content

Commit

Permalink
scaffolding code for generic trade processor
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikiyer56 committed Dec 8, 2024
1 parent 3b3bf8c commit b4cf033
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions ingest/trades/generic_trades_offers_processor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package trades

import (
"github.com/stellar/go/ingest"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
"io"
)

func ProcessTradesFromLedger(ledger xdr.LedgerCloseMeta, networkPassPhrase string) ([]TradeEvent, error) {
changeReader, err := ingest.NewLedgerChangeReaderFromLedgerCloseMeta(networkPassPhrase, ledger)
if err != nil {
return []TradeEvent{}, errors.Wrap(err, "Error creating ledger change reader")
}
defer changeReader.Close()

tradeEvents := make([]TradeEvent, 0)
for {
change, err := changeReader.Read()
if err == io.EOF {
break
}
if err != nil {
return []TradeEvent{}, errors.Wrap(err, "Error reading ledger change")
}
// Process trades from the change
tradesFromChange, err := processTradesFromChange(change)
if err != nil {
return nil, errors.Wrap(err, "Error processing trades from change")
}

// Append to the overall trade events slice
tradeEvents = append(tradeEvents, tradesFromChange...)

Check failure on line 33 in ingest/trades/generic_trades_offers_processor.go

View workflow job for this annotation

GitHub Actions / check (ubuntu-22.04, 1.22.1)

this result of append is never used, except maybe in other appends (SA4010)
}

return []TradeEvent{}, nil
}

func processTradesFromChange(change ingest.Change) ([]TradeEvent, error) {
var tradeEvents []TradeEvent

switch change.Type {
case xdr.LedgerEntryTypeOffer:
trades, err := processOffersFromChange(change)
if err != nil {
return nil, errors.Wrap(err, "Error processing offers")
}
tradeEvents = append(tradeEvents, trades...)
case xdr.LedgerEntryTypeLiquidityPool:
trades, err := processLiquidityPoolEventsFromChange(change)
if err != nil {
return nil, errors.Wrap(err, "Error processing liquidity pool events")
}
tradeEvents = append(tradeEvents, trades...)

default:
// Nothing to do
}

return tradeEvents, nil
}

func processOffersFromChange(change ingest.Change) ([]TradeEvent, error) {

return []TradeEvent{}, nil
}

func processLiquidityPoolEventsFromChange(change ingest.Change) ([]TradeEvent, error) {
return []TradeEvent{}, nil
}

0 comments on commit b4cf033

Please sign in to comment.