예제 #1
0
 public BitcoinWitScriptAddress(WitScriptId segwitScriptId, Network network)
     : base(
         NotNull(segwitScriptId) ?? Network.CreateBech32(Bech32Type.WITNESS_SCRIPT_ADDRESS,
                                                         segwitScriptId.ToBytes(), 0, network), network)
 {
     this.Hash = segwitScriptId;
 }
예제 #2
0
 private static string NotNull(WitScriptId segwitScriptId)
 {
     if (segwitScriptId == null)
     {
         throw new ArgumentNullException("segwitScriptId");
     }
     return(null);
 }
예제 #3
0
        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);
        }
예제 #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);
     }
 }
예제 #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);
        }
예제 #6
0
 public Script GenerateScriptPubKey(WitScriptId scriptHash)
 {
     return(scriptHash.ScriptPubKey);
 }
예제 #7
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 = 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;
		}
예제 #8
0
		public Script GenerateScriptPubKey(WitScriptId scriptHash)
		{
			return scriptHash.ScriptPubKey;
		}
예제 #9
0
 public BitcoinWitScriptAddress(WitScriptId segwitKeyId, Network network)
     : base(new[] { (byte)OpcodeType.OP_0, (byte)0x00 }.Concat(segwitKeyId.ToBytes(true)).ToArray(), network)
 {
 }
예제 #10
0
 public virtual BitcoinAddress CreateP2WSH(WitScriptId scriptId, Network network)
 {
     return(new BitcoinWitScriptAddress(scriptId, network));
 }
예제 #11
0
 internal BitcoinWitScriptAddress(string str, byte[] keyId, Network network) : base(str, network)
 {
     _Hash = new WitScriptId(keyId);
 }
예제 #12
0
		public BitcoinWitScriptAddress(WitScriptId segwitKeyId, Network network)
	: base(new[] { (byte)OpcodeType.OP_0, (byte)0x00 }.Concat(segwitKeyId.ToBytes(true)).ToArray(), network)
		{
		}