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"));
        }
Beispiel #2
0
        public void P2PKH_GetSender_Passes()
        {
            var successResult = GetSenderResult.CreateSuccess(new uint160(0));

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

            Transaction transaction = this.network.CreateTransaction();

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

            // Mempool check works
            this.rule.CheckTransaction(new MempoolValidationContext(transaction, new MempoolValidationState(false)));

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

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