二期c++接口

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by Heng Well

Key.cpp

Committer:
webmaster
Date:
2017-11-03
Revision:
10:aabd720e632c

File content as of revision 10:aabd720e632c:

#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;
}