Exemplo n.º 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();

            UgoChain.Features.Wallet.TxOutput minerTxOutput = new UgoChain.Features.Wallet.TxOutput()
            {
                Address = minerWallet.PublicKey.Key,
                Amount  = Block.MINER_REWARD
            };
            TxOutputs.Add(minerTxOutput);

            SignTransaction(blockchainWallet);
            return(true, "Reward Transaction Created Successfully");
        }
Exemplo n.º 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

            UgoChain.Features.Wallet.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;
            UgoChain.Features.Wallet.TxOutput newRecipientOutput = new UgoChain.Features.Wallet.TxOutput()
            {
                Address = recipientAddress,
                Amount  = amountToSend
            };
            TxOutputs.Add(newRecipientOutput);
            SignTransaction(senderWallet);
            return(true, "Transaction Updated Successfully");
        }
Exemplo n.º 3
0
        public (bool, string) CreateTransaction(Wallet senderWallet, string recipientAddress, decimal amount)
        {
            if (amount > senderWallet.Balance)
            {
                return(false, $"Amount {amount} exceeds balance");
            }

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

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