public static Gen <Transaction> TX(Network network) => from version in Gen.Choose(0, Int32.MaxValue) from inputs in NonEmptyInputs() from outputs in NonEmptyOutputs() from locktime in PrimitiveGenerator.UInt32() let tx = LegacyTransactionGenerators.ComposeTx(Transaction.Create(network), inputs, outputs, locktime) where tx.HasWitness select tx;
public static Gen <PSBTInput> PSBTInputNonFinal() => from nonWitnessUtxo in SegwitTransactionGenerators.TX() from witnessUtxo in LegacyTransactionGenerators.Output() from redeem in ScriptGenerator.RandomScriptSig() from witnessS in ScriptGenerator.RandomScriptSig() from hdKeyPaths in HDKeyPaths() from partialSigs in PartialSigs() from unknown in UnknownKVMap() select ComposePSBTInput(new PSBTInput() { NonWitnessUtxo = nonWitnessUtxo, WitnessUtxo = witnessUtxo, RedeemScript = redeem, WitnessScript = witnessS, }, hdKeyPaths, partialSigs, unknown);
/// <summary> /// This is slow, provably because `Add*` methods will iterate over inputs. /// </summary> /// <param name="network"></param> /// <returns></returns> public static Gen <PSBT> SanePSBT(Network network) => from inputN in Gen.Choose(0, 8) from scripts in Gen.ListOf(inputN, ScriptGenerator.RandomScriptSig()) from txOuts in Gen.Sequence(scripts.Select(sc => OutputFromRedeem(sc))) from prevN in Gen.Choose(0, 5) from prevTxs in Gen.Sequence(txOuts.Select(o => TXFromOutput(o, network, prevN))) let txins = prevTxs.Select(tx => new TxIn(new OutPoint(tx.GetHash(), prevN))) from locktime in PrimitiveGenerator.UInt32() let tx = LegacyTransactionGenerators.ComposeTx(network.CreateTransaction(), txins.ToList(), txOuts.ToList(), locktime) from TxsToAdd in Gen.SubListOf(prevTxs) from CoinsToAdd in Gen.SubListOf(prevTxs.SelectMany(tx => tx.Outputs.AsCoins())) from scriptsToAdd in Gen.SubListOf <Script>(scripts) let psbt = tx.CreatePSBT() .AddTransactions(prevTxs.ToArray()) .AddCoins(CoinsToAdd.ToArray()) .AddScripts(scriptsToAdd.ToArray()) select psbt;
public static Gen <TxIn> WitnessInput() => from txin in LegacyTransactionGenerators.Input() from witscript in ScriptGenerator.RandomWitScript() select AttachWitScript(txin, witscript);