]> Git Repo - VerusCoin.git/commitdiff
[REST] add /rest/chaininfos
authorJonas Schnelli <[email protected]>
Sat, 27 Dec 2014 12:18:36 +0000 (13:18 +0100)
committerJonas Schnelli <[email protected]>
Mon, 29 Dec 2014 19:19:48 +0000 (20:19 +0100)
qa/rpc-tests/rest.py
src/rest.cpp

index 704d889739faf56a42e96c2dcc49ea8f953ca8ed..a9d41cf367273d5ad126eda937fa864541f1eeee 100755 (executable)
@@ -78,7 +78,7 @@ class RESTTest (BitcoinTestFramework):
 
         # check hex format response
         hex_string = http_get_call(url.hostname, url.port, '/rest/tx/'+tx_hash+self.FORMAT_SEPARATOR+"hex", True)
-        assert_equal(response.status, 200)
+        assert_equal(hex_string.status, 200)
         assert_greater_than(int(response.getheader('content-length')), 10)
 
         # check block tx details
@@ -106,5 +106,12 @@ class RESTTest (BitcoinTestFramework):
         for tx in txs:
             assert_equal(tx in json_obj['tx'], True)
 
+        #test rest bestblock
+        bb_hash = self.nodes[0].getbestblockhash()
+        
+        json_string = http_get_call(url.hostname, url.port, '/rest/chaininfo.json')
+        json_obj = json.loads(json_string)
+        assert_equal(json_obj['bestblockhash'], bb_hash)
+
 if __name__ == '__main__':
     RESTTest ().main ()
index 4702f0d707019d317f83d04be4f39cd99c3c64c5..c9535c3b45445960bfb442c533a9aa92d4080d16 100644 (file)
@@ -95,7 +95,7 @@ static bool rest_headers(AcceptedConnection* conn,
                          bool fRun)
 {
     vector<string> params;
-    enum RetFormat rf = ParseDataFormat(params, strReq);
+    const RetFormat rf = ParseDataFormat(params, strReq);
     vector<string> path;
     boost::split(path, params[0], boost::is_any_of("/"));
 
@@ -159,7 +159,7 @@ static bool rest_block(AcceptedConnection* conn,
                        bool showTxDetails)
 {
     vector<string> params;
-    enum RetFormat rf = ParseDataFormat(params, strReq);
+    const RetFormat rf = ParseDataFormat(params, strReq);
 
     string hashStr = params[0];
     uint256 hash;
@@ -226,13 +226,39 @@ static bool rest_block_notxdetails(AcceptedConnection* conn,
     return rest_block(conn, strReq, mapHeaders, fRun, false);
 }
 
+static bool rest_chaininfo(AcceptedConnection* conn,
+                                   const std::string& strReq,
+                                   const std::map<std::string, std::string>& mapHeaders,
+                                   bool fRun)
+{
+    vector<string> params;
+    const RetFormat rf = ParseDataFormat(params, strReq);
+    
+    switch (rf) {
+    case RF_JSON: {
+        Array rpcParams;
+        Value chainInfoObject = getblockchaininfo(rpcParams, false);
+        
+        string strJSON = write_string(chainInfoObject, false) + "\n";
+        conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
+        return true;
+    }
+    default: {
+        throw RESTERR(HTTP_NOT_FOUND, "output format not found (available: json)");
+    }
+    }
+    
+    // not reached
+    return true; // continue to process further HTTP reqs on this cxn
+}
+
 static bool rest_tx(AcceptedConnection* conn,
                     const std::string& strReq,
                     const std::map<std::string, std::string>& mapHeaders,
                     bool fRun)
 {
     vector<string> params;
-    enum RetFormat rf = ParseDataFormat(params, strReq);
+    const RetFormat rf = ParseDataFormat(params, strReq);
 
     string hashStr = params[0];
     uint256 hash;
@@ -287,6 +313,7 @@ static const struct {
       {"/rest/tx/", rest_tx},
       {"/rest/block/notxdetails/", rest_block_notxdetails},
       {"/rest/block/", rest_block_extended},
+      {"/rest/chaininfo", rest_chaininfo},
       {"/rest/headers/", rest_headers},
 };
 
This page took 0.030943 seconds and 4 git commands to generate.