static void Main(string[] args) { BitcoinSecret secret = new BitcoinSecret("cTfANynUR2MCPC8uBpfo2yUfAzX5PucDNuXaJ8jXT8CpQDgvfUNr", Network); BitcoinAddress address = new BitcoinAddress("n2upyU7axtvHHhAPTMvdaRSkP5Mjufoffx", Network); BlockrTransactionRepository blockr = new BlockrTransactionRepository(Network); List<Coin> unspentCoins = blockr.GetUnspentAsync(secret.GetAddress().ToString(), true).Result; TransactionBuilder builder = new TransactionBuilder(); builder.AddKeys(secret); builder.AddCoins(unspentCoins); builder.Send(address, Money.Coins(0.005m)); builder.SendFees(Money.Coins(0.00001m)); builder.SetChange(secret.ScriptPubKey); Transaction tx = builder.BuildTransaction(true); if (builder.Verify(tx)) SendTransaction(tx); }
static void Main(string[] args) { BitcoinSecret paymentSecret = new BitcoinSecret("L51eDMcsRUFSReQpz587UgcBSXGgskc6ssUGibXXHcYK6aMsAVzr"); BitcoinAddress address = paymentSecret.GetAddress(); Console.WriteLine("Address: {0}", address); var blockr = new BlockrTransactionRepository(); Transaction fundingTransaction = blockr.Get("2ab7d787b02ebd40f5de87aa27569b118ff1cc801088fbf7bab3eec304011878"); Pay(paymentSecret, new BitcoinAddress("1KF8kUVHK42XzgcmJF4Lxz4wcL5WDL97PB"), Money.Coins(0.004m), fundingTransaction); //Select the chapter here: //var chapter = new Chapter2(); ////call the lesson here //chapter.Lesson1(); //hold open the output window Console.WriteLine("\n\n\nPress enter to continue"); Console.ReadLine(); }
static void Main(string[] args) { var goldGuy = new BitcoinSecret("KyuzoVnpsqW529yzozkzP629wUDBsPmm4QEkh9iKnvw3Dy5JJiNg"); var silverGuy = new BitcoinSecret("L4KvjpqDtdGEn7Lw6HdDQjbg74MwWRrFZMQTgJozeHAKJw5rQ2Kn"); var firstPerson = new BitcoinSecret("5Jnw9Td7PaG6PWBrU7ZCfxyVXsHSsNxdZ9sg5dnZstcr12DLVbJ"); var secondPerson = new BitcoinSecret("5Jn4zJkzS2BWNu7AMRTdSJ6mS7JYfJg27oXKAichaRBbp97ZKks"); var exchangeEntity = new BitcoinSecret("5KA7FeABKmMKerWmkJzYM9FdoqScZEMVcS9u6wvT3EhgF5ZUWv5"); var bitcoinProviderEntity = new BitcoinSecret("5Jcz2A17aAt4bcQP5GEn6itt72JsLwrksNRVKqazy7n284b1bKj"); var issuanceCoinsTransaction = new Transaction() { Outputs = { new TxOut("1.0", goldGuy.PubKey), new TxOut("1.0", silverGuy.PubKey), new TxOut("1.0", firstPerson.PubKey), new TxOut("1.0", secondPerson.PubKey), } }; IssuanceCoin[] issuanceCoins = issuanceCoinsTransaction .Outputs .Take(2) .Select((o, i) => new Coin(new OutPoint(issuanceCoinsTransaction.GetHash(), i), o)) .Select(c => new IssuanceCoin(c)) .ToArray(); var goldIssuanceCoin = issuanceCoins[0]; var silverIssuanceCoin = issuanceCoins[1]; var firstPersonInitialCoin = new Coin(new OutPoint(issuanceCoinsTransaction, 2), issuanceCoinsTransaction.Outputs[2]); var secondPersonInitialCoin = new Coin(new OutPoint(issuanceCoinsTransaction, 3), issuanceCoinsTransaction.Outputs[3]); var goldId = goldIssuanceCoin.AssetId; var silverId = silverIssuanceCoin.AssetId; var txRepo = new NoSqlTransactionRepository(); txRepo.Put(issuanceCoinsTransaction.GetHash(), issuanceCoinsTransaction); var ctxRepo = new NoSqlColoredTransactionRepository(txRepo); TransactionBuilder txBuilder = new TransactionBuilder(); // Issuing gold to first person // This happens in gold issuer client Transaction tx = txBuilder .AddKeys(goldGuy.PrivateKey) .AddCoins(goldIssuanceCoin) .IssueAsset(firstPerson.GetAddress(), new AssetMoney(goldId, 20)) .SetChange(goldGuy.GetAddress()) .BuildTransaction(true); txRepo.Put(tx.GetHash(), tx); var ctx = tx.GetColoredTransaction(ctxRepo); var coloredCoins = ColoredCoin.Find(tx, ctx).ToArray(); ColoredCoin firstPersonGoldCoin = coloredCoins[0]; // Issuing silver to second person // This happens in silver issuer client txBuilder = new TransactionBuilder(); tx = txBuilder .AddKeys(silverGuy.PrivateKey) .AddCoins(silverIssuanceCoin) .IssueAsset(secondPerson.GetAddress(), new AssetMoney(silverId, 30)) .SetChange(silverGuy.GetAddress()) .BuildTransaction(true); txRepo.Put(tx.GetHash(), tx); ctx = tx.GetColoredTransaction(ctxRepo); coloredCoins = ColoredCoin.Find(tx, ctx).ToArray(); ColoredCoin secondPersonSilverCoin = coloredCoins[0]; // Sending first person gold to exchange // This happens in first user client var bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo); txBuilder = new TransactionBuilder(); tx = txBuilder .AddCoins(bitcoinProviderCoin) .AddKeys(bitcoinProviderEntity.PrivateKey) .AddCoins(firstPersonGoldCoin) .AddKeys(firstPerson.PrivateKey) .SendAssetToExchange(exchangeEntity.GetAddress(), new AssetMoney(goldId, 5)) .SetChange(firstPerson.PubKey) .BuildTransaction(true); txRepo.Put(tx.GetHash(), tx); ctx = tx.GetColoredTransaction(ctxRepo); coloredCoins = ColoredCoin.Find(tx, ctx).ToArray(); ColoredCoin firstPersonColoredCoinInExchange = coloredCoins[1]; // Creating the time-locked transaction which the first user can post to the // network to claim his/her coin from exchange (it works if the exchange does not touch the coins // This happens in exchange and the transaction is delivered to first user client bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo); txBuilder = new TransactionBuilder(); tx = txBuilder .AddCoins(bitcoinProviderCoin) .AddKeys(bitcoinProviderEntity.PrivateKey) .AddCoins(firstPersonColoredCoinInExchange) .AddKeys(firstPerson.PrivateKey) .SendAsset(firstPerson.PubKey, new AssetMoney(firstPersonColoredCoinInExchange.Amount.Id, firstPersonColoredCoinInExchange.Amount.Quantity)) .SetChange(exchangeEntity.PubKey) .SetLockTime(new LockTime(1000000)) .BuildTransaction(true); string reclaimTransactionForFirstUser = tx.ToHex(); // Create first person exchange request // This happens in first person client JObject firstPersonRequestToExchange = CreateExchangeRequest("ExactMatch", goldId.ToString(), silverId.ToString(), 5, 2); var firstRequestSignature = firstPerson.PrivateKey.SignMessage(firstPersonRequestToExchange.ToString(Formatting.None)); // Sending second person silver to exchange // This happens in second person client bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo); txBuilder = new TransactionBuilder(); tx = txBuilder .AddCoins(bitcoinProviderCoin) .AddKeys(bitcoinProviderEntity.PrivateKey) .AddCoins(secondPersonSilverCoin) .AddKeys(secondPerson.PrivateKey) .SendAssetToExchange(exchangeEntity.GetAddress(), new AssetMoney(silverId, 12)) .SetChange(secondPerson.PubKey) .BuildTransaction(true); txRepo.Put(tx.GetHash(), tx); ctx = tx.GetColoredTransaction(ctxRepo); coloredCoins = ColoredCoin.Find(tx, ctx).ToArray(); ColoredCoin secondPersonColoredCoinInExchange = coloredCoins[1]; // Create second person exchange request // This happens in second person client JObject secondPersonRequestToExchange = CreateExchangeRequest("ExactMatch", silverId.ToString(), goldId.ToString(), 30, 0.5f); var secondRequestSignature = secondPerson.PrivateKey.SignMessage(secondPersonRequestToExchange.ToString(Formatting.None)); // Creating exchange reason // This happens in exchange var exchangeReason = CreateExchangeMatch(firstPersonRequestToExchange, firstRequestSignature, secondPersonRequestToExchange, secondRequestSignature, exchangeEntity.PrivateKey); // Performing the exchange operation // This happens in exchange bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo); txBuilder = new TransactionBuilder(); tx = txBuilder .AddCoins(bitcoinProviderCoin) .AddKeys(bitcoinProviderEntity.PrivateKey) .AddCoins(firstPersonColoredCoinInExchange) .AddKeys(exchangeEntity.PrivateKey) .AddCoins(secondPersonColoredCoinInExchange) .AddKeys(exchangeEntity.PrivateKey) .PerformExchangeOperation(firstPerson.GetAddress(), new AssetMoney(silverId, 10), secondPerson.GetAddress(), new AssetMoney(goldId, 5), exchangeReason.ToString(Formatting.None)) .SetChange(exchangeEntity.GetAddress()) .BuildTransaction(true); txRepo.Put(tx.GetHash(), tx); ctx = tx.GetColoredTransaction(ctxRepo); coloredCoins = ColoredCoin.Find(tx, ctx).ToArray(); txRepo.Put(tx.GetHash(), tx); }
static void Main(string[] args) { const String BobAddress = "mxSimcis5yCPkBaFZ7ZrJ7fsPqLXatxTax"; const String BobAssetAddress = "bX8Qc1nYCZT65cRjcbjg2wyaSjSWhY2gB5p"; const String AliceAddress = "muJjaSHk99LGMnaFduU9b3pWHdT1ZRPASF"; const String AliceAssetAddress = "bX5Gcpc75cdDxE2jcgXaLEuj5dEdBUdnpDu"; BitcoinSecret alice = new BitcoinSecret(AliceWIFKey); BitcoinSecret bob = new BitcoinSecret(BobWIFKey); BitcoinSecret carol = new BitcoinSecret(CarolWIFKey); Console.WriteLine(carol.GetAddress().ToColoredAddress().ToString()); //Check Debug.Assert(BobAddress == bob.GetAddress().ToString()); Debug.Assert(AliceAddress == alice.GetAddress().ToString()); Debug.Assert(BobAssetAddress == bob.GetAddress().ToColoredAddress().ToString()); Debug.Assert(AliceAssetAddress == alice.GetAddress().ToColoredAddress().ToString()); const String SILVER = "oLcV5F6R59zbChoTBQ962Har24tAnhbtHo"; const String GOLD = "oWoYDF1Fxc7pSSoo97MMeH5NAmpqZhq5Ys"; const String USD = "oSANrbK92PePSWkmjP7FtVqLtHWPwFTKWc"; const String AUD = "oM4tzMCMyxQ5zgtb3QtPkFaoBtQKBG2WdP"; //SIMPLE TRANSFERS //String result = Transfer(BobAddress, 4, AliceAddress, GOLD); //confirmed //String result = Transfer(AliceAddress, 10000, BobAddress, AUD); //confirmed //String result = Transfer(BobAddress, 1000, AliceAddress, USD); //confirmed //String result = Transfer(BobAddress, 15000, AliceAddress, USD); //confirmed //String result = Transfer(BobAddress, 100, AliceAddress, USD); //SENT //String result = Transfer(AliceAddress, 100, BobAddress, USD); //SENT //String result = Transfer(BobAddress, 100, AliceAddress, AUD); //SENT //new address //String result = Transfer(BobAddress, 100, carol.GetAddress().ToString(), SILVER); //CONFIRMED //String result = Transfer(BobAddress, 50000, carol.GetAddress().ToString(), USD); //CONFIRMED String result = Trade(BobAddress, 1, GOLD, carol.GetAddress().ToString(), 5000, USD); //BitcoinAssetId silverAsset = new BitcoinAssetId(SILVER, Network.TestNet); //BitcoinAssetId usdAsset = new BitcoinAssetId(SILVER, Network.TestNet); Console.WriteLine(result); Console.ReadLine(); }