private GetSenderResult GetAddressFromScript(Script script)
        {
            // Borrowed from SenderRetriever
            PubKey payToPubKey = PayToPubkeyTemplate.Instance.ExtractScriptPubKeyParameters(script);

            if (payToPubKey != null)
            {
                var address = new uint160(payToPubKey.Hash.ToBytes());
                return(GetSenderResult.CreateSuccess(address));
            }

            if (PayToPubkeyHashTemplate.Instance.CheckScriptPubKey(script))
            {
                var address = new uint160(PayToPubkeyHashTemplate.Instance.ExtractScriptPubKeyParameters(script).ToBytes());
                return(GetSenderResult.CreateSuccess(address));
            }

            return(GetSenderResult.CreateFailure("Addresses can only be retrieved from Pay to Pub Key or Pay to Pub Key Hash"));
        }
Пример #2
0
        public void P2PKH_GetSender_Fails()
        {
            var failResult = GetSenderResult.CreateFailure("String error");

            this.senderRetriever.Setup(x => x.GetSender(It.IsAny <Transaction>(), It.IsAny <MempoolCoinView>()))
            .Returns(failResult);
            this.senderRetriever.Setup(x => x.GetSender(It.IsAny <Transaction>(), It.IsAny <ICoinView>(), It.IsAny <IList <Transaction> >()))
            .Returns(failResult);

            Transaction transaction = this.network.CreateTransaction();

            transaction.Outputs.Add(new TxOut(100, new Script(new byte[] { (byte)ScOpcodeType.OP_CREATECONTRACT })));

            // Mempool check fails
            Assert.ThrowsAny <ConsensusErrorException>(() => this.rule.CheckTransaction(new MempoolValidationContext(transaction, new MempoolValidationState(false))));

            // Block validation check fails
            Block block = this.network.CreateBlock();

            block.AddTransaction(transaction);
            Assert.ThrowsAnyAsync <ConsensusErrorException>(() => this.rule.RunAsync(new RuleContext(new ValidationContext {
                BlockToValidate = block
            }, DateTimeOffset.Now)));
        }