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); }
public bool CheckBreezeRegistration(BreezeConfiguration config, DBUtils db) { var network = Network.StratisMain; if (config.IsTestNet) { // TODO: Change to StratisTest when it is added to NStratis network = Network.TestNet; } // In order to determine if the registration sequence has been performed // before, and to see if a previous performance is still valid, interrogate // the database to see if any transactions have been recorded. var transactions = db.GetDictionary <string, string>("RegistrationTransactions"); // If no transactions exist, the registration definitely needs to be done if (transactions == null || transactions.Count == 0) { return(false); } string highestKey = null; foreach (var txn in transactions) { // Find most recent transaction. Assume that the rowKeys are ordered // lexicographically. if (highestKey == null) { highestKey = txn.Key; } if (String.Compare(txn.Key, highestKey) == 1) { highestKey = txn.Key; } } var mostRecentTxn = new Transaction(transactions[highestKey]); // Decode transaction and check if the decoded bitstream matches the // current configuration // TODO: Check if transaction is actually confirmed on the blockchain? var registrationToken = new RegistrationToken(); registrationToken.ParseTransaction(mostRecentTxn, network); if (!config.Ipv4Address.Equals(registrationToken.Ipv4Addr)) { return(false); } if (!config.Ipv6Address.Equals(registrationToken.Ipv6Addr)) { return(false); } if (config.OnionAddress != registrationToken.OnionAddress) { return(false); } if (config.Port != registrationToken.Port) { return(false); } return(true); }
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); }