BitSharp.Core.Rules.LibbitcoinConsensus.VerifyScript C# (CSharp) Method

VerifyScript() public static method

public static VerifyScript ( ImmutableArray txBytes, ImmutableArray prevTxOutputPublicScriptBytes, int inputIndex, verify_flags_type flags ) : bool
txBytes ImmutableArray
prevTxOutputPublicScriptBytes ImmutableArray
inputIndex int
flags verify_flags_type
return bool
        public static bool VerifyScript(ImmutableArray<byte> txBytes, ImmutableArray<byte> prevTxOutputPublicScriptBytes, int inputIndex, verify_flags_type flags)
        {
            //TODO
            if (!Environment.Is64BitProcess)
                return true;

            return verify_script(txBytes.ToArray(), (UIntPtr)txBytes.Length, prevTxOutputPublicScriptBytes.ToArray(), (UIntPtr)prevTxOutputPublicScriptBytes.Length, (uint)inputIndex, flags)
                == verify_result_type.verify_result_eval_true;
        }
    }

Usage Example

Example #1
0
        public void ValidationTransactionScript(Chain newChain, BlockTx tx, TxInput txInput, int txInputIndex, PrevTxOutput prevTxOutput)
        {
            var chainedHeader = newChain.LastBlock;

            // BIP16 didn't become active until Apr 1 2012
            var nBIP16SwitchTime      = DateTimeOffset.FromUnixTimeSeconds(1333238400U);
            var strictPayToScriptHash = chainedHeader.Time >= nBIP16SwitchTime;

            var flags = strictPayToScriptHash ? verify_flags_type.verify_flags_p2sh : verify_flags_type.verify_flags_none;

            // Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks,
            // when 75% of the network has upgraded:
            if (chainedHeader.Version >= 3 &&
                IsSuperMajority(3, newChain, ChainParams.MajorityEnforceBlockUpgrade))
            {
                flags |= verify_flags_type.verify_flags_dersig;
            }

            // Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
            // blocks, when 75% of the network has upgraded:
            if (chainedHeader.Version >= 4 &&
                IsSuperMajority(4, newChain, ChainParams.MajorityEnforceBlockUpgrade))
            {
                flags |= verify_flags_type.verify_flags_checklocktimeverify;
            }

            var result = LibbitcoinConsensus.VerifyScript(
                tx.TxBytes,
                prevTxOutput.ScriptPublicKey,
                txInputIndex,
                flags);

            if (!result)
            {
                logger.Debug($"Script did not pass in block: {chainedHeader.Hash}, tx: {tx.Index}, {tx.Hash}, input: {txInputIndex}");
                throw new ValidationException(chainedHeader.Hash);
            }
        }