hwelltech block chain cpp sdk
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed uniqueCPUID
Fork of bcsdk by
bcsdk 是 block chain sdk 的简写。它是由江苏恒为信息科技有限公司开发的 BlockChain 的 基于 mbed os 的 C++ 版本SDK,它能帮助开发者快速的在支持 mbed os 的芯片上开发 BlockChain 的应用。 bcsdk 的demo文件中包含了BlockChain中的 Key、Account、Asset、Transaction等方面的示例。其中: (1) Key 加密私钥是区块链上的主要授权机制。他们控制资产单位的发行和转让。 资产或帐户将定义发行或转移所需的单个密钥。 在 Key_test.cpp 中,我们实现了: 创建HSM密钥 键入密钥别名的名称(例如'gold','silver','bronze'),密钥别名是用于区分密钥的标签。
(2) Asset 资产是一种可以在区块链上发布的值类型。资产的所有单位均可互换,可以在各方之间直接交易,无需发行人参与。 在 Asset_test.cpp 中,我们实现了: 创建资产 键入资产别名的名称(例如'gold','silver','bronze'),资产别名是用于区分资产的标签。 选择“Key”键以使用现有的HSM密键,此密钥将用于此帐户中资产单位的发放和转移。
(3) Account 加帐户是恒为区块链核心平台中的一个对象,通过创建和跟踪控制程序来跟踪区块链上的资产的所有权。创建帐户时,您提供一个或多个“root”密钥和仲裁。 在 Account_test.cpp 中,我们实现了: 创建帐户 1 输入帐户别名的名称(例如'alice','bob'),帐户别名是用于区分帐户的标签。 2 键入名称以生成新的HSM密钥(例如'alice key','bob key'),此密钥将用于此帐户中资产单位的发放和转移。
(4) Transaction 交易包含一个或多个输入,以及一个或多个输出。恒为区块链核心平台的API允许您使用操作(包括发出,支出和返还)构建交易。 在 Transaction_test.cpp 中,我们实现了: 资产的交易 1 添加“账户支出”操作 2 为资产别名选择“Asset” 3 输入“100”作为金额 4 添加“使用帐户控制”操作 5 为帐户别名选择“Account” 6 为资产别名选择“Asset” 7 输入“100”作为金额 8 “提交”
UnitTest.cpp
- Committer:
- webmaster
- Date:
- 2017-11-03
- Revision:
- 10:aabd720e632c
- Parent:
- 8:f2a567ee3a46
File content as of revision 10:aabd720e632c:
#include "UnitTest.h" #include "BlockChain.h" int test_bc() { string strInfo = "POST /info HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ Content-Length: 2\n\ accept: application/json\n\ content-type: application/json\n\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ \n\ {}\n"; string strCreateKey = "POST /mockhsm/create-key HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ Content-Length: 77\n\ accept: application/json\n\ Origin: http://testbc.hwelltech.com\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Referer: http://testbc.hwelltech.com/dashboard/mockhsms/create\n\ Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\ \n\ {\"alias\":\"mbed_key_a1\",\"client_token\":\"a37b1fe0-d952-4e1e-a09f-d1fe2c9dc282\"}\n"; string strCreateAccount = "POST /create-account HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ Content-Length: 250\n\ accept: application/json\n\ Origin: http://testbc.hwelltech.com\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Referer: http://testbc.hwelltech.com/dashboard/accounts/create\n\ Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\ \n\ [{\"alias\":\"mbed_account_a1\",\"tags\":{},\"quorum\":1,\"root_xpubs\":[\"62b33131fff6493ce37cf86396984902932baaf08eb5260cc17a4138f0403e4f261a0569c75aeddfd8f09548b891b360a8e72a514c082826920d3f87e325ea9b\"],\"client_token\":\"641dc851-4bce-45d8-bedb-96766abff223\"}]\n"; string strCreateAsset = "POST /create-asset HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ Content-Length: 261\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n\ \n\ [{\"alias\":\"mbed_asset\",\"tags\":{},\"definition\":{},\"quorum\":1,\"root_xpubs\":[\"62b33131fff6493ce37cf86396984902932baaf08eb5260cc17a4138f0403e4f261a0569c75aeddfd8f09548b891b360a8e72a514c082826920d3f87e325ea9b\"],\"client_token\":\"de4bf755-1278-400d-9a16-bdca5ffaed0f\"}]\n"; string strListAssets = "POST /list-assets HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Accept-Language: zh-CN,zh;q=0.8\n\ Content-Length: 82\n\ \n\ {\"filter\":\"id='bd3b443fc05c2d1d6be7c27d6a34c98070efa178fc53d2ddcd444542ef5b7a8b'\"}\n"; string strCreateTransaction = "POST /build-transaction HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Accept-Language: zh-CN,zh;q=0.8\n\ Content-Length: 233\n\ \n\ [{\"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"; string strSignTransaction = "POST /mockhsm/sign-transaction HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Accept-Language: zh-CN,zh;q=0.8\n\ Content-Length: 1244\n\ \n\ {\"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"; string strCommitTransaction = "POST /submit-transaction HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Accept-Language: zh-CN,zh;q=0.8\n\ Content-Length: 1435\n\ \n\ {\"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"; string strListTransactions = "POST /list-transactions HTTP/1.1\n\ Host: testbc.hwelltech.com\n\ Connection: keep-alive\n\ accept: application/json\n\ 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\ authorization: Basic YmxvY2tnZW5lcmF0b3I6MTM3NzQzMDJlNTcyYmU4MWMxZmRmZjg2NGZiODA2Yjc2NjcxMzg5NzMwZjBjMDYwZDNlODExNTQ4OGRjNjQ2Mg==\n\ content-type: application/json\n\ Referer: http://testbc.hwelltech.com/dashboard/transactions/7e5f97a9295370f19e73ccbf3ae8eb66ee01a5551eb073b310aedbde360c0628\n\ Accept-Language: zh-CN,zh;q=0.8\n\ Content-Length: 82\n\ \n\ {\"filter\":\"id='7e5f97a9295370f19e73ccbf3ae8eb66ee01a5551eb073b310aedbde360c0628'\"}\n"; string strRep; strRep = ""; http_post_bc(strInfo,strRep); cout<<"#####strRep: "<<strRep.c_str()<<endl; strRep = ""; http_post_bc(strCreateKey,strRep); cout<<"#####strRep: "<<strRep.c_str()<<endl; strRep = ""; http_post_bc(strCreateAccount,strRep); cout<<"#####strRep: "<<strRep.c_str()<<endl; return 0; } int http_get() { // GET https://api.connector.mbed.com/endpoints/?type=helloworld HTTP/1.1 // HOST: https://api.connector.mbed.com // Content-Type: ; charset=UTF-8 // Connection: keep-alive // Pragma: no-cache // Cache-Control: no-cache // X-Requested-With: XMLHttpRequest return 0; }