コード例 #1
0
        public void SendTransaction(NodeCoreAdminClient adminClient)
        {
            Console.WriteLine("SendTransaction");
            Console.WriteLine("NC_CLI command: send <amount> <destinationAddress> [sourceAddress]");

            //Sending implies also signing

            String sourceAddress = "V4m6JbAs8VaEa3wwemJPgsPRY8ETdk";
            String targetAddress = "VDPNEDihaDAuKqcH35YJ1DNHaFbj2R";
            double amount        = 10.5;

            SendCoinsRequest request = new SendCoinsRequest();

            request.SourceAddress = Utils.ConvertAddressToByteString(sourceAddress);
            Output o = new Output();

            o.Address = Utils.ConvertAddressToByteString(targetAddress);
            o.Amount  = Utils.ConvertVbkToAtomicUnits(amount);
            request.Amounts.Add(o);

            SendCoinsReply reply = adminClient.AdminClient.SendCoins(request);

            if (reply.Success)
            {
                //Note - could create multiple Tx, pick just the first one for demo:
                Console.WriteLine("Created transaction: {0}", reply.TxIds[0].ToHexString());
            }
            else
            {
                Console.WriteLine("Error sending transaction: {0}", reply.Results[0].Details);
            }

            Console.WriteLine("--------------------");
            Console.WriteLine();
        }
コード例 #2
0
        public async Task <string> SendCoins(string address, int amount, int targetConf = -1, int satoshiPerByte = -1)
        {
            var sendCoinsRequest = new SendCoinsRequest()
            {
                Addr = address, Amount = amount
            };

            if (targetConf != -1)
            {
                sendCoinsRequest.TargetConf = targetConf;
            }
            if (satoshiPerByte != -1)
            {
                sendCoinsRequest.SatPerByte = satoshiPerByte;
            }

            var sendCoinsResponse = await lndClient.SendCoinsAsync(sendCoinsRequest);

            return(sendCoinsResponse.Txid);
        }
コード例 #3
0
        private void SubmitButtonOnClick(object sender, EventArgs e)
        {
            ClearErrorData();
            if (typeof(TRequestMessage) == typeof(ConnectPeerRequest))
            {
                var fullAddress = (string)Ws.Cells[_fieldToRow["addr"], EndColumn].Value2;
                if (fullAddress == null)
                {
                    return;
                }
                var addressParts = fullAddress.Split('@');

                string pubkey;
                string host;
                switch (addressParts.Length)
                {
                case 0:
                    return;

                case 2:
                    pubkey = addressParts[0];
                    host   = addressParts[1];
                    break;

                default:
                    Utilities.DisplayError(ErrorData, "Error", "Invalid address, must be pubkey@ip:host");
                    return;
                }

                var  permanent = Ws.Cells[_fieldToRow["perm"], EndColumn].Value2;
                bool perm      = permanent == null || (bool)permanent;

                var address = new LightningAddress {
                    Host = host, Pubkey = pubkey
                };
                var request = new ConnectPeerRequest {
                    Addr = address, Perm = perm
                };
                try
                {
                    _lApp.LndClient.ConnectPeer(request);
                    _lApp.Refresh(SheetNames.Peers);
                    ClearForm();
                }
                catch (RpcException rpcException)
                {
                    DisplayError(rpcException);
                }
            }
            else if (typeof(TRequestMessage) == typeof(SendCoinsRequest))
            {
                var request = new SendCoinsRequest
                {
                    Addr   = Ws.Cells[_fieldToRow["addr"], EndColumn].Value2,
                    Amount = (long)Ws.Cells[_fieldToRow["amount"], EndColumn].Value2
                };
                var satPerByte = Ws.Cells[_fieldToRow["sat_per_byte"], EndColumn].Value2;
                if (satPerByte == null)
                {
                    satPerByte = 0;
                }
                if (satPerByte > 0)
                {
                    request.SatPerByte = satPerByte;
                }

                var targetConf = Ws.Cells[_fieldToRow["target_conf"], EndColumn].Value2;
                if (targetConf == null)
                {
                    targetConf = 0;
                }
                if (targetConf > 0)
                {
                    request.TargetConf = targetConf;
                }

                try
                {
                    _lApp.LndClient.SendCoins(request);
                    _lApp.Refresh(SheetNames.Transactions);
                    ClearForm();
                }
                catch (RpcException rpcException)
                {
                    DisplayError(rpcException);
                }
            }
            else if (typeof(TRequestMessage) == typeof(OpenChannelRequest))
            {
                var localFundingAmount = long.Parse(GetValue("local_funding_amount"));
                var minConfs           = int.Parse(GetValue("min_confs"));
                var minHtlcMsat        = long.Parse(GetValue("min_htlc_msat"));
                var nodePubKeyString   = GetValue("node_pubkey");
                var isPrivate          = true;
                if (bool.TryParse(GetValue("private"), out var result))
                {
                    isPrivate = result;
                }
                var pushSat        = long.Parse(GetValue("push_sat"));
                var remoteCsvDelay = uint.Parse(GetValue("remote_csv_delay"));
                var satPerByte     = long.Parse(GetValue("sat_per_byte"));
                var targetConf     = int.Parse(GetValue("target_conf"));
                var request        = new OpenChannelRequest
                {
                    LocalFundingAmount = localFundingAmount,
                    MinConfs           = minConfs,
                    MinHtlcMsat        = minHtlcMsat,
                    NodePubkeyString   = nodePubKeyString,
                    Private            = isPrivate,
                    PushSat            = pushSat
                };
                if (remoteCsvDelay > 0)
                {
                    request.RemoteCsvDelay = remoteCsvDelay;
                }
                if (satPerByte > 0)
                {
                    request.SatPerByte = satPerByte;
                }
                if (targetConf > 0)
                {
                    request.TargetConf = targetConf;
                }

                try
                {
                    _lApp.LndClient.OpenChannel(request);
                    _lApp.Refresh(SheetNames.Channels);
                    ClearForm();
                }
                catch (RpcException rpcException)
                {
                    DisplayError(rpcException);
                }
            }
            else
            {
                var request   = new TRequestMessage();
                var rowNumber = _dataStartRow;
                foreach (var field in Fields)
                {
                    Range dataCell = Ws.Cells[rowNumber, EndColumn];
                    var   value    = dataCell.Value2;
                    if (!string.IsNullOrWhiteSpace(value?.ToString()))
                    {
                        field.Accessor.SetValue(request, dataCell.Value2);
                    }
                }

                _query(request);
            }
        }