二期c++接口

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by Heng Well

Revision:
10:aabd720e632c
Parent:
9:d7468574ef8f
Child:
11:6d9cefb14158
--- a/main.cpp	Wed Sep 27 01:18:12 2017 +0000
+++ b/main.cpp	Fri Nov 03 01:07:32 2017 +0000
@@ -2,7 +2,6 @@
 #include "EthernetInterface.h"
 #include "SDFileSystem.h"
 #include <stdio.h>
-//#include <string.h>
 #include "uniqueCPUID.h"
 
 #include <iostream>  
@@ -10,6 +9,10 @@
 #include "UnitTest.h"
 //#include "BlockChain.h"
 #include "MockHsm.h"
+#include "Asset.h"
+#include "Transaction.h"
+#include "Account.h"
+#include "Key.h"
 
 using namespace std;  
 
@@ -19,6 +22,8 @@
 #define HTTPD_MAX_FNAME_LENGTH   127
 #define HTTPD_MAX_DNAME_LENGTH   127
 
+#define DEBUG_LOG 1
+
 const char* ECHO_SERVER_ADDRESS = "192.168.31.185";
 const int ECHO_SERVER_PORT = 10003;
 
@@ -49,15 +54,7 @@
 int socket_init();
 int socket_fini();
 
-int test_MockHsm()
-{
-    MockHsm mh;
-    mh.setAlias("cpp_key");
-    //cout<<mh.getAlias()<<endl;
-    //cout<<mh.createKey()<<endl;
-    cout<< mh.listKeys() <<endl;
-    return 0;
-}
+
 void test_uuid()
 {
     char pUUID[128] = {0};
@@ -66,17 +63,110 @@
     //printUniqueId(uart);
 }
 
+int test_MockHsm()
+{
+    MockHsm mh;
+    mh.setAlias("t_key_6");
+    cout<<mh.getAlias()<<endl;
+    cout<<mh.createKey()<<endl;
+    cout<< mh.listKeys() <<endl;
+    return 0;
+}
+
+int test_Asset()
+{
+    Asset asset;
+    asset.setAlias("t_asset_6");
+
+    cout<< asset.createAsset() << endl;
+    cout<< asset.listAssets() << endl;
+    
+    
+    return 0;
+}
+
+int test_Account()
+{
+    Key key;
+    key.setAlias("t_key");
+    key.listKeys();
+
+    Account act(key);
+    act.setAlias("t_acc_8");
+    act.createAccount();
+    act.listAccounts();
+
+    return 0;
+}
+
+int test_transaction(string type)
+{
+    Transaction ts;
+    //cout << ts.buildTransaction() << endl;
+    ts.buildTransaction(type);
+    ts.signTransaction();
+    ts.submitTransaction();
+    ts.listTransactions();
+    return 0;
+}
+
+int test_transaction()
+{
+    vector<Actions> vActions;
+    Actions act;
+    MbedJSONValue reference_data;
+
+    act.accounts_alias = "t_acc_1";
+    act.amount = 51;
+    act.asset_alias = "t_asset";
+    act.reference_data = reference_data;
+    act.type = "spend_account";
+    vActions.push_back(act);
+
+    Actions act1 = {"t_acc_2",  "t_asset", 49, reference_data, "spend_account"  };
+    Actions act2 = {"tom",      "t_asset", 80, reference_data, "control_account"};
+    Actions act3 = {"Jerry",    "t_asset", 20, reference_data, "control_account"};
+
+    vActions.push_back(act1);
+    vActions.push_back(act2);
+    vActions.push_back(act3);
+ printf("=============2========\r\n");
+    Transaction ts;
+    ts.buildTransaction(vActions);
+    ts.signTransaction();
+    ts.submitTransaction();
+    ts.listTransactions();
+
+    return 0;
+}
+
+
 int main(void)
 {
     printf("main start\n");
     
     test_uuid();
+
     
     socket_init();
     
     test_MockHsm();
+    test_Asset();
+    test_Account();
+
+    //char isContinue = 'y';
+   // do
+    //{
+        string type = "spend_account";
+        //string type = "issue";
+        //test_transaction(type);
+        test_transaction();
+        printf("=============5========\n");
+   // }while(1);
+    //}while (isContinue = getch() != 'q');
     
-    test_socket_client();
+    
+    //test_socket_client();
     
     socket_fini();