public async Task BroadcastTransactionToBlockchain(string transaction) { var settings = settingsProvider.GetSettings(); var tx = new Transaction(transaction); var rpcClient = Helper.GetRPCClient(settings); await rpcClient.SendRawTransactionAsync(tx); await daemonHelper.GenerateBlocks(1); await blockchainExplorerHelper.WaitUntillBlockchainExplorerHasIndexed(blockchainExplorerHelper.HasTransactionIndexed, new string[] { tx.GetHash().ToString() }, null); }
private static async Task <UnsignedClientCommitmentTransactionResponse> GetOffchainSignedSetup (string[] privateKeys) { var settings = settingsProvider.GetSettings(); var clientPrivateKey = new BitcoinSecret(privateKeys[0]); var hubPrivateKey = new BitcoinSecret(privateKeys[1]); var hubSelfRevokKey = new BitcoinSecret(privateKeys[3]); var multisig = GetMultiSigFromTwoPubKeys(clientPrivateKey.PubKey, hubPrivateKey.PubKey); var coloredRPC = GetColoredRPCClient(settings as IBlockchainStateManagerSettings); BitcoinColoredAddress[] addresses = new BitcoinColoredAddress[3]; addresses[0] = clientPrivateKey.PubKey.WitHash.ScriptPubKey.GetScriptAddress(settings.Network).ToColoredAddress(); // c74X52L89exgnqwrFmeKzZTAxi49sLxqoNS addresses[1] = hubPrivateKey.PubKey.WitHash.ScriptPubKey.GetScriptAddress(settings.Network).ToColoredAddress(); // c7Acx1CTvvwPr9kEa91roJDeNLjB1evkXWG addresses[2] = BitcoinAddress.Create(multisig.SegwitMultiSigAddress).ToColoredAddress(); // c7GuJuSS5aNg9s791bDk6RgSpYCge3kaiHn long[] valuesToSend = new long[3]; valuesToSend[0] = 100 * DESIREDASSETMULTIPLICATIONFACTOR; valuesToSend[1] = 100 * DESIREDASSETMULTIPLICATIONFACTOR; valuesToSend[2] = 85 * DESIREDASSETMULTIPLICATIONFACTOR; uint256[] txIds = new uint256[3]; for (int i = 0; i < 3; i++) { if (ASSET.ToLower().Trim() == "btc") { txIds[i] = await daemonHelper.SendBitcoinToDestination(addresses[i].Address, valuesToSend[i]); } else { txIds[i] = await coloredRPC.IssueAssetAsync(Constants.USDAssetPrivateKey.GetAddress(), addresses[i], valuesToSend[i]); } } var bitcoinRPCCLient = GetRPCClient(settings as IBlockchainStateManagerSettings); var blkIds = await bitcoinRPCCLient.GenerateBlocksAsync(1); await blockchainExplorerHelper.WaitUntillBlockchainExplorerHasIndexed (blockchainExplorerHelper.HasBlockIndexed, blkIds); for (int i = 0; i < txIds.Count(); i++) { await blockchainExplorerHelper.WaitUntillBlockchainExplorerHasIndexed (blockchainExplorerHelper.HasTransactionIndexed, new string[] { txIds[i].ToString() }); await blockchainExplorerHelper.WaitUntillBlockchainExplorerHasIndexed(blockchainExplorerHelper.HasBalanceIndexed, new string[] { txIds[i].ToString() }, addresses[i].Address.ToString()); } var unsignedChannelsetup = await offchainHelper.GenerateUnsignedChannelSetupTransaction (clientPrivateKey.PubKey, 10, hubPrivateKey.PubKey, 10, ASSET, 7); var clientSignedTx = await Helper.SignTransactionWorker(new TransactionSignRequest { TransactionToSign = unsignedChannelsetup.UnsigndTransaction, PrivateKey = clientPrivateKey.ToString() }); var unsignedResp = await offchainHelper.CreateUnsignedClientCommitmentTransaction (unsignedChannelsetup.UnsigndTransaction, clientSignedTx, 30, 75, clientPrivateKey.PubKey, hubPrivateKey.ToString(), ASSET, hubSelfRevokKey.PubKey, 144); return(unsignedResp); }