public Balance GetBalance() { Balance res = new Balance(); ulong available = Quantum.Sum(GetUnspents()); ulong locked = Quantum.Sum(GetLocked()); res.Available = (decimal)(available / Config.DecimalPoint); res.Locked = (decimal)(locked / Config.DecimalPoint); return(res); }
public Transaction Transfer(string recipientAddress, decimal amount) { List <Quantum> validInputs = new List <Quantum>(); var inputs = Database.GetInputs(); var output = new Quantum(amount); ulong sum = 0; bool valid; foreach (var input in inputs) { valid = true; foreach (var tx in TXPool) { if (tx.Value.Inputs.AsQueryable <Quantum>().Contains <Quantum>(input, new QuantumComparer())) { valid = false; break; } } if (valid) { validInputs.Add(input); sum = Quantum.Sum(validInputs); if (sum >= output.Amount) { break; } } } if (sum < output.Amount) { throw new Exception(Resources.ExceptionNotEnoughFunds); } Transaction transaction = new Transaction(Wallet.PublicKey, recipientAddress, validInputs, output); transaction.Sign(Wallet.PrivateKey); //txPool.Add(transaction.Hash, transaction); Broadcast(transaction); Process(transaction); return(transaction); }
public Transaction(byte[] publicKey, string recipient, List <Quantum> inputs, Quantum output) { Key = publicKey.ToHex(); Recipient = recipient; Inputs = inputs; Output = output; ulong sum = Quantum.Sum(inputs); if (sum != output.Amount) { Change = new Quantum(sum - output.Amount); } Hash = Crypto.CalculateHash(ExtractData()); }