Example #1
0
        public decimal GetEstimateFeeForSendToAddress(string Address, decimal Amount)
        {
            var txRequest = new CreateRawTransactionRequest();

            txRequest.AddOutput(Address, Amount);
            return(GetFundRawTransaction(CreateRawTransaction(txRequest)).Fee);
        }
Example #2
0
        //public string CreateRawTransaction(JArray transactions, JObject addresses)
        //{
        //    FloRPC conn = new FloRPC(username, password, wallet_url, wallet_port);
        //    string resp = conn.MakeRequest("createrawtransaction", transactions, addresses);
        //    return resp;
        //}

        public string CreateRawTransaction(CreateRawTransactionRequest rawTransaction)
        {
            FloRPC conn = new FloRPC(username, password, wallet_url, wallet_port);
            string resp = conn.MakeRequest("createrawtransaction", rawTransaction.Inputs, rawTransaction.Outputs, rawTransaction.locktime, rawTransaction.replaceable, rawTransaction.floData);

            return(resp);
        }
Example #3
0
        public async Task <decimal> GetEstimateFeeForSendToAddressAsync(string Address, decimal Amount, CancellationToken cancellationToken)
        {
            var txRequest = new CreateRawTransactionRequest();

            txRequest.AddOutput(Address, Amount);
            var rawTransaction = await CreateRawTransactionAsync(txRequest, cancellationToken);

            var fundTransaction = await GetFundRawTransactionAsync(rawTransaction, cancellationToken);

            return(fundTransaction.Fee);
        }
Example #4
0
        private CreateRawTransactionRequest createNewRawTransactionRequest(ICoinService coinService, decimal sendAmount, string toAddress, string changeAddress)
        {
            var listUnspent = coinService.ListUnspent().OrderBy(utxo => utxo.Amount);

            //TODO: Read from appdata cloudchains config
            decimal minimumFee    = coinService.Parameters.MinimumTransactionFeeInCoins;
            decimal calculatedFee = 0;
            decimal sum           = 0;

            var utxos = listUnspent.TakeWhile(x =>
            {
                var temp = sum;
                sum     += x.Amount;
                return(temp < sendAmount);
            }).ToList();

            var rawTransactionRequest = new CreateRawTransactionRequest();

            foreach (var utxo in utxos)
            {
                rawTransactionRequest.AddInput(new CreateRawTransactionInput
                {
                    TxId = utxo.TxId,
                    Vout = utxo.Vout
                });
            }

            var inputSum = utxos.Sum(utxo => utxo.Amount);

            if (inputSum > sendAmount)
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = toAddress,
                    Amount  = sendAmount
                });

                calculatedFee = calculateFee(coinService, rawTransactionRequest.Inputs.Count(), 2);
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = changeAddress,
                    Amount  = inputSum - sendAmount - (calculatedFee <= minimumFee ? minimumFee : calculatedFee)
                });
            }
            else
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = toAddress,
                    Amount  = sendAmount - calculateFee(coinService, rawTransactionRequest.Inputs.Count(), 1)
                });
            }
            return(rawTransactionRequest);
        }
        public Decimal GetTransactionPriority(CreateRawTransactionRequest transaction)
        {
            if (transaction.Inputs.Count == 0)
            {
                return(0);
            }

            List <ListUnspentResponse> unspentInputs = (this as ICoinService).ListUnspent().ToList();
            Decimal sumOfInputsValueInBaseUnitsMultipliedByTheirAge = transaction.Inputs.Select(input => unspentInputs.First(x => x.TxId == input.TxId)).Select(unspentResponse => (unspentResponse.Amount * Parameters.OneCoinInBaseUnits) * unspentResponse.Confirmations).Sum();

            return(sumOfInputsValueInBaseUnitsMultipliedByTheirAge / GetTransactionSizeInBytes(transaction));
        }
        private void DoCoinControl(List <UnspentResponse> unspentInNeedOfCoinControl)
        {
            decimal fee = GetFee();

            if (fee < 0)
            {
                return;
            }

            string errorMessage;

            if (!TryUnlockWallet(out errorMessage))
            {
                MessageService.Error(errorMessage);
                return;
            }

            CreateRawTransactionRequest createRequest = new CreateRawTransactionRequest();

            createRequest.Inputs = new List <TransactionInput>();

            foreach (UnspentResponse transaction in unspentInNeedOfCoinControl)
            {
                createRequest.Inputs.Add(TransactionInput.CreateFromUnspent(transaction));
            }

            createRequest.SendFullAmountTo(m_config.AddressToCoinControl, fee);

            MessageService.Info(string.Format("Amount: {0} LINDA.", createRequest.AmountAfterFee + fee));
            MessageService.Info(string.Format("Amount After Fee: {0} LINDA.", createRequest.AmountAfterFee));

            TransactionHelper helper = new TransactionHelper(m_dataConnector);
            string            transactionId;

            if (!helper.TrySendRawTransaction(
                    createRequest,
                    out transactionId,
                    out errorMessage))
            {
                MessageService.Error(errorMessage);
                return;
            }

            MessageService.Info(string.Format("Coin control transaction sent: {0}.", transactionId));
            MessageService.Info("Coin control complete!");

            if (!TryUnlockWalletForStakingOnly(out errorMessage))
            {
                MessageService.Error(string.Format(
                                         "Failed to unlock wallet for staking only!  Wallet may remain entirely unlocked for up to 5 more seconds.  See error: {0}",
                                         errorMessage));
            }
        }
        public async Task <decimal> GetTransactionPriorityAsync(CreateRawTransactionRequest transaction)
        {
            if (transaction.Inputs.Count == 0)
            {
                return(0);
            }

            var result        = await(this as ICoinService).ListUnspentAsync(0);
            var unspentInputs = result.ToList();
            var sumOfInputsValueInBaseUnitsMultipliedByTheirAge = transaction.Inputs.Select(input => unspentInputs.First(x => x.TxId == input.TxId)).Select(unspentResponse => (unspentResponse.Amount * Parameters.OneCoinInBaseUnits) * unspentResponse.Confirmations).Sum();

            return(sumOfInputsValueInBaseUnitsMultipliedByTheirAge / GetTransactionSizeInBytes(transaction));
        }
Example #8
0
        public string GenerateRawTx(List <TxInput> inputs, List <TxOutput> outputs)
        {
            var request = new CreateRawTransactionRequest();

            foreach (var input in inputs)
            {
                request.AddInput(input.Tx, input.OutputIndex);
            }
            foreach (var output in outputs)
            {
                request.AddOutput(output.Address, output.Amount);
            }
            AdditionalErrorInformation = request;
            return(service.CreateRawTransaction(request));
        }
        public async Task <decimal> GetTransactionPriorityAsync(CreateRawTransactionRequest transaction, CancellationToken cancellationToken)
        {
            if (transaction.Inputs.Count == 0)
            {
                return(0);
            }

            var unspentInputs = await ListUnspentAsync(0, 99999, null, cancellationToken).ConfigureAwait(false);

            var sumOfInputsValueInBaseUnitsMultipliedByTheirAge = transaction.Inputs
                                                                  .Select(input => unspentInputs.First(x => x.TxId == input.TxId))
                                                                  .Select(unspentResponse => unspentResponse.Amount * Parameters.OneCoinInBaseUnits * unspentResponse.Confirmations)
                                                                  .Sum();

            return(sumOfInputsValueInBaseUnitsMultipliedByTheirAge / GetTransactionSizeInBytes(transaction));
        }
        public bool TrySendRawTransaction(
            CreateRawTransactionRequest createRequest,
            out string transactionId,
            out string errorMessage)
        {
            transactionId = null;

            string unsignedHex;

            if (!m_dataConnector.TryPost <string>(createRequest, out unsignedHex, out errorMessage))
            {
                return(false);
            }

            SignRawTransactionRequest signRequest = new SignRawTransactionRequest()
            {
                RawHex = unsignedHex
            };
            SignRawTransactionResponse signResponse;

            if (!m_dataConnector.TryPost <SignRawTransactionResponse>(signRequest, out signResponse, out errorMessage))
            {
                return(false);
            }

            if (!signResponse.Complete)
            {
                errorMessage = "Sign raw transaction response is incomplete!";
                return(false);
            }

            SendRawTransactionRequest sendRequest = new SendRawTransactionRequest()
            {
                RawHex = signResponse.RawHex
            };
            string tmpTransactionId;

            if (!m_dataConnector.TryPost <string>(sendRequest, out tmpTransactionId, out errorMessage))
            {
                return(false);
            }

            transactionId = tmpTransactionId;
            return(true);
        }
Example #11
0
        public Decimal GetMinimumNonZeroTransactionFeeEstimate(Int16 numberOfInputs = 1, Int16 numberOfOutputs = 1)
        {
            CreateRawTransactionRequest rawTransactionRequest = new CreateRawTransactionRequest(new List <CreateRawTransactionInput>(numberOfInputs), new Dictionary <String, Decimal>(numberOfOutputs));

            for (Int16 i = 0; i < numberOfInputs; i++)
            {
                rawTransactionRequest.AddInput(new CreateRawTransactionInput {
                    TxId = "dummyTxId" + i.ToString(CultureInfo.InvariantCulture), Vout = i
                });
            }

            for (Int16 i = 0; i < numberOfOutputs; i++)
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput {
                    Address = "dummyAddress" + i.ToString(CultureInfo.InvariantCulture), Amount = i + 1
                });
            }

            return(GetTransactionFee(rawTransactionRequest, false, true));
        }
Example #12
0
        private string Send(IList <CreateRawTransactionInput> inputs, IDictionary <string, decimal> outputs)
        {
            const int maxTries   = 10;
            var       currentTry = 0;
            var       finished   = false;

            Log.Debug("Call of method: string ProcessWallet.Send(IList<CreateRawTransactionInput> inputs, IDictionary<string, decimal> outputs).");
            Log.Verbose("Parameter inputs: {@inputs}.", inputs);
            Log.Verbose("Parameter outputs: {@outputs}.", outputs);
            while (!finished)
            {
                try
                {
                    ++currentTry;
                    var    request = new CreateRawTransactionRequest(inputs, outputs);
                    string txId    = AccessWallet.CreateRawTransaction(request);

                    SignRawTransactionResponse res = AccessWallet.SignRawTransaction(txId);
                    string ret = res.Complete ? AccessWallet.SendRawTransaction(res.Hex) : null;
                    finished = true;
                    Log.Verbose("Returnvalue of ProcessWallet.Send(IList<CreateRawTransactionInput> inputs, IDictionary<string, decimal> outputs): {ret}.", ret);
                    return(ret);
                }
                catch (Exception e)
                {
                    if (currentTry <= maxTries)
                    {
                        Log.Warning("Unable to send zero fee transaction. Retry...");
                        Task.Delay(TimeSpan.FromMinutes(1D)).Wait();
                        continue;
                    }

                    Log.Error(e, "An unresolveable Error occured. Giving up.");
                    throw;
                }
            }

            throw new Exception("An unresolveable Error occured.");
        }
        public async Task <decimal> GetMinimumNonZeroTransactionFeeEstimateAsync(short numberOfInputs = 1, short numberOfOutputs = 1)
        {
            var rawTransactionRequest = new CreateRawTransactionRequest(new List <CreateRawTransactionInput>(numberOfInputs), new Dictionary <string, decimal>(numberOfOutputs));

            for (short i = 0; i < numberOfInputs; i++)
            {
                rawTransactionRequest.AddInput(new CreateRawTransactionInput
                {
                    TxId = "dummyTxId" + i.ToString(CultureInfo.InvariantCulture), Vout = i
                });
            }

            for (short i = 0; i < numberOfOutputs; i++)
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = "dummyAddress" + i.ToString(CultureInfo.InvariantCulture), Amount = i + 1
                });
            }

            return(await GetTransactionFeeAsync(rawTransactionRequest, false, true));
        }
        public async Task <decimal> GetTransactionFeeAsync(CreateRawTransactionRequest transaction, bool checkIfTransactionQualifiesForFreeRelay, bool enforceMinimumTransactionFeePolicy, CancellationToken cancellationToken)
        {
            if (checkIfTransactionQualifiesForFreeRelay && await IsTransactionFreeAsync(transaction, cancellationToken).ConfigureAwait(false))
            {
                return(0);
            }

            decimal transactionSizeInBytes = GetTransactionSizeInBytes(transaction);
            var     transactionFee         = ((transactionSizeInBytes / Parameters.FreeTransactionMaximumSizeInBytes) + (transactionSizeInBytes % Parameters.FreeTransactionMaximumSizeInBytes == 0 ? 0 : 1)) * Parameters.FeePerThousandBytesInCoins;

            if (transactionFee.GetNumberOfDecimalPlaces() > Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces())
            {
                transactionFee = decimal.Round(transactionFee, Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces(), MidpointRounding.AwayFromZero);
            }

            if (enforceMinimumTransactionFeePolicy && Parameters.MinimumTransactionFeeInCoins != 0 && transactionFee < Parameters.MinimumTransactionFeeInCoins)
            {
                transactionFee = Parameters.MinimumTransactionFeeInCoins;
            }

            return(transactionFee);
        }
        public Decimal GetTransactionFee(CreateRawTransactionRequest transaction, Boolean checkIfTransactionQualifiesForFreeRelay, Boolean enforceMinimumTransactionFeePolicy)
        {
            if (checkIfTransactionQualifiesForFreeRelay && IsTransactionFree(transaction))
            {
                return(0);
            }

            Decimal transactionSizeInBytes = GetTransactionSizeInBytes(transaction);
            Decimal transactionFee         = ((transactionSizeInBytes / Parameters.FreeTransactionMaximumSizeInBytes) + (transactionSizeInBytes % Parameters.FreeTransactionMaximumSizeInBytes == 0 ? 0 : 1)) * Parameters.FeePerThousandBytesInCoins;

            if (transactionFee.GetNumberOfDecimalPlaces() > Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces())
            {
                transactionFee = Decimal.Round(transactionFee, Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces(), MidpointRounding.AwayFromZero);
            }

            if (enforceMinimumTransactionFeePolicy && Parameters.MinimumTransactionFeeInCoins != 0 && transactionFee < Parameters.MinimumTransactionFeeInCoins)
            {
                transactionFee = Parameters.MinimumTransactionFeeInCoins;
            }

            return(transactionFee);
        }
Example #16
0
        public TestWallet()
        {
            //var secret = new BitcoinSecret("cS6XuFcnuRQTXSZiBZC7MNkmhGCixUWfNZ4yDkvLCJX3h161LhgX"); //mnDJL3XEYNKCNwYoJg3RNK56ikTp9nQCVU, bitcoin core: importprivkey
            //var secret = new BitcoinSecret("L1wCJhdePmVds249szRqGkUwYxNhxkLHG9xHfdRyPrD87NfuHmWY"); //  n2z9HfufPiMWUBFtFnJ14hsbtP5FJ7UUKw

            ToAddress = address2pub;

            Init();

            // TEST CODE

            var unsent = CoinService.ListUnspent();

            CreateRawTransactionRequest rawTransaction = new CreateRawTransactionRequest();

            rawTransaction.AddInput(unsent[0].TxId, unsent[0].Vout);
            rawTransaction.AddOutput("mnDJL3XEYNKCNwYoJg3RNK56ikTp9nQCVU", 0.0001m);

            var rts = CoinService.CreateRawTransaction(rawTransaction);

            //CoinService.CreateRawTransaction()
        }
Example #17
0
 public string CreateRawTransaction(CreateRawTransactionRequest rawTransaction)
 {
     return(_rpcConnector.MakeRequest <string>(RpcMethods.createrawtransaction, rawTransaction.Inputs, rawTransaction.Outputs));
 }
Example #18
0
 /// <summary>
 ///     Creates a new raw transaction.
 /// </summary>
 /// <param name="rawTransactionRequest">The request holding the inputs and outputs for the transaction.</param>
 /// <returns>
 ///     The hex string of the transaction.
 /// </returns>
 public string CreateRawTransaction([NotNull] CreateRawTransactionRequest rawTransactionRequest) =>
 CallWallet <string>("createrawtransaction", rawTransactionRequest.Inputs, rawTransactionRequest.Outputs);
 public Boolean IsTransactionFree(CreateRawTransactionRequest transaction)
 {
     return(transaction.Outputs.Any(x => x.Value < Parameters.FreeTransactionMinimumOutputAmountInCoins) &&
            GetTransactionSizeInBytes(transaction) < Parameters.FreeTransactionMaximumSizeInBytes &&
            GetTransactionPriority(transaction) > Parameters.FreeTransactionMinimumPriority);
 }
 public Int32 GetTransactionSizeInBytes(CreateRawTransactionRequest transaction)
 {
     return(GetTransactionSizeInBytes(transaction.Inputs.Count, transaction.Outputs.Count));
 }
 public async Task <bool> IsTransactionFreeAsync(CreateRawTransactionRequest transaction)
 {
     return(transaction.Outputs.Any(x => x.Value < Parameters.FreeTransactionMinimumOutputAmountInCoins) &&
            GetTransactionSizeInBytes(transaction) < Parameters.FreeTransactionMaximumSizeInBytes &&
            await GetTransactionPriorityAsync(transaction) > Parameters.FreeTransactionMinimumPriority);
 }
Example #22
0
        static void Main(string[] args)
        {
            string username    = ConfigurationManager.AppSettings.Get("username");
            string password    = ConfigurationManager.AppSettings.Get("password");
            string wallet_url  = ConfigurationManager.AppSettings.Get("wallet_url");
            string wallet_port = ConfigurationManager.AppSettings.Get("wallet_port");


            RpcMethods rpc = new RpcMethods(username, password, wallet_url, wallet_port);


            try
            {
                //string toaddr = "oTw4kEvB3MWrN97ujWb6JAs3ye574DvuKV";
                //string fromaddr = "oWVv5huYoVsicv9wLqDSt9hKTYERchm2DY";
                //string response = Call_Service_Get("http://localhost:53722/FloAPI.svc/listunspentbyaddress/"+ fromaddr);
                //JObject objapi = JObject.Parse(response);
                //JArray arrunspent = JArray.Parse(objapi["result"].ToString());
                //decimal amtosent = 2.65m;
                //decimal fee = 0.0001m;
                //decimal bal = 0.0m;



                //CreateRawTransactionRequest req1 = new CreateRawTransactionRequest();
                //List<CreateRawTransactionInput> inputs1 = new List<CreateRawTransactionInput>();

                //foreach (JObject o in arrunspent.Children<JObject>())
                //{
                //    CreateRawTransactionInput input1 = new CreateRawTransactionInput();
                //    string tid = o["txid"].ToString();
                //    string vout = o["vout"].ToString();
                //    string scriptPubKey = o["scriptPubKey"].ToString();
                //    decimal amt = Convert.ToDecimal(o["amount"].ToString());
                //    input1.txid = tid;
                //    input1.vout = Convert.ToInt32(vout);
                //    input1.scriptPubKey = scriptPubKey;
                //    inputs1.Add(input1);

                //    bal += amt;
                //    if(bal >= (amtosent+fee))
                //    {
                //        break;
                //    }

                //}
                //decimal change = bal - (amtosent + fee);
                //Dictionary<string, decimal> output1 = new Dictionary<string, decimal>();
                //output1.Add(toaddr, amtosent);
                //output1.Add(fromaddr, change);

                //req1.Inputs = inputs1;
                //req1.Outputs = output1;
                //req1.floData = "Test Raw Transaction API";
                //req1.locktime = 0;
                //req1.replaceable = false;
                //string rawreqjson = JsonConvert.SerializeObject(req1);

                //string rawresp = Call_Service_Post(rawreqjson, "http://localhost:53722/FloAPI.svc/createrawtransaction","text/plain");

                //JObject objraw1 = JObject.Parse(rpc.CreateRawTransaction(req1));

                //string rawHex1 = "";

                //if (string.IsNullOrEmpty(objraw1["error"].ToString()))
                //{
                //    Console.WriteLine("Raw Transaction : " + objraw1["result"]);
                //    rawHex1 = objraw1["result"].ToString();
                //}
                //else
                //{
                //    Console.WriteLine("Raw Transaction Error : " + objraw1["error"]);
                //}

                //string responsepriv = Call_Service_Get("http://localhost:53722/FloAPI.svc/dumpprivkey/" + fromaddr);
                //JObject objpriv = JObject.Parse(responsepriv);
                //string privkey1 = objpriv["result"].ToString();
                //List<string> privkeys1 = new List<string>();
                //privkeys1.Add(privkey1);


                //SignRawTransactionRequest signreq1 = new SignRawTransactionRequest();
                //signreq1.Inputs = inputs1;
                //signreq1.PrivateKeys = privkeys1;
                //signreq1.RawTransactionHex = rawHex1;
                //signreq1.SigHashType = "ALL";

                //string signjson = JsonConvert.SerializeObject(signreq1);

                //string signresp = Call_Service_Post(signjson,"http://localhost:53722/FloAPI.svc/signrawtransaction","application/json");
                //JObject objsign1 = JObject.Parse(signresp);
                //string signHex1 = "";

                //if (string.IsNullOrEmpty(objsign1["error"].ToString()))
                //{
                //    Console.WriteLine("Sign Raw Transaction : " + objsign1["result"]);
                //    signHex1 = objsign1["result"]["hex"].ToString();
                //}
                //else
                //{
                //    Console.WriteLine("Sign Raw Transaction Error : " + objsign1["error"]);
                //}

                //SendRawTransactionRequest sendreq = new SendRawTransactionRequest();
                //sendreq.signedHex = signHex1;
                //string sendreq1 = JsonConvert.SerializeObject(sendreq);

                //string sendresp1 = Call_Service_Post(sendreq1,"http://localhost:53722/FloAPI.svc/sendrawtransaction","application/json");
                //JObject objsend1 = JObject.Parse(sendresp1);

                //string txid = "";

                //if (string.IsNullOrEmpty(objsend1["error"].ToString()))
                //{
                //    Console.WriteLine("Sign Raw Transaction : " + objsend1["result"]);
                //    txid = objsend1["result"].ToString();
                //}
                //else
                //{
                //    Console.WriteLine("Sign Raw Transaction Error : " + objsend1["error"]);
                //}



                JArray jarrlu = new JArray();
                jarrlu.Add("");
                //jarrlu.Add("oHQMHm1eFz3PLgTPWPcYYDNvrB4G241Atd");
                //List Unspent
                JObject objlu = JObject.Parse(rpc.ListUnspent(jarrlu));

                if (string.IsNullOrEmpty(objlu["error"].ToString()))
                {
                    Console.WriteLine("Get Info : " + objlu["result"]);
                }
                else
                {
                    Console.WriteLine("Get Info Error : " + objlu["error"]);
                }

                CreateRawTransactionRequest req   = new CreateRawTransactionRequest();
                CreateRawTransactionInput   input = new CreateRawTransactionInput();
                input.txid         = "5b30f0bf684b90ccc2a3f8cef896b0ed155c9b785fbaf9fca1c1272dc40af4bd";
                input.vout         = 0;
                input.scriptPubKey = "76a914ac73b43a12d4ef3a2e71384ae3e35460cf4e91df88ac";
                List <CreateRawTransactionInput> inputs = new List <CreateRawTransactionInput>();
                inputs.Add(input);

                Dictionary <string, decimal> output = new Dictionary <string, decimal>();
                output.Add("oJsvAWvNWZ1jk3fV1BpaWHR3wPrYVaVxwZ", 1.0m);
                output.Add("oYbD4joh3G6d3k3wKbFtBQfgq9BPFxzWPn", 181.4795m);

                req.Inputs      = inputs;
                req.Outputs     = output;
                req.floData     = "Test Raw Transaction";
                req.locktime    = 0;
                req.replaceable = false;
                JObject objraw = JObject.Parse(rpc.CreateRawTransaction(req));

                string rawHex = "";

                if (string.IsNullOrEmpty(objraw["error"].ToString()))
                {
                    Console.WriteLine("Raw Transaction : " + objraw["result"]);
                    rawHex = objraw["result"].ToString();
                }
                else
                {
                    Console.WriteLine("Raw Transaction Error : " + objraw["error"]);
                }

                string        privkey  = "cTd24uWL7Sb6KsJXZzwBQR3mkyg2baEzHJNEhkgBmXPpFxy1Ypf9";
                List <string> privkeys = new List <string>();
                privkeys.Add(privkey);

                SignRawTransactionRequest signreq = new SignRawTransactionRequest();
                signreq.Inputs            = inputs;
                signreq.PrivateKeys       = privkeys;
                signreq.RawTransactionHex = rawHex;
                signreq.SigHashType       = "ALL";

                JObject objsign = JObject.Parse(rpc.SignRawTransaction(signreq));

                string signHex = "";

                if (string.IsNullOrEmpty(objsign["error"].ToString()))
                {
                    Console.WriteLine("Sign Raw Transaction : " + objsign["result"]);
                    signHex = objsign["result"]["hex"].ToString();
                }
                else
                {
                    Console.WriteLine("Sign Raw Transaction Error : " + objsign["error"]);
                }

                JObject objsend = JObject.Parse(rpc.SendRawTransaction(signHex));
                string  txid1   = "";

                if (string.IsNullOrEmpty(objsend["error"].ToString()))
                {
                    Console.WriteLine("Sign Raw Transaction : " + objsend["result"]);
                    txid1 = objsend["result"].ToString();
                }
                else
                {
                    Console.WriteLine("Sign Raw Transaction Error : " + objsend["error"]);
                }



                //Get Info
                JObject obj = JObject.Parse(rpc.GetInfo());

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Get Info : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Get Info Error : " + obj["error"]);
                }

                obj = JObject.Parse(rpc.Preciousblock("31300e805d4f949e455f20f045162290c920b76e14ec6e614c2c8d5bd4fe119e"));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Get Memory Info : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Get Memory Info Error : " + obj["error"]);
                }

                //Get Help

                obj = JObject.Parse(rpc.Help("getinfo"));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Get Help : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Get Help Error : " + obj["error"]);
                }

                //Get Balance

                obj = JObject.Parse(rpc.GetBalance(""));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Balance : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Get Balance Error : " + obj["error"]);
                }

                //Get Wallet Info
                obj = JObject.Parse(rpc.GetWalletInfo());

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Wallet Info : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Wallet Info Error : " + obj["error"]);
                }

                //Test

                var jsonObject = new JObject();
                jsonObject.Add("oQDkguVz7CW2eEYCWD2G636tWCg23YcnRx", 1.2);
                jsonObject.Add("oXRrzwxUMcpxHCQWP4T1MQAocudWDzL1UJ", 0.2);

                var job1 = new JObject();
                var job2 = new JObject();
                job1.Add("txid", "b1aa06d72323ae923784d80ebb890c286d963d37901d73806fa2a4fff91865f3");
                job1.Add("vout", 1);
                job2.Add("txid", "b1aa06d72323ae923784d80ebb890c286d963d37901d73806fa2a4fff91865f4");
                job2.Add("vout", 2);

                //create raw transaction
                var jarr = new JArray();
                jarr.Add(job1);
                jarr.Add(job2);

                //obj = JObject.Parse(rpc.CreateRawTransaction(jarr, jsonObject));

                //if (string.IsNullOrEmpty(obj["error"].ToString()))
                //{
                //    Console.WriteLine("Create Raw Transaction : " + obj["result"]);
                //}
                //else
                //{
                //    Console.WriteLine("Error : " + obj["error"]);
                //}

                //decode raw transaction
                obj = JObject.Parse(rpc.DecodeRawTransaction("0200000002f36518f9ffa4a26f80731d90373d966d280c89bb0ed8843792ae2323d706aab10100000000fffffffff46518f9ffa4a26f80731d90373d966d280c89bb0ed8843792ae2323d706aab10200000000ffffffff02000e2707000000001976a91450a3f1d1f0d046af51cc150a6d4c33b37b7daf3988ac002d3101000000001976a9149fb715b93dac58ff46cdafd43c34762109ca604388ac0000000000"));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Decode Raw Transaction : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Error : " + obj["error"]);
                }

                //create multi sig
                jarr = new JArray();
                jarr.Add("oYbD4joh3G6d3k3wKbFtBQfgq9BPFxzWPn");
                jarr.Add("oJsvAWvNWZ1jk3fV1BpaWHR3wPrYVaVxwZ");

                obj = JObject.Parse(rpc.AddMultisigAddress(2, jarr));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Add Multisig : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Error : " + obj["error"]);
                }



                //obj = JObject.Parse(rpc.SendMany("AbhijeetTest", jsonObject));

                //if (string.IsNullOrEmpty(obj["error"].ToString()))
                //{
                //    Console.WriteLine("Send To Many : " + obj["result"]);
                //}
                //else
                //{
                //    Console.WriteLine("Error : " + obj["error"]);
                //}


                //Get Wallet Info
                obj = JObject.Parse(rpc.SubmitBlock("123456ffggg"));

                if (string.IsNullOrEmpty(obj["error"].ToString()))
                {
                    Console.WriteLine("Wallet Info : " + obj["result"]);
                }
                else
                {
                    Console.WriteLine("Wallet Info Error : " + obj["error"]);
                }
            }
            catch (RpcInternalServerErrorException exception)
            {
                var errorCode    = 0;
                var errorMessage = string.Empty;

                if (exception.RpcErrorCode.GetHashCode() != 0)
                {
                    errorCode    = exception.RpcErrorCode.GetHashCode();
                    errorMessage = exception.RpcErrorCode.ToString();
                }

                Console.WriteLine("[Failed] {0} {1} {2}", exception.Message, errorCode != 0 ? "Error code: " + errorCode : string.Empty, !string.IsNullOrWhiteSpace(errorMessage) ? errorMessage : string.Empty);
            }
            catch (Exception exception)
            {
                Console.WriteLine("[Failed]\n\nPlease check your configuration and make sure that the daemon is up and running and that it is synchronized. \n\nException: " + exception);
            }

            Console.Read();
        }
 public Task <string> CreateRawTransactionAsync(CreateRawTransactionRequest rawTransaction, CancellationToken cancellationToken)
 {
     return(_asyncRpcConnector.MakeRequestAsync <string>(RpcMethods.createrawtransaction, cancellationToken, rawTransaction.Inputs, rawTransaction.Outputs));
 }
Example #24
0
 public async Task <string> CreateRawTransactionAsync(CreateRawTransactionRequest rawTransaction)
 {
     return(await _rpcConnector.MakeRequest <string>(RpcMethods.createrawtransaction, rawTransaction.Inputs, rawTransaction.Outputs));
 }