mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-12 13:43:43 +01:00
Refactor: split CKeyID/CScriptID/CTxDestination from CBitcoinAddress
This introduces internal types: * CKeyID: reference (hash160) of a key * CScriptID: reference (hash160) of a script * CTxDestination: a boost::variant of the former two CBitcoinAddress is retrofitted to be a Base58 encoding of a CTxDestination. This allows all internal code to only use the internal types, and only have RPC and GUI depend on the base58 code. Furthermore, the header dependencies are a lot saner now. base58.h is at the top (right below rpc and gui) instead of at the bottom. For the rest: wallet -> script -> keystore -> key. Only keystore still requires a forward declaration of CScript. Solving that would require splitting script into two layers.
This commit is contained in:
@@ -175,12 +175,12 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
//
|
||||
CBasicKeyStore keystore, emptykeystore, partialkeystore;
|
||||
CKey key[3];
|
||||
CBitcoinAddress keyaddr[3];
|
||||
CTxDestination keyaddr[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
key[i].MakeNewKey(true);
|
||||
keystore.AddKey(key[i]);
|
||||
keyaddr[i].SetPubKey(key[i].GetPubKey());
|
||||
keyaddr[i] = key[i].GetPubKey().GetID();
|
||||
}
|
||||
partialkeystore.AddKey(key[0]);
|
||||
|
||||
@@ -191,8 +191,8 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
s << key[0].GetPubKey() << OP_CHECKSIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK(solutions.size() == 1);
|
||||
CBitcoinAddress addr;
|
||||
BOOST_CHECK(ExtractAddress(s, addr));
|
||||
CTxDestination addr;
|
||||
BOOST_CHECK(ExtractDestination(s, addr));
|
||||
BOOST_CHECK(addr == keyaddr[0]);
|
||||
BOOST_CHECK(IsMine(keystore, s));
|
||||
BOOST_CHECK(!IsMine(emptykeystore, s));
|
||||
@@ -201,11 +201,11 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
vector<valtype> solutions;
|
||||
txnouttype whichType;
|
||||
CScript s;
|
||||
s << OP_DUP << OP_HASH160 << Hash160(key[0].GetPubKey().Raw()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
s << OP_DUP << OP_HASH160 << key[0].GetPubKey().GetID() << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK(solutions.size() == 1);
|
||||
CBitcoinAddress addr;
|
||||
BOOST_CHECK(ExtractAddress(s, addr));
|
||||
CTxDestination addr;
|
||||
BOOST_CHECK(ExtractDestination(s, addr));
|
||||
BOOST_CHECK(addr == keyaddr[0]);
|
||||
BOOST_CHECK(IsMine(keystore, s));
|
||||
BOOST_CHECK(!IsMine(emptykeystore, s));
|
||||
@@ -214,11 +214,11 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
vector<valtype> solutions;
|
||||
txnouttype whichType;
|
||||
CScript s;
|
||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey().Raw() << OP_2 << OP_CHECKMULTISIG;
|
||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4);
|
||||
CBitcoinAddress addr;
|
||||
BOOST_CHECK(!ExtractAddress(s, addr));
|
||||
CTxDestination addr;
|
||||
BOOST_CHECK(!ExtractDestination(s, addr));
|
||||
BOOST_CHECK(IsMine(keystore, s));
|
||||
BOOST_CHECK(!IsMine(emptykeystore, s));
|
||||
BOOST_CHECK(!IsMine(partialkeystore, s));
|
||||
@@ -227,12 +227,12 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
vector<valtype> solutions;
|
||||
txnouttype whichType;
|
||||
CScript s;
|
||||
s << OP_1 << key[0].GetPubKey().Raw() << key[1].GetPubKey().Raw() << OP_2 << OP_CHECKMULTISIG;
|
||||
s << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4);
|
||||
vector<CBitcoinAddress> addrs;
|
||||
vector<CTxDestination> addrs;
|
||||
int nRequired;
|
||||
BOOST_CHECK(ExtractAddresses(s, whichType, addrs, nRequired));
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addrs, nRequired));
|
||||
BOOST_CHECK(addrs[0] == keyaddr[0]);
|
||||
BOOST_CHECK(addrs[1] == keyaddr[1]);
|
||||
BOOST_CHECK(nRequired = 1);
|
||||
@@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
vector<valtype> solutions;
|
||||
txnouttype whichType;
|
||||
CScript s;
|
||||
s << OP_2 << key[0].GetPubKey().Raw() << key[1].GetPubKey().Raw() << key[2].GetPubKey().Raw() << OP_3 << OP_CHECKMULTISIG;
|
||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK(solutions.size() == 5);
|
||||
}
|
||||
@@ -262,13 +262,13 @@ BOOST_AUTO_TEST_CASE(multisig_Sign)
|
||||
}
|
||||
|
||||
CScript a_and_b;
|
||||
a_and_b << OP_2 << key[0].GetPubKey().Raw() << key[1].GetPubKey().Raw() << OP_2 << OP_CHECKMULTISIG;
|
||||
a_and_b << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
|
||||
CScript a_or_b;
|
||||
a_or_b << OP_1 << key[0].GetPubKey().Raw() << key[1].GetPubKey().Raw() << OP_2 << OP_CHECKMULTISIG;
|
||||
a_or_b << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
|
||||
CScript escrow;
|
||||
escrow << OP_2 << key[0].GetPubKey().Raw() << key[1].GetPubKey().Raw() << key[2].GetPubKey().Raw() << OP_3 << OP_CHECKMULTISIG;
|
||||
escrow << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG;
|
||||
|
||||
CTransaction txFrom; // Funding transaction
|
||||
txFrom.vout.resize(3);
|
||||
|
||||
Reference in New Issue
Block a user