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(), "创世区块:");
        }
Example #2
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(), "交易构造完成,但没有足够的签名:", "签名不完整");
            }
        }
Example #3
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(), "小蚁股签名上下文");
        }
Example #4
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(), "创世区块");
        }
        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(), "小蚁股发行签名上下文:");
            }
        }
Example #6
0
        public static void SignAndShowInformation(Transaction tx)
        {
            if (tx == null)
            {
                MessageBox.Show("余额不足以支付系统费用。");
                return;
            }
            SignatureContext context = new SignatureContext(tx);

            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(), "交易构造完成,但没有足够的签名:", "签名不完整");
            }
        }
Example #7
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(), "小蚁股签名上下文:");
        }
Example #8
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);
            }
        }
Example #9
0
 private void button2_Click(object sender, EventArgs e)
 {
     InformationBox.Show(context.ToString(), "SignatureContext", "SignatureContext");
 }