]> Git Repo - VerusCoin.git/commitdiff
Fixes #1960: z_getoperationstatus/result now includes operation details.
authorSimon <[email protected]>
Sat, 7 Jan 2017 15:41:42 +0000 (07:41 -0800)
committerSimon <[email protected]>
Tue, 17 Jan 2017 00:45:27 +0000 (16:45 -0800)
doc/payment-api.md
qa/rpc-tests/wallet_protectcoinbase.py
src/asyncrpcoperation.h
src/wallet/asyncrpcoperation_sendmany.cpp
src/wallet/asyncrpcoperation_sendmany.h
src/wallet/rpcwallet.cpp

index 3560add649e255ebc7dd72504f58ce24d0c98d51..69877e5db58d9a3fdd35e4daa7ff848d4485fee5 100644 (file)
@@ -89,6 +89,10 @@ Asynchronous calls return an OperationStatus object which is a JSON object with
   * code : number
   * message: error message
 
+Depending on the type of asynchronous call, there may be other key-value pairs.  For example, a z_sendmany operation will also include the following in an OperationStatus object:
+
+* params : an object containing the parameters to z_sendmany
+
 Currently, as soon as you retrieve the operation status for an operation which has finished, that is it has either succeeded, failed, or been cancelled, the operation and any associated information is removed.
 
 It is currently not possible to cancel operations.
index 5f0c285c0482ad343986b594f9562a89905a03c4..ddef5fdaf1ea1e7ccd00d2034f5acd294fd666a9 100755 (executable)
@@ -98,6 +98,14 @@ class WalletProtectCoinbaseTest (BitcoinTestFramework):
             else:
                 status = results[0]["status"]
                 errorString = results[0]["error"]["message"]
+
+                # Test that the returned status object contains a params field with the operation's input parameters
+                params =results[0]["params"]
+                assert_equal(params["fee"], Decimal('0.0001')) # default
+                assert_equal(params["minconf"], Decimal('1')) # default
+                assert_equal(params["fromaddress"], mytaddr)
+                assert_equal(params["amounts"][0]["address"], myzaddr)
+                assert_equal(params["amounts"][0]["amount"], Decimal('1.23456789'))
                 break
         assert_equal("failed", status)
         assert_equal("wallet does not allow any change" in errorString, True)
index bcfda892e21487f0ef0518253605584965a0a2ac..526a62ad0f8168016f5c25d5480f11aa343f990e 100644 (file)
@@ -66,7 +66,8 @@ public:
         return creation_time_;
     }
 
-    Value getStatus() const;
+    // Override this method to add data to the default status object.
+    virtual Value getStatus() const;
 
     Value getError() const;
     
index c65664eaeeba0d6117688fba0d2084417d26a9c8..c9b5b3ef244bf9dcd18241583881e7f05795b5f3 100644 (file)
@@ -51,8 +51,9 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
         std::vector<SendManyRecipient> tOutputs,
         std::vector<SendManyRecipient> zOutputs,
         int minDepth,
-        CAmount fee) :
-        fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee)
+        CAmount fee,
+        Value contextInfo) :
+        fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee), contextinfo_(contextInfo)
 {
     assert(fee_ > 0);
 
@@ -1089,4 +1090,18 @@ boost::array<unsigned char, ZC_MEMO_SIZE> AsyncRPCOperation_sendmany::get_memo_f
     return memo;
 }
 
+/**
+ * Override getStatus() to append the operation's input parameters to the default status object.
+ */
+Value AsyncRPCOperation_sendmany::getStatus() const {
+    Value v = AsyncRPCOperation::getStatus();
+    if (contextinfo_.is_null()) {
+        return v;
+    }
+
+    Object obj = v.get_obj();
+    obj.push_back(Pair("method", "z_sendmany"));
+    obj.push_back(Pair("params", contextinfo_ ));
+    return Value(obj);
+}
 
index 0382f0241739fcbd19b09681ff45c70c41555945..5108de8c5d904674b592f20c3a0950ded76c87e4 100644 (file)
@@ -50,7 +50,7 @@ struct WitnessAnchorData {
 
 class AsyncRPCOperation_sendmany : public AsyncRPCOperation {
 public:
-    AsyncRPCOperation_sendmany(std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth, CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE);
+    AsyncRPCOperation_sendmany(std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth, CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE, Value contextInfo = Value::null);
     virtual ~AsyncRPCOperation_sendmany();
     
     // We don't want to be copied or moved around
@@ -61,11 +61,15 @@ public:
     
     virtual void main();
 
+    virtual Value getStatus() const;
+
     bool testmode = false;  // Set to true to disable sending txs and generating proofs
 
 private:
     friend class TEST_FRIEND_AsyncRPCOperation_sendmany;    // class for unit testing
 
+    Value contextinfo_;     // optional data to include in return value from getStatus()
+
     CAmount fee_;
     int mindepth_;
     std::string fromaddress_;
index 6b0f5f5283155e3a90b7b1f96a5c7fdf6c3e6981..143c28f65ae607a496f3ec1980b504fe6f934c5b 100644 (file)
@@ -3353,9 +3353,17 @@ Value z_sendmany(const Array& params, bool fHelp)
         }
     }
 
+    // Use input parameters as the optional context info to be returned by z_getoperationstatus and z_getoperationresult.
+    Object o;
+    o.push_back(Pair("fromaddress", params[0]));
+    o.push_back(Pair("amounts", params[1]));
+    o.push_back(Pair("minconf", nMinDepth));
+    o.push_back(Pair("fee", std::stod(FormatMoney(nFee))));
+    Value contextInfo = Value(o);
+
     // Create operation and add to global queue
     std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
-    std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(fromaddress, taddrRecipients, zaddrRecipients, nMinDepth, nFee) );
+    std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(fromaddress, taddrRecipients, zaddrRecipients, nMinDepth, nFee, contextInfo) );
     q->addOperation(operation);
     AsyncRPCOperationId operationId = operation->getId();
     return operationId;
This page took 0.034242 seconds and 4 git commands to generate.