Esempio n. 1
0
        private Transaction[] SetupDummyInputs(TxOutRepository coinsRet)
        {
            Transaction[] dummyTransactions = Enumerable.Range(0, 2).Select(_ => new Transaction()).ToArray();

            // Add some keys to the keystore:
            Key[] key = Enumerable.Range(0, 4).Select((_, i) => new Key(i % 2 != 0)).ToArray();


            // Create some dummy input transactions
            dummyTransactions[0].Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            dummyTransactions[0].Outputs[0].Value        = 11 * Money.CENT;
            dummyTransactions[0].Outputs[0].ScriptPubKey = dummyTransactions[0].Outputs[0].ScriptPubKey + key[0].PubKey.ToBytes() + OpcodeType.OP_CHECKSIG;
            dummyTransactions[0].Outputs[1].Value        = 50 * Money.CENT;
            dummyTransactions[0].Outputs[1].ScriptPubKey = dummyTransactions[0].Outputs[1].ScriptPubKey + key[1].PubKey.ToBytes() + OpcodeType.OP_CHECKSIG;
            coinsRet.AddFromTransaction(dummyTransactions[0]);


            dummyTransactions[1].Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            dummyTransactions[1].Outputs[0].Value        = 21 * Money.CENT;
            dummyTransactions[1].Outputs[0].ScriptPubKey = StandardScripts.PayToAddress(key[2].PubKey.GetAddress(Network.Main));
            dummyTransactions[1].Outputs[1].Value        = 22 * Money.CENT;
            dummyTransactions[1].Outputs[1].ScriptPubKey = StandardScripts.PayToAddress(key[3].PubKey.GetAddress(Network.Main));
            coinsRet.AddFromTransaction(dummyTransactions[1]);


            return(dummyTransactions);
        }
Esempio n. 2
0
        public void test_Get()
        {
            //CBasicKeyStore keystore;
            //CCoinsView coinsDummy;
            TxOutRepository coins = new TxOutRepository();             //(coinsDummy);

            Transaction[] dummyTransactions = SetupDummyInputs(coins); //(keystore, coins);

            Transaction t1 = new Transaction();

            t1.Inputs.AddRange(Enumerable.Range(0, 3).Select(_ => new TxIn()));
            t1.Inputs[0].PrevOut.Hash = dummyTransactions[0].GetHash();
            t1.Inputs[0].PrevOut.N    = 1;
            t1.Inputs[0].ScriptSig   += new byte[65];
            t1.Inputs[1].PrevOut.Hash = dummyTransactions[1].GetHash();
            t1.Inputs[1].PrevOut.N    = 0;
            t1.Inputs[1].ScriptSig    = t1.Inputs[1].ScriptSig + new byte[65] + Enumerable.Range(0, 33).Select(_ => (byte)4);
            t1.Inputs[2].PrevOut.Hash = dummyTransactions[1].GetHash();
            t1.Inputs[2].PrevOut.N    = 1;
            t1.Inputs[2].ScriptSig    = t1.Inputs[2].ScriptSig + new byte[65] + Enumerable.Range(0, 33).Select(_ => (byte)4);
            t1.Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            t1.Outputs[0].Value         = 90 * Money.CENT;
            t1.Outputs[0].ScriptPubKey += OpcodeType.OP_1;

            Assert.True(StandardScripts.AreInputsStandard(t1, coins));
            //Assert.Equal(coins.GetValueIn(t1), (50+21+22)*Money.CENT);

            //// Adding extra junk to the scriptSig should make it non-standard:
            t1.Inputs[0].ScriptSig += OpcodeType.OP_11;
            Assert.True(!StandardScripts.AreInputsStandard(t1, coins));

            //// ... as should not having enough:
            t1.Inputs[0].ScriptSig = new Script();
            Assert.True(!StandardScripts.AreInputsStandard(t1, coins));
        }
Esempio n. 3
0
        public void test_Get()
        {
            //CBasicKeyStore keystore;
            //CCoinsView coinsDummy;
            TxOutRepository coins = new TxOutRepository();//(coinsDummy);
            Transaction[] dummyTransactions = SetupDummyInputs(coins);//(keystore, coins);

            Transaction t1 = new Transaction();
            t1.Inputs.AddRange(Enumerable.Range(0, 3).Select(_ => new TxIn()));
            t1.Inputs[0].PrevOut.Hash = dummyTransactions[0].GetHash();
            t1.Inputs[0].PrevOut.N = 1;
            t1.Inputs[0].ScriptSig += new byte[65];
            t1.Inputs[1].PrevOut.Hash = dummyTransactions[1].GetHash();
            t1.Inputs[1].PrevOut.N = 0;
            t1.Inputs[1].ScriptSig = t1.Inputs[1].ScriptSig + new byte[65] + Enumerable.Range(0, 33).Select(_ => (byte)4);
            t1.Inputs[2].PrevOut.Hash = dummyTransactions[1].GetHash();
            t1.Inputs[2].PrevOut.N = 1;
            t1.Inputs[2].ScriptSig = t1.Inputs[2].ScriptSig + new byte[65] + Enumerable.Range(0, 33).Select(_ => (byte)4);
            t1.Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            t1.Outputs[0].Value = 90 * Money.CENT;
            t1.Outputs[0].ScriptPubKey += OpcodeType.OP_1;

            Assert.True(StandardScripts.AreInputsStandard(t1, coins));
            //Assert.Equal(coins.GetValueIn(t1), (50+21+22)*Money.CENT);

            //// Adding extra junk to the scriptSig should make it non-standard:
            t1.Inputs[0].ScriptSig += OpcodeType.OP_11;
            Assert.True(!StandardScripts.AreInputsStandard(t1, coins));

            //// ... as should not having enough:
            t1.Inputs[0].ScriptSig = new Script();
            Assert.True(!StandardScripts.AreInputsStandard(t1, coins));
        }
Esempio n. 4
0
        public void test_IsStandard()
        {
            var coins = new TxOutRepository();

            Transaction[] dummyTransactions = SetupDummyInputs(coins);

            Transaction t = new Transaction();

            t.Inputs.Add(new TxIn());
            t.Inputs[0].PrevOut.Hash = dummyTransactions[0].GetHash();
            t.Inputs[0].PrevOut.N    = 1;
            t.Inputs[0].ScriptSig    = new Script(Op.GetPushOp(new byte[65]));
            t.Outputs.Add(new TxOut());
            t.Outputs[0].Value = 90 * Money.CENT;
            Key key       = new Key(true);
            var payToHash = new PayToPubkeyHashTemplate();

            t.Outputs[0].ScriptPubKey = payToHash.GenerateScriptPubKey(key.PubKey.ID);

            Assert.True(StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].Value = 501;             //dust
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].Value = 601;             // not dust
            Assert.True(StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_1;
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            // 40-byte TX_NULL_DATA (standard)
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            Assert.True(StandardScripts.IsStandardTransaction(t));

            // 41-byte TX_NULL_DATA (non-standard)
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800");
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            // TX_NULL_DATA w/o PUSHDATA
            t.Outputs.Clear();
            t.Outputs.Add(new TxOut());
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(StandardScripts.IsStandardTransaction(t));

            // Only one TX_NULL_DATA permitted in all cases
            t.Outputs.Add(new TxOut());
            t.Outputs.Add(new TxOut());
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(!StandardScripts.IsStandardTransaction(t));
        }
Esempio n. 5
0
        private Transaction[] SetupDummyInputs(TxOutRepository coinsRet)
        {
            Transaction[] dummyTransactions = Enumerable.Range(0, 2).Select(_ => new Transaction()).ToArray();

            // Add some keys to the keystore:
            Key[] key = Enumerable.Range(0, 4).Select((_, i) => new Key(i % 2 != 0)).ToArray();

            // Create some dummy input transactions
            dummyTransactions[0].Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            dummyTransactions[0].Outputs[0].Value = 11 * Money.CENT;
            dummyTransactions[0].Outputs[0].ScriptPubKey = dummyTransactions[0].Outputs[0].ScriptPubKey + key[0].PubKey.ToBytes() + OpcodeType.OP_CHECKSIG;
            dummyTransactions[0].Outputs[1].Value = 50 * Money.CENT;
            dummyTransactions[0].Outputs[1].ScriptPubKey = dummyTransactions[0].Outputs[1].ScriptPubKey + key[1].PubKey.ToBytes() + OpcodeType.OP_CHECKSIG;
            coinsRet.AddFromTransaction(dummyTransactions[0]);

            dummyTransactions[1].Outputs.AddRange(Enumerable.Range(0, 2).Select(_ => new TxOut()));
            dummyTransactions[1].Outputs[0].Value = 21 * Money.CENT;
            dummyTransactions[1].Outputs[0].ScriptPubKey = StandardScripts.PayToAddress(key[2].PubKey.GetAddress(Network.Main));
            dummyTransactions[1].Outputs[1].Value = 22 * Money.CENT;
            dummyTransactions[1].Outputs[1].ScriptPubKey = StandardScripts.PayToAddress(key[3].PubKey.GetAddress(Network.Main));
            coinsRet.AddFromTransaction(dummyTransactions[1]);

            return dummyTransactions;
        }
Esempio n. 6
0
        public void test_IsStandard()
        {
            var coins = new TxOutRepository();
            Transaction[] dummyTransactions = SetupDummyInputs(coins);

            Transaction t = new Transaction();
            t.Inputs.Add(new TxIn());
            t.Inputs[0].PrevOut.Hash = dummyTransactions[0].GetHash();
            t.Inputs[0].PrevOut.N = 1;
            t.Inputs[0].ScriptSig = new Script(Op.GetPushOp(new byte[65]));
            t.Outputs.Add(new TxOut());
            t.Outputs[0].Value = 90 * Money.CENT;
            Key key = new Key(true);
            var payToHash = new PayToPubkeyHashTemplate();
            t.Outputs[0].ScriptPubKey = payToHash.GenerateScriptPubKey(key.PubKey.ID);

            Assert.True(StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].Value = 501; //dust
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].Value = 601; // not dust
            Assert.True(StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_1;
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            // 40-byte TX_NULL_DATA (standard)
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            Assert.True(StandardScripts.IsStandardTransaction(t));

            // 41-byte TX_NULL_DATA (non-standard)
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800");
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            // TX_NULL_DATA w/o PUSHDATA
            t.Outputs.Clear();
            t.Outputs.Add(new TxOut());
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(StandardScripts.IsStandardTransaction(t));

            // Only one TX_NULL_DATA permitted in all cases
            t.Outputs.Add(new TxOut());
            t.Outputs.Add(new TxOut());
            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN + ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(!StandardScripts.IsStandardTransaction(t));

            t.Outputs[0].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            t.Outputs[1].ScriptPubKey = new Script() + OpcodeType.OP_RETURN;
            Assert.True(!StandardScripts.IsStandardTransaction(t));
        }