SDchain C Plus Plus Team / Mbed 2 deprecated bcsdk

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by Heng Well

MockHsm.cpp

Committer:
MrAI
Date:
2018-06-08
Revision:
17:82d09b5a9189
Parent:
10:aabd720e632c

File content as of revision 17:82d09b5a9189:

#include "MockHsm.h"
//#include "Uuid.h"

MockHsm::MockHsm()
{
// 	Uuid u;
// 	GUID guid = u.CreateGuid();
// 	string strUuid = u.GuidToString(guid);

	alias = "";
	client_token = "962cd39d-6496-4b23-a2c5-85e445069a12"; 
}

MockHsm::~MockHsm()
{
	alias = "";
	client_token = ""; 
}


string MockHsm::getAlias()
{
	return this->alias;
}

void MockHsm::setAlias(string newAlias)
{
	this->alias = newAlias;
}

string MockHsm::createKey()
{
	string strJson = "";

	MbedJSONValue val;

	//fill the object
	val["alias"] = this->alias;
	val["client_token"] = this->client_token;

	//serialize it into a JSON string
	strJson = val.serialize();
	printf("json: %s\r\n", strJson.c_str());

	string strRep = "";
	string strUrl = "/mockhsm/create-key";
	client.http_post(strUrl,strJson,strRep);
	//cout<< "HTTP Response:\n" << strRep.length() << endl << strRep.c_str() << endl;

	return strJson;
}

string MockHsm::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;

	return strJson;
}


string MockHsm::listTransactionFeeds()
{
	string strJson = "";

	MbedJSONValue val;

	strJson = val.serialize();
	if ("null" == strJson)
	{
		strJson = "{}";
	}

	string strRep = "";
	string strUrl = "/list-transaction-feeds";
	client.http_post(strUrl,strJson,strRep);

	return strJson;
}