blockchain , sdchain cpp sdk and demo

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by SDchain C Plus Plus Team

Revision:
13:e77c7ae3a285
Parent:
12:1b24ea479a59
Child:
14:59412fcf8fa2
--- a/main.cpp	Wed May 16 13:46:01 2018 +0000
+++ b/main.cpp	Thu May 17 13:36:46 2018 +0000
@@ -172,6 +172,9 @@
     int iLedger = act.getLedger(objJson);
     bool bSuccess = act.getRequestRet(objJson);
     int iCurrenciesNum = act.getBalanceSize(objJson,"balances");
+    char pLedger[16] = {0};
+    sprintf(pLedger, "%d", iLedger);
+    cout<<"Ledger is :"<<pLedger<<endl;
     for (int i = 0; i < iCurrenciesNum; i++)
     {
         string value = act.getBalanceArray(objJson, "balances", i, "value");
@@ -277,11 +280,11 @@
         string direction = pay.getKeyValue(objJson, "direction");
         string timestamp = pay.getKeyValue(objJson, "timestamp");
         string fee = pay.getKeyValue(objJson, "fee");
-        cout << "hash:" << hash << " ledger:" << ledger << " state:" << state
-            << " source_account:" << source_account << " dst_account:" << dst_account
-            << " amount_cur:" << amount_cur << " value:" << value << " amount_issuer:" << amount_issuer
-            << " currency:" << currency << " issuer" << issuer << " direction" << direction
-            << " timestamp:" << timestamp << " fee" << fee;
+        cout << "hash:" << hash <<endl<<"ledger:" << ledger <<endl<< " state:" << state
+            <<endl<< " source_account:" << source_account <<endl<< " dst_account:" << dst_account
+            <<endl<< " amount_cur:" << amount_cur <<endl<< " value:" << value <<endl<< " amount_issuer:" << amount_issuer
+            <<endl<< " currency:" << currency <<endl<< " issuer" << issuer <<endl<< " direction" << direction
+            <<endl<< " timestamp:" << timestamp <<endl<< " fee" << fee <<endl;
         int iCurrenciesNum = pay.getBalanceSize(objJson, "memos");
         for (int i = 0; i < iCurrenciesNum; i++)
         {
@@ -333,7 +336,9 @@
         int inLedger = pay.getKeyValueInt(objJson, "transaction", "inLedger");
         int ledger_index = pay.getKeyValueInt(objJson, "transaction", "ledger_index");
         bool validated = pay.getKeyValueBool(objJson, "transaction", "validated");
-
+        cout<<"TransactionType:"<<TransactionType<<endl<<"Amount:"<<Amount<<endl<<"Fee:"<<Fee<<endl
+        <<"SigningPubKey:"<<SigningPubKey<<endl<<"TxnSignature:"<<TxnSignature<<endl
+        <<"Account:"<<Account<<endl<<"Destination:"<<Destination<<endl;
     }
     return 0;
 }
@@ -383,6 +388,9 @@
                 string memo_data = pay.getBalanceArray(objJson, "transaction", "memos", i, "memo_data");
                 cout << i << ":" << memo_type << "--" << memo_data << endl;
             }
+            cout<<"hash:"<<hash<<endl<<"ledger:"<<ledger<<endl<<"source_account:"<<source_account<<endl
+            <<"destination_account:"<<destination_account<<endl<<"currency:"<<currency<<endl<<"timestamp:"
+            <<timestamp<<endl;
         }
     }
     return 0;
@@ -427,7 +435,7 @@
         string complete_ledgers = serInfo.getKeyValue(objJson, "sdchaind_server_status", "complete_ledgers");
         string server_state = serInfo.getKeyValue(objJson, "sdchaind_server_status", "server_state");
         int reserve_base_sda = serInfo.getKeyValueInt(objJson, "sdchaind_server_status", "reserve_base_sda");
-        cout << "complete_ledgers:" << complete_ledgers << "server_state:" << server_state << "reserve_base_sda:" << reserve_base_sda << endl;
+        cout << "complete_ledgers:" << complete_ledgers <<endl<< "server_state:" << server_state<<endl << "reserve_base_sda:" << reserve_base_sda << endl;
     }
     return 0;
 }
@@ -448,6 +456,10 @@
     if (bSuccess)
     {
         bool connected = serInfo.getKeyValueBool(objJson, "connected");
+        if(connected)
+        {cout<<"server is running"<<endl;}
+        else
+        {cout<<"server  stopped"<<endl;}
     }
     return 0;
 }
@@ -480,11 +492,11 @@
             string currency_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "currency");
             string value_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "value");
             string counterparty_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "counterparty");
-            cout << "type:" << type << "currency_gets:" << currency_gets << "value_gets:" << value_gets
-                << "counterparty_gets:" << counterparty_gets << "currency_pays:" << currency_pays
-                << "value_pays:" << value_pays << "counterparty_pays:" << counterparty_pays << endl;
+            cout << "type:" << type <<endl<< "currency_gets:" << currency_gets <<endl<< "value_gets:" << value_gets<<endl
+                << "counterparty_gets:" << counterparty_gets <<endl<< "currency_pays:" << currency_pays<<endl
+                << "value_pays:" << value_pays <<endl<< "counterparty_pays:" << counterparty_pays << endl;
         }
-        cout << "ledger:" << ledger << "validated:" << validated << endl;
+        cout << "ledger:" << ledger <<endl<< "validated:" << validated << endl;
     }
     return 0;
 }
@@ -521,6 +533,7 @@
         string hash = orderCommit.getKeyValue(objJson, "hash");
         int ledger = orderCommit.getLedger(objJson);
         string state = orderCommit.getKeyValue(objJson, "state");
+        cout<<"account:"<<account<<endl<<"fee:"<<fee<<endl<<"hash:"<<hash<<endl<<"state:"<<state<<endl;
     }
     return 0;
 }
@@ -552,8 +565,8 @@
         string hash = orderCommit.getKeyValue(objJson, "hash");
         string ledger = orderCommit.getKeyValue(objJson, "ledger");
         string state = orderCommit.getKeyValue(objJson, "state");
-        cout << "account:" << account << "fee:" << fee << "offer_sequence:" << offer_sequence
-            << "sequence:" << sequence << "hash:" << hash << "ledger:" << ledger << "state:" << state << endl;
+        cout << "account:" << account <<endl<< "fee:" << fee <<endl<< "offer_sequence:" << offer_sequence<<endl
+            << "sequence:" << sequence <<endl<< "hash:" << hash <<endl<<"ledger:" << ledger <<endl<< "state:" << state << endl;
     }
     return 0;
 }
@@ -583,12 +596,15 @@
         for (int i = 0; i < iBalanceNum; i++)
         {
             string counterparty = orderInfo.getBalanceArray(objJson, "balance_changes", i, "counterparty");
+            cout<<"counterparty:"<<counterparty<<endl;
         }
         int iOrderChangesNum = orderInfo.getBalanceSize(objJson, "order_changes");
         for (int j = 0; j < iOrderChangesNum; j++)
         {
             string currency_gets = orderInfo.getBalanceArray(objJson, "order_changes", "taker_gets", j, "currency");
+            cout<<"currency_gets:"<<currency_gets<<endl;
         }
+        cout<<"hash:"<<hash<<endl;
 
     }
     cout << "call sd_queryorderdetailed end" << endl;
@@ -606,31 +622,55 @@
     //test_MockHsm();
    // test_Asset();
    // test_Account();
-
+    cout<<"**************************GET NEW WALLET****************************"<<endl;
     sd_wallet();
+    wait(2);
+    cout<<"**************************GET ACCOUNT BALANCE************************"<<endl;
     sd_account();
-    //sd_postpayment();
-    //sd_getpaymentinfo();
-    //sd_gettransactions();
-    //sd_getpaymenthistory();
-    //sd_getdefaultfee();
-    //sd_getserverinfo();
-    //sd_getserverconnected();
-    //sd_queryorderlist();
-    //sd_commitorder();
-    //sd_deleteorder();
-    //sd_queryorderdetailed();
+    wait(2);
+    cout<<"*************************POST PAYMENT REQUEST********************"<<endl;
+    sd_postpayment();
+    wait(2);
+    cout<<"*************************GET PAYMENT INFO****************"<<endl;
+    sd_getpaymentinfo();
+    wait(2);
+    cout<<"*************************GET TRANSACTIONS INFO***********"<<endl;
+    sd_gettransactions();
+    wait(2);
+    cout<<"*************************GET PAYMENT HISTORY*****************"<<endl;
+    sd_getpaymenthistory();
+    wait(2);
+    cout<<"*************************GET DEFAULT FEE**********************"<<endl;
+    sd_getdefaultfee();
+    wait(2);
+    cout<<"*************************GET SERVER INFO******************"<<endl;
+    sd_getserverinfo();
+    wait(2);
+    cout<<"*************************GET SERVER CONNECTED******************"<<endl;
+    sd_getserverconnected();
+    wait(2);
+    cout<<"*************************GET ORDER LIST********************"<<endl;
+    sd_queryorderlist();
+    wait(2);
+    cout<<"*************************POST ORDER INFO********************"<<endl;
+    sd_commitorder();
+    wait(2);
+    cout<<"*************************DELETE ORDER INFO********************"<<endl;
+    sd_deleteorder();
+    wait(2);
+    cout<<"*************************GET ORDER DETAILED*******************"<<endl;
+    sd_queryorderdetailed();
 
 
 
     //char isContinue = 'y';
    // do
     //{
-        string type = "spend_account";
+       //tring type = "spend_account";
         //string type = "issue";
         //test_transaction(type);
-        test_transaction();
-        printf("=============5========\n");
+       //est_transaction();
+       //rintf("=============5========\n");
    // }while(1);
     //}while (isContinue = getch() != 'q');