public BitcoinWitScriptAddress(WitScriptId segwitScriptId, Network network)
     : base(
         NotNull(segwitScriptId) ?? Network.CreateBech32(Bech32Type.WITNESS_SCRIPT_ADDRESS,
                                                         segwitScriptId.ToBytes(), 0, network), network)
 {
     this.Hash = segwitScriptId;
 }
 private static string NotNull(WitScriptId segwitScriptId)
 {
     if (segwitScriptId == null)
     {
         throw new ArgumentNullException("segwitScriptId");
     }
     return(null);
 }
        public BitcoinWitScriptAddress(string bech32, Network expectedNetwork = null)
            : base(Validate(bech32, ref expectedNetwork), expectedNetwork)
        {
            var  encoder = expectedNetwork.GetBech32Encoder(Bech32Type.WITNESS_SCRIPT_ADDRESS, true);
            byte witVersion;
            var  decoded = encoder.Decode(bech32, out witVersion);

            _Hash = new WitScriptId(decoded);
        }
Example #4
0
 public BitcoinWitScriptAddress(string bech32, Network expectedNetwork)
     : base(Validate(bech32, expectedNetwork), expectedNetwork)
 {
     if (expectedNetwork.GetBech32Encoder(Bech32Type.WITNESS_SCRIPT_ADDRESS, false) is Bech32Encoder encoder)
     {
         var decoded = encoder.Decode(bech32, out _);
         _Hash = new WitScriptId(decoded);
     }
     else
     {
         throw expectedNetwork.Bech32NotSupported(Bech32Type.WITNESS_SCRIPT_ADDRESS);
     }
 }
Example #5
0
        /// <summary>
        /// Extract witness redeem from WitScript
        /// </summary>
        /// <param name="witScript">Witscript to extract information from</param>
        /// <param name="expectedScriptId">Expected redeem hash</param>
        /// <returns>The witness redeem</returns>
        public Script ExtractWitScriptParameters(WitScript witScript, WitScriptId expectedScriptId)
        {
            if (witScript.PushCount == 0)
            {
                return(null);
            }
            var    last   = witScript.GetUnsafePush(witScript.PushCount - 1);
            Script redeem = new Script(last);

            if (expectedScriptId != null)
            {
                if (expectedScriptId != redeem.WitHash)
                {
                    return(null);
                }
            }
            return(redeem);
        }
Example #6
0
 public Script GenerateScriptPubKey(WitScriptId scriptHash)
 {
     return(scriptHash.ScriptPubKey);
 }
		/// <summary>
		/// Extract witness redeem from WitScript
		/// </summary>
		/// <param name="witScript">Witscript to extract information from</param>
		/// <param name="expectedScriptId">Expected redeem hash</param>
		/// <returns>The witness redeem</returns>
		public Script ExtractWitScriptParameters(WitScript witScript, WitScriptId expectedScriptId = null)
		{
			if(witScript.PushCount == 0)
				return null;
			var last = witScript.GetUnsafePush(witScript.PushCount - 1);
			Script redeem = new Script(last);
			if(expectedScriptId != null)
			{
				if(expectedScriptId != redeem.WitHash)
					return null;
			}
			return redeem;
		}
		public Script GenerateScriptPubKey(WitScriptId scriptHash)
		{
			return scriptHash.ScriptPubKey;
		}
Example #9
0
 public BitcoinWitScriptAddress(WitScriptId segwitKeyId, Network network)
     : base(new[] { (byte)OpcodeType.OP_0, (byte)0x00 }.Concat(segwitKeyId.ToBytes(true)).ToArray(), network)
 {
 }
Example #10
0
 public virtual BitcoinAddress CreateP2WSH(WitScriptId scriptId, Network network)
 {
     return(new BitcoinWitScriptAddress(scriptId, network));
 }
Example #11
0
 internal BitcoinWitScriptAddress(string str, byte[] keyId, Network network) : base(str, network)
 {
     _Hash = new WitScriptId(keyId);
 }
Example #12
0
		public BitcoinWitScriptAddress(WitScriptId segwitKeyId, Network network)
	: base(new[] { (byte)OpcodeType.OP_0, (byte)0x00 }.Concat(segwitKeyId.ToBytes(true)).ToArray(), network)
		{
		}