Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Allred
crown-core
Commits
59b922b4
Commit
59b922b4
authored
10 years ago
by
Pieter Wuille
Browse files
Options
Download
Email Patches
Plain Diff
Move CTxDestination from script/script to script/standard
parent
9521ece5
No related merge requests found
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
src/base58.h
+1
-0
src/base58.h
src/bitcoin-tx.cpp
+2
-3
src/bitcoin-tx.cpp
src/qt/guiutil.cpp
+3
-1
src/qt/guiutil.cpp
src/qt/paymentserver.cpp
+2
-2
src/qt/paymentserver.cpp
src/qt/walletmodel.cpp
+1
-2
src/qt/walletmodel.cpp
src/rpcdump.cpp
+3
-1
src/rpcdump.cpp
src/rpcmisc.cpp
+1
-2
src/rpcmisc.cpp
src/rpcrawtransaction.cpp
+1
-2
src/rpcrawtransaction.cpp
src/rpcwallet.cpp
+3
-6
src/rpcwallet.cpp
src/script/script.cpp
+0
-40
src/script/script.cpp
src/script/script.h
+0
-17
src/script/script.h
src/script/standard.cpp
+47
-0
src/script/standard.cpp
src/script/standard.h
+17
-0
src/script/standard.h
src/test/DoS_tests.cpp
+3
-3
src/test/DoS_tests.cpp
src/test/miner_tests.cpp
+1
-1
src/test/miner_tests.cpp
src/test/script_P2SH_tests.cpp
+21
-24
src/test/script_P2SH_tests.cpp
src/test/script_tests.cpp
+3
-3
src/test/script_tests.cpp
src/test/sigopcount_tests.cpp
+4
-5
src/test/sigopcount_tests.cpp
src/test/transaction_tests.cpp
+3
-3
src/test/transaction_tests.cpp
src/wallet.cpp
+3
-4
src/wallet.cpp
with
119 additions
and
119 deletions
+119
-119
src/base58.h
View file @
59b922b4
...
...
@@ -17,6 +17,7 @@
#include "chainparams.h"
#include "key.h"
#include "script/script.h"
#include "script/standard.h"
#include <string>
#include <vector>
...
...
This diff is collapsed.
Click to expand it.
src/bitcoin-tx.cpp
View file @
59b922b4
...
...
@@ -224,9 +224,8 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
if
(
!
addr
.
IsValid
())
throw
runtime_error
(
"invalid TX output address"
);
// build standard output script via SetDestination()
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
addr
.
Get
());
// build standard output script via GetScriptForDestination()
CScript
scriptPubKey
=
GetScriptForDestination
(
addr
.
Get
());
// construct TxOut, append to transaction output list
CTxOut
txout
(
value
,
scriptPubKey
);
...
...
This diff is collapsed.
Click to expand it.
src/qt/guiutil.cpp
View file @
59b922b4
...
...
@@ -13,6 +13,8 @@
#include "init.h"
#include "main.h"
#include "protocol.h"
#include "script/script.h"
#include "script/standard.h"
#include "util.h"
#ifdef WIN32
...
...
@@ -222,7 +224,7 @@ QString formatBitcoinURI(const SendCoinsRecipient &info)
bool
isDust
(
const
QString
&
address
,
qint64
amount
)
{
CTxDestination
dest
=
CBitcoinAddress
(
address
.
toStdString
()).
Get
();
CScript
script
;
s
cript
.
Set
Destination
(
dest
);
CScript
script
=
GetS
cript
For
Destination
(
dest
);
CTxOut
txOut
(
amount
,
script
);
return
txOut
.
IsDust
(
::
minRelayTxFee
);
}
...
...
This diff is collapsed.
Click to expand it.
src/qt/paymentserver.cpp
View file @
59b922b4
...
...
@@ -609,7 +609,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
std
::
string
strAccount
=
account
.
toStdString
();
set
<
CTxDestination
>
refundAddresses
=
wallet
->
GetAccountAddresses
(
strAccount
);
if
(
!
refundAddresses
.
empty
())
{
CScript
s
;
s
.
Set
Destination
(
*
refundAddresses
.
begin
());
CScript
s
=
GetScriptFor
Destination
(
*
refundAddresses
.
begin
());
payments
::
Output
*
refund_to
=
payment
.
add_refund_to
();
refund_to
->
set_script
(
&
s
[
0
],
s
.
size
());
}
...
...
@@ -620,7 +620,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
CKeyID
keyID
=
newKey
.
GetID
();
wallet
->
SetAddressBook
(
keyID
,
strAccount
,
"refund"
);
CScript
s
;
s
.
Set
Destination
(
keyID
);
CScript
s
=
GetScriptFor
Destination
(
keyID
);
payments
::
Output
*
refund_to
=
payment
.
add_refund_to
();
refund_to
->
set_script
(
&
s
[
0
],
s
.
size
());
}
...
...
This diff is collapsed.
Click to expand it.
src/qt/walletmodel.cpp
View file @
59b922b4
...
...
@@ -241,8 +241,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
setAddress
.
insert
(
rcp
.
address
);
++
nAddresses
;
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
CBitcoinAddress
(
rcp
.
address
.
toStdString
()).
Get
());
CScript
scriptPubKey
=
GetScriptForDestination
(
CBitcoinAddress
(
rcp
.
address
.
toStdString
()).
Get
());
vecSend
.
push_back
(
std
::
pair
<
CScript
,
int64_t
>
(
scriptPubKey
,
rcp
.
amount
));
total
+=
rcp
.
amount
;
...
...
This diff is collapsed.
Click to expand it.
src/rpcdump.cpp
View file @
59b922b4
...
...
@@ -6,6 +6,8 @@
#include "rpcserver.h"
#include "init.h"
#include "main.h"
#include "script/script.h"
#include "script/standard.h"
#include "sync.h"
#include "util.h"
#include "utiltime.h"
...
...
@@ -161,7 +163,7 @@ Value importaddress(const Array& params, bool fHelp)
CBitcoinAddress
address
(
params
[
0
].
get_str
());
if
(
address
.
IsValid
())
{
script
.
Set
Destination
(
address
.
Get
());
script
=
GetScriptFor
Destination
(
address
.
Get
());
}
else
if
(
IsHex
(
params
[
0
].
get_str
()))
{
std
::
vector
<
unsigned
char
>
data
(
ParseHex
(
params
[
0
].
get_str
()));
script
=
CScript
(
data
.
begin
(),
data
.
end
());
...
...
This diff is collapsed.
Click to expand it.
src/rpcmisc.cpp
View file @
59b922b4
...
...
@@ -250,8 +250,7 @@ CScript _createmultisig_redeemScript(const Array& params)
throw
runtime_error
(
" Invalid public key: "
+
ks
);
}
}
CScript
result
;
result
.
SetMultisig
(
nRequired
,
pubkeys
);
CScript
result
=
GetScriptForMultisig
(
nRequired
,
pubkeys
);
if
(
result
.
size
()
>
MAX_SCRIPT_ELEMENT_SIZE
)
throw
runtime_error
(
...
...
This diff is collapsed.
Click to expand it.
src/rpcrawtransaction.cpp
View file @
59b922b4
...
...
@@ -366,8 +366,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
throw
JSONRPCError
(
RPC_INVALID_PARAMETER
,
string
(
"Invalid parameter, duplicated address: "
)
+
s
.
name_
);
setAddress
.
insert
(
address
);
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
address
.
Get
());
CScript
scriptPubKey
=
GetScriptForDestination
(
address
.
Get
());
int64_t
nAmount
=
AmountFromValue
(
s
.
value_
);
CTxOut
out
(
nAmount
,
scriptPubKey
);
...
...
This diff is collapsed.
Click to expand it.
src/rpcwallet.cpp
View file @
59b922b4
...
...
@@ -124,8 +124,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
// Check if the current key has been used
if
(
account
.
vchPubKey
.
IsValid
())
{
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
account
.
vchPubKey
.
GetID
());
CScript
scriptPubKey
=
GetScriptForDestination
(
account
.
vchPubKey
.
GetID
());
for
(
map
<
uint256
,
CWalletTx
>::
iterator
it
=
pwalletMain
->
mapWallet
.
begin
();
it
!=
pwalletMain
->
mapWallet
.
end
()
&&
account
.
vchPubKey
.
IsValid
();
++
it
)
...
...
@@ -472,10 +471,9 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
// Bitcoin address
CBitcoinAddress
address
=
CBitcoinAddress
(
params
[
0
].
get_str
());
CScript
scriptPubKey
;
if
(
!
address
.
IsValid
())
throw
JSONRPCError
(
RPC_INVALID_ADDRESS_OR_KEY
,
"Invalid Bitcoin address"
);
scriptPubKey
.
Set
Destination
(
address
.
Get
());
CScript
scriptPubKey
=
GetScriptFor
Destination
(
address
.
Get
());
if
(
!
IsMine
(
*
pwalletMain
,
scriptPubKey
))
return
(
double
)
0.0
;
...
...
@@ -849,8 +847,7 @@ Value sendmany(const Array& params, bool fHelp)
throw
JSONRPCError
(
RPC_INVALID_PARAMETER
,
string
(
"Invalid parameter, duplicated address: "
)
+
s
.
name_
);
setAddress
.
insert
(
address
);
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
address
.
Get
());
CScript
scriptPubKey
=
GetScriptForDestination
(
address
.
Get
());
int64_t
nAmount
=
AmountFromValue
(
s
.
value_
);
totalAmount
+=
nAmount
;
...
...
This diff is collapsed.
Click to expand it.
src/script/script.cpp
View file @
59b922b4
...
...
@@ -253,43 +253,3 @@ bool CScript::HasCanonicalPushes() const
}
return
true
;
}
class
CScriptVisitor
:
public
boost
::
static_visitor
<
bool
>
{
private:
CScript
*
script
;
public:
CScriptVisitor
(
CScript
*
scriptin
)
{
script
=
scriptin
;
}
bool
operator
()(
const
CNoDestination
&
dest
)
const
{
script
->
clear
();
return
false
;
}
bool
operator
()(
const
CKeyID
&
keyID
)
const
{
script
->
clear
();
*
script
<<
OP_DUP
<<
OP_HASH160
<<
keyID
<<
OP_EQUALVERIFY
<<
OP_CHECKSIG
;
return
true
;
}
bool
operator
()(
const
CScriptID
&
scriptID
)
const
{
script
->
clear
();
*
script
<<
OP_HASH160
<<
scriptID
<<
OP_EQUAL
;
return
true
;
}
};
void
CScript
::
SetDestination
(
const
CTxDestination
&
dest
)
{
boost
::
apply_visitor
(
CScriptVisitor
(
this
),
dest
);
}
void
CScript
::
SetMultisig
(
int
nRequired
,
const
std
::
vector
<
CPubKey
>&
keys
)
{
this
->
clear
();
*
this
<<
EncodeOP_N
(
nRequired
);
BOOST_FOREACH
(
const
CPubKey
&
key
,
keys
)
*
this
<<
key
;
*
this
<<
EncodeOP_N
(
keys
.
size
())
<<
OP_CHECKMULTISIG
;
}
This diff is collapsed.
Click to expand it.
src/script/script.h
View file @
59b922b4
...
...
@@ -320,20 +320,6 @@ inline std::string ValueString(const std::vector<unsigned char>& vch)
return
HexStr
(
vch
);
}
class
CNoDestination
{
public:
friend
bool
operator
==
(
const
CNoDestination
&
a
,
const
CNoDestination
&
b
)
{
return
true
;
}
friend
bool
operator
<
(
const
CNoDestination
&
a
,
const
CNoDestination
&
b
)
{
return
true
;
}
};
/** A txout script template with a specific destination. It is either:
* * CNoDestination: no destination set
* * CKeyID: TX_PUBKEYHASH destination
* * CScriptID: TX_SCRIPTHASH destination
* A CTxDestination is the internal data type encoded in a CBitcoinAddress
*/
typedef
boost
::
variant
<
CNoDestination
,
CKeyID
,
CScriptID
>
CTxDestination
;
/** Serialized script, used inside transaction inputs and outputs */
class
CScript
:
public
std
::
vector
<
unsigned
char
>
{
...
...
@@ -604,9 +590,6 @@ public:
return
(
size
()
>
0
&&
*
begin
()
==
OP_RETURN
);
}
void
SetDestination
(
const
CTxDestination
&
address
);
void
SetMultisig
(
int
nRequired
,
const
std
::
vector
<
CPubKey
>&
keys
);
std
::
string
ToString
()
const
{
std
::
string
str
;
...
...
This diff is collapsed.
Click to expand it.
src/script/standard.cpp
View file @
59b922b4
...
...
@@ -252,3 +252,50 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto
return
true
;
}
namespace
{
class
CScriptVisitor
:
public
boost
::
static_visitor
<
bool
>
{
private:
CScript
*
script
;
public:
CScriptVisitor
(
CScript
*
scriptin
)
{
script
=
scriptin
;
}
bool
operator
()(
const
CNoDestination
&
dest
)
const
{
script
->
clear
();
return
false
;
}
bool
operator
()(
const
CKeyID
&
keyID
)
const
{
script
->
clear
();
*
script
<<
OP_DUP
<<
OP_HASH160
<<
keyID
<<
OP_EQUALVERIFY
<<
OP_CHECKSIG
;
return
true
;
}
bool
operator
()(
const
CScriptID
&
scriptID
)
const
{
script
->
clear
();
*
script
<<
OP_HASH160
<<
scriptID
<<
OP_EQUAL
;
return
true
;
}
};
}
CScript
GetScriptForDestination
(
const
CTxDestination
&
dest
)
{
CScript
script
;
boost
::
apply_visitor
(
CScriptVisitor
(
&
script
),
dest
);
return
script
;
}
CScript
GetScriptForMultisig
(
int
nRequired
,
const
std
::
vector
<
CPubKey
>&
keys
)
{
CScript
script
;
script
<<
CScript
::
EncodeOP_N
(
nRequired
);
BOOST_FOREACH
(
const
CPubKey
&
key
,
keys
)
script
<<
key
;
script
<<
CScript
::
EncodeOP_N
(
keys
.
size
())
<<
OP_CHECKMULTISIG
;
return
script
;
}
This diff is collapsed.
Click to expand it.
src/script/standard.h
View file @
59b922b4
...
...
@@ -45,6 +45,20 @@ enum txnouttype
TX_NULL_DATA
,
};
class
CNoDestination
{
public:
friend
bool
operator
==
(
const
CNoDestination
&
a
,
const
CNoDestination
&
b
)
{
return
true
;
}
friend
bool
operator
<
(
const
CNoDestination
&
a
,
const
CNoDestination
&
b
)
{
return
true
;
}
};
/** A txout script template with a specific destination. It is either:
* * CNoDestination: no destination set
* * CKeyID: TX_PUBKEYHASH destination
* * CScriptID: TX_SCRIPTHASH destination
* A CTxDestination is the internal data type encoded in a CBitcoinAddress
*/
typedef
boost
::
variant
<
CNoDestination
,
CKeyID
,
CScriptID
>
CTxDestination
;
const
char
*
GetTxnOutputType
(
txnouttype
t
);
bool
Solver
(
const
CScript
&
scriptPubKey
,
txnouttype
&
typeRet
,
std
::
vector
<
std
::
vector
<
unsigned
char
>
>&
vSolutionsRet
);
...
...
@@ -53,4 +67,7 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
bool
ExtractDestination
(
const
CScript
&
scriptPubKey
,
CTxDestination
&
addressRet
);
bool
ExtractDestinations
(
const
CScript
&
scriptPubKey
,
txnouttype
&
typeRet
,
std
::
vector
<
CTxDestination
>&
addressRet
,
int
&
nRequiredRet
);
CScript
GetScriptForDestination
(
const
CTxDestination
&
dest
);
CScript
GetScriptForMultisig
(
int
nRequired
,
const
std
::
vector
<
CPubKey
>&
keys
);
#endif // H_BITCOIN_SCRIPT_STANDARD
This diff is collapsed.
Click to expand it.
src/test/DoS_tests.cpp
View file @
59b922b4
...
...
@@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx
.
vin
[
0
].
scriptSig
<<
OP_1
;
tx
.
vout
.
resize
(
1
);
tx
.
vout
[
0
].
nValue
=
1
*
CENT
;
tx
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
.
GetPubKey
().
GetID
());
tx
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
.
GetPubKey
().
GetID
());
AddOrphanTx
(
tx
,
i
);
}
...
...
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
tx
.
vin
[
0
].
prevout
.
hash
=
txPrev
.
GetHash
();
tx
.
vout
.
resize
(
1
);
tx
.
vout
[
0
].
nValue
=
1
*
CENT
;
tx
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
.
GetPubKey
().
GetID
());
tx
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
.
GetPubKey
().
GetID
());
SignSignature
(
keystore
,
txPrev
,
tx
,
0
);
AddOrphanTx
(
tx
,
i
);
...
...
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
CMutableTransaction
tx
;
tx
.
vout
.
resize
(
1
);
tx
.
vout
[
0
].
nValue
=
1
*
CENT
;
tx
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
.
GetPubKey
().
GetID
());
tx
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
.
GetPubKey
().
GetID
());
tx
.
vin
.
resize
(
500
);
for
(
unsigned
int
j
=
0
;
j
<
tx
.
vin
.
size
();
j
++
)
{
...
...
This diff is collapsed.
Click to expand it.
src/test/miner_tests.cpp
View file @
59b922b4
...
...
@@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx
.
vin
[
0
].
scriptSig
=
CScript
()
<<
OP_1
;
tx
.
vout
[
0
].
nValue
=
4900000000LL
;
script
=
CScript
()
<<
OP_0
;
tx
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
script
.
GetID
());
tx
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
script
.
GetID
());
hash
=
tx
.
GetHash
();
mempool
.
addUnchecked
(
hash
,
CTxMemPoolEntry
(
tx
,
11
,
GetTime
(),
111.0
,
11
));
tx
.
vin
[
0
].
prevout
.
hash
=
hash
;
...
...
This diff is collapsed.
Click to expand it.
src/test/script_P2SH_tests.cpp
View file @
59b922b4
...
...
@@ -68,14 +68,14 @@ BOOST_AUTO_TEST_CASE(sign)
// different keys, straight/P2SH, pubkey/pubkeyhash
CScript
standardScripts
[
4
];
standardScripts
[
0
]
<<
key
[
0
].
GetPubKey
()
<<
OP_CHECKSIG
;
standardScripts
[
1
]
.
Set
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
standardScripts
[
1
]
=
GetScriptFor
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
standardScripts
[
2
]
<<
key
[
1
].
GetPubKey
()
<<
OP_CHECKSIG
;
standardScripts
[
3
]
.
Set
Destination
(
key
[
2
].
GetPubKey
().
GetID
());
standardScripts
[
3
]
=
GetScriptFor
Destination
(
key
[
2
].
GetPubKey
().
GetID
());
CScript
evalScripts
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
keystore
.
AddCScript
(
standardScripts
[
i
]);
evalScripts
[
i
]
.
Set
Destination
(
standardScripts
[
i
].
GetID
());
evalScripts
[
i
]
=
GetScriptFor
Destination
(
standardScripts
[
i
].
GetID
());
}
CMutableTransaction
txFrom
;
// Funding transaction:
...
...
@@ -129,8 +129,7 @@ BOOST_AUTO_TEST_CASE(norecurse)
CScript
invalidAsScript
;
invalidAsScript
<<
OP_INVALIDOPCODE
<<
OP_INVALIDOPCODE
;
CScript
p2sh
;
p2sh
.
SetDestination
(
invalidAsScript
.
GetID
());
CScript
p2sh
=
GetScriptForDestination
(
invalidAsScript
.
GetID
());
CScript
scriptSig
;
scriptSig
<<
Serialize
(
invalidAsScript
);
...
...
@@ -140,8 +139,7 @@ BOOST_AUTO_TEST_CASE(norecurse)
// Try to recur, and verification should succeed because
// the inner HASH160 <> EQUAL should only check the hash:
CScript
p2sh2
;
p2sh2
.
SetDestination
(
p2sh
.
GetID
());
CScript
p2sh2
=
GetScriptForDestination
(
p2sh
.
GetID
());
CScript
scriptSig2
;
scriptSig2
<<
Serialize
(
invalidAsScript
)
<<
Serialize
(
p2sh
);
...
...
@@ -163,15 +161,15 @@ BOOST_AUTO_TEST_CASE(set)
}
CScript
inner
[
4
];
inner
[
0
]
.
Set
Destination
(
key
[
0
].
GetPubKey
().
GetID
());
inner
[
1
]
.
Set
Multisig
(
2
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
2
));
inner
[
2
]
.
Set
Multisig
(
1
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
2
));
inner
[
3
]
.
Set
Multisig
(
2
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
3
));
inner
[
0
]
=
GetScriptFor
Destination
(
key
[
0
].
GetPubKey
().
GetID
());
inner
[
1
]
=
GetScriptFor
Multisig
(
2
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
2
));
inner
[
2
]
=
GetScriptFor
Multisig
(
1
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
2
));
inner
[
3
]
=
GetScriptFor
Multisig
(
2
,
std
::
vector
<
CPubKey
>
(
keys
.
begin
(),
keys
.
begin
()
+
3
));
CScript
outer
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
outer
[
i
]
.
Set
Destination
(
inner
[
i
].
GetID
());
outer
[
i
]
=
GetScriptFor
Destination
(
inner
[
i
].
GetID
());
keystore
.
AddCScript
(
inner
[
i
]);
}
...
...
@@ -244,8 +242,7 @@ BOOST_AUTO_TEST_CASE(switchover)
CScript
scriptSig
;
scriptSig
<<
Serialize
(
notValid
);
CScript
fund
;
fund
.
SetDestination
(
notValid
.
GetID
());
CScript
fund
=
GetScriptForDestination
(
notValid
.
GetID
());
// Validation should succeed under old rules (hash is correct):
...
...
@@ -274,11 +271,11 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
txFrom
.
vout
.
resize
(
7
);
// First three are standard:
CScript
pay1
;
pay1
.
Set
Destination
(
key
[
0
].
GetPubKey
().
GetID
());
CScript
pay1
=
GetScriptFor
Destination
(
key
[
0
].
GetPubKey
().
GetID
());
keystore
.
AddCScript
(
pay1
);
CScript
pay1of3
;
pay1of3
.
Set
Multisig
(
1
,
keys
);
CScript
pay1of3
=
GetScriptFor
Multisig
(
1
,
keys
);
txFrom
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
pay1
.
GetID
());
// P2SH (OP_CHECKSIG)
txFrom
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
pay1
.
GetID
());
// P2SH (OP_CHECKSIG)
txFrom
.
vout
[
0
].
nValue
=
1000
;
txFrom
.
vout
[
1
].
scriptPubKey
=
pay1
;
// ordinary OP_CHECKSIG
txFrom
.
vout
[
1
].
nValue
=
2000
;
...
...
@@ -293,7 +290,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
oneAndTwo
<<
OP_2
<<
key
[
3
].
GetPubKey
()
<<
key
[
4
].
GetPubKey
()
<<
key
[
5
].
GetPubKey
();
oneAndTwo
<<
OP_3
<<
OP_CHECKMULTISIG
;
keystore
.
AddCScript
(
oneAndTwo
);
txFrom
.
vout
[
3
].
scriptPubKey
.
Set
Destination
(
oneAndTwo
.
GetID
());
txFrom
.
vout
[
3
].
scriptPubKey
=
GetScriptFor
Destination
(
oneAndTwo
.
GetID
());
txFrom
.
vout
[
3
].
nValue
=
4000
;
// vout[4] is max sigops:
...
...
@@ -302,17 +299,17 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
fifteenSigops
<<
key
[
i
%
3
].
GetPubKey
();
fifteenSigops
<<
OP_15
<<
OP_CHECKMULTISIG
;
keystore
.
AddCScript
(
fifteenSigops
);
txFrom
.
vout
[
4
].
scriptPubKey
.
Set
Destination
(
fifteenSigops
.
GetID
());
txFrom
.
vout
[
4
].
scriptPubKey
=
GetScriptFor
Destination
(
fifteenSigops
.
GetID
());
txFrom
.
vout
[
4
].
nValue
=
5000
;
// vout[5/6] are non-standard because they exceed MAX_P2SH_SIGOPS
CScript
sixteenSigops
;
sixteenSigops
<<
OP_16
<<
OP_CHECKMULTISIG
;
keystore
.
AddCScript
(
sixteenSigops
);
txFrom
.
vout
[
5
].
scriptPubKey
.
Set
Destination
(
fifteenSigops
.
GetID
());
txFrom
.
vout
[
5
].
scriptPubKey
=
GetScriptFor
Destination
(
fifteenSigops
.
GetID
());
txFrom
.
vout
[
5
].
nValue
=
5000
;
CScript
twentySigops
;
twentySigops
<<
OP_CHECKMULTISIG
;
keystore
.
AddCScript
(
twentySigops
);
txFrom
.
vout
[
6
].
scriptPubKey
.
Set
Destination
(
twentySigops
.
GetID
());
txFrom
.
vout
[
6
].
scriptPubKey
=
GetScriptFor
Destination
(
twentySigops
.
GetID
());
txFrom
.
vout
[
6
].
nValue
=
6000
;
...
...
@@ -320,7 +317,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
CMutableTransaction
txTo
;
txTo
.
vout
.
resize
(
1
);
txTo
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txTo
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txTo
.
vin
.
resize
(
5
);
for
(
int
i
=
0
;
i
<
5
;
i
++
)
...
...
@@ -352,7 +349,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
CMutableTransaction
txToNonStd1
;
txToNonStd1
.
vout
.
resize
(
1
);
txToNonStd1
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txToNonStd1
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txToNonStd1
.
vout
[
0
].
nValue
=
1000
;
txToNonStd1
.
vin
.
resize
(
1
);
txToNonStd1
.
vin
[
0
].
prevout
.
n
=
5
;
...
...
@@ -364,7 +361,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
CMutableTransaction
txToNonStd2
;
txToNonStd2
.
vout
.
resize
(
1
);
txToNonStd2
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txToNonStd2
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
[
1
].
GetPubKey
().
GetID
());
txToNonStd2
.
vout
[
0
].
nValue
=
1000
;
txToNonStd2
.
vin
.
resize
(
1
);
txToNonStd2
.
vin
[
0
].
prevout
.
n
=
6
;
...
...
This diff is collapsed.
Click to expand it.
src/test/script_tests.cpp
View file @
59b922b4
...
...
@@ -280,7 +280,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
CMutableTransaction
txFrom
;
txFrom
.
vout
.
resize
(
1
);
txFrom
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
keys
[
0
].
GetPubKey
().
GetID
());
txFrom
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
keys
[
0
].
GetPubKey
().
GetID
());
CScript
&
scriptPubKey
=
txFrom
.
vout
[
0
].
scriptPubKey
;
CMutableTransaction
txTo
;
txTo
.
vin
.
resize
(
1
);
...
...
@@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
// P2SH, single-signature case:
CScript
pkSingle
;
pkSingle
<<
keys
[
0
].
GetPubKey
()
<<
OP_CHECKSIG
;
keystore
.
AddCScript
(
pkSingle
);
scriptPubKey
.
Set
Destination
(
pkSingle
.
GetID
());
scriptPubKey
=
GetScriptFor
Destination
(
pkSingle
.
GetID
());
SignSignature
(
keystore
,
txFrom
,
txTo
,
0
);
combined
=
CombineSignatures
(
scriptPubKey
,
txTo
,
0
,
scriptSig
,
empty
);
BOOST_CHECK
(
combined
==
scriptSig
);
...
...
@@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
BOOST_CHECK
(
combined
==
scriptSig
);
// Hardest case: Multisig 2-of-3
scriptPubKey
.
Set
Multisig
(
2
,
pubkeys
);
scriptPubKey
=
GetScriptFor
Multisig
(
2
,
pubkeys
);
keystore
.
AddCScript
(
scriptPubKey
);
SignSignature
(
keystore
,
txFrom
,
txTo
,
0
);
combined
=
CombineSignatures
(
scriptPubKey
,
txTo
,
0
,
scriptSig
,
empty
);
...
...
This diff is collapsed.
Click to expand it.
src/test/sigopcount_tests.cpp
View file @
59b922b4
...
...
@@ -4,6 +4,7 @@
#include "key.h"
#include "script/script.h"
#include "script/standard.h"
#include "uint256.h"
#include <vector>
...
...
@@ -37,8 +38,7 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
BOOST_CHECK_EQUAL
(
s1
.
GetSigOpCount
(
true
),
3U
);
BOOST_CHECK_EQUAL
(
s1
.
GetSigOpCount
(
false
),
21U
);
CScript
p2sh
;
p2sh
.
SetDestination
(
s1
.
GetID
());
CScript
p2sh
=
GetScriptForDestination
(
s1
.
GetID
());
CScript
scriptSig
;
scriptSig
<<
OP_0
<<
Serialize
(
s1
);
BOOST_CHECK_EQUAL
(
p2sh
.
GetSigOpCount
(
scriptSig
),
3U
);
...
...
@@ -50,12 +50,11 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
k
.
MakeNewKey
(
true
);
keys
.
push_back
(
k
.
GetPubKey
());
}
CScript
s2
;
s2
.
SetMultisig
(
1
,
keys
);
CScript
s2
=
GetScriptForMultisig
(
1
,
keys
);
BOOST_CHECK_EQUAL
(
s2
.
GetSigOpCount
(
true
),
3U
);
BOOST_CHECK_EQUAL
(
s2
.
GetSigOpCount
(
false
),
20U
);
p2sh
.
Set
Destination
(
s2
.
GetID
());
p2sh
=
GetScriptFor
Destination
(
s2
.
GetID
());
BOOST_CHECK_EQUAL
(
p2sh
.
GetSigOpCount
(
true
),
0U
);
BOOST_CHECK_EQUAL
(
p2sh
.
GetSigOpCount
(
false
),
0U
);
CScript
scriptSig2
;
...
...
This diff is collapsed.
Click to expand it.
src/test/transaction_tests.cpp
View file @
59b922b4
...
...
@@ -248,9 +248,9 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsView & coinsRet)
dummyTransactions
[
1
].
vout
.
resize
(
2
);
dummyTransactions
[
1
].
vout
[
0
].
nValue
=
21
*
CENT
;
dummyTransactions
[
1
].
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
[
2
].
GetPubKey
().
GetID
());
dummyTransactions
[
1
].
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
[
2
].
GetPubKey
().
GetID
());
dummyTransactions
[
1
].
vout
[
1
].
nValue
=
22
*
CENT
;
dummyTransactions
[
1
].
vout
[
1
].
scriptPubKey
.
Set
Destination
(
key
[
3
].
GetPubKey
().
GetID
());
dummyTransactions
[
1
].
vout
[
1
].
scriptPubKey
=
GetScriptFor
Destination
(
key
[
3
].
GetPubKey
().
GetID
());
coinsRet
.
SetCoins
(
dummyTransactions
[
1
].
GetHash
(),
CCoins
(
dummyTransactions
[
1
],
0
));
return
dummyTransactions
;
...
...
@@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
t
.
vout
[
0
].
nValue
=
90
*
CENT
;
CKey
key
;
key
.
MakeNewKey
(
true
);
t
.
vout
[
0
].
scriptPubKey
.
Set
Destination
(
key
.
GetPubKey
().
GetID
());
t
.
vout
[
0
].
scriptPubKey
=
GetScriptFor
Destination
(
key
.
GetPubKey
().
GetID
());
string
reason
;
BOOST_CHECK
(
IsStandardTx
(
t
,
reason
));
...
...
This diff is collapsed.
Click to expand it.
src/wallet.cpp
View file @
59b922b4
...
...
@@ -1385,7 +1385,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
// coin control: send change to custom address
if
(
coinControl
&&
!
boost
::
get
<
CNoDestination
>
(
&
coinControl
->
destChange
))
scriptChange
.
Set
Destination
(
coinControl
->
destChange
);
scriptChange
=
GetScriptFor
Destination
(
coinControl
->
destChange
);
// no coin control: send change to newly generated address
else
...
...
@@ -1403,7 +1403,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
ret
=
reservekey
.
GetReservedKey
(
vchPubKey
);
assert
(
ret
);
// should never fail, as we just unlocked
scriptChange
.
Set
Destination
(
vchPubKey
.
GetID
());
scriptChange
=
GetScriptFor
Destination
(
vchPubKey
.
GetID
());
}
CTxOut
newTxOut
(
nChange
,
scriptChange
);
...
...
@@ -1556,8 +1556,7 @@ string CWallet::SendMoney(const CTxDestination &address, int64_t nValue, CWallet
}
// Parse Bitcoin address
CScript
scriptPubKey
;
scriptPubKey
.
SetDestination
(
address
);
CScript
scriptPubKey
=
GetScriptForDestination
(
address
);
// Create and send the transaction
CReserveKey
reservekey
(
this
);
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help