public static Gen <TxIn> Input() => from prevout in OutPoint()
 from ss in ScriptGenerator.RandomScriptSig()
 from nSequence in PrimitiveGenerator.UInt32()
 select new TxIn(prevout, ss)
 {
     Sequence = nSequence
 };
Ejemplo n.º 2
0
 public static Gen <UnknownKVMap> UnknownKVMap() =>
 from itemNum in Gen.Choose(0, 15)
 from keys in Gen.ListOf(itemNum, PrimitiveGenerator.RandomBytes())
     where PSBTConstants.PSBT_IN_ALL.All(i => keys.Select(k => k.First()).All(k => k != i))
 let uniqKeys = keys.Distinct()
                from values in Gen.ListOf(uniqKeys.Count(), PrimitiveGenerator.RandomBytes())
                select Utils.DictionaryFromList <byte[], byte[]>(uniqKeys.ToList(), values.ToList());
Ejemplo n.º 3
0
 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;
Ejemplo n.º 4
0
 private static Gen <TxOut> OutputFromRedeem(Script sc) =>
 from money in MoneyGenerator.Money()
 from isP2WSH in PrimitiveGenerator.Bool()
 from isP2SH in PrimitiveGenerator.Bool()
     where isP2WSH || isP2SH
 let redeem = (isP2SH && isP2WSH) ? sc.WitHash.ScriptPubKey : sc
              let scriptPubKey = isP2SH ? redeem.Hash.ScriptPubKey : redeem.WitHash.ScriptPubKey
                                 select new TxOut(money, scriptPubKey);
Ejemplo n.º 5
0
 public static Gen <Op> NonPushOpcode()
 => from b in PrimitiveGenerator.RandomByte()
     where Enum.IsDefined(typeof(OpcodeType), b)
 let op = (OpcodeType)b
              where !Op.IsPushCode(op)
          let opc = (Op)(OpcodeType)b
                        where !opc.IsInvalid
                    select opc;
Ejemplo n.º 6
0
 /// <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(network)
                                 .AddTransactions(prevTxs.ToArray())
                                 .AddCoins(CoinsToAdd.ToArray())
                                 .AddScripts(scriptsToAdd.ToArray())
                                 select psbt;
Ejemplo n.º 7
0
 public static Gen <HDFingerprint> HDFingerprint() =>
 from bytes in PrimitiveGenerator.RandomBytes(4)
 select new HDFingerprint(bytes);
Ejemplo n.º 8
0
 public static Gen <Dictionary <byte[], byte[]> > UnknownKVMap() =>
 from itemNum in Gen.Choose(0, 15)
 from keys in Gen.ListOf(itemNum, PrimitiveGenerator.RandomBytes())
 from values in Gen.ListOf(itemNum, PrimitiveGenerator.RandomBytes())
 select Utils.DictionaryFromList <byte[], byte[]>(keys.ToList(), values.ToList());
Ejemplo n.º 9
0
 public static Gen <KeyPath> KeyPath() =>
 from raw in Gen.NonEmptyListOf(PrimitiveGenerator.RandomBytes(4))
 let flattenBytes = raw.ToList().Aggregate((a, b) => a.Concat(b))
                    select Bitcoin3.KeyPath.FromBytes(flattenBytes);
Ejemplo n.º 10
0
 public static Gen <uint160> Hash160() =>
 from bytes in PrimitiveGenerator.RandomBytes(20)
 select new uint160(bytes);
Ejemplo n.º 11
0
 public static Gen <uint256> Hash256() =>
 from bytes in PrimitiveGenerator.RandomBytes(32)
 select new uint256(bytes);
Ejemplo n.º 12
0
 private static Gen <TxOut> OutputFromKey(PubKey key) =>
 from money in MoneyGenerator.Money()
 from isP2WPKH in PrimitiveGenerator.Bool()
 from isP2SH in PrimitiveGenerator.Bool()
 let scriptPubKey = (isP2SH && isP2WPKH) ? key.WitHash.ScriptPubKey.Hash.ScriptPubKey : isP2WPKH ? key.WitHash.ScriptPubKey : key.Hash.ScriptPubKey
                    select new TxOut(money, scriptPubKey);
Ejemplo n.º 13
0
 public static Gen <Money> Money() =>
 (from bytes in Gen.ListOf(6, PrimitiveGenerator.RandomByte())                 // Make sure we are below 21M
  select Bitcoin3.Utils.ToUInt64(bytes.Concat(new byte[] { 0, 0 }).ToArray(), true))
 .Select(u64 => new Money(u64));
 public static Gen <Transaction> TX(Network network) =>
 from version in Gen.Choose(0, Int32.MaxValue)
 from txin in NonEmptyInputs()
 from txout in NonEmptyOutputs()
 from locktime in PrimitiveGenerator.UInt32()
 select ComposeTx(Transaction.Create(network), txin, txout, locktime);
Ejemplo n.º 15
0
 private static Gen <Op> PushOnlyOpcode() =>
 from bytes in PrimitiveGenerator.RandomBytes(4)
 select Op.GetPushOp(bytes);