コード例 #1
0
        public Transaction PerformBreezeRegistration(BreezeConfiguration config, DBUtils db)
        {
            var network = Network.StratisMain;

            if (config.IsTestNet)
            {
                // TODO: Change to StratisTest when support is added to NStratis
                network = Network.TestNet;
            }

            RPCHelper     stratisHelper   = null;
            RPCClient     stratisRpc      = null;
            BitcoinSecret privateKeyEcdsa = null;

            try {
                stratisHelper   = new RPCHelper(network);
                stratisRpc      = stratisHelper.GetClient(config.RpcUser, config.RpcPassword, config.RpcUrl);
                privateKeyEcdsa = stratisRpc.DumpPrivKey(BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
            }
            catch (Exception e) {
                Console.WriteLine("ERROR: Unable to retrieve private key to fund registration transaction");
                Console.WriteLine("Is the wallet unlocked?");
                Console.WriteLine(e);
                Environment.Exit(0);
            }

            // Retrieve tumbler's parameters so that the registration details can be constructed
            //var tumblerApi = new TumblerApiAccess(config.TumblerApiBaseUrl);
            //string json = tumblerApi.GetParameters().Result;
            //var tumblerParameters = JsonConvert.DeserializeObject<TumblerParameters>(json);
            var registrationToken = new RegistrationToken(255, config.Ipv4Address, config.Ipv6Address, config.OnionAddress, config.Port, config.TumblerRsaKeyPath);
            var msgBytes          = registrationToken.GetRegistrationTokenBytes(privateKeyEcdsa);

            // Create the registration transaction using the bytes generated above
            var rawTx = CreateBreezeRegistrationTx(network, msgBytes, config.TxOutputValueSetting);

            var txUtils = new TransactionUtils();

            try {
                // Replace fundrawtransaction with C# implementation. The legacy wallet
                // software does not support the RPC call.
                var fundedTx = txUtils.FundRawTx(stratisRpc, rawTx, config.TxFeeValueSetting, BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
                var signedTx = stratisRpc.SendCommand("signrawtransaction", fundedTx.ToHex());
                var txToSend = new Transaction(((JObject)signedTx.Result)["hex"].Value <string>());

                db.UpdateOrInsert <string>("RegistrationTransactions", DateTime.Now.ToString("yyyyMMddHHmmss"), txToSend.ToHex(), (o, n) => n);
                stratisRpc.SendRawTransaction(txToSend);

                return(txToSend);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Unable to broadcast registration transaction");
                Console.WriteLine(e);
            }

            return(null);
        }
コード例 #2
0
        public Transaction PerformBreezeRegistration(BreezeConfiguration config, string regStorePath, string configurationHash, string onionAddress, RsaKey tumblerKey)
        {
            Network network = Network.ImpleumMain;

            if (config.TumblerNetwork == Network.TestNet || config.TumblerNetwork == Network.RegTest)
            {
                network = Network.ImpleumTest;
            }

            RPCHelper     stratisHelper   = null;
            RPCClient     stratisRpc      = null;
            BitcoinSecret privateKeyEcdsa = null;

            try {
                stratisHelper   = new RPCHelper(network);
                stratisRpc      = stratisHelper.GetClient(config.RpcUser, config.RpcPassword, config.RpcUrl);
                privateKeyEcdsa = stratisRpc.DumpPrivKey(BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
            }
            catch (Exception e) {
                Console.WriteLine("ERROR: Unable to retrieve private key to fund registration transaction");
                Console.WriteLine("Is the Stratis wallet unlocked & RPC enabled?");
                Console.WriteLine(e);
                Environment.Exit(0);
            }

            RegistrationToken registrationToken = new RegistrationToken(PROTOCOL_VERSION_TO_USE, config.TumblerEcdsaKeyAddress, config.Ipv4Address, config.Ipv6Address, onionAddress, configurationHash, config.Port, privateKeyEcdsa.PubKey);

            byte[] msgBytes = registrationToken.GetRegistrationTokenBytes(tumblerKey, privateKeyEcdsa);

            // Create the registration transaction using the bytes generated above
            Transaction rawTx = CreateBreezeRegistrationTx(network, msgBytes, config.TxOutputValueSetting);

            TransactionUtils  txUtils  = new TransactionUtils();
            RegistrationStore regStore = new RegistrationStore(regStorePath);

            try {
                // Replace fundrawtransaction with C# implementation. The legacy wallet
                // software does not support the RPC call.
                Transaction fundedTx = txUtils.FundRawTx(stratisRpc, rawTx, config.TxFeeValueSetting, BitcoinAddress.Create(config.TumblerEcdsaKeyAddress));
                RPCResponse signedTx = stratisRpc.SendCommand("signrawtransaction", fundedTx.ToHex());
                Transaction txToSend = new Transaction(((JObject)signedTx.Result)["hex"].Value <string>());

                RegistrationRecord regRecord = new RegistrationRecord(DateTime.Now,
                                                                      Guid.NewGuid(),
                                                                      txToSend.GetHash().ToString(),
                                                                      txToSend.ToHex(),
                                                                      registrationToken,
                                                                      null);

                regStore.Add(regRecord);

                stratisRpc.SendRawTransaction(txToSend);

                return(txToSend);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Unable to broadcast registration transaction");
                Console.WriteLine(e);
            }

            return(null);
        }