blockchain , sdchain cpp sdk and demo

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by SDchain C Plus Plus Team

Revision:
10:aabd720e632c
Parent:
8:f2a567ee3a46
Child:
12:1b24ea479a59
--- a/Account.cpp	Wed Sep 27 01:18:12 2017 +0000
+++ b/Account.cpp	Fri Nov 03 01:07:32 2017 +0000
@@ -1,31 +1,116 @@
-/***********************************************************************
- * Module:  Account.h
- * Author:  Administrator
- * Modified: 2017Äê8ÔÂ18ÈÕ 11:06:20
- * Purpose: Declaration of the class Account
- * Comment: ÕË»§
- ***********************************************************************/
+#include "Account.h"
+#include "Uuid.h"
+
+
+Account::Account()
+{
+	this->id = "";
+	this->alias = "";
+	//this->tags = "{}";
+	this->quorum = 1;
+}
+
+Account::Account(Key  &key)
+{
+	this->id = "";
+	this->alias = "";
+	//this->tags = "{}";
+	this->quorum = 1;
+	this->m_Keys = key;
+}
+
+Account::~Account()
+{
+
+}
+
 
-#if !defined(__Account_Account_h)
-#define __Account_Account_h
-#include <string>
-#include <map>
-#include "Key.h"
-#include "Object.h"
-using namespace std;
+// ����
+// ע���˺�json�Ǹ�����[]
+string Account::createAccount()
+{
+	string strJson = "";
+
+	MbedJSONValue val;
+	MbedJSONValue valNull;
+	MbedJSONValue vals;
+
+	//fill the object
+	val["alias"] = this->alias;
+	val["tags"]  = valNull;
+	val["quorum"] = this->getQuorum();
+	for (int i=0; i<getQuorum(); i++)
+	{
+		// should be Key Get root_xpubs vector keys[i]
+		val["root_xpubs"][i] = "62b33131fff6493ce37cf86396984902932baaf08eb5260cc17a4138f0403e4f261a0569c75aeddfd8f09548b891b360a8e72a514c082826920d3f87e325ea9b";
+		//val["root_xpubs"][i] = m_Keys.getRootXpub();
+	}
+	Uuid u;
+	//GUID guid = u.CreateGuid();
+	//string strUuid = u.GuidToString(guid);
+	string strUuid = u.getUuid();
+
+// 	GUID guid = CreateGuid();
+// 	string strUuid = GuidToString(guid);
+
+	val["client_token"] = strUuid;//"17e48179-3500-48db-9335-b69d9af1117f";
 
-class Account
+	//serialize it into a JSON string
+	vals[0] = val;
+	strJson = vals.serialize();
+	if ("null" == strJson)
+	{
+		strJson = "{}";
+	}
+	//printf("json: %s\r\n", strJson.c_str());
+
+	string strRep = "";
+	string strUrl = "/create-account";
+	client.http_post(strUrl,strJson,strRep);
+
+	// get http response content
+	string content = client.get_content(strRep);
+
+	// decode content json 
+	MbedJSONValue valRep;
+	string err = parse(valRep,content.c_str());
+
+	int ret = 0;
+	ret = err.find("error");
+	if ( ret > 1)
+	{
+		return err;
+	}
+
+	id = valRep[0]["id"].get<std::string>();
+
+	return id;
+}
+
+string Account::listAccounts()
 {
-public:
-   std::string id;
-   std::string alias;
-   Key* keys;
-   int quorum;
-   map<std::string,Object> tags;
+	string strJson = "";
+
+	MbedJSONValue val;
+
+	//fill the object
+	if (!this->id.empty())
+	{
+		string filter = "id='" + this->id +"'";
+		val["filter"] = filter;
+	}	
 
-protected:
-private:
+	//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 = "/list-accounts";
+	client.http_post(strUrl,strJson,strRep);
 
-#endif
+	return strJson;
+}
\ No newline at end of file