コード例 #1
0
        public BlockTransaction GenerateNewTransaction(string _sender,
                                                       string _receiver,
                                                       double _amount,
                                                       Int64 _blockHeight,
                                                       BlockChain _chain,
                                                       byte[]      _privateKey,
                                                       byte[]      _publicKey,
                                                       /*From here is optional*/
                                                       string _description)
        {
            //TODO: Validate keys vs public address (_sender)
            if (_amount <= 0)
            {
                Console.WriteLine("Transaction has amount equal or less than 0, not allowed");
                return(null);
            }
            if (_blockHeight == 0)
            {
                Console.WriteLine("Cannot add a transaction to the genesis block");
                return(null);
            }

            if (!KeyManager.ValidateInput(_privateKey, _publicKey, _sender))
            {
                Console.WriteLine("Wrong keys were added for the transaction, transaction not accepted");
                return(null);
            }

            Sender        = _sender;
            Receiver      = _receiver;
            Amount        = _amount;
            Description   = _description;
            blockHeight   = _blockHeight;
            TransactionID = Guid.NewGuid();

            TransactionSigning Signing = new TransactionSigning();

            Signing.SignTransaction(TransactionID, _chain);

            isSigned = true;

            _chain.AddTransactionToChainCue(this);  //new unconfirmed transaction

            return(this);
        }
コード例 #2
0
 public void AddSignedTransactionToChain(TransactionSigning _TransactionSigning)
 {
     //Add signing to chain to counter double spending and stuff like that
     Array.Resize(ref signedTransactions, signedTransactions.Length + 1);
     signedTransactions[signedTransactions.Length - 1] = _TransactionSigning;
 }