Add implicit hidden rate rule for sats in parser

This commit is contained in:
Kukks 2020-01-12 13:54:06 +01:00
parent f5cbf6672a
commit a63502873c

View File

@ -99,6 +99,8 @@ namespace BTCPayServer.Rating
RuleList ruleList;
decimal _Spread;
private const string ImplicitSatsRule = "SATS_X = SATS_BTC * BTC_X;\nSATS_BTC = 0.00000001;\n";
public decimal Spread
{
get
@ -126,6 +128,7 @@ namespace BTCPayServer.Rating
}
public static bool TryParse(string str, out RateRules rules, out List<RateRulesErrors> errors)
{
str = ImplicitSatsRule + str;
rules = null;
errors = null;
var expression = CSharpSyntaxTree.ParseText(str, new CSharpParseOptions(LanguageVersion.Default).WithKind(SourceCodeKind.Script));
@ -195,6 +198,7 @@ namespace BTCPayServer.Rating
{
return root.NormalizeWhitespace("", "\n")
.ToFullString()
.Replace(ImplicitSatsRule, string.Empty, StringComparison.OrdinalIgnoreCase)
.Replace("{\n", string.Empty, StringComparison.OrdinalIgnoreCase)
.Replace("\n}", string.Empty, StringComparison.OrdinalIgnoreCase);
}