예제 #1
0
 public void Lesson1()
 {
     var blockr = new BlockrTransactionRepository();
     Transaction transaction = blockr.Get("d6a57b2ca44327acae03eb408eedab50ea6d4fb304f03aeb5d5251ec37b4baf5");
     // Console.WriteLine(transaction.ToString());
     Console.WriteLine(transaction.Outputs[0].ScriptPubKey.GetDestinationAddress(Network.Main));
 }
예제 #2
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
파일: Program.cs 프로젝트: zilveer/BitPoker
        private static async Task CreateLightningTx()
        {
            //Begin lightning test
            //For testing

            NBitcoin.Transaction aliceFunding = new NBitcoin.Transaction()
            {
                Outputs =
                {
                    new NBitcoin.TxOut("1.0", alice)
                }
            };

            NBitcoin.Coin[] aliceCoinsx = aliceFunding
                                          .Outputs
                                          .Select((o, i) => new NBitcoin.Coin(new NBitcoin.OutPoint(aliceFunding.GetHash(), i), o))
                                          .ToArray();

            //Create 2 of 2
            NBitcoin.Script table = NBitcoin.PayToMultiSigTemplate
                                    .Instance
                                    .GenerateScriptPubKey(2, new[] { alice_secret.PubKey, alice_secret.PubKey });


            Console.WriteLine(table);
            Console.WriteLine(table.Hash.GetAddress(NBitcoin.Network.TestNet));

            NBitcoin.IDestination tableAddress = table.Hash.GetAddress(NBitcoin.Network.TestNet);


            var         blockr  = new NBitcoin.BlockrTransactionRepository(NBitcoin.Network.TestNet);
            Transaction aliceTx = blockr.GetAsync(new NBitcoin.uint256("f5c5e008f0cb9fc52487deb7531a8019e2d78c51c3c40e53a45248e0712102a3")).Result;

            NBitcoin.Transaction bobTx = blockr.GetAsync(new NBitcoin.uint256("c60193a33174a1252df9deb522bac3e5532e0c756d053e4ac9999ca17a79c74e")).Result;

            NBitcoin.Coin[] alicCoins = aliceTx
                                        .Outputs
                                        .Select((o, i) => new NBitcoin.Coin(new NBitcoin.OutPoint(aliceTx.GetHash(), i), o))
                                        .ToArray();

            Coin[] bobCoins = bobTx
                              .Outputs
                              .Select((o, i) => new NBitcoin.Coin(new NBitcoin.OutPoint(bobTx.GetHash(), i), o))
                              .ToArray();

            var txBuilder = new TransactionBuilder();

            var tx_alice = txBuilder
                           .AddKeys(alice_secret.PrivateKey)
                           .AddCoins(alicCoins)
                           .Send(tableAddress, new NBitcoin.Money(5000000))
                           .SetChange(alice)
                           .SendFees(NBitcoin.Money.Coins(0.001m))
                           .BuildTransaction(true);

            //Console.WriteLine(tx_alice.ToHex());

            string signature = alice_secret.PrivateKey.SignMessage("1msPJhg9GPzMN6twknwmSQvrUKZbZnk51Tv398b5fe2-da27-4772-81ce-37fa615719b52CALL 5000000");

            Console.WriteLine(signature);

            Console.ReadKey();

            var tx = txBuilder
                     .AddKeys(bob_secret.PrivateKey)
                     .AddCoins(bobCoins)
                     .Send(tableAddress, new NBitcoin.Money(100000))
                     .SetChange(bob)
                     .SendFees(NBitcoin.Money.Coins(0.001m))
                     .BuildTransaction(true);

            Boolean ok = txBuilder.Verify(tx);

            signature = bob_secret.PrivateKey.SignMessage("CALL 100000");
            Console.WriteLine(signature);

            //BE.Providers.Blockr blockr = new BE.Providers.Blockr(true);
            //return blockr.BroadCastTx(tx.ToHex());

            Console.WriteLine(tx.ToHex());
        }