二期c++接口

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by Heng Well

Revision:
10:aabd720e632c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Key.cpp	Fri Nov 03 01:07:32 2017 +0000
@@ -0,0 +1,51 @@
+#include "Key.h"
+
+string Key::listKeys()
+{
+	string strJson = "";
+
+	MbedJSONValue val;
+
+	//serialize it into a JSON string
+	strJson = val.serialize();
+	if ("null" == strJson)
+	{
+		strJson = "{}";
+	}
+	//printf("json: %s\r\n", strJson.c_str());
+
+	string strRep = "";
+	string strUrl = "/mockhsm/list-keys";
+	client.http_post(strUrl,strJson,strRep);
+	//cout<< "HTTP Response:\n" << strRep.length() << endl << strRep.c_str() << endl;
+
+	//////////////////////////////////////////////////////////////////////////
+	// get http response content
+	string content = client.get_content(strRep);
+
+	// decode content json 
+	MbedJSONValue valRep;
+	parse(valRep,content.c_str());
+
+	int items = valRep["items"].size();
+	//valRep.hasMember();
+	string key_alias = getAlias();
+	string str;
+	for (int i = 0; i < items; i++)
+	{
+		string alias = "";
+		if (valRep["items"][i]["alias"].serialize() != "null")
+		{
+			 alias = valRep["items"][i]["alias"].get<std::string>();
+		}
+		
+
+		if (alias == key_alias)
+		{
+			string xpub = valRep["items"][i]["xpub"].get<std::string>();
+			setRootXpub(xpub);
+		}
+	}
+
+	return strJson;
+}
\ No newline at end of file