blockchain , sdchain cpp sdk and demo

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by SDchain C Plus Plus Team

Committer:
webmaster
Date:
Thu Sep 21 02:09:04 2017 +0000
Revision:
8:f2a567ee3a46
Child:
16:50646cf2e9a0
test create asset;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
webmaster 8:f2a567ee3a46 1 #include "UnitTest.h"
webmaster 8:f2a567ee3a46 2 #include "BlockChain.h"
webmaster 8:f2a567ee3a46 3
webmaster 8:f2a567ee3a46 4 int test_bc()
webmaster 8:f2a567ee3a46 5 {
webmaster 8:f2a567ee3a46 6 string strInfo = "POST /info HTTP/1.1\n\
webmaster 8:f2a567ee3a46 7 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 8 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 9 Content-Length: 2\n\
webmaster 8:f2a567ee3a46 10 accept: application/json\n\
webmaster 8:f2a567ee3a46 11 content-type: application/json\n\
webmaster 8:f2a567ee3a46 12 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 13 \n\
webmaster 8:f2a567ee3a46 14 {}\n";
webmaster 8:f2a567ee3a46 15
webmaster 8:f2a567ee3a46 16 string strCreateKey = "POST /mockhsm/create-key HTTP/1.1\n\
webmaster 8:f2a567ee3a46 17 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 18 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 19 Content-Length: 77\n\
webmaster 8:f2a567ee3a46 20 accept: application/json\n\
webmaster 8:f2a567ee3a46 21 Origin: http://testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 22 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 23 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 24 content-type: application/json\n\
webmaster 8:f2a567ee3a46 25 Referer: http://testbc.hwelltech.com/dashboard/mockhsms/create\n\
webmaster 8:f2a567ee3a46 26 Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\
webmaster 8:f2a567ee3a46 27 \n\
webmaster 8:f2a567ee3a46 28 {\"alias\":\"mbed_key_a1\",\"client_token\":\"a37b1fe0-d952-4e1e-a09f-d1fe2c9dc282\"}\n";
webmaster 8:f2a567ee3a46 29
webmaster 8:f2a567ee3a46 30
webmaster 8:f2a567ee3a46 31
webmaster 8:f2a567ee3a46 32 string strCreateAccount = "POST /create-account HTTP/1.1\n\
webmaster 8:f2a567ee3a46 33 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 34 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 35 Content-Length: 250\n\
webmaster 8:f2a567ee3a46 36 accept: application/json\n\
webmaster 8:f2a567ee3a46 37 Origin: http://testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 38 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 39 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 40 content-type: application/json\n\
webmaster 8:f2a567ee3a46 41 Referer: http://testbc.hwelltech.com/dashboard/accounts/create\n\
webmaster 8:f2a567ee3a46 42 Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\
webmaster 8:f2a567ee3a46 43 \n\
webmaster 8:f2a567ee3a46 44 [{\"alias\":\"mbed_account_a1\",\"tags\":{},\"quorum\":1,\"root_xpubs\":[\"62b33131fff6493ce37cf86396984902932baaf08eb5260cc17a4138f0403e4f261a0569c75aeddfd8f09548b891b360a8e72a514c082826920d3f87e325ea9b\"],\"client_token\":\"641dc851-4bce-45d8-bedb-96766abff223\"}]\n";
webmaster 8:f2a567ee3a46 45
webmaster 8:f2a567ee3a46 46 string strCreateAsset = "POST /create-asset HTTP/1.1\n\
webmaster 8:f2a567ee3a46 47 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 48 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 49 Content-Length: 261\n\
webmaster 8:f2a567ee3a46 50 accept: application/json\n\
webmaster 8:f2a567ee3a46 51 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 52 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 53 content-type: application/json\n\
webmaster 8:f2a567ee3a46 54 Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\
webmaster 8:f2a567ee3a46 55 \n\
webmaster 8:f2a567ee3a46 56 [{\"alias\":\"mbed_asset\",\"tags\":{},\"definition\":{},\"quorum\":1,\"root_xpubs\":[\"62b33131fff6493ce37cf86396984902932baaf08eb5260cc17a4138f0403e4f261a0569c75aeddfd8f09548b891b360a8e72a514c082826920d3f87e325ea9b\"],\"client_token\":\"de4bf755-1278-400d-9a16-bdca5ffaed0f\"}]\n";
webmaster 8:f2a567ee3a46 57
webmaster 8:f2a567ee3a46 58 string strListAssets = "POST /list-assets HTTP/1.1\n\
webmaster 8:f2a567ee3a46 59 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 60 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 61 accept: application/json\n\
webmaster 8:f2a567ee3a46 62 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 63 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 64 content-type: application/json\n\
webmaster 8:f2a567ee3a46 65 Accept-Language: zh-CN,zh;q=0.8\n\
webmaster 8:f2a567ee3a46 66 Content-Length: 82\n\
webmaster 8:f2a567ee3a46 67 \n\
webmaster 8:f2a567ee3a46 68 {\"filter\":\"id='bd3b443fc05c2d1d6be7c27d6a34c98070efa178fc53d2ddcd444542ef5b7a8b'\"}\n";
webmaster 8:f2a567ee3a46 69
webmaster 8:f2a567ee3a46 70 string strCreateTransaction = "POST /build-transaction HTTP/1.1\n\
webmaster 8:f2a567ee3a46 71 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 72 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 73 accept: application/json\n\
webmaster 8:f2a567ee3a46 74 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 75 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 76 content-type: application/json\n\
webmaster 8:f2a567ee3a46 77 Accept-Language: zh-CN,zh;q=0.8\n\
webmaster 8:f2a567ee3a46 78 Content-Length: 233\n\
webmaster 8:f2a567ee3a46 79 \n\
webmaster 8:f2a567ee3a46 80 [{\"actions\":[{\"account_alias\":\"t_acc_1\",\"asset_alias\":\"t_asset\",\"amount\":123,\"reference_data\":{},\"type\":\"spend_account\"},{\"account_alias\":\"t_acc_2\",\"asset_alias\":\"t_asset\",\"amount\":123,\"reference_data\":{},\"type\":\"control_account\"}]}]\n";
webmaster 8:f2a567ee3a46 81
webmaster 8:f2a567ee3a46 82 string strSignTransaction = "POST /mockhsm/sign-transaction HTTP/1.1\n\
webmaster 8:f2a567ee3a46 83 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 84 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 85 accept: application/json\n\
webmaster 8:f2a567ee3a46 86 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 87 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 88 content-type: application/json\n\
webmaster 8:f2a567ee3a46 89 Accept-Language: zh-CN,zh;q=0.8\n\
webmaster 8:f2a567ee3a46 90 Content-Length: 1244\n\
webmaster 8:f2a567ee3a46 91 \n\
webmaster 8:f2a567ee3a46 92 {\"transactions\":[{\"raw_transaction\":\"07010700fae2ffd5e52b000101710187249e9a82f75589f67b6d3166454b8cca8882d7f74c456f4b8b14278f84f4ee4fa592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110c445012b766baa2029072ca3b5f2b3f77d28cc9cb44dbbfe54a03d9a9a95fb60aea517f296adb47d5151ad696c00c0027b7d010002014fa592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110c944012b766baa20754817056c29955a9787b7db7fe98b135d1adecc7986b4c957e57fd2b6da86225151ad696c00c00000014ea592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a1107b012b766baa20e10131cfd7c51d3f43c933fe1e7be4ff75860e6bcf3d1a495332305df95b067e5151ad696c00c0027b7d0000\",\"signing_instructions\":[{\"position\":0,\"asset_id\":\"a592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110\",\"amount\":8900,\"witness_components\":[{\"type\":\"signature\",\"quorum\":1,\"keys\":[{\"xpub\":\"eae173767ebfdf7ef6ee10ee4edcd9e809492b97b8a5f3135754924d54641d53337d717aff01468e9561d7b54c04f042f23aee956ec5135654cf111d1cb3fb9d\",\"derivation_path\":[\"014200000000000000\",\"6eea000000000000\"]}],\"signatures\":null}]}],\"local\":true,\"allow_additional_actions\":false}],\"xpubs\":[\"eae173767ebfdf7ef6ee10ee4edcd9e809492b97b8a5f3135754924d54641d53337d717aff01468e9561d7b54c04f042f23aee956ec5135654cf111d1cb3fb9d\"]}\n";
webmaster 8:f2a567ee3a46 93
webmaster 8:f2a567ee3a46 94 string strCommitTransaction = "POST /submit-transaction HTTP/1.1\n\
webmaster 8:f2a567ee3a46 95 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 96 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 97 accept: application/json\n\
webmaster 8:f2a567ee3a46 98 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 99 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 100 content-type: application/json\n\
webmaster 8:f2a567ee3a46 101 Accept-Language: zh-CN,zh;q=0.8\n\
webmaster 8:f2a567ee3a46 102 Content-Length: 1435\n\
webmaster 8:f2a567ee3a46 103 \n\
webmaster 8:f2a567ee3a46 104 {\"transactions\":[{\"raw_transaction\":\"07010700fae2ffd5e52b000101710187249e9a82f75589f67b6d3166454b8cca8882d7f74c456f4b8b14278f84f4ee4fa592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110c445012b766baa2029072ca3b5f2b3f77d28cc9cb44dbbfe54a03d9a9a95fb60aea517f296adb47d5151ad696c00c0027b7d670300407c1aa8c9e4795a3c7380cc569371d667a0002521f8c1305352463809e1aca463a07474c5f1a4075fbbb14fde77306cf1a7fa448f748aa02c70143d7d1452770a2320e52e1d2df43edd81ef65fd92430a390e42fa05b731aaf87eb5fecd8a74555b57ae8702014fa592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110c944012b766baa20754817056c29955a9787b7db7fe98b135d1adecc7986b4c957e57fd2b6da86225151ad696c00c00000014ea592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a1107b012b766baa20e10131cfd7c51d3f43c933fe1e7be4ff75860e6bcf3d1a495332305df95b067e5151ad696c00c0027b7d0000\",\"signing_instructions\":[{\"position\":0,\"asset_id\":\"a592bcb4e3aaaf2f6a7460ce61b708ea9289af5519be46d1481b83c1f237a110\",\"amount\":8900,\"witness_components\":[{\"type\":\"signature\",\"quorum\":1,\"keys\":[{\"xpub\":\"eae173767ebfdf7ef6ee10ee4edcd9e809492b97b8a5f3135754924d54641d53337d717aff01468e9561d7b54c04f042f23aee956ec5135654cf111d1cb3fb9d\",\"derivation_path\":[\"014200000000000000\",\"6eea000000000000\"]}],\"signatures\":[\"7c1aa8c9e4795a3c7380cc569371d667a0002521f8c1305352463809e1aca463a07474c5f1a4075fbbb14fde77306cf1a7fa448f748aa02c70143d7d1452770a\"]}]}],\"local\":true,\"allow_additional_actions\":false}]}\n";
webmaster 8:f2a567ee3a46 105
webmaster 8:f2a567ee3a46 106 string strListTransactions = "POST /list-transactions HTTP/1.1\n\
webmaster 8:f2a567ee3a46 107 Host: testbc.hwelltech.com\n\
webmaster 8:f2a567ee3a46 108 Connection: keep-alive\n\
webmaster 8:f2a567ee3a46 109 accept: application/json\n\
webmaster 8:f2a567ee3a46 110 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36\n\
webmaster 8:f2a567ee3a46 111 authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\
webmaster 8:f2a567ee3a46 112 content-type: application/json\n\
webmaster 8:f2a567ee3a46 113 Referer: http://testbc.hwelltech.com/dashboard/transactions/7e5f97a9295370f19e73ccbf3ae8eb66ee01a5551eb073b310aedbde360c0628\n\
webmaster 8:f2a567ee3a46 114 Accept-Language: zh-CN,zh;q=0.8\n\
webmaster 8:f2a567ee3a46 115 Content-Length: 82\n\
webmaster 8:f2a567ee3a46 116 \n\
webmaster 8:f2a567ee3a46 117 {\"filter\":\"id='7e5f97a9295370f19e73ccbf3ae8eb66ee01a5551eb073b310aedbde360c0628'\"}\n";
webmaster 8:f2a567ee3a46 118
webmaster 8:f2a567ee3a46 119 string strRep;
webmaster 8:f2a567ee3a46 120
webmaster 8:f2a567ee3a46 121 strRep = "";
webmaster 8:f2a567ee3a46 122 http_post_bc(strInfo,strRep);
webmaster 8:f2a567ee3a46 123 cout<<"#####strRep: "<<strRep.c_str()<<endl;
webmaster 8:f2a567ee3a46 124
webmaster 8:f2a567ee3a46 125 strRep = "";
webmaster 8:f2a567ee3a46 126 http_post_bc(strCreateKey,strRep);
webmaster 8:f2a567ee3a46 127 cout<<"#####strRep: "<<strRep.c_str()<<endl;
webmaster 8:f2a567ee3a46 128
webmaster 8:f2a567ee3a46 129 strRep = "";
webmaster 8:f2a567ee3a46 130 http_post_bc(strCreateAccount,strRep);
webmaster 8:f2a567ee3a46 131 cout<<"#####strRep: "<<strRep.c_str()<<endl;
webmaster 8:f2a567ee3a46 132
webmaster 8:f2a567ee3a46 133 return 0;
webmaster 8:f2a567ee3a46 134 }
webmaster 8:f2a567ee3a46 135
webmaster 8:f2a567ee3a46 136
webmaster 8:f2a567ee3a46 137 int http_get()
webmaster 8:f2a567ee3a46 138 {
webmaster 8:f2a567ee3a46 139 // GET https://api.connector.mbed.com/endpoints/?type=helloworld HTTP/1.1
webmaster 8:f2a567ee3a46 140 // HOST: https://api.connector.mbed.com
webmaster 8:f2a567ee3a46 141 // Content-Type: ; charset=UTF-8
webmaster 8:f2a567ee3a46 142 // Connection: keep-alive
webmaster 8:f2a567ee3a46 143 // Pragma: no-cache
webmaster 8:f2a567ee3a46 144 // Cache-Control: no-cache
webmaster 8:f2a567ee3a46 145 // X-Requested-With: XMLHttpRequest
webmaster 8:f2a567ee3a46 146 return 0;
webmaster 8:f2a567ee3a46 147 }
webmaster 8:f2a567ee3a46 148
webmaster 8:f2a567ee3a46 149