src/Stratis.FederatedPeg.Features.FederationGateway/Wallet/FederationWalletTransactionHandler.cs
/// <summary>
/// Find all available outputs (UTXO's) that belong to the multisig address.
/// Then add them to the <see cref="TransactionBuildContext.UnspentOutputs"/> or <see cref="TransactionBuildContext.UnspentMultiSigOutputs"/>.
/// </summary>
/// <param name="context">The context associated with the current transaction being built.</param>
Find all available outputs (UTXO's) that belong to the multisig address.
Then add them to the  or .
Find all available outputs ( UTXO ' s ) that belong to the multisig address . Then add them to the or .
private void AddCoins(TransactionBuildContext context)
        {
            context.UnspentOutputs = this.walletManager.GetSpendableTransactionsInWallet(context.MinConfirmations).ToList();
            if (context.UnspentOutputs.Count == 0)
            {
                throw new WalletException("No spendable transactions found.");
            }
            long balance = context.UnspentOutputs.Sum(t => t.Transaction.Amount);
            long totalToSend = context.Recipients.Sum(s => s.Amount);
            if (balance < totalToSend)
                throw new WalletException("Not enough funds.");
            if (context.SelectedInputs.Any())
            {
                Dictionary<OutPoint, UnspentOutputReference> availableHashList = context.UnspentOutputs.ToDictionary(item => item.ToOutPoint(), item => item);
                if (!context.SelectedInputs.All(input => availableHashList.ContainsKey(input)))
                    throw new WalletException("Not all the selected inputs were found on the wallet.");
                if (!context.AllowOtherInputs)
                {
                    foreach (KeyValuePair<OutPoint, UnspentOutputReference> unspentOutputsItem in availableHashList)
                        if (!context.SelectedInputs.Contains(unspentOutputsItem.Key))
                            context.UnspentOutputs.Remove(unspentOutputsItem.Value);
                }
            }
            long sum = 0;
            int index = 0;
            var coins = new List<Coin>();
            foreach (UnspentOutputReference item in context.OrderCoinsDeterministic ?
                this.GetOrderedUnspentOutputs(context) : context.UnspentOutputs.OrderByDescending(a => a.Transaction.Amount))
            {
                coins.Add(ScriptCoin.Create(this.network, item.Transaction.Id, (uint)item.Transaction.Index, item.Transaction.Amount, item.Transaction.ScriptPubKey, this.walletManager.GetWallet().MultiSigAddress.RedeemScript));
                sum += item.Transaction.Amount;
                index++;
                if (sum >= (totalToSend + context.TransactionFee))
                    break;
            }
            context.TransactionBuilder.AddCoins(coins);
        }
private void AddCoins ( TransactionBuildContext context ) { context . UnspentOutputs = this . walletManager . GetSpendableTransactionsInWallet ( context . MinConfirmations ) . ToList ( ) ; if ( context . UnspentOutputs . Count == 0 ) { throw new WalletException ( " " ) ; } long balance = context . UnspentOutputs . Sum ( t => t . Transaction . Amount ) ; long totalToSend = context . Recipients . Sum ( s => s . Amount ) ; if ( balance < totalToSend ) throw new WalletException ( " " ) ; if ( context . SelectedInputs . Any ( ) ) { Dictionary < OutPoint , UnspentOutputReference > availableHashList = context . UnspentOutputs . ToDictionary ( item => item . ToOutPoint ( ) , item => item ) ; if ( ! context . SelectedInputs . All ( input => availableHashList . ContainsKey ( input ) ) ) throw new WalletException ( " " ) ; if ( ! context . AllowOtherInputs ) { foreach ( KeyValuePair < OutPoint , UnspentOutputReference > unspentOutputsItem in availableHashList ) if ( ! context . SelectedInputs . Contains ( unspentOutputsItem . Key ) ) context . UnspentOutputs . Remove ( unspentOutputsItem . Value ) ; } } long sum = 0 ; int index = 0 ; var coins = new List < Coin > ( ) ; foreach ( UnspentOutputReference item in context . OrderCoinsDeterministic ? this . GetOrderedUnspentOutputs ( context ) : context . UnspentOutputs . OrderByDescending ( a => a . Transaction . Amount ) ) { coins . Add ( ScriptCoin . Create ( this . network , item . Transaction . Id , ( uint ) item . Transaction . Index , item . Transaction . Amount , item . Transaction . ScriptPubKey , this . walletManager . GetWallet ( ) . MultiSigAddress . RedeemScript ) ) ; sum += item . Transaction . Amount ; index ++ ; if ( sum >= ( totalToSend + context . TransactionFee ) ) break ; } context . TransactionBuilder . AddCoins ( coins ) ; }
Find all available outputs (UTXO's) that belong to the multisig address.
Find all available outputs ( UTXO ' s ) that belong to the multisig address .
// Get total spendable balance in the account. // 'SelectedInputs' are inputs that must be included in the // current transaction. At this point we check the given // input is part of the UTXO set and filter out UTXOs that are not // in the initial list if 'context.AllowOtherInputs' is false. // Sufficient UTXOs are selected to cover the value of the outputs + fee.
context
TransactionBuildContext
The context associated with the current transaction being built.
The context associated with the current transaction being built .