Beispiel #1
0
        public virtual async Task <IActionResult> OpenChannel(string cryptoCode, OpenLightningChannelRequest request)
        {
            var lightningClient = await GetLightningClient(cryptoCode, true);

            if (lightningClient == null)
            {
                return(NotFound());
            }

            if (TryGetNodeInfo(request.Node, out var nodeInfo))
            {
                ModelState.AddModelError(nameof(request.Node),
                                         "A valid node info was not provided to open a channel with");
            }

            if (request.ChannelAmount == null)
            {
                ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount is missing");
            }
            else if (request.ChannelAmount.Satoshi <= 0)
            {
                ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount must be more than 0");
            }

            if (request.FeeRate == null)
            {
                ModelState.AddModelError(nameof(request.FeeRate), "FeeRate is missing");
            }
            else if (request.FeeRate.SatoshiPerByte <= 0)
            {
                ModelState.AddModelError(nameof(request.FeeRate), "FeeRate must be more than 0");
            }

            if (CheckValidation(out var errorActionResult))
            {
                return(errorActionResult);
            }

            try
            {
                var response = await lightningClient.OpenChannel(new Lightning.OpenChannelRequest()
                {
                    ChannelAmount = request.ChannelAmount, FeeRate = request.FeeRate, NodeInfo = nodeInfo
                });

                if (response.Result == OpenChannelResult.Ok)
                {
                    return(Ok());
                }

                ModelState.AddModelError(string.Empty, response.Result.ToString());
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }
        }
Beispiel #2
0
        public virtual async Task OpenLightningChannel(string cryptoCode, OpenLightningChannelRequest request,
                                                       CancellationToken token = default)
        {
            var response = await _httpClient.SendAsync(
                CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels", bodyPayload : request,
                                  method : HttpMethod.Post), token);

            await HandleResponse(response);
        }
Beispiel #3
0
        public async Task <string> OpenLightningChannel(string bitcoinCode, OpenLightningChannelRequest request,
                                                        CancellationToken token = default)
        {
            var response = await _httpClient.SendAsync(
                CreateHttpRequest($"api/v1/server/lightning/{bitcoinCode}/channels", bodyPayload : request,
                                  method : HttpMethod.Post), token);

            return(await HandleResponse <string>(response));
        }
Beispiel #4
0
        public virtual async Task <IActionResult> OpenChannel(string cryptoCode, OpenLightningChannelRequest request, CancellationToken cancellationToken = default)
        {
            var lightningClient = await GetLightningClient(cryptoCode, true);

            if (request?.NodeURI is null)
            {
                ModelState.AddModelError(nameof(request.NodeURI),
                                         "A valid node info was not provided to open a channel with");
            }

            if (request.ChannelAmount == null)
            {
                ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount is missing");
            }
            else if (request.ChannelAmount.Satoshi <= 0)
            {
                ModelState.AddModelError(nameof(request.ChannelAmount), "ChannelAmount must be more than 0");
            }

            if (request.FeeRate == null)
            {
                ModelState.AddModelError(nameof(request.FeeRate), "FeeRate is missing");
            }
            else if (request.FeeRate.SatoshiPerByte <= 0)
            {
                ModelState.AddModelError(nameof(request.FeeRate), "FeeRate must be more than 0");
            }

            if (!ModelState.IsValid)
            {
                return(this.CreateValidationError(ModelState));
            }

            var response = await lightningClient.OpenChannel(new OpenChannelRequest
            {
                ChannelAmount = request.ChannelAmount,
                FeeRate       = request.FeeRate,
                NodeInfo      = request.NodeURI
            }, cancellationToken);

            string errorCode, errorMessage;

            switch (response.Result)
            {
            case OpenChannelResult.Ok:
                return(Ok());

            case OpenChannelResult.AlreadyExists:
                errorCode    = "channel-already-exists";
                errorMessage = "The channel already exists";
                break;

            case OpenChannelResult.CannotAffordFunding:
                errorCode    = "cannot-afford-funding";
                errorMessage = "Not enough money to open a channel";
                break;

            case OpenChannelResult.NeedMoreConf:
                errorCode    = "need-more-confirmations";
                errorMessage = "Need to wait for more confirmations";
                break;

            case OpenChannelResult.PeerNotConnected:
                errorCode    = "peer-not-connected";
                errorMessage = "Not connected to peer";
                break;

            default:
                throw new NotSupportedException("Unknown OpenChannelResult");
            }
            return(this.CreateAPIError(errorCode, errorMessage));
        }
Beispiel #5
0
 public override Task <IActionResult> OpenChannel(string cryptoCode, OpenLightningChannelRequest request)
 {
     return(base.OpenChannel(cryptoCode, request));
 }
Beispiel #6
0
 public override Task <IActionResult> OpenChannel(string cryptoCode, OpenLightningChannelRequest request, CancellationToken cancellationToken = default)
 {
     return(base.OpenChannel(cryptoCode, request, cancellationToken));
 }
Beispiel #7
0
        public async Task <ActionResult <string> > OpenLightningChannel(OpenLightningChannelRequest req)
        {
            var result = await _btcpayService.OpenLightningChannel(req);

            return(Ok(result));
        }
 public async Task <string> OpenLightningChannel(OpenLightningChannelRequest req, CancellationToken cancellationToken = default)
 {
     return(await _client.OpenLightningChannel(_storeId, CryptoCode, req, cancellationToken));
 }