-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(price-feeder): computed price api routes (#1445)
* Save tvwap by provider to oracle * Add api routes and read locks
- Loading branch information
Showing
11 changed files
with
224 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package oracle | ||
|
||
import ( | ||
"sync" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/umee-network/umee/price-feeder/oracle/provider" | ||
) | ||
|
||
type ( | ||
PricesByProvider map[provider.Name]map[string]sdk.Dec | ||
|
||
PricesWithMutex struct { | ||
prices PricesByProvider | ||
mx sync.RWMutex | ||
} | ||
) | ||
|
||
// SetPrices sets the PricesWithMutex.prices value surrounded by a write lock | ||
func (pwm *PricesWithMutex) SetPrices(prices PricesByProvider) { | ||
pwm.mx.Lock() | ||
defer pwm.mx.Unlock() | ||
|
||
pwm.prices = prices | ||
} | ||
|
||
// GetPricesClone retrieves a clone of PricesWithMutex.prices | ||
// surrounded by a read lock | ||
func (pwm *PricesWithMutex) GetPricesClone() PricesByProvider { | ||
pwm.mx.RLock() | ||
defer pwm.mx.RUnlock() | ||
return pwm.clonePrices() | ||
} | ||
|
||
// clonePrices returns a deep copy of PricesWithMutex.prices | ||
func (pwm *PricesWithMutex) clonePrices() PricesByProvider { | ||
clone := make(PricesByProvider, len(pwm.prices)) | ||
for provider, prices := range pwm.prices { | ||
pricesClone := make(map[string]sdk.Dec, len(prices)) | ||
for denom, price := range prices { | ||
pricesClone[denom] = price | ||
} | ||
clone[provider] = pricesClone | ||
} | ||
return clone | ||
} |
Oops, something went wrong.