Exemplo n.º 1
0
 private void SignPayload(ConsensusPayload payload, KeyPair kp)
 {
     ContractParametersContext sc;
     try
     {
         sc = new ContractParametersContext(payload);
         byte[] signature = sc.Verifiable.Sign(kp);
         sc.AddSignature(Contract.CreateSignatureContract(kp.PublicKey), kp.PublicKey, signature);
     }
     catch (InvalidOperationException)
     {
         return;
     }
     payload.Witness = sc.GetWitnesses()[0];
 }
        private void button4_Click(object sender, EventArgs e)
        {
            context.Verifiable.Witnesses = context.GetWitnesses();
            IInventory        inventory = (IInventory)context.Verifiable;
            RelayResultReason reason    = Program.NeoSystem.Blockchain.Ask <RelayResultReason>(inventory).Result;

            if (reason == RelayResultReason.Succeed)
            {
                InformationBox.Show(inventory.Hash.ToString(), Strings.RelaySuccessText, Strings.RelaySuccessTitle);
            }
            else
            {
                MessageBox.Show($"Transaction cannot be broadcast: {reason}");
            }
        }
        private void SignPayload(ExtensiblePayload payload)
        {
            ContractParametersContext sc;

            try
            {
                sc = new ContractParametersContext(neoSystem.StoreView, payload, dbftSettings.Network);
                wallet.Sign(sc);
            }
            catch (InvalidOperationException exception)
            {
                Utility.Log(nameof(ConsensusContext), LogLevel.Debug, exception.ToString());
                return;
            }
            payload.Witness = sc.GetWitnesses()[0];
        }
Exemplo n.º 4
0
        private void button4_Click(object sender, EventArgs e)
        {
            ContractParametersContext context = ContractParametersContext.Parse(textBox2.Text);

            if (!(context.Verifiable is Transaction tx))
            {
                MessageBox.Show("Only support to broadcast transaction.");
                return;
            }
            tx.Witnesses = context.GetWitnesses();
            Program.OXSystem.LocalNode.Tell(new LocalNode.Relay {
                Inventory = tx
            });
            InformationBox.Show(tx.Hash.ToString(), LanHelper.LocalLanguage("Data broadcast success, the hash is shown as follows:"), LanHelper.LocalLanguage("Broadcast Success"));
            button4.Visible = false;
        }
Exemplo n.º 5
0
        public async Task <UInt256> ExecuteAsync(Wallet wallet, UInt160 accountHash, WitnessScope witnessScope, Neo.VM.Script script, decimal additionalGas = 0)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(OfflineNode));
            }

            var signer = new Signer()
            {
                Account = accountHash, Scopes = witnessScope
            };
            var tx = wallet.MakeTransaction(neoSystem.StoreView, script, accountHash, new[] { signer });

            if (additionalGas > 0.0m)
            {
                tx.SystemFee += (long)additionalGas.ToBigInteger(NativeContract.GAS.Decimals);
            }

            var context = new ContractParametersContext(neoSystem.StoreView, tx, ProtocolSettings.Network);
            var account = wallet.GetAccount(accountHash) ?? throw new Exception();

            if (account.IsMultiSigContract())
            {
                var multiSigWallets = chain.GetMultiSigWallets(neoSystem.Settings, accountHash);
                for (int i = 0; i < multiSigWallets.Count; i++)
                {
                    multiSigWallets[i].Sign(context);
                    if (context.Completed)
                    {
                        break;
                    }
                }
            }
            else
            {
                wallet.Sign(context);
            }

            if (!context.Completed)
            {
                throw new Exception();
            }

            tx.Witnesses = context.GetWitnesses();
            return(await SubmitTransactionAsync(tx).ConfigureAwait(false));
        }
Exemplo n.º 6
0
        public static Block CreateSignedBlock(Header prevHeader, IReadOnlyList <KeyPair> keyPairs, uint network, Transaction[]?transactions = null, ulong timestamp = 0)
        {
            transactions ??= Array.Empty <Transaction>();

            var blockHeight = prevHeader.Index + 1;
            var block       = new Block
            {
                Header = new Header
                {
                    Version    = 0,
                    PrevHash   = prevHeader.Hash,
                    MerkleRoot = MerkleTree.ComputeRoot(transactions.Select(t => t.Hash).ToArray()),
                    Timestamp  = timestamp > prevHeader.Timestamp
                        ? timestamp
                        : Math.Max(Neo.Helper.ToTimestampMS(DateTime.UtcNow), prevHeader.Timestamp + 1),
                    Index         = blockHeight,
                    PrimaryIndex  = 0,
                    NextConsensus = prevHeader.NextConsensus
                },
                Transactions = transactions
            };

            // generate the block header witness. Logic lifted from ConsensusContext.CreateBlock
            var m              = keyPairs.Count - (keyPairs.Count - 1) / 3;
            var contract       = Contract.CreateMultiSigContract(m, keyPairs.Select(k => k.PublicKey).ToList());
            var signingContext = new ContractParametersContext(null, new BlockScriptHashes(prevHeader.NextConsensus), network);

            for (int i = 0; i < keyPairs.Count; i++)
            {
                var signature = block.Header.Sign(keyPairs[i], network);
                signingContext.AddSignature(contract, keyPairs[i].PublicKey, signature);
                if (signingContext.Completed)
                {
                    break;
                }
            }
            if (!signingContext.Completed)
            {
                throw new Exception("block signing incomplete");
            }
            block.Header.Witness = signingContext.GetWitnesses()[0];

            return(block);
        }