Skip to content

Commit

Permalink
Merge pull request #51 from Elenpay/develop
Browse files Browse the repository at this point in the history
Release 0.3.1
  • Loading branch information
Jossec101 authored Jan 11, 2023
2 parents 0783540 + ce9b29d commit f4fdb67
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 24 deletions.
18 changes: 8 additions & 10 deletions src/Helpers/JobTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,19 @@ public static async Task Execute(IJobExecutionContext context, Func<Task> callba

var trigger = context.Trigger as SimpleTriggerImpl;

if (trigger!.TimesTriggered >= intervals.Length)
if (trigger!.TimesTriggered <= intervals.Length)
{
return;
var repeatInterval = intervals[trigger!.TimesTriggered - 1];

var prevTriggerTime = trigger.GetPreviousFireTimeUtc();
trigger.SetNextFireTimeUtc(prevTriggerTime!.Value.AddMinutes(repeatInterval));

await context.Scheduler.RescheduleJob(context.Trigger.Key, trigger);
}

var repeatInterval = intervals[trigger!.TimesTriggered - 1];

var prevTriggerTime = trigger.GetPreviousFireTimeUtc();
trigger.SetNextFireTimeUtc(prevTriggerTime!.Value.AddMinutes(repeatInterval));

await context.Scheduler.RescheduleJob(context.Trigger.Key, trigger);

await callback();

var schedule = context.Scheduler.DeleteJob(context.JobDetail.Key, token);
await context.Scheduler.DeleteJob(context.JobDetail.Key, token);
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/Pages/Withdrawals.razor
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@

private decimal _maxWithdrawal;
private decimal _minWithdrawal;
private const decimal DefaultMin = 0.0m;
private const decimal DefaultMax = 21_000_000;

private decimal _btcPrice;

Expand All @@ -440,19 +442,14 @@
{
ToastService.ShowError("Bitcoin price in USD could not be retrieved.");
}

try
{
_maxWithdrawal = decimal.Parse(Environment.GetEnvironmentVariable("MAXIMUM_WITHDRAWAL_BTC_AMOUNT") ?? throw new InvalidOperationException(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
_minWithdrawal = decimal.Parse(Environment.GetEnvironmentVariable("MINIMUM_WITHDRAWAL_BTC_AMOUNT") ?? throw new InvalidOperationException(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
if (_maxWithdrawal == 0) _maxWithdrawal = 21000000;
if (_minWithdrawal == 0) _minWithdrawal = 0;
}
catch (Exception e)
{
ToastService.ShowError("Getting maximum of Bitcoins for withdrawal has failed");
}


var environmentVariableMin = Environment.GetEnvironmentVariable("MINIMUM_WITHDRAWAL_BTC_AMOUNT");
var environmentVariableMax = Environment.GetEnvironmentVariable("MAXIMUM_WITHDRAWAL_BTC_AMOUNT");
if (environmentVariableMin == null) _minWithdrawal = DefaultMin;
else _minWithdrawal = decimal.Parse(environmentVariableMin, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
if (environmentVariableMax == null) _maxWithdrawal = DefaultMax;
else _maxWithdrawal = decimal.Parse(environmentVariableMax, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);

if (LoggedUser != null)
{
if (ClaimsPrincipal.IsInRole(ApplicationUserRole.FinanceManager.ToString()))
Expand Down
65 changes: 64 additions & 1 deletion src/Services/LightningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,74 @@ public async Task OpenChannel(ChannelOperationRequest channelOperationRequest)
NodePubkey = ByteString.CopyFrom(Convert.FromHexString(destination.PubKey)),
};

//Prior to opening the channel, we add the remote node as a peer
var remoteNodeInfo = await GetNodeInfo(channelOperationRequest.DestNode?.PubKey);
if (remoteNodeInfo == null)
{
_logger.LogError("Error, remote node with {Pubkey} not found",
channelOperationRequest.DestNode?.PubKey);
throw new InvalidOperationException();
}

//For now, we only rely on pure tcp IPV4 connections
var addr = remoteNodeInfo.Addresses.FirstOrDefault(x => x.Network == "tcp").Addr;

if(addr == null)
{
_logger.LogError("Error, remote node with {Pubkey} has no tcp IPV4 address",
channelOperationRequest.DestNode?.PubKey);
throw new InvalidOperationException();
}
var isPeerAlreadyConnected = false;

ConnectPeerResponse connectPeerResponse = null;
try
{
connectPeerResponse = await client.ConnectPeerAsync(new ConnectPeerRequest
{
Addr = new LightningAddress {Host = addr, Pubkey = remoteNodeInfo.PubKey},
Perm = true
}, new Metadata
{
{"macaroon", source.ChannelAdminMacaroon}
});
}
//We avoid to stop the method if the peer is already connected
catch (RpcException e)
{
if (!e.Message.Contains("already connected to peer"))
{
throw;
}
else
{
isPeerAlreadyConnected = true;
}
}

if (connectPeerResponse != null || isPeerAlreadyConnected)
{
if (isPeerAlreadyConnected)
{
_logger.LogInformation("Peer: {Pubkey} already connected", remoteNodeInfo.PubKey);
}
else
{
_logger.LogInformation("Peer connected to {Pubkey}", remoteNodeInfo.PubKey);
}
}
else
{
_logger.LogError("Error, peer not connected to {Pubkey} on address: {address}",
remoteNodeInfo.PubKey, addr);
throw new InvalidOperationException();
}

//We launch a openstatusupdate stream for all the events when calling OpenChannel api method from LND
if (source.ChannelAdminMacaroon != null)
{
var openStatusUpdateStream = client.OpenChannel(openChannelRequest,
new Metadata { { "macaroon", source.ChannelAdminMacaroon } }
new Metadata {{"macaroon", source.ChannelAdminMacaroon}}
);

await foreach (var response in openStatusUpdateStream.ResponseStream.ReadAllAsync())
Expand Down

0 comments on commit f4fdb67

Please sign in to comment.