From 0cf9d8944125bbc0a65fd4255f9f22ab033bc0d8 Mon Sep 17 00:00:00 2001 From: Mark Friedenbach Date: Sat, 4 Mar 2017 15:55:41 -0800 Subject: [PATCH] CA: Switch to standard CAsset::IsNull() API instead of comparing against CAset() --- src/amount.h | 1 + src/bitcoin-tx.cpp | 2 +- src/test/blind_tests.cpp | 2 +- src/wallet/rpcwallet.cpp | 16 ++++++++-------- src/wallet/wallet.cpp | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/amount.h b/src/amount.h index 282b990adc..bee4948ddc 100644 --- a/src/amount.h +++ b/src/amount.h @@ -42,6 +42,7 @@ struct CAsset { READWRITE(id); } + bool IsNull() const { return id.IsNull(); } void SetNull() { id.SetNull(); } unsigned char* begin() { return id.begin(); } diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index b53f2ae489..cbd4be1c36 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -272,7 +272,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn // extract and validate ASSET std::string strAsset = vStrOutAddrParts[2]; CAsset asset(uint256S(strAsset)); - if (asset == CAsset()) + if (asset.IsNull()) throw std::runtime_error("invalid TX output asset type"); // build standard output script via GetScriptForDestination() diff --git a/src/test/blind_tests.cpp b/src/test/blind_tests.cpp index d9e601f344..a0a7b3c8da 100644 --- a/src/test/blind_tests.cpp +++ b/src/test/blind_tests.cpp @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(naive_blinding_test) BOOST_CHECK(factor == uint256()); BOOST_CHECK(asset_factor == uint256()); - BOOST_CHECK(asset == CAsset()); + BOOST_CHECK(asset.IsNull()); BOOST_CHECK(pubkey == CPubKey()); BOOST_CHECK(amount == -1); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5eda1c51e8..dd597dcf5c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -73,17 +73,17 @@ UniValue PushAssetBalance(CAmountMap& balance, CWallet* wallet, std::string& str UniValue obj(UniValue::VOBJ); CAsset id = wallet->GetAssetFromLabel(strasset); std::string label = wallet->GetLabelFromAsset(CAsset(uint256S(strasset))); - if (strasset != "*" && (id == CAsset() && label == "")) { + if (strasset != "*" && (id.IsNull() && label == "")) { throw JSONRPCError(RPC_WALLET_ERROR, "Input does not match a known asset tag/label pair."); } - else if (id != CAsset()) { + else if (!id.IsNull()) { strasset = id.GetHex(); } if (strasset == "*") { for(std::map::const_iterator it = balance.begin(); it != balance.end(); ++it) { // Unknown assets - if (it->first == CAsset()) + if (it->first.IsNull()) continue; UniValue pair(UniValue::VOBJ); if (wallet->GetLabelFromAsset(it->first) != "") { @@ -500,7 +500,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request) CAsset id(uint256S(asset)); if (pwalletMain->GetLabelFromAsset(CAsset(uint256S(asset))) == "") id = pwalletMain->GetAssetFromLabel(asset); - if (id == CAsset()) + if (id.IsNull()) throw JSONRPCError(RPC_WALLET_ERROR, "Unknown or invalid asset id/label"); EnsureWalletIsUnlocked(); @@ -1016,7 +1016,7 @@ UniValue sendmany(const JSONRPCRequest& request) CAsset asset(uint256S(strasset)); if (pwalletMain->GetLabelFromAsset(CAsset(uint256S(strasset))) == "") asset = pwalletMain->GetAssetFromLabel(strasset); - if (asset == CAsset()) + if (asset.IsNull()) throw JSONRPCError(RPC_WALLET_ERROR, "Unknown or invalid asset id/label"); if (!address.IsValid()) @@ -1279,7 +1279,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) CAsset id(uint256S(asset)); if (asset != "*" && pwalletMain->GetLabelFromAsset(CAsset(uint256S(asset))) == "") id = pwalletMain->GetAssetFromLabel(asset); - if (asset != "*" && id == CAsset()) + if (asset != "*" && id.IsNull()) throw JSONRPCError(RPC_WALLET_ERROR, "Unknown or invalid asset id/label"); // Tally @@ -2651,7 +2651,7 @@ UniValue listunspent(const JSONRPCRequest& request) CAsset asset; if (assetstr != "*") { asset = pwalletMain->GetAssetFromString(assetstr); - if (asset == CAsset()) + if (asset.IsNull()) throw JSONRPCError(RPC_WALLET_ERROR, "Unknown or invalid asset id/label"); } @@ -2673,7 +2673,7 @@ UniValue listunspent(const JSONRPCRequest& request) CAmount nValue = out.tx->GetValueOut(out.i); CAsset assetid = out.tx->GetAsset(out.i); - if (nValue == -1 || assetid == CAsset()) + if (nValue == -1 || assetid.IsNull()) continue; if (assetstr != "*" && asset != assetid) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0d7c56e0a4..cdc4f50796 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2627,7 +2627,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt unsigned int nSubtractFeeFromAmount = 0; for (const auto& recipient : vecSend) { - if (mapValue[recipient.asset] < 0 || recipient.nAmount < 0 || recipient.asset == CAsset()) + if (mapValue[recipient.asset] < 0 || recipient.nAmount < 0 || recipient.asset.IsNull()) { strFailReason = _("Transaction amounts must not be negative"); return false; @@ -2953,7 +2953,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt for (unsigned int i = 0; i< vAmounts.size(); i++) { assert((output_pubkeys[i] == CPubKey())==(output_blinds[i] == uint256())); assert((output_pubkeys[i] == CPubKey())==(output_asset_blinds[i] == uint256())); - assert(output_assets[i] != CAsset()); + assert(!output_assets[i].IsNull()); wtxNew.SetBlindingData(i, vAmounts[i], output_pubkeys[i], output_blinds[i], output_assets[i], output_asset_blinds[i]); }