Skip to content

Commit 585b5db

Browse files
committed
Merge pull request #6036
f89b092 add rpc test for listunspents support for zero value txouts (Jonas Schnelli) 219953c Show zero value txouts in listunspent. (Gregory Maxwell)
2 parents c271304 + f89b092 commit 585b5db

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

qa/rpc-tests/wallet.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,33 @@ def run_test (self):
151151

152152
assert(txid1 in self.nodes[3].getrawmempool())
153153

154+
#check if we can list zero value tx as available coins
155+
#1. create rawtx
156+
#2. hex-changed one output to 0.0
157+
#3. sign and send
158+
#4. check if recipient (node0) can list the zero value tx
159+
usp = self.nodes[1].listunspent()
160+
inputs = [{"txid":usp[0]['txid'], "vout":usp[0]['vout']}]
161+
outputs = {self.nodes[1].getnewaddress(): 49.998, self.nodes[0].getnewaddress(): 11.11}
162+
163+
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
164+
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
165+
signedRawTx = self.nodes[1].signrawtransaction(rawTx)
166+
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex'])
167+
zeroValueTxid= decRawTx['txid']
168+
sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex'])
169+
170+
self.sync_all()
171+
self.nodes[1].generate(1) #mine a block
172+
self.sync_all()
173+
174+
unspentTxs = self.nodes[0].listunspent() #zero value tx must be in listunspents output
175+
found = False
176+
for uTx in unspentTxs:
177+
if uTx['txid'] == zeroValueTxid:
178+
found = True
179+
assert_equal(uTx['amount'], Decimal('0.00000000'));
180+
assert(found)
154181

155182
#do some -walletbroadcast tests
156183
stop_nodes(self.nodes)

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ Value listunspent(const Array& params, bool fHelp)
23012301
vector<COutput> vecOutputs;
23022302
assert(pwalletMain != NULL);
23032303
LOCK2(cs_main, pwalletMain->cs_wallet);
2304-
pwalletMain->AvailableCoins(vecOutputs, false);
2304+
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
23052305
BOOST_FOREACH(const COutput& out, vecOutputs) {
23062306
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
23072307
continue;

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const
14811481
/**
14821482
* populate vCoins with vector of available COutputs.
14831483
*/
1484-
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl) const
1484+
void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue) const
14851485
{
14861486
vCoins.clear();
14871487

@@ -1508,7 +1508,7 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
15081508
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
15091509
isminetype mine = IsMine(pcoin->vout[i]);
15101510
if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO &&
1511-
!IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue > 0 &&
1511+
!IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) &&
15121512
(!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i)))
15131513
vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO));
15141514
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
540540
//! check whether we are allowed to upgrade (or already support) to the named feature
541541
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
542542

543-
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const;
543+
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false) const;
544544
bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
545545

546546
bool IsSpent(const uint256& hash, unsigned int n) const;

0 commit comments

Comments
 (0)