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