Exemplo n.º 1
0
        public static (bool suc, string hash) PushTx2Bc(string netStr, Transaction tx, bool useTor = false)
        {
            try
            {
                string req = "";


                if (useTor)
                {
                    req = Tech.webreqTor($"https://api.blockcypher.com/v1/btc/{netStr}/txs/push", "POST", JsonConvert.SerializeObject(new { tx = tx.ToHex() }));
                }
                else
                {
                    req = Tech.webreq($"https://api.blockcypher.com/v1/btc/{netStr}/txs/push", "POST", JsonConvert.SerializeObject(new { tx = tx.ToHex() }));
                }

                var parse = JsonConvert.DeserializeObject <BCtcPushResult>(req);

                return(true, parse.tx.hash);
            }
            catch (Exception e)
            {
                return(false, "");
            }
        }
Exemplo n.º 2
0
        //public static string IssuanceCoin()
        //{
        //    var net = Network.TestNet;

        //    var coin = new Coin(
        //        fromTxHash: new uint256("35d08a7ffa218b78dec3038eb51fe6108dedca5bf011a7e152dd9e124924470c"),
        //        fromOutputIndex: 0,
        //        amount: 9990000,
        //        scriptPubKey: new Script(Encoders.Hex.DecodeData("a914b6fe120e0a50a9cb3ad5a7ccf8be8cac9b9bbad887")));

        //    var issuance = new IssuanceCoin(coin);


        //    var nico = BitcoinAddress.Create("2MvF83UXQRq783WFBd6kSjFBJznji6urGMS", net);
        //    var bookKey = new BitcoinSecret("cQR1X2ooR8MhjTxPYEzid6h3dUjXgbh38DR916JtfTn3ZaxCJoqJ");
        //    var builder = net.CreateTransactionBuilder();

        //    var tx = builder
        //        .AddKeys(bookKey)
        //        .AddCoins(issuance)
        //        .IssueAsset(nico, new AssetMoney(issuance.AssetId, 21000000m, 8))
        //        .SendFees(Money.Coins(0.0005m))
        //        .SetChange(bookKey.GetAddress(ScriptPubKeyType.Legacy))
        //        .BuildTransaction(true);

        //    Console.WriteLine(tx);
        //    Console.WriteLine(nico.ToColoredAddress());
        //    Console.WriteLine(builder.Verify(tx));


        //    var assetId = new AssetId(bookKey).GetWif(net);
        //    Console.WriteLine(assetId); // AVAVfLSb1KZf9tJzrUVpktjxKUXGxUTD4e

        //    var ttt = PushTx2Bc("test3", tx);


        //    return ttt.hash;
        //}

        public static decimal GetBallance(string addr, string net = "test3")
        {
            var url = $"https://api.blockcypher.com/v1/btc/{net}/addrs/{addr}/balance";
            var b   = Tech.webreq(url);

            if (b == null)
            {
                return(-1);
            }
            try
            {
                var req = JsonConvert.DeserializeObject <req2>(b);
                return(req.final_balance / 100000000);
            }
            catch (Exception e)
            {
                return(-2);
            }
        }
Exemplo n.º 3
0
        static txref[] UnspenttxBc(string addr, string net = "test3")
        {
            var url = $"https://api.blockcypher.com/v1/btc/{net}/addrs/{addr}?unspentOnly=true&includeScript=true";
            var req = Tech.webreq(url);

            if (req == null)
            {
                return(null);
            }

            try
            {
                var res = JsonConvert.DeserializeObject <txxx>(req).txrefs.ToArray();
                return(res);
            }
            catch (Exception e)
            {
                throw new Exception("UnspenttxBc JsonConvert.DeserializeObject<txxx> error, maybe there are unconfirmed transactions, wait until they are confirmed");
            }
        }