public HistoryItem(TransactionViewModel txvm, Amount accountDebit, Amount accountCredit, Amount runningBalance) { Transaction = txvm; AccountDebit = accountDebit; AccountCredit = accountCredit; RunningBalance = runningBalance; }
public Output(Amount amount, ushort version, byte[] pkScript) { if (pkScript == null) throw new ArgumentNullException(nameof(pkScript)); Amount = amount; Version = version; PkScript = pkScript; }
public Tuple<long, double> Split(Amount amount) { if (amount < 0) { amount = -amount; } var wholePart = amount / _atomsPerUnit; var decimalPart = (double)(amount % _atomsPerUnit) / _atomsPerUnit; return Tuple.Create(wholePart, decimalPart); }
public Input(OutPoint previousOutPoint, uint sequence, Amount inputAmount, uint blockHeight, uint blockIndex, byte[] signatureScript) { if (signatureScript == null) throw new ArgumentNullException(nameof(signatureScript)); PreviousOutpoint = previousOutPoint; Sequence = sequence; SignatureScript = signatureScript; InputAmount = inputAmount; BlockHeight = blockHeight; BlockIndex = blockIndex; }
/// <summary> /// Check whether an output amount is considered dust for a given transaction relay fee. /// Transactions with dust outputs are rejected by mempool. /// </summary> /// <param name="amount">Output amount</param> /// <param name="scriptSize">Size of the output script in bytes</param> /// <param name="relayFeePerKb">Mempool relay fee/kB</param> /// <returns>Whether the output is dust</returns> public static bool IsDustAmount(Amount amount, int scriptSize, Amount relayFeePerKb) { // Calculate the total (estimated) cost to the network. This is // calculated using the serialize size of the output plus the serial // size of a transaction input which redeems it. The output is assumed // to be compressed P2PKH as this is the most common script type. Use // the average size of a compressed P2PKH redeem input (165) rather than // the largest possible (Transaction.RedeemPayToPubKeyHashInputSize). var totalSize = 8 + 2 + CompactInt.SerializeSize((ulong)scriptSize) + scriptSize + 165; // Dust is defined as an output value where the total cost to the network // (output size + input size) is greater than 1/3 of the relay fee. return amount * 1000 / (3 * totalSize) < relayFeePerKb; }
public string FormatAmount(Amount amount) { // The negative sign has to be printed separately. It can not be displayed as a // negative whole part, since there is no such thing as negative zero for longs. var negativeSign = ""; var negative = amount < 0; if (negative) { amount = -amount; negativeSign = "-"; } var wholePart = amount / _atomsPerUnit; var decimalPart = (double)(amount % _atomsPerUnit) / _atomsPerUnit; return string.Format(_formatString, negativeSign, wholePart, decimalPart); }
/// <summary> /// Perform a preliminary check that the Amount is within the bounds of valid /// transaction output values. Additional checks are required before authoring /// a valid transaction to ensure the total output amount does not exceed the /// total previous output amount referenced by the inputs. /// </summary> public static bool IsSaneOutputValue(Amount a) => a >= 0 && a <= MaxOutputValue;
public static Input AddWitness(Input input, Amount inputAmount, uint blockHeight, uint blockIndex, byte[] signatureScript) => new Input(input.PreviousOutpoint, input.Sequence, inputAmount, blockHeight, blockIndex, signatureScript);
public Output(Amount amount, string destination) { Amount = amount; Destination = destination; }
private void PopulateHistory(Account account) { var synchronizer = ViewModelLocator.SynchronizerViewModel as SynchronizerViewModel; var wallet = synchronizer?.Wallet; if (wallet == null) return; Amount totalDebits = 0; Amount totalCredits = 0; foreach (var histItem in EnumerateAccountTransactions(wallet, account)) { totalDebits += histItem.AccountDebit; totalCredits += histItem.AccountCredit; Application.Current.Dispatcher.Invoke(() => Transactions.Add(histItem)); } DebitSum = totalDebits; CreditSum = totalCredits; }
public async Task<Tuple<List<UnspentOutput>, Amount>> FundTransactionAsync( Account account, Amount targetAmount, int requiredConfirmations) { var client = new WalletService.WalletServiceClient(_channel); var request = new FundTransactionRequest { Account = account.AccountNumber, TargetAmount = targetAmount, RequiredConfirmations = requiredConfirmations, IncludeImmatureCoinbases = false, IncludeChangeScript = false, }; var response = await client.FundTransactionAsync(request, cancellationToken: _tokenSource.Token); var outputs = response.SelectedOutputs.Select(MarshalUnspentOutput).ToList(); var total = (Amount)response.TotalAmount; return Tuple.Create(outputs, total); }
public void AppendNewTransactions(Wallet wallet, List<Tuple<WalletTransaction, BlockIdentity>> txs) { var account = SelectedAccount.Account; var totalDebits = DebitSum; var totalCredits = CreditSum; var runningBalance = totalDebits + totalCredits; foreach (var tx in txs) { var accountTxOption = AccountTransaction.Create(account, tx.Item1); if (accountTxOption == null) continue; var accountTx = accountTxOption.Value; var txvm = new TransactionViewModel(wallet, accountTx.Transaction, tx.Item2); totalDebits += accountTx.Debit; totalCredits += accountTx.Credit; runningBalance += accountTx.DebitCredit; var histItem = new HistoryItem(txvm, accountTx.Debit, accountTx.Credit, runningBalance); App.Current.Dispatcher.Invoke(() => Transactions.Add(histItem)); } DebitSum = totalDebits; CreditSum = totalCredits; }
public double DoubleFromAmount(Amount amount) { return (double)amount / _atomsPerUnit; }
private void SetPendingTransaction(Amount totalAccountBalance, Transaction unsignedTransaction, Amount inputAmount, Amount targetOutput) { var actualFee = TransactionFees.ActualFee(unsignedTransaction, inputAmount); _pendingTransaction = unsignedTransaction; EstimatedFee = actualFee; EstimatedRemainingBalance = totalAccountBalance - targetOutput - actualFee; FinishCreateTransaction.Executable = true; }
// TODO: Figure out what to do with exceptions. another message box? private async Task PopulateHistoryAsync(Account account) { var synchronizer = ViewModelLocator.SynchronizerViewModel as SynchronizerViewModel; var walletMutex = synchronizer?.WalletMutex; if (walletMutex == null) return; using (var walletGuard = await walletMutex.LockAsync()) { Amount totalDebits = 0; Amount totalCredits = 0; foreach (var histItem in EnumerateAccountTransactions(walletGuard.Instance, account)) { totalDebits += histItem.AccountDebit; totalCredits += histItem.AccountCredit; Application.Current.Dispatcher.Invoke(() => Transactions.Add(histItem)); } DebitSum = totalDebits; CreditSum = totalCredits; } }
private void SetPendingTransaction(Transaction unsignedTransaction, Amount inputAmount, Amount targetOutput) { var wallet = App.Current.Synchronizer.Wallet; if (wallet == null) return; var actualFee = TransactionFees.ActualFee(unsignedTransaction, inputAmount); var totalAccountBalance = wallet.LookupAccountProperties(SelectedAccount.Account).TotalBalance; _pendingTransaction = unsignedTransaction; EstimatedFee = actualFee; EstimatedRemainingBalance = totalAccountBalance - targetOutput - actualFee; FinishCreateTransaction.Executable = true; }
public Input(Amount amount, string previousAccount) { Amount = amount; PreviousAccount = previousAccount; }
public async Task<List<Blake256Hash>> PurchaseTicketsAsync(Account account, Amount spendLimit, int reqConfs, Address ticketAddress, uint number, Address poolAddress, double poolFees, uint expiry, Amount txFee, Amount ticketFee, string passphrase) { var ticketAddressStr = ""; if (ticketAddress != null) { ticketAddressStr = ticketAddress.ToString(); } var poolAddressStr = ""; if (poolAddress != null) { poolAddressStr = poolAddress.ToString(); } if (poolAddressStr == "") { poolFees = 0.0; } var client = new WalletService.WalletServiceClient(_channel); var request = new PurchaseTicketsRequest { Passphrase = ByteString.CopyFromUtf8(passphrase), Account = account.AccountNumber, SpendLimit = spendLimit, RequiredConfirmations = (uint)reqConfs, TicketAddress = ticketAddressStr, NumTickets = number, PoolAddress = poolAddressStr, PoolFees = poolFees, Expiry = expiry, TxFee = txFee, TicketFee = ticketFee, }; var response = await client.PurchaseTicketsAsync(request, cancellationToken: _tokenSource.Token); return response.TicketHashes.Select(h => new Blake256Hash(h.ToByteArray())).ToList(); }