From f7cfb52d3cb24aa4c101ac2f8dde33bb6c394f1b Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 6 Oct 2016 18:55:14 -0700 Subject: [PATCH] Add vjoinsplit to JSON output of RPC call gettransaction --- qa/rpc-tests/wallet.py | 11 +++++- src/rpcrawtransaction.cpp | 73 +++++++++++++++++++++------------------ src/wallet/rpcwallet.cpp | 15 ++++++++ 3 files changed, 64 insertions(+), 35 deletions(-) diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 7f9541fb3..e4822c2f9 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -225,13 +225,17 @@ class WalletTest (BitcoinTestFramework): # send from node 0 to node 2 taddr mytaddr = self.nodes[2].getnewaddress(); - self.nodes[0].sendtoaddress(mytaddr, 10.0); + mytxid = self.nodes[0].sendtoaddress(mytaddr, 10.0); self.nodes[0].generate(1) self.sync_all() mybalance = self.nodes[2].z_getbalance(mytaddr) assert_equal(self.nodes[2].z_getbalance(mytaddr), Decimal('10.0')); + mytxdetails = self.nodes[2].gettransaction(mytxid) + myvjoinsplits = mytxdetails["vjoinsplit"] + assert_equal(0, len(myvjoinsplits)) + # add zaddr to node 2 myzaddr = self.nodes[2].z_getnewaddress() @@ -251,6 +255,7 @@ class WalletTest (BitcoinTestFramework): sleep(1) else: status = results[0]["status"] + mytxid = results[0]["result"]["txid"] break assert_equal("success", status) @@ -274,6 +279,10 @@ class WalletTest (BitcoinTestFramework): assert_equal(Decimal(resp["private"]), zsendmanynotevalue) assert_equal(Decimal(resp["total"]), node2utxobalance + zsendmanynotevalue) + # there should be at least one joinsplit + mytxdetails = self.nodes[2].gettransaction(mytxid) + myvjoinsplits = mytxdetails["vjoinsplit"] + assert_greater_than(len(myvjoinsplits), 0) # send from private note to node 0 and node 2 node0balance = self.nodes[0].getbalance() # 25.99794745 diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a5d74f22a..5cca9df9d 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -55,41 +55,8 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH out.push_back(Pair("addresses", a)); } -void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) -{ - entry.push_back(Pair("txid", tx.GetHash().GetHex())); - entry.push_back(Pair("version", tx.nVersion)); - entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); - Array vin; - BOOST_FOREACH(const CTxIn& txin, tx.vin) { - Object in; - if (tx.IsCoinBase()) - in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); - else { - in.push_back(Pair("txid", txin.prevout.hash.GetHex())); - in.push_back(Pair("vout", (int64_t)txin.prevout.n)); - Object o; - o.push_back(Pair("asm", txin.scriptSig.ToString())); - o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); - in.push_back(Pair("scriptSig", o)); - } - in.push_back(Pair("sequence", (int64_t)txin.nSequence)); - vin.push_back(in); - } - entry.push_back(Pair("vin", vin)); - Array vout; - for (unsigned int i = 0; i < tx.vout.size(); i++) { - const CTxOut& txout = tx.vout[i]; - Object out; - out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - out.push_back(Pair("n", (int64_t)i)); - Object o; - ScriptPubKeyToJSON(txout.scriptPubKey, o, true); - out.push_back(Pair("scriptPubKey", o)); - vout.push_back(out); - } - entry.push_back(Pair("vout", vout)); +Array TxJoinSplitToJSON(const CTransaction& tx) { Array vjoinsplit; for (unsigned int i = 0; i < tx.vjoinsplit.size(); i++) { const JSDescription& jsdescription = tx.vjoinsplit[i]; @@ -126,7 +93,45 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) vjoinsplit.push_back(joinsplit); } + return vjoinsplit; +} + +void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) +{ + entry.push_back(Pair("txid", tx.GetHash().GetHex())); + entry.push_back(Pair("version", tx.nVersion)); + entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); + Array vin; + BOOST_FOREACH(const CTxIn& txin, tx.vin) { + Object in; + if (tx.IsCoinBase()) + in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); + else { + in.push_back(Pair("txid", txin.prevout.hash.GetHex())); + in.push_back(Pair("vout", (int64_t)txin.prevout.n)); + Object o; + o.push_back(Pair("asm", txin.scriptSig.ToString())); + o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); + in.push_back(Pair("scriptSig", o)); + } + in.push_back(Pair("sequence", (int64_t)txin.nSequence)); + vin.push_back(in); + } + entry.push_back(Pair("vin", vin)); + Array vout; + for (unsigned int i = 0; i < tx.vout.size(); i++) { + const CTxOut& txout = tx.vout[i]; + Object out; + out.push_back(Pair("value", ValueFromAmount(txout.nValue))); + out.push_back(Pair("n", (int64_t)i)); + Object o; + ScriptPubKeyToJSON(txout.scriptPubKey, o, true); + out.push_back(Pair("scriptPubKey", o)); + vout.push_back(out); + } + entry.push_back(Pair("vout", vout)); + Array vjoinsplit = TxJoinSplitToJSON(tx); entry.push_back(Pair("vjoinsplit", vjoinsplit)); if (!hashBlock.IsNull()) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4bf5606ae..ab75ffb59 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -39,6 +39,8 @@ using namespace json_spirit; using namespace libzcash; +extern Array TxJoinSplitToJSON(const CTransaction& tx); + int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -92,6 +94,8 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); + + entry.push_back(Pair("vjoinsplit", TxJoinSplitToJSON(wtx))); } string AccountFromValue(const Value& value) @@ -1702,6 +1706,17 @@ Value gettransaction(const Array& params, bool fHelp) " }\n" " ,...\n" " ],\n" + " \"vjoinsplit\" : [\n" + " {\n" + " \"anchor\" : \"treestateref\", (string) Merkle root of note commitment tree\n" + " \"nullifiers\" : [ string, ... ] (string) Nullifiers of input notes\n" + " \"commitments\" : [ string, ... ] (string) Note commitments for note outputs\n" + " \"macs\" : [ string, ... ] (string) Message authentication tags\n" + " \"vpub_old\" : x.xxx (numeric) The amount removed from the transparent value pool\n" + " \"vpub_new\" : x.xxx, (numeric) The amount added to the transparent value pool\n" + " }\n" + " ,...\n" + " ],\n" " \"hex\" : \"data\" (string) Raw data for transaction\n" "}\n"