-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from wavesplatform/release/v0.31.4
Release/v0.31.4
- Loading branch information
Showing
13 changed files
with
292 additions
and
151 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
import * as LRU from 'lru-cache'; | ||
import { BigNumber } from "@waves/data-entities"; | ||
import { Task, of as taskOf, rejected } from 'folktale/concurrency/task'; | ||
|
||
import { AppError } from "../../errorHandling"; | ||
import { WavesId } from "../.."; | ||
import { PairsService } from "../pairs"; | ||
|
||
export interface IThresholdAssetRateService { | ||
get(): Task<AppError, BigNumber> | ||
}; | ||
|
||
export class ThresholdAssetRateService implements IThresholdAssetRateService { | ||
private cache: LRU<string, BigNumber>; | ||
|
||
constructor(private readonly thresholdAssetId: string, private readonly matcherAddress: string, private readonly pairsService: PairsService) { | ||
this.cache = new LRU({ maxAge: 60000 }); | ||
} | ||
|
||
get(): Task<AppError, BigNumber> { | ||
let rate = this.cache.get(this.thresholdAssetId); | ||
if (rate === undefined) { | ||
// rate was not set or is stale | ||
return this.pairsService.get({ | ||
pair: { | ||
amountAsset: WavesId, | ||
priceAsset: this.thresholdAssetId, | ||
}, matcher: this.matcherAddress | ||
}).chain(m => { | ||
return m.matchWith({ | ||
Just: ({ value }) => { | ||
if (value.data === null) { | ||
return rejected(AppError.Resolver(`Rate for pair WAVES/${this.thresholdAssetId} not found`)); | ||
} | ||
this.cache.set(this.thresholdAssetId, value.data.weightedAveragePrice); | ||
return taskOf(value.data.weightedAveragePrice); | ||
}, | ||
Nothing: () => { | ||
return rejected(AppError.Resolver(`Pair WAVES/${this.thresholdAssetId} not found`)); | ||
} | ||
}) | ||
}); | ||
} else { | ||
return taskOf(rate); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.