public void IsSpentConfirmedHavingBlockHeightReturnsTrue() { var spendingDetails = new SpendingDetails { BlockHeight = 15 }; Assert.True(spendingDetails.IsSpentConfirmed()); }
public void IsConfirmedHavingNoBlockHeightReturnsFalse() { var spendingDetails = new SpendingDetails { BlockHeight = null }; Assert.False(spendingDetails.IsSpentConfirmed()); }
public static SpendingDetails CreateSpendingDetails(TransactionData changeTransaction, PaymentDetails paymentDetails) { var spendingDetails = new SpendingDetails { TransactionId = changeTransaction.Id, CreationTime = new DateTimeOffset(new DateTime(2017, 6, 23, 1, 2, 3)), BlockHeight = changeTransaction.BlockHeight }; spendingDetails.Payments.Add(paymentDetails); return(spendingDetails); }
public static SpendingDetails CreateSpendingDetails(TransactionData changeTransaction, PaymentDetails paymentDetails) { var spendingDetails = new SpendingDetails { TransactionId = changeTransaction.Id, CreationTime = new DateTimeOffset(new DateTime(2017, 6, 23, 1, 2, 3)), BlockHeight = changeTransaction.BlockHeight }; spendingDetails.Payments.Add(paymentDetails); spendingDetails.Change.Add(new PaymentDetails() { Amount = changeTransaction.Amount, DestinationAddress = paymentDetails.DestinationAddress, DestinationScriptPubKey = paymentDetails.DestinationScriptPubKey, OutputIndex = paymentDetails.OutputIndex }); return(spendingDetails); }
/// <summary> /// Calculates the fee paid by the user on a transaction sent. /// </summary> /// <param name="transactionId">The transaction id to look for.</param> /// <returns>The fee paid.</returns> public Money GetSentTransactionFee(uint256 transactionId) { List <TransactionOutputData> allTransactions = this.GetAllTransactions(Wallet.NormalAccounts).ToList(); // Get a list of all the inputs spent in this transaction. List <TransactionOutputData> inputsSpentInTransaction = allTransactions.Where(t => t.SpendingDetails?.TransactionId == transactionId).ToList(); if (!inputsSpentInTransaction.Any()) { throw new WalletException("Not a sent transaction"); } // Get the details of the spending transaction, which can be found on any input spent. SpendingDetails spendingTransaction = inputsSpentInTransaction.Select(s => s.SpendingDetails).First(); // The change is the output paid into one of our addresses. We make sure to exclude the output received to one of // our addresses if this transaction is self-sent. IEnumerable <TransactionOutputData> changeOutput = allTransactions.Where(t => t.Id == transactionId && spendingTransaction.Payments.All(p => p.OutputIndex != t.Index)).ToList(); Money inputsAmount = new Money(inputsSpentInTransaction.Sum(i => i.Amount)); Money outputsAmount = new Money(spendingTransaction.Payments.Sum(p => p.Amount) + changeOutput.Sum(c => c.Amount)); return(inputsAmount - outputsAmount); }
public static TransactionData CreateTransaction(uint256 id, Money amount, int?blockHeight, SpendingDetails spendingDetails = null, DateTimeOffset?creationTime = null, Script script = null) { if (creationTime == null) { creationTime = new DateTimeOffset(new DateTime(2017, 6, 23, 1, 2, 3)); } return(new TransactionData { Amount = amount, Id = id, CreationTime = creationTime.Value, BlockHeight = blockHeight, SpendingDetails = spendingDetails, ScriptPubKey = script }); }
public static TransactionOutputData CreateTransaction(uint256 id, Money amount, int?blockHeight, SpendingDetails spendingDetails = null, DateTimeOffset?creationTime = null, Script script = null, string address = null, int accountIndex = 0) { if (creationTime == null) { creationTime = new DateTimeOffset(new DateTime(2017, 6, 23, 1, 2, 3)); } return(new TransactionOutputData { OutPoint = new OutPoint(id, blockHeight ?? 1), Address = address ?? script?.ToHex(), Amount = amount, AccountIndex = accountIndex, Id = id, CreationTime = creationTime.Value, BlockHeight = blockHeight, SpendingDetails = spendingDetails, ScriptPubKey = script }); }
public void TransactionsByDepositDictCantContainNullWithdrawals() { var multiSigTransactions = new MultiSigTransactions(); // Add the transaction to the collection. var spendingDetails1 = new SpendingDetails() { WithdrawalDetails = new WithdrawalDetails() { Amount = Money.Zero, MatchingDepositId = 2 } }; var spendingDetails2 = new SpendingDetails() { WithdrawalDetails = new WithdrawalDetails() { Amount = Money.Zero, MatchingDepositId = 2 } }; TransactionData txData1Fact() => new TransactionData() { Amount = Money.Zero, Id = 1, Index = 0, SpendingDetails = spendingDetails1 }; TransactionData txData2Fact() => new TransactionData() { Amount = Money.Zero, Id = 2, Index = 0, SpendingDetails = spendingDetails2 }; TransactionData txData1 = txData1Fact(); TransactionData txData2 = txData2Fact(); multiSigTransactions.Add(txData1); multiSigTransactions.Add(txData2); // Retrieve the transaction. List <TransactionData> txDataMatch = multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList; Assert.Contains(txDataMatch, txDataMatch => txData1.Id == txDataMatch.Id && txData1.Index == txDataMatch.Index); Assert.Contains(txDataMatch, txDataMatch => txData2.Id == txDataMatch.Id && txData2.Index == txDataMatch.Index); multiSigTransactions.Remove(txData1Fact()); multiSigTransactions.Remove(txData2Fact()); multiSigTransactions.Add(txData1); multiSigTransactions.Add(txData2); // Replace the SpendingDetails with one containing WithdrawalDetails set to null. var spendingDetails3 = new SpendingDetails() { WithdrawalDetails = null }; var spendingDetails4 = new SpendingDetails() { WithdrawalDetails = null }; // Remove and restore one. txData2.SpendingDetails = spendingDetails4; Assert.Single(multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList); txData2.SpendingDetails = spendingDetails2; // Retrieve the transaction again. List <TransactionData> txDataMatch2 = multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList; Assert.Contains(txDataMatch2, txDataMatch => txData1.Id == txDataMatch.Id && txData1.Index == txDataMatch.Index); Assert.Contains(txDataMatch2, txDataMatch => txData2.Id == txDataMatch.Id && txData2.Index == txDataMatch.Index); // Remove and restore one. txData1.SpendingDetails = spendingDetails3; Assert.Single(multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList); txData1.SpendingDetails = spendingDetails1; // Retrieve the transaction again. List <TransactionData> txDataMatch3 = multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList; Assert.Contains(txDataMatch3, txDataMatch => txData1.Id == txDataMatch.Id && txData1.Index == txDataMatch.Index); Assert.Contains(txDataMatch3, txDataMatch => txData2.Id == txDataMatch.Id && txData2.Index == txDataMatch.Index); // Remove and restore both. txData1.SpendingDetails = spendingDetails3; txData2.SpendingDetails = spendingDetails4; Assert.Empty(multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList); txData1.SpendingDetails = spendingDetails1; txData2.SpendingDetails = spendingDetails2; // Retrieve the transaction again. List <TransactionData> txDataMatch4 = multiSigTransactions.GetSpendingTransactionsByDepositId(2).Single().txList; Assert.Contains(txDataMatch4, txDataMatch => txData1.Id == txDataMatch.Id && txData1.Index == txDataMatch.Index); Assert.Contains(txDataMatch4, txDataMatch => txData2.Id == txDataMatch.Id && txData2.Index == txDataMatch.Index); }