Skip to content

Commit

Permalink
Added configurable values for scanning through nbxplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jossec101 committed Aug 1, 2024
1 parent 24c41c9 commit ccbae18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Data/Repositories/WalletRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public async Task TrackAndScanWallet(Wallet wallet){

//Since already existing wallet's utxos are not tracked by NBXplorer, we need to rescan the UTXO set for this wallet
//This is a long running operation in nbxplorer and should be queried in the background
await _nbXplorerService.ScanUTXOSetAsync(derivationStrategyBase, 1000, 30000, null, default);
await _nbXplorerService.ScanUTXOSetAsync(derivationStrategyBase, Constants.SCAN_BATCH_SIZE, Constants.SCAN_GAP_LIMIT, null, default);
}

public async Task<(bool, string?)> ImportWatchOnlyWallet(string name, string? description, string outputDescriptor, string? userId = null)
Expand Down
32 changes: 22 additions & 10 deletions src/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ public class Constants
/// <summary>
/// Max ratio of the tx total input sum that could be used as fee
/// </summary>
public static decimal MAX_TX_FEE_RATIO =0.5m;
public static decimal MAX_TX_FEE_RATIO = 0.5m;

public const string IsFrozenTag = "frozen";


// Constants for the NBXplorer API
public static int SCAN_GAP_LIMIT = 1000;
public static int SCAN_BATCH_SIZE = 1000;

private static string? GetEnvironmentalVariableOrThrowIfNotTesting(string envVariableName, string? errorMessage = null)
{
// If it is a command from ef or a test, ignore the empty env variables
var command = Assembly.GetEntryAssembly()?.GetName().Name?.ToLowerInvariant();
var ignoreMissingVar = command == "ef" || (command != null && command.Contains("test"));

var envVariable = Environment.GetEnvironmentVariable(envVariableName);
if (!ignoreMissingVar && envVariable == null) {
if (!ignoreMissingVar && envVariable == null)
{
throw new EnvironmentalVariableMissingException(errorMessage ?? envVariableName);
}
return envVariable;
Expand All @@ -116,7 +121,7 @@ static Constants()
ALLOW_SIMULTANEOUS_CHANNEL_OPENING_OPERATIONS = Environment.GetEnvironmentVariable("ALLOW_SIMULTANEOUS_CHANNEL_OPENING_OPERATIONS") == "true";

// Connections
POSTGRES_CONNECTIONSTRING = Environment.GetEnvironmentVariable("POSTGRES_CONNECTIONSTRING") ?? POSTGRES_CONNECTIONSTRING;
POSTGRES_CONNECTIONSTRING = Environment.GetEnvironmentVariable("POSTGRES_CONNECTIONSTRING") ?? POSTGRES_CONNECTIONSTRING;

NBXPLORER_URI = GetEnvironmentalVariableOrThrowIfNotTesting("NBXPLORER_URI");

Expand Down Expand Up @@ -166,7 +171,7 @@ static Constants()
}

API_TOKEN_SALT = Environment.GetEnvironmentVariable("API_TOKEN_SALT") ?? "H/fCx1+maAFMcdi6idIYEg==";

// Crons & Jobs
MONITOR_WITHDRAWALS_CRON = Environment.GetEnvironmentVariable("MONITOR_WITHDRAWALS_CRON") ?? MONITOR_WITHDRAWALS_CRON;

Expand Down Expand Up @@ -218,18 +223,25 @@ static Constants()

//Sat/vb ratio
var minSatPerVbRatioEnv = Environment.GetEnvironmentVariable("MIN_SAT_PER_VB_RATIO");
MIN_SAT_PER_VB_RATIO = minSatPerVbRatioEnv!= null ? decimal.Parse(minSatPerVbRatioEnv) : MIN_SAT_PER_VB_RATIO;
MIN_SAT_PER_VB_RATIO = minSatPerVbRatioEnv != null ? decimal.Parse(minSatPerVbRatioEnv) : MIN_SAT_PER_VB_RATIO;

var maxSatPerVbRatioEnv = Environment.GetEnvironmentVariable("MAX_SAT_PER_VB_RATIO");
MAX_SAT_PER_VB_RATIO = maxSatPerVbRatioEnv!= null ? decimal.Parse(maxSatPerVbRatioEnv) : MAX_SAT_PER_VB_RATIO;
MAX_SAT_PER_VB_RATIO = maxSatPerVbRatioEnv != null ? decimal.Parse(maxSatPerVbRatioEnv) : MAX_SAT_PER_VB_RATIO;

//NBXplorer scan
var scanGapLimit = Environment.GetEnvironmentVariable("SCAN_GAP_LIMIT");
SCAN_GAP_LIMIT = scanGapLimit != null ? int.Parse(scanGapLimit) : SCAN_GAP_LIMIT;

var scanBatchSize = Environment.GetEnvironmentVariable("SCAN_BATCH_SIZE");
SCAN_BATCH_SIZE = scanBatchSize != null ? int.Parse(scanBatchSize) : SCAN_BATCH_SIZE;

}

}

public class EnvironmentalVariableMissingException: ArgumentNullException
public class EnvironmentalVariableMissingException : ArgumentNullException
{
public EnvironmentalVariableMissingException(string message): base(message + " must be set")
public EnvironmentalVariableMissingException(string message) : base(message + " must be set")
{
}
}

0 comments on commit ccbae18

Please sign in to comment.