示例#1
0
        /// <summary>
        /// 1. Reward transaction has only one TxOutput which has the miners address
        /// 2. The TxInput is signed by the instance of the blockchain wallet
        /// </summary>
        /// <param name="minerWallet"></param>
        /// <param name="blockchainWallet"></param>
        /// <returns></returns>
        public (bool, string) CreateRewardTransaction(Wallet minerWallet)
        {
            Wallet blockchainWallet = Wallet.GetBlockchainWallet();

            TxOutput minerTxOutput = new TxOutput()
            {
                Address = minerWallet.PublicKey.Key,
                Amount  = Block.MINER_REWARD
            };

            TxOutputs.Add(minerTxOutput);

            SignTransaction(blockchainWallet);
            return(true, "Reward Transaction Created Successfully");
        }
示例#2
0
        /// <summary>
        /// Update current transaction by adding a new transaction output and modifying
        /// the senders changeback output
        /// </summary>
        /// <param name="senderWallet"></param>
        /// <param name="recipientAddress"></param>
        /// <param name="amountToSend"></param>
        public (bool, string) UpdateTransaction(Wallet senderWallet, string recipientAddress, decimal amountToSend)
        {
            //get the current senders change back address and modify the amount to get back

            TxOutput changeBack = TxOutputs.Find(p => p.Address == senderWallet.PublicKey.Key);

            if (amountToSend > changeBack.Amount)
            {
                return(false, $"Amount {amountToSend} exceeds balance");
            }
            TxOutputs.Where(p => p.Address == senderWallet.PublicKey.Key).FirstOrDefault().Amount = changeBack.Amount - amountToSend;
            TxOutput newRecipientOutput = new TxOutput()
            {
                Address = recipientAddress,
                Amount  = amountToSend
            };

            TxOutputs.Add(newRecipientOutput);
            SignTransaction(senderWallet);
            return(true, "Transaction Updated Successfully");
        }
示例#3
0
        public (bool, string) CreateTransaction(Wallet senderWallet, string recipientAddress, decimal amount)
        {
            if (amount > senderWallet.Balance)
            {
                return(false, $"Amount {amount} exceeds balance");
            }

            TxOutput senderChangeBack = new TxOutput()
            {
                Address = senderWallet.PublicKey.Key,
                Amount  = senderWallet.Balance - amount
            };
            TxOutput recipientOutput = new TxOutput()
            {
                Address = recipientAddress,
                Amount  = amount
            };

            TxOutputs.Add(senderChangeBack);
            TxOutputs.Add(recipientOutput);

            SignTransaction(senderWallet);
            return(true, "Transaction Created Successfully");
        }