예제 #1
0
        internal IEnumerable <Script> GetDestinations(Script redeemScript)
        {
            ScriptTemplate scriptTemplate = this.network.StandardScriptsRegistry.GetTemplateFromScriptPubKey(redeemScript);

            if (scriptTemplate != null)
            {
                // We need scripts suitable for matching to HDAddress.ScriptPubKey.
                switch (scriptTemplate.Type)
                {
                case TxOutType.TX_PUBKEYHASH:
                    yield return(redeemScript);

                    break;

                case TxOutType.TX_PUBKEY:
                    yield return(PayToPubkeyTemplate.Instance.ExtractScriptPubKeyParameters(redeemScript).Hash.ScriptPubKey);

                    break;

                case TxOutType.TX_SCRIPTHASH:
                    yield return(PayToScriptHashTemplate.Instance.ExtractScriptPubKeyParameters(redeemScript).ScriptPubKey);

                    break;

                case TxOutType.TX_SEGWIT:
                    TxDestination txDestination = PayToWitTemplate.Instance.ExtractScriptPubKeyParameters(this.network, redeemScript);
                    if (txDestination != null)
                    {
                        yield return(new KeyId(txDestination.ToBytes()).ScriptPubKey);
                    }
                    break;

                default:
                    if (this.scriptAddressReader is ScriptDestinationReader scriptDestinationReader)
                    {
                        foreach (TxDestination destination in scriptDestinationReader.GetDestinationFromScriptPubKey(this.network, redeemScript))
                        {
                            yield return(destination.ScriptPubKey);
                        }
                    }
                    else
                    {
                        string        address     = this.scriptAddressReader.GetAddressFromScriptPubKey(this.network, redeemScript);
                        TxDestination destination = ScriptDestinationReader.GetDestinationForAddress(address, this.network);
                        if (destination != null)
                        {
                            yield return(destination.ScriptPubKey);
                        }
                    }

                    break;
                }
            }
        }
        public virtual IEnumerable <TxDestination> GetDestinationFromScriptPubKey(Network network, Script redeemScript)
        {
            string base58 = this.scriptAddressReader.GetAddressFromScriptPubKey(network, redeemScript);

            if (base58 != null)
            {
                TxDestination destination = ScriptDestinationReader.GetDestinationForAddress(base58, network);

                if (destination != null)
                {
                    yield return(destination);
                }
            }
        }