Ejemplo n.º 1
0
 public WhatIsAddress(BitcoinAddress address)
     : base(address)
 {
     IsP2SH         = address is BitcoinScriptAddress;
     ScriptPubKey   = new WhatIsScript(address.ScriptPubKey, address.Network);
     Hash           = GetHash(address);
     ColoredAddress = address.ToColoredAddress().ToString();
 }
Ejemplo n.º 2
0
 public WhatIsAddress(BitcoinAddress address)
     : base(address)
 {
     IsP2SH         = address is BitcoinScriptAddress;
     ScriptPubKey   = new WhatIsScript(address.ScriptPubKey, address.Network);
     Hash           = new uint160(address.Hash.ToBytes(true), false);
     ColoredAddress = address.ToColoredAddress().ToString();
 }
            private static XlsxTransactionInputOutput Create(BitcoinAddress address,
                                                             ICoin source,
                                                             BlockInformation block,
                                                             uint256 transactionHash,
                                                             IDictionary <string, IAssetDefinition> assetDictionary,
                                                             int index,
                                                             Network network,
                                                             CoinType coinType)
            {
                string coloredAddress = null;

                try
                {
                    coloredAddress = address?.ToColoredAddress()?.ToWif();
                }
                catch
                {
                }
                var result = new XlsxTransactionInputOutput
                {
                    Address         = address?.ToString(),
                    ColoredAddress  = coloredAddress,
                    TransactionHash = transactionHash.ToString(),
                    Index           = index,
                    CoinType        = coinType,
                };

                if (block != null)
                {
                    result.BlockDate = block.BlockTime.UtcDateTime;
                    result.BlockHash = block.BlockId.ToString();
                }
                if (source is ColoredCoin colored)
                {
                    var assetId = colored.AssetId.GetWif(network).ToString();

                    var asset        = assetDictionary.ContainsKey(assetId) ? assetDictionary[assetId] : null;
                    var divisibility = asset?.Divisibility ?? 0;

                    result.ColouredAssetValue = BitcoinUtils.CalculateColoredAssetQuantity(colored.Amount.Quantity, divisibility);
                    result.BtcValue           = BitcoinUtils.SatoshiToBtc(colored.Bearer.Amount.Satoshi);

                    result.ColouredAssetName = asset != null ? asset.Name : assetId;
                }

                if (source is Coin uncolored)
                {
                    result.BtcValue = BitcoinUtils.SatoshiToBtc(uncolored.Amount.Satoshi);
                }

                return(result);
            }
 private void UpdateQrCore()
 {
     if (_Address == null)
     {
         _QrCode = null;
         OnPropertyChanged(() => this.QrCode);
     }
     else
     {
         _QrCode = IsColored ? Address.ToColoredAddress().ToString() : Address.ToString();
         OnPropertyChanged(() => this.QrCode);
     }
 }
Ejemplo n.º 5
0
        public void CanParseColoredAddress()
        {
            var address = new BitcoinAddress("16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM");
            var colored = address.ToColoredAddress();

            Assert.Equal("akB4NBW9UuCmHuepksob6yfZs6naHtRCPNy", colored.ToWif());
            Assert.Equal(address.ScriptPubKey, colored.ScriptPubKey);

            var testAddress = address.ToNetwork(Network.TestNet);
            var testColored = testAddress.ToColoredAddress();

            Assert.Equal(Network.TestNet, testAddress.Network);
            Assert.Equal(address.Hash, testAddress.Hash);

            Assert.Equal(colored.ToNetwork(Network.TestNet), testColored);

            Assert.Equal(testAddress.ScriptPubKey, testColored.ScriptPubKey);

            Assert.Equal(Network.TestNet, testColored.Network);
            testColored = new BitcoinColoredAddress("bWqaKUZETiECYgmJNbNZUoanBxnAzoVjCNx");
            Assert.Equal(Network.TestNet, testColored.Network);
            Assert.Equal(colored.ToNetwork(Network.TestNet), testColored);
        }
Ejemplo n.º 6
0
        // Colored Coinの発行
        public static void createIssuanceCoin(String TxId)
        {
            // UTXOから、ColoredCoin発行に消費するcoinを作成
            // ここで設定したScriptPubKeyが、ColoredCoinの所有者となる
            BitcoinAddress myAddress = BitcoinAddress.Create(mMyBitcoinAddress, Network.TestNet);
            var            coin      = new Coin(
                fromTxHash: new uint256(mUtXo),
                fromOutputIndex: mUtXoIndex,
                amount: Money.Coins(mUtXoCoin),
                scriptPubKey: myAddress.ScriptPubKey);
            var issuance = new IssuanceCoin(coin);

            // Broadcastするトランザクションの作成
            // Assetのquantitis(量)は'10'。
            TransactionBuilder builder = new TransactionBuilder();
            var mykey = new BitcoinSecret(mMyWif);
            var tx    = builder
                        .AddKeys(mykey)
                        .AddCoins(issuance)
                        .IssueAsset(myAddress, new AssetMoney(issuance.AssetId, 10))
                        .SendFees(Money.Coins(0.0004m))
                        .SetChange(mykey.GetAddress())
                        .BuildTransaction(true);

            // 作成したトランザクションのVerify
            Console.WriteLine(builder.Verify(tx));

            // トランザクションのHexデータ(Broadcast用)
            Console.WriteLine("ToHex:{0}", tx.ToHex());

            // 発行したColoredCoinの確認用アドレス、AssetID
            Console.WriteLine("ColoredAddress:{0}", myAddress.ToColoredAddress());
            var assetId = new AssetId(myAddress).GetWif(Network.TestNet);

            Console.WriteLine("AssetID:{0}", assetId);
        }
Ejemplo n.º 7
0
        public static void Execute()
        {
            // use the following coin for issuing assets.

            /*
             * {
             *  "transactionId": "a416cc07134b6049aebfc36712fe3385b57325ae8c0dc1218adc2bda839ae319",
             *  "index": 0,
             *  "value": 2000000,
             *  "scriptPubKey": "OP_DUP OP_HASH160 761165aeb773479007b4bad25dc594980b0deb68 OP_EQUALVERIFY OP_CHECKSIG",
             *  "redeemScript": null
             * }
             */
            Keys    keys         = JsonConvert.DeserializeObject <Keys>(File.ReadAllText(@"Keys.json"));
            Network btcTestNet   = Network.TestNet;
            string  txnId        = "a416cc07134b6049aebfc36712fe3385b57325ae8c0dc1218adc2bda839ae319";
            string  scriptPubKey = "OP_DUP OP_HASH160 761165aeb773479007b4bad25dc594980b0deb68 OP_EQUALVERIFY OP_CHECKSIG";

            string         aliceAddressHex  = keys.alice.Address;
            string         bobPrivateKeyHex = keys.bob.PrivateKey;
            BitcoinAddress aliceAddress     = BitcoinAddress.Create(aliceAddressHex, btcTestNet);
            BitcoinSecret  bobPrivateKey    = new BitcoinSecret(bobPrivateKeyHex);

            Coin coin = new Coin(fromTxHash: new uint256(txnId),
                                 fromOutputIndex: 0,
                                 amount: Money.Satoshis(490000),
                                 scriptPubKey: new Script(scriptPubKey));
            IssuanceCoin issuance = new IssuanceCoin(coin);

            // build transaction and sign the transaction using TransactionBuilder
            TransactionBuilder builder = new TransactionBuilder();
            Transaction        tx      = builder.AddKeys(bobPrivateKey)
                                         .AddCoins(issuance)
                                         .IssueAsset(aliceAddress, new AssetMoney(issuance.AssetId, quantity: 10))
                                         .SendFees(Money.Coins(0.0001m))
                                         .SetChange(bobPrivateKey.GetAddress())
                                         .BuildTransaction(sign: true);

            // After transaction verifications it is ready to be sent to the network.
            Console.WriteLine(tx);
            Console.WriteLine("Verify Txn: " + builder.Verify(tx));

            /*
             * // With QBitNinja
             * var client = new QBitNinjaClient(btcNetwork);
             * BroadcastResponse broadcastResponse = client.Broadcast(tx).Result;
             *
             * if (!broadcastResponse.Success)
             * {
             *  Console.WriteLine("ErrorCode: " + broadcastResponse.Error.ErrorCode);
             *  Console.WriteLine("Error message: " + broadcastResponse.Error.Reason);
             * }
             * else
             * {
             *  Console.WriteLine("Txn Broadcast Success!");
             * }
             *
             * // Or with local Bitcoin core
             * using (var node = Node.ConnectToLocal(Network.Main)) //Connect to the node
             * {
             *  node.VersionHandshake(); //Say hello
             *  //Advertize your transaction (send just the hash)
             *  node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));
             *  //Send it
             *  node.SendMessage(new TxPayload(tx));
             *  Thread.Sleep(500); //Wait a bit
             * }
             */

            // preventing a user from sending Colored Coin to a wallet that do not support it,
            // Open Asset have its own address format, that only colored coin wallets understand
            Console.WriteLine("receiverAddress: " + aliceAddress);
            Console.WriteLine("ColoredCoinAddress: " + aliceAddress.ToColoredAddress());

            // Asset ID is derived from the issuer’s ScriptPubKey, here is how to get it in code
            var assetId = (new AssetId(aliceAddress)).GetWif(btcTestNet);

            Console.WriteLine("assetId: " + assetId); // oNRXXFo48zQ5AMtTMuW5Ss1NtMoSe39Cek
        }
Ejemplo n.º 8
0
		public void CanParseColoredAddress()
		{
			var address = new BitcoinAddress("16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM");
			var colored = address.ToColoredAddress();
			Assert.Equal("akB4NBW9UuCmHuepksob6yfZs6naHtRCPNy", colored.ToWif());
			Assert.Equal(address.ScriptPubKey, colored.ScriptPubKey);

			var testAddress = address.ToNetwork(Network.TestNet);
			var testColored = testAddress.ToColoredAddress();

			Assert.Equal(Network.TestNet, testAddress.Network);
			Assert.Equal(address.Hash, testAddress.Hash);

			Assert.Equal(colored.ToNetwork(Network.TestNet), testColored);

			Assert.Equal(testAddress.ScriptPubKey, testColored.ScriptPubKey);

			Assert.Equal(Network.TestNet, testColored.Network);
			testColored = new BitcoinColoredAddress("bWqaKUZETiECYgmJNbNZUoanBxnAzoVjCNx");
			Assert.Equal(Network.TestNet, testColored.Network);
			Assert.Equal(colored.ToNetwork(Network.TestNet), testColored);
		}