Skip to content

Commit

Permalink
horizon/ingest: Add method to ingest.Change that returns liquidity po…
Browse files Browse the repository at this point in the history
…ol type (#4158)

* Add method to ingest.Change that returns liquidity pool type
  • Loading branch information
erika-sdf committed Jan 4, 2022
1 parent 86c210b commit 97c628e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 24 additions & 0 deletions ingest/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ func (c *Change) LedgerEntryChangeType() xdr.LedgerEntryChangeType {
}
}

// getLiquidityPool gets the most recent state of the LiquidityPool that exists or existed.
func (c *Change) getLiquidityPool() (*xdr.LiquidityPoolEntry, error) {
var entry *xdr.LiquidityPoolEntry
if c.Pre != nil {
entry = c.Pre.Data.LiquidityPool
}
if c.Post != nil {
entry = c.Post.Data.LiquidityPool
}
if entry == nil {
return &xdr.LiquidityPoolEntry{}, errors.New("this change does not include a liquidity pool")
}
return entry, nil
}

// GetLiquidityPoolType returns the liquidity pool type.
func (c *Change) GetLiquidityPoolType() (xdr.LiquidityPoolType, error) {
lp, err := c.getLiquidityPool()
if err != nil {
return xdr.LiquidityPoolType(0), err
}
return lp.Body.Type, nil
}

// AccountChangedExceptSigners returns true if account has changed WITHOUT
// checking the signers (except master key weight!). In other words, if the only
// change is connected to signers, this function will return false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,9 @@ func (s AssetStatSet) AddLiquidityPool(change ingest.Change) error {
return ingest.NewStateError(errors.New("both pre and post liquidity pools cannot be nil"))
}

var lpType xdr.LiquidityPoolType
if pre != nil {
lpType = pre.Body.Type
}
if post != nil {
lpType = post.Body.Type
lpType, err := change.GetLiquidityPoolType()
if err != nil {
return ingest.NewStateError(err)
}

var assetA, assetB xdr.Asset
Expand Down

0 comments on commit 97c628e

Please sign in to comment.