blockchain , sdchain cpp sdk and demo
Dependencies: EthernetInterface mbed-rtos mbed uniqueCPUID
Fork of bcsdk by
Diff: main.cpp
- Revision:
- 15:7ec76c840343
- Parent:
- 14:59412fcf8fa2
--- a/main.cpp Wed May 23 02:40:40 2018 +0000 +++ b/main.cpp Wed Jun 06 06:14:09 2018 +0000 @@ -3,6 +3,7 @@ //#include "SDFileSystem.h" #include <stdio.h> #include "uniqueCPUID.h" +#include <sstream> // header of stringsteam #include <iostream> #include <string> @@ -144,8 +145,30 @@ } +// cover int to string +void int2str(const int &int_temp,string &string_temp) +{ + stringstream stream; + stream<<int_temp; + string_temp=stream.str(); //此处也可以用 stream>>string_temp +} -int sd_account() +// cover string to int +void str2int(int &int_temp,const string &string_temp) +{ + stringstream stream(string_temp); + stream>>int_temp; +} + +// cover string to long +void str2long(long &long_temp,const string &string_temp) +{ + stringstream stream(string_temp); + stream>>long_temp; +} + + +long sd_account() { string balance = ""; Account act; @@ -175,6 +198,7 @@ char pLedger[16] = {0}; sprintf(pLedger, "%d", iLedger); cout<<"Ledger is :"<<pLedger<<endl; + long sda = 0; for (int i = 0; i < iCurrenciesNum; i++) { string value = act.getBalanceArray(objJson, "balances", i, "value"); @@ -182,8 +206,9 @@ string counterparty = act.getBalanceArray(objJson, "balances", i, "counterparty"); cout << "The " << i <<" record:" << endl << "value:" << value << endl << "currency:"<<currency<<endl << "counterparty:" << counterparty << endl; + if("SDA" == currency) str2long(sda,value); } - return 0; + return sda; } int sd_wallet() @@ -614,78 +639,7 @@ cout << "call sd_queryorderdetailed end" << endl; return 0; } -int main(void) -{ - printf("main start\n"); - - // test_uuid(); - - socket_init(); - - //test_MockHsm(); - // test_Asset(); - // test_Account(); - cout<<"**************************GET NEW WALLET****************************"<<endl; - sd_wallet(); - wait(2); - cout<<"**************************GET ACCOUNT BALANCE************************"<<endl; - sd_account(); - 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 - //{ - //tring type = "spend_account"; - //string type = "issue"; - //test_transaction(type); - //est_transaction(); - //rintf("=============5========\n"); - // }while(1); - //}while (isContinue = getch() != 'q'); - - - //test_socket_client(); - - socket_fini(); - - printf("main end\n"); - return 0; -} int socket_init() { @@ -915,4 +869,95 @@ eth.disconnect(); while(true) {} +} + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); + +int main(void) +{ + printf("main start\n"); + + // test_uuid(); + + + socket_init(); + + // cout<<"**************************GET NEW WALLET****************************"<<endl; + // sd_wallet(); + // wait(2); + cout<<"**************************GET ACCOUNT BALANCE************************"<<endl; + while(1) + { + long balance = sd_account(); + wait(2); + if(balance > 2000000) + { + myled1 = 1; + myled2 = 0; + myled3 = 0; + } + else + { + myled1 = 0; + myled2 = 1; + myled3 = 0; + } + } + + /* + 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 + //{ + //tring type = "spend_account"; + //string type = "issue"; + //test_transaction(type); + //est_transaction(); + //rintf("=============5========\n"); + // }while(1); + //}while (isContinue = getch() != 'q'); + + + //test_socket_client(); + + socket_fini(); + + printf("main end\n"); + return 0; } \ No newline at end of file