/// Initializes a new instance of Hash class with first 20 bytes from supplied list
/// </summary>
/// <param name="bytesList">List of bytes</param>
- public Hash(IList<byte> bytesList)
+ public Hash(IEnumerable<byte> bytes)
{
- _hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
+ _hashBytes = bytes.Take<byte>(hashSize).ToArray<byte>();
}
- public Hash(byte[] bytesArray)
+ public Hash(byte[] bytes)
{
- _hashBytes = bytesArray;
+ _hashBytes = bytes;
}
public bool IsZero()
}
public Hash160() : base() { }
- public Hash160(byte[] bytesArray) : base(bytesArray) { }
- public Hash160(IList<byte> bytesList) : base(bytesList) { }
+ public Hash160(byte[] bytes) : base(bytes) { }
+ public Hash160(IEnumerable<byte> bytes) : base(bytes) { }
public static Hash160 Compute160(IEnumerable<byte> inputBytes)
{
}
public Hash256() : base() { }
- public Hash256(byte[] bytesArray) : base(bytesArray) { }
- public Hash256(IList<byte> bytesList) : base(bytesList) { }
+ public Hash256(byte[] bytes) : base(bytes) { }
+ public Hash256(IEnumerable<byte> bytes) : base(bytes) { }
public static Hash256 Compute256(IEnumerable<byte> inputBytes)
{
foreach (Tuple<txnouttype, IEnumerable<byte>> templateTuple in templateTuples)
{
- CScript script2 = new CScript(templateTuple.Item2);
CScript script1 = scriptPubKey;
+ CScript script2 = new CScript(templateTuple.Item2);
opcodetype opcode1, opcode2;
while (true)
{
- if (wl1.GetItem() == last1 && wl2.GetItem() == last2)
+ if (wl1.GetCurrentItem() == last1 && wl2.GetCurrentItem() == last2)
{
// Found a match
typeRet = templateTuple.Item1;
break;
}
}
- else if (opcode1 != opcode2 || args1.SequenceEqual(args2))
+ else if (opcode1 != opcode2 || !args1.SequenceEqual(args2))
{
// Others must match exactly
break;
}
public ScryptHash256() : base() { }
- public ScryptHash256(byte[] bytesArray) : base(bytesArray) { }
- public ScryptHash256(IList<byte> bytesList) : base(bytesList) { }
+ public ScryptHash256(byte[] bytes) : base(bytes) { }
+ public ScryptHash256(IEnumerable<byte> bytes) : base(bytes) { }
/// <summary>
/// Calculate scrypt hash and return new instance of ScryptHash256 class
IEnumerable<byte> dataBytesForScrypt = b1.header.ToBytes();
ScryptHash256 scryptHash = ScryptHash256.Compute256(dataBytesForScrypt);
- Console.WriteLine("block1 header hash: {0}", scryptHash.ToString());
+ Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString());
+
+ /// Solver tests
+ CScript scriptPubKey = new CScript(Interop.ParseHex("21021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749ac"));
+ CScript scriptPubKeyHash = new CScript(Interop.ParseHex("76a914edbf189bece45d4afa9848276e949183936bf6a488ac"));
+
+ txnouttype typeRet;
+ IList<IEnumerable<byte>> solutions;
+
+ Console.WriteLine("scriptPubKey solved: {0}", ScriptCode.Solver(scriptPubKey, out typeRet, out solutions));
+ Console.WriteLine("scriptPubKey address: {0}", new CPubKey(solutions.First()).GetKeyID().ToString());
+
+ Console.WriteLine("scriptPubKeyHash solved: {0}", ScriptCode.Solver(scriptPubKeyHash, out typeRet, out solutions));
+ Console.WriteLine("scriptPubKeyHash address: {0}", new CKeyID(new Hash160(solutions.First())).ToString());
Console.ReadLine();
}