public void CanCheckBlockWithWitness()
        {
            Block block = Block.Load(Encoders.Hex.DecodeData("000000202f6f6a130549473222411b5c6f54150d63b32aadf10e57f7d563cfc7010000001e28204471ef9ef11acd73543894a96a3044932b85e99889e731322a8ec28a9f9ae9fc56ffff011d0011b40202010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff2c028027266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779010effffffff0250b5062a0100000023210263ed47e995cbbf1bc560101e3b76c6bdb1b094a185450cea533781ce598ff2b6ac0000000000000000266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779012000000000000000000000000000000000000000000000000000000000000000000000000001000000000101cecd90cd38ac6858c47f2fe9f28145d6e18f9c5abc7ef1a41e2f19e6fe0362580100000000ffffffff0130b48d06000000001976a91405481b7f1d90c5a167a15b00e8af76eb6984ea5988ac0247304402206104c335e4adbb920184957f9f710b09de17d015329fde6807b9d321fd2142db02200b24ad996b4aa4ff103000348b5ad690abfd9fddae546af9e568394ed4a83113012103a65786c1a48d4167aca08cf6eb8eed081e13f45c02dc6000fd8f3bb16242579a00000000"), this.network);

            var consensusFlags = new DeploymentFlags
            {
                ScriptFlags   = ScriptVerify.Witness | ScriptVerify.P2SH | ScriptVerify.Standard,
                LockTimeFlags = LockTimeFlags.MedianTimePast,
                EnforceBIP34  = true
            };

            var context = new RuleContext
            {
                Time = DateTimeOffset.UtcNow,
                ValidationContext = new ValidationContext {
                    BlockToValidate = block
                },
                Flags = consensusFlags,
            };

            this.network.Consensus.Options = new ConsensusOptions();
            new WitnessCommitmentsRule().RunAsync(context).GetAwaiter().GetResult();

            var rule    = new CheckPowTransactionRule();
            var options = this.network.Consensus.Options;

            foreach (Transaction tx in block.Transactions)
            {
                rule.CheckTransaction(this.network, options, tx);
            }
        }
示例#2
0
        public void CanCheckBlockWithWitnessInInput()
        {
            var network = new StraxRegTest();

            var blockHex = "00000020e46299aa9ab7a76ce77c705ac50d6b031386246689cea9bde33fb851ca3c287726236faaa13be02ea891cdffbc229c9c39f9fdd957009ccf86d8c3311c377353eda4645fffff7f200500000001010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff025100ffffffff0200d2496b000000002321033ee9fd42c7ea8a3374710ea4e8af00d56015e1ed7c61a31eac29114e080f120fac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9012000000000000000000000000000000000000000000000000000000000000000000000000000";

            Block block = Block.Load(Encoders.Hex.DecodeData(blockHex), network.Consensus.ConsensusFactory);

            var consensusFlags = new DeploymentFlags
            {
                ScriptFlags   = ScriptVerify.Witness | ScriptVerify.P2SH | ScriptVerify.Standard,
                LockTimeFlags = Transaction.LockTimeFlags.MedianTimePast,
                EnforceBIP34  = true
            };

            var context = new RuleContext
            {
                Time = DateTimeOffset.UtcNow,
                ValidationContext = new ValidationContext {
                    BlockToValidate = block
                },
                Flags = consensusFlags,
            };

            network.Consensus.Options = new ConsensusOptions();
            new WitnessCommitmentsRule().ValidateWitnessCommitment(context, network).GetAwaiter().GetResult();

            var rule    = new CheckPowTransactionRule();
            var options = network.Consensus.Options;

            foreach (Transaction tx in block.Transactions)
            {
                rule.CheckTransaction(network, options, tx);
            }
        }
        public void CanCheckBlockWithWitness()
        {
            var block = Block.Load(Encoders.Hex.DecodeData("000000202f6f6a130549473222411b5c6f54150d63b32aadf10e57f7d563cfc7010000001e28204471ef9ef11acd73543894a96a3044932b85e99889e731322a8ec28a9f9ae9fc56ffff011d0011b40202010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff2c028027266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779010effffffff0250b5062a0100000023210263ed47e995cbbf1bc560101e3b76c6bdb1b094a185450cea533781ce598ff2b6ac0000000000000000266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779012000000000000000000000000000000000000000000000000000000000000000000000000001000000000101cecd90cd38ac6858c47f2fe9f28145d6e18f9c5abc7ef1a41e2f19e6fe0362580100000000ffffffff0130b48d06000000001976a91405481b7f1d90c5a167a15b00e8af76eb6984ea5988ac0247304402206104c335e4adbb920184957f9f710b09de17d015329fde6807b9d321fd2142db02200b24ad996b4aa4ff103000348b5ad690abfd9fddae546af9e568394ed4a83113012103a65786c1a48d4167aca08cf6eb8eed081e13f45c02dc6000fd8f3bb16242579a00000000"), Network.Main);

            var consensusFlags = new DeploymentFlags
            {
                ScriptFlags   = ScriptVerify.Witness | ScriptVerify.P2SH | ScriptVerify.Standard,
                LockTimeFlags = LockTimeFlags.MedianTimePast,
                EnforceBIP34  = true
            };

            var context = new RuleContext
            {
                BestBlock = new ContextBlockInformation
                {
                    MedianTimePast = DateTimeOffset.Parse("2016-03-31T09:02:19+00:00", CultureInfo.InvariantCulture),
                    Height         = 10111
                },
                NextWorkRequired       = block.Header.Bits,
                Time                   = DateTimeOffset.UtcNow,
                BlockValidationContext = new BlockValidationContext {
                    Block = block
                },
                Flags = consensusFlags,
            };

            Network.Main.Consensus.Options = new PowConsensusOptions();
            context.Consensus = Network.Main.Consensus;
            ConsensusSettings consensusSettings = new ConsensusSettings().Load(NodeSettings.Default());
            var validator = new PowConsensusValidator(Network.Main, new Checkpoints(Network.Main, consensusSettings), DateTimeProvider.Default, this.loggerFactory);

            new WitnessCommitmentsRule().RunAsync(context).GetAwaiter().GetResult();

            CheckPowTransactionRule rule = new CheckPowTransactionRule();
            var options = Network.Main.Consensus.Option <PowConsensusOptions>();

            foreach (Transaction tx in block.Transactions)
            {
                rule.CheckTransaction(Network.Main, options, tx);
            }
        }