Example #1
0
        /// <summary>
        /// Initializes an instance of the <see cref="ScriptPubKey"/> class.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="network">The network where the transaction was conducted.</param>
        public ScriptPubKey(Consensus.ScriptInfo.Script script, Network network) : base(script)
        {
            var destinations = new List <TxDestination> {
                script.GetDestination(network)
            };

            this.Type = this.GetScriptType(script.FindTemplate(network));

            if (destinations[0] == null)
            {
                destinations = script.GetDestinationPublicKeys(network).Select(p => p.Hash).ToList <TxDestination>();
            }

            if (destinations.Count == 1)
            {
                this.ReqSigs   = 1;
                this.Addresses = new List <string> {
                    destinations[0].GetAddress(network).ToString()
                };
            }
            else if (destinations.Count > 1)
            {
                PayToMultiSigTemplateParameters multi = PayToMultiSigTemplate.Instance.ExtractScriptPubKeyParameters(script);
                this.ReqSigs   = multi.SignatureCount;
                this.Addresses = multi.PubKeys.Select(m => m.GetAddress(network).ToString()).ToList();
            }
        }