mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Use CBitcoinAddress instead of string/uint160
Instead of conversion functions between pubkey/uint160/address in base58.h, have a fully fledged class CBitcoinAddress (CAddress was already taken) to represent addresses.
This commit is contained in:
30
src/script.h
30
src/script.h
@@ -622,7 +622,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
uint160 GetBitcoinAddressHash160() const
|
||||
CBitcoinAddress GetBitcoinAddress() const
|
||||
{
|
||||
opcodetype opcode;
|
||||
std::vector<unsigned char> vch;
|
||||
@@ -634,36 +634,18 @@ public:
|
||||
if (!GetOp(pc, opcode, vch) || opcode != OP_EQUALVERIFY) return 0;
|
||||
if (!GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG) return 0;
|
||||
if (pc != end()) return 0;
|
||||
return hash160;
|
||||
return CBitcoinAddress(hash160);
|
||||
}
|
||||
|
||||
std::string GetBitcoinAddress() const
|
||||
{
|
||||
uint160 hash160 = GetBitcoinAddressHash160();
|
||||
if (hash160 == 0)
|
||||
return "";
|
||||
return Hash160ToAddress(hash160);
|
||||
}
|
||||
|
||||
void SetBitcoinAddress(const uint160& hash160)
|
||||
void SetBitcoinAddress(const CBitcoinAddress& address)
|
||||
{
|
||||
this->clear();
|
||||
*this << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
*this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
}
|
||||
|
||||
void SetBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
|
||||
{
|
||||
SetBitcoinAddress(Hash160(vchPubKey));
|
||||
}
|
||||
|
||||
bool SetBitcoinAddress(const std::string& strAddress)
|
||||
{
|
||||
this->clear();
|
||||
uint160 hash160;
|
||||
if (!AddressToHash160(strAddress, hash160))
|
||||
return false;
|
||||
SetBitcoinAddress(hash160);
|
||||
return true;
|
||||
SetBitcoinAddress(CBitcoinAddress(vchPubKey));
|
||||
}
|
||||
|
||||
|
||||
@@ -710,7 +692,7 @@ public:
|
||||
|
||||
bool IsStandard(const CScript& scriptPubKey);
|
||||
bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
|
||||
bool ExtractHash160(const CScript& scriptPubKey, const CKeyStore* pkeystore, uint160& hash160Ret);
|
||||
bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* pkeystore, CBitcoinAddress& addressRet);
|
||||
bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL, CScript scriptPrereq=CScript());
|
||||
bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, int nHashType=0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user