Skip to content

Commit 3ce7e66

Browse files
author
Jeff Garzik
committed
bitcoin-cli, rpcrawtransaction: harmonize "{" styling
1 parent 2a58400 commit 3ce7e66

File tree

2 files changed

+37
-75
lines changed

2 files changed

+37
-75
lines changed

src/bitcoin-cli.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ static bool AppInitRPC(int argc, char* argv[])
5050
// Parameters
5151
//
5252
ParseParameters(argc, argv);
53-
if (!boost::filesystem::is_directory(GetDataDir(false)))
54-
{
53+
if (!boost::filesystem::is_directory(GetDataDir(false))) {
5554
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
5655
return false;
5756
}
@@ -66,11 +65,9 @@ static bool AppInitRPC(int argc, char* argv[])
6665
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
6766
return false;
6867
}
69-
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
70-
{
68+
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) {
7169
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
72-
if (!mapArgs.count("-version"))
73-
{
70+
if (!mapArgs.count("-version")) {
7471
strUsage += "\n" + _("Usage:") + "\n" +
7572
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
7673
" bitcoin-cli [options] help " + _("List commands") + "\n" +
@@ -153,11 +150,9 @@ int CommandLineRPC(int argc, char *argv[])
153150
{
154151
string strPrint;
155152
int nRet = 0;
156-
try
157-
{
153+
try {
158154
// Skip switches
159-
while (argc > 1 && IsSwitchChar(argv[1][0]))
160-
{
155+
while (argc > 1 && IsSwitchChar(argv[1][0])) {
161156
argc--;
162157
argv++;
163158
}
@@ -178,15 +173,12 @@ int CommandLineRPC(int argc, char *argv[])
178173
const Value& result = find_value(reply, "result");
179174
const Value& error = find_value(reply, "error");
180175

181-
if (error.type() != null_type)
182-
{
176+
if (error.type() != null_type) {
183177
// Error
184178
strPrint = "error: " + write_string(error, false);
185179
int code = find_value(error.get_obj(), "code").get_int();
186180
nRet = abs(code);
187-
}
188-
else
189-
{
181+
} else {
190182
// Result
191183
if (result.type() == null_type)
192184
strPrint = "";
@@ -208,8 +200,7 @@ int CommandLineRPC(int argc, char *argv[])
208200
throw;
209201
}
210202

211-
if (strPrint != "")
212-
{
203+
if (strPrint != "") {
213204
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
214205
}
215206
return nRet;
@@ -219,8 +210,7 @@ int main(int argc, char* argv[])
219210
{
220211
SetupEnvironment();
221212

222-
try
223-
{
213+
try {
224214
if(!AppInitRPC(argc, argv))
225215
return EXIT_FAILURE;
226216
}
@@ -233,8 +223,7 @@ int main(int argc, char* argv[])
233223
}
234224

235225
int ret = EXIT_FAILURE;
236-
try
237-
{
226+
try {
238227
ret = CommandLineRPC(argc, argv);
239228
}
240229
catch (std::exception& e) {

src/rpcrawtransaction.cpp

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH
3737
if (fIncludeHex)
3838
out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
3939

40-
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired))
41-
{
40+
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
4241
out.push_back(Pair("type", GetTxnOutputType(type)));
4342
return;
4443
}
@@ -58,13 +57,11 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
5857
entry.push_back(Pair("version", tx.nVersion));
5958
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
6059
Array vin;
61-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
62-
{
60+
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
6361
Object in;
6462
if (tx.IsCoinBase())
6563
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
66-
else
67-
{
64+
else {
6865
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
6966
in.push_back(Pair("vout", (int64_t)txin.prevout.n));
7067
Object o;
@@ -77,8 +74,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
7774
}
7875
entry.push_back(Pair("vin", vin));
7976
Array vout;
80-
for (unsigned int i = 0; i < tx.vout.size(); i++)
81-
{
77+
for (unsigned int i = 0; i < tx.vout.size(); i++) {
8278
const CTxOut& txout = tx.vout[i];
8379
Object out;
8480
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
@@ -90,15 +86,12 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
9086
}
9187
entry.push_back(Pair("vout", vout));
9288

93-
if (hashBlock != 0)
94-
{
89+
if (hashBlock != 0) {
9590
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
9691
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
97-
if (mi != mapBlockIndex.end() && (*mi).second)
98-
{
92+
if (mi != mapBlockIndex.end() && (*mi).second) {
9993
CBlockIndex* pindex = (*mi).second;
100-
if (chainActive.Contains(pindex))
101-
{
94+
if (chainActive.Contains(pindex)) {
10295
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
10396
entry.push_back(Pair("time", pindex->GetBlockTime()));
10497
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
@@ -244,11 +237,9 @@ Value listunspent(const Array& params, bool fHelp)
244237
nMaxDepth = params[1].get_int();
245238

246239
set<CBitcoinAddress> setAddress;
247-
if (params.size() > 2)
248-
{
240+
if (params.size() > 2) {
249241
Array inputs = params[2].get_array();
250-
BOOST_FOREACH(Value& input, inputs)
251-
{
242+
BOOST_FOREACH(Value& input, inputs) {
252243
CBitcoinAddress address(input.get_str());
253244
if (!address.IsValid())
254245
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+input.get_str());
@@ -262,13 +253,11 @@ Value listunspent(const Array& params, bool fHelp)
262253
vector<COutput> vecOutputs;
263254
assert(pwalletMain != NULL);
264255
pwalletMain->AvailableCoins(vecOutputs, false);
265-
BOOST_FOREACH(const COutput& out, vecOutputs)
266-
{
256+
BOOST_FOREACH(const COutput& out, vecOutputs) {
267257
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
268258
continue;
269259

270-
if (setAddress.size())
271-
{
260+
if (setAddress.size()) {
272261
CTxDestination address;
273262
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
274263
continue;
@@ -283,18 +272,15 @@ Value listunspent(const Array& params, bool fHelp)
283272
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
284273
entry.push_back(Pair("vout", out.i));
285274
CTxDestination address;
286-
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
287-
{
275+
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
288276
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
289277
if (pwalletMain->mapAddressBook.count(address))
290278
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
291279
}
292280
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
293-
if (pk.IsPayToScriptHash())
294-
{
281+
if (pk.IsPayToScriptHash()) {
295282
CTxDestination address;
296-
if (ExtractDestination(pk, address))
297-
{
283+
if (ExtractDestination(pk, address)) {
298284
const CScriptID& hash = boost::get<const CScriptID&>(address);
299285
CScript redeemScript;
300286
if (pwalletMain->GetCScript(hash, redeemScript))
@@ -351,8 +337,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
351337

352338
CMutableTransaction rawTx;
353339

354-
BOOST_FOREACH(const Value& input, inputs)
355-
{
340+
BOOST_FOREACH(const Value& input, inputs) {
356341
const Object& o = input.get_obj();
357342

358343
uint256 txid = ParseHashO(o, "txid");
@@ -369,8 +354,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
369354
}
370355

371356
set<CBitcoinAddress> setAddress;
372-
BOOST_FOREACH(const Pair& s, sendTo)
373-
{
357+
BOOST_FOREACH(const Pair& s, sendTo) {
374358
CBitcoinAddress address(s.name_);
375359
if (!address.IsValid())
376360
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+s.name_);
@@ -550,8 +534,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
550534
vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
551535
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
552536
vector<CMutableTransaction> txVariants;
553-
while (!ssData.empty())
554-
{
537+
while (!ssData.empty()) {
555538
try {
556539
CMutableTransaction tx;
557540
ssData >> tx;
@@ -590,12 +573,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
590573

591574
bool fGivenKeys = false;
592575
CBasicKeyStore tempKeystore;
593-
if (params.size() > 2 && params[2].type() != null_type)
594-
{
576+
if (params.size() > 2 && params[2].type() != null_type) {
595577
fGivenKeys = true;
596578
Array keys = params[2].get_array();
597-
BOOST_FOREACH(Value k, keys)
598-
{
579+
BOOST_FOREACH(Value k, keys) {
599580
CBitcoinSecret vchSecret;
600581
bool fGood = vchSecret.SetString(k.get_str());
601582
if (!fGood)
@@ -610,11 +591,9 @@ Value signrawtransaction(const Array& params, bool fHelp)
610591
#endif
611592

612593
// Add previous txouts given in the RPC call:
613-
if (params.size() > 1 && params[1].type() != null_type)
614-
{
594+
if (params.size() > 1 && params[1].type() != null_type) {
615595
Array prevTxs = params[1].get_array();
616-
BOOST_FOREACH(Value& p, prevTxs)
617-
{
596+
BOOST_FOREACH(Value& p, prevTxs) {
618597
if (p.type() != obj_type)
619598
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
620599

@@ -649,12 +628,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
649628

650629
// if redeemScript given and not using the local wallet (private keys
651630
// given), add redeemScript to the tempKeystore so it can be signed:
652-
if (fGivenKeys && scriptPubKey.IsPayToScriptHash())
653-
{
631+
if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
654632
RPCTypeCheck(prevOut, map_list_of("txid", str_type)("vout", int_type)("scriptPubKey", str_type)("redeemScript",str_type));
655633
Value v = find_value(prevOut, "redeemScript");
656-
if (!(v == Value::null))
657-
{
634+
if (!(v == Value::null)) {
658635
vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
659636
CScript redeemScript(rsData.begin(), rsData.end());
660637
tempKeystore.AddCScript(redeemScript);
@@ -670,8 +647,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
670647
#endif
671648

672649
int nHashType = SIGHASH_ALL;
673-
if (params.size() > 3 && params[3].type() != null_type)
674-
{
650+
if (params.size() > 3 && params[3].type() != null_type) {
675651
static map<string, int> mapSigHashValues =
676652
boost::assign::map_list_of
677653
(string("ALL"), int(SIGHASH_ALL))
@@ -691,12 +667,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
691667
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
692668

693669
// Sign what we can:
694-
for (unsigned int i = 0; i < mergedTx.vin.size(); i++)
695-
{
670+
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
696671
CTxIn& txin = mergedTx.vin[i];
697672
CCoins coins;
698-
if (!view.GetCoins(txin.prevout.hash, coins) || !coins.IsAvailable(txin.prevout.n))
699-
{
673+
if (!view.GetCoins(txin.prevout.hash, coins) || !coins.IsAvailable(txin.prevout.n)) {
700674
fComplete = false;
701675
continue;
702676
}
@@ -708,8 +682,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
708682
SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
709683

710684
// ... and merge in other signatures:
711-
BOOST_FOREACH(const CMutableTransaction& txv, txVariants)
712-
{
685+
BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
713686
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
714687
}
715688
if (!VerifyScript(txin.scriptSig, prevPubKey, mergedTx, i, STANDARD_SCRIPT_VERIFY_FLAGS, 0))

0 commit comments

Comments
 (0)