Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            SignatureContext context;
            JObject          json1 = JObject.Parse(textBox2.Text);

            if (json1.ContainsProperty("hex"))
            {
                context = SignatureContext.FromJson(json1);
            }
            else
            {
                ContractTransaction tx1 = JsonToRequest(json1);
                ContractTransaction tx2 = JsonToRequest(JObject.Parse(textBox3.Text));
                context = new SignatureContext(new ContractTransaction
                {
                    Attributes = new TransactionAttribute[0],
                    Inputs     = tx1.Inputs.Concat(tx2.Inputs).ToArray(),
                    Outputs    = tx1.Outputs.Concat(tx2.Outputs).ToArray()
                });
            }
            Program.CurrentWallet.Sign(context);
            if (context.Completed)
            {
                context.Signable.Scripts = context.GetScripts();
                ContractTransaction tx = (ContractTransaction)context.Signable;
                Program.CurrentWallet.SendTransaction(tx);
                Program.LocalNode.Relay(tx);
                InformationBox.Show(tx.Hash.ToString(), "交易已发送,这是交易编号(TXID):", "交易成功");
            }
            else
            {
                InformationBox.Show(context.ToString(), "交易构造完成,请将以下信息发送给对方进行签名:", "签名不完整");
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Block block = new Block
            {
                PrevBlock    = UInt256.Zero,
                Timestamp    = DateTime.Now.ToTimestamp(),
                Height       = 0,
                Nonce        = 2083236893, //向比特币致敬
                NextMiner    = Contract.CreateMultiSigContract(Blockchain.GetMinSignatureCount(Blockchain.StandbyMiners.Length), Blockchain.StandbyMiners).ScriptHash,
                Transactions = new Transaction[]
                {
                    new GenerationTransaction
                    {
                        Nonce   = 0,
                        Inputs  = new TransactionInput[0],
                        Outputs = new TransactionOutput[0],
                        Scripts = { }
                    },
                    textBox3.Text.HexToBytes().AsSerializable <RegisterTransaction>()
                }
            };

            block.RebuildMerkleRoot();
            SignatureContext context = new SignatureContext(block.Header);

            InformationBox.Show(context.ToString(), "创世区块头签名上下文");
        }
Esempio n. 3
0
        public static void SignAndShowInformation(Transaction tx)
        {
            if (tx == null)
            {
                MessageBox.Show("余额不足以支付系统费用。");
                return;
            }
            SignatureContext context;

            try
            {
                context = new SignatureContext(tx);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("钱包余额不足,或区块链未同步完成,无法发送该交易。");
                return;
            }
            Program.CurrentWallet.Sign(context);
            if (context.Completed)
            {
                context.Signable.Scripts = context.GetScripts();
                Program.LocalNode.Relay(tx);
                InformationBox.Show(tx.Hash.ToString(), "交易已发送,这是交易编号(TXID):", "交易成功");
            }
            else
            {
                InformationBox.Show(context.ToString(), "交易构造完成,但没有足够的签名:", "签名不完整");
            }
        }
Esempio n. 4
0
        private void button7_Click(object sender, EventArgs e)
        {
            SignatureContext context = SignatureContext.Parse(textBox8.Text);

            context.Signable.Scripts = context.GetScripts();
            InformationBox.Show(context.Signable.ToArray().ToHexString(), "原始数据:");
        }
Esempio n. 5
0
        private void button4_Click(object sender, EventArgs e)
        {
            context.Signable.Scripts = context.GetScripts();
            IInventory inventory = (IInventory)context.Signable;

            Program.LocalNode.Relay(inventory);
            InformationBox.Show(inventory.Hash.ToString(), Strings.RelaySuccessText, Strings.RelaySuccessTitle);
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            ContractTransaction tx = Program.CurrentWallet.MakeTransaction(new ContractTransaction {
                Outputs = txOutListBox1.Items.Select(p => p.Output).ToArray()
            }, Fixed8.Zero);

            textBox3.Text = RequestToJson(tx).ToString();
            InformationBox.Show(textBox3.Text, "交易请求已生成,请发送给对方,或与对方的请求合并:", "交易请求");
            tabControl1.SelectedTab = tabPage2;
        }
Esempio n. 7
0
        private async void button8_Click(object sender, EventArgs e)
        {
            SignatureContext context = SignatureContext.Parse(textBox8.Text);

            context.Signable.Scripts = context.GetScripts();
            Inventory inventory = (Inventory)context.Signable;
            await Program.LocalNode.RelayAsync(inventory);

            InformationBox.Show(inventory.Hash.ToString(), "数据广播成功,这是广播数据的散列值:", "广播成功");
        }
Esempio n. 8
0
 public static DialogResult Show(string text, string title = null)
 {
     using (InformationBox box = new InformationBox())
     {
         box.textBox1.Text = text;
         if (title != null)
         {
             box.Text = title;
         }
         return(box.ShowDialog());
     }
 }
Esempio n. 9
0
 public static DialogResult Show(string text, string title = null)
 {
     using (InformationBox box = new InformationBox())
     {
         box.textBox1.Text = text;
         if (title != null)
         {
             box.Text = title;
         }
         return box.ShowDialog();
     }
 }
Esempio n. 10
0
 public static void ShowInformation(SignatureContext context)
 {
     if (context.Completed)
     {
         context.Signable.Scripts = context.GetScripts();
         Transaction tx = (Transaction)context.Signable;
         Program.LocalNode.Relay(tx);
         InformationBox.Show(tx.Hash.ToString(), "交易已发送,这是交易编号(TXID):", "交易成功");
     }
     else
     {
         InformationBox.Show(context.ToString(), "交易构造完成,但没有足够的签名:", "签名不完整");
     }
 }
Esempio n. 11
0
        private void button3_Click(object sender, EventArgs e)
        {
            const uint BitCoinNonce = 2083236893; //向比特币致敬
            Block      block        = new Block
            {
                PrevBlock = UInt256.Zero,
                Timestamp = DateTime.Now.ToTimestamp(),
                Height    = 0,
                Nonce     = BitCoinNonce,
                NextMiner = Blockchain.GetMinerAddress(Blockchain.StandbyMiners),
                Script    = new Script
                {
                    StackScript  = new byte[0],
                    RedeemScript = new byte[0]
                },
                Transactions = new Transaction[]
                {
                    new MinerTransaction
                    {
                        Nonce      = BitCoinNonce,
                        Attributes = new TransactionAttribute[0],
                        Inputs     = new TransactionInput[0],
                        Outputs    = new TransactionOutput[0],
                        Scripts    = new Script[0]
                    },
                    textBox3.Text.HexToBytes().AsSerializable <RegisterTransaction>(),
                    new RegisterTransaction
                    {
                        AssetType = AssetType.AntCoin,
#if TESTNET
                        Name = "[{'lang':'zh-CN','name':'小蚁币(测试)'},{'lang':'en','name':'AntCoin(TestNet)'}]",
#else
                        Name = "[{'lang':'zh-CN','name':'小蚁币'},{'lang':'en','name':'AntCoin'}]",
#endif
                        Amount     = Fixed8.FromDecimal(Blockchain.MintingAmount.Sum(p => p * Blockchain.DecrementInterval)),
                        Issuer     = ECCurve.Secp256r1.Infinity,
                        Admin      = new UInt160(),
                        Attributes = new TransactionAttribute[0],
                        Inputs     = new TransactionInput[0],
                        Outputs    = new TransactionOutput[0],
                        Scripts    = new Script[0]
                    },
                    textBox5.Text.HexToBytes().AsSerializable <IssueTransaction>()
                }
            };

            block.RebuildMerkleRoot();
            InformationBox.Show(block.ToArray().ToHexString(), "创世区块:");
        }
Esempio n. 12
0
        private async Task ShowInformationAsync(SignatureContext context)
        {
            if (context.Completed)
            {
                context.Signable.Scripts = context.GetScripts();
                Transaction tx = (Transaction)context.Signable;
                await Program.LocalNode.RelayAsync(tx);

                InformationBox.Show(tx.Hash.ToString(), "交易已发送,这是交易编号(TXID):", "交易成功");
            }
            else
            {
                InformationBox.Show(context.ToString(), "交易构造完成,但没有足够的签名:", "签名不完整");
            }
        }
Esempio n. 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            RegisterTransaction antshare = new RegisterTransaction
            {
                AssetType = AssetType.AntShare,
                Name      = "[{'lang':'zh-CN','name':'小蚁股'},{'lang':'en','name':'AntShare'}]",
                Amount    = Fixed8.FromDecimal(numericUpDown1.Value),
                Issuer    = Wallet.ToScriptHash(textBox1.Text),
                Admin     = Wallet.ToScriptHash(textBox2.Text),
                Inputs    = new TransactionInput[0],
                Outputs   = new TransactionOutput[0]
            };
            SignatureContext context = new SignatureContext(antshare);

            InformationBox.Show(context.ToString(), "小蚁股签名上下文");
        }
Esempio n. 14
0
        private void button3_Click(object sender, EventArgs e)
        {
            Block block = textBox4.Text.HexToBytes().AsSerializable <Block>();

            block.Transactions = new Transaction[]
            {
                new GenerationTransaction
                {
                    Nonce   = 0,
                    Inputs  = new TransactionInput[0],
                    Outputs = new TransactionOutput[0],
                    Scripts = { }
                },
                textBox3.Text.HexToBytes().AsSerializable <RegisterTransaction>()
            };
            Debug.Assert(MerkleTree.ComputeRoot(block.Transactions.Select(p => p.Hash).ToArray()) == block.MerkleRoot);
            InformationBox.Show(block.ToArray().ToHexString(), "创世区块");
        }
Esempio n. 15
0
        private void button2_Click(object sender, EventArgs e)
        {
            RegisterTransaction antshare = textBox3.Text.HexToBytes().AsSerializable <RegisterTransaction>();

            using (IssueDialog dialog = new IssueDialog(antshare))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                IssueTransaction tx = dialog.GetTransaction();
                if (tx.Outputs.Sum(p => p.Value) != antshare.Amount)
                {
                    MessageBox.Show("发行量不等于总量!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                SignatureContext context = new SignatureContext(tx);
                InformationBox.Show(context.ToString(), "小蚁股发行签名上下文:");
            }
        }
Esempio n. 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            RegisterTransaction antshare = new RegisterTransaction
            {
                AssetType = AssetType.AntShare,
#if TESTNET
                Name = "[{'lang':'zh-CN','name':'小蚁股(测试)'},{'lang':'en','name':'AntShare(TestNet)'}]",
#else
                Name = "[{'lang':'zh-CN','name':'小蚁股'},{'lang':'en','name':'AntShare'}]",
#endif
                Amount     = Fixed8.FromDecimal(numericUpDown1.Value),
                Issuer     = ECPoint.Parse(textBox1.Text, ECCurve.Secp256r1),
                Admin      = Wallet.ToScriptHash(textBox2.Text),
                Attributes = new TransactionAttribute[0],
                Inputs     = new TransactionInput[0],
                Outputs    = new TransactionOutput[0]
            };
            SignatureContext context = new SignatureContext(antshare);

            InformationBox.Show(context.ToString(), "小蚁股签名上下文:");
        }
Esempio n. 17
0
        public static void SignAndShowInformation(Transaction tx)
        {
            if (tx == null)
            {
                MessageBox.Show(Strings.InsufficientFunds);
                return;
            }
            if (tx.Attributes.All(p => p.Usage != TransactionAttributeUsage.Vote) && tx.Outputs.Any(p => p.AssetId.Equals(Blockchain.AntShare.Hash)) && Settings.Default.Votes.Count > 0)
            {
                tx.Attributes = tx.Attributes.Concat(Settings.Default.Votes.OfType <string>().Select(p => new TransactionAttribute
                {
                    Usage = TransactionAttributeUsage.Vote,
                    Data  = UInt256.Parse(p).ToArray()
                })).ToArray();
            }
            SignatureContext context;

            try
            {
                context = new SignatureContext(tx);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show(Strings.UnsynchronizedBlock);
                return;
            }
            Program.CurrentWallet.Sign(context);
            if (context.Completed)
            {
                context.Signable.Scripts = context.GetScripts();
                Program.CurrentWallet.SaveTransaction(tx);
                Program.LocalNode.Relay(tx);
                InformationBox.Show(tx.Hash.ToString(), Strings.SendTxSucceedMessage, Strings.SendTxSucceedTitle);
            }
            else
            {
                InformationBox.Show(context.ToString(), Strings.IncompletedSignatureMessage, Strings.IncompletedSignatureTitle);
            }
        }
Esempio n. 18
0
 private void button2_Click(object sender, EventArgs e)
 {
     InformationBox.Show(context.ToString(), "SignatureContext", "SignatureContext");
 }