예제 #1
0
        /// <summary>
        /// This will initialize the script as an P2PKH-locking script (Pay To Private Key Hash)
        /// </summary>
        /// <param name="address">The hashed and BASE58 encoded address</param>
        public LockingScript(string address) : base(SCRIPTTYPE.LOCK_P2PKH)
        {
            if (address.Length < 20)
            {
                throw new ArgumentException("Address is invalid: too short");
            }
            if (address.Length > 255)
            {
                throw new ArgumentException("Address is invalid: too big");
            }

            byte[] addressHash = BASE58.Decode(address);
            if (addressHash.Length != 20)
            {
                throw new ArgumentException("Invalid address. Address byte[] size must be 20 (HASH160)");
            }

            this.Add(OPCODE.DUP);       //OPCODE = Duplicate the original public key, first instruction
            this.Add(OPCODE.HASH160);   //OPCODE = Hash public key
            this.Add(OPCODE.PUBKEY_HASH);
            this.AddRange(addressHash); //Hashed publicKey
            this.Add(OPCODE.EQ_VERIFY); //OPCODE = Check if equal: address and hashed public key
            this.Add(OPCODE.CHECKSIG);  //Validate signature with the provided public key
        }