当前位置:党团工作 > BUMO,区块链开发文档x

BUMO,区块链开发文档x

时间:2025-08-02 05:18:33 浏览次数:

 BUMO 区块链开发文档 • BUMO 区块链开发文档 – 基础知识 了解 protocol buffer3 protocol buffer 3 和 json websocket 和 http 端口配置 交易执行的基本过程 • 试一试 – HTTP 接口 生成公私钥对-测试用 账号基本信息 询资产 询 metadata 交易 缓存队列交易 查询区块头 提交交易 序列化交易 调用合约 • 评估费用 – 定义交易 交易的基本结构 • 操作 操作码 创建账号 发行 转移资产 置 metadata 设置权限 转移 BU 资产 – 记录日志 – 高级功能 • 控制权的分配

 版本化控制 • 合约(推荐使用新的接口)

 语法说明 函数 内置变量 – 异常处理(推荐使用新的接口)

 • 验证者节点创建选举合约账户 申请成为验证节点候选人 对验证节点候选人申请者投票 收回押金 废止恶意节点 取消废止恶意节点 对废止恶意节点投票 – 查询功能 • 费用选举合约 结构 费用种类 历史费用 查询费用提案 提案 – 费用选举 错误码 – 示例 基础知识 了解 protocol buffer3 BUMO 区块链是用 protocol buffer 3 序列化数据的,protocol buffer 3 是 google 推出的数据序列化协议,您如果不了解 protocol buffer 3,请点击https://developers.google.com/protocol-buffers/docs/proto3 了解更多。

 我们使用的所有数据格式都能在源码的 src\proto 目录中找到。其中 chain.proto 文件中定义的数据是和交易、区块、账号密切相关的。

 protocol buffer 3 和 和 json http 接口中的数据都是 json 格式的,这些格式都是由 protocolbuffer 自动转化的。由于 json 中无法直接使用不可见字符, 凡是 protocolbuffer 结构定义中为 bytes 的,在 json 中都是 16 进制格式。

 websocket 和 和 http BUMO 区块链提供了 websocket 和 http 两种 API 接口。您可以在 安装目录/config/bumo.json 文件种找到 "webserver" 和 "wsserver" 两个对象,它们指定了http 服务端口和 websocket 服务端口。

  "webserver":

 {

 "listen_addresses": "0.0.0.0:36002"

 },

 "wsserver":

 {

 "listen_address": "0.0.0.0:36003"

 }

 端口配置 网络类型 网络 ID(network_id)

 WebServer P2P WebSocket mainnet 1 1 11 testnet 2 2 22 内测版本 30000 36002 36001 36003 交易执行的基本过程 1 根据意愿组装交易对象 Transaction

 2 交易对象序列化(protocol buffer 3 格式)为字节流 transaction_blob

 3 用私钥 skey 对 transaction_blob 签名得到 sign_data , skey 的公钥为 pkey

 4 提交交易,见提交交易 5. 查询以确定交易是否成功或接收推送(websocket API)判断交易是否成功 试一试 如果您的区块链刚刚部署完成,那么目前区块链系统中只有创世账号。您可以通过http 接口查询创世账号 HTTP GET host:36002/getGenesisAccount

 您会得到类似这样的返回内容 {

  "error_code" : 0,

  "result" : {

 "address" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3",

 "assets" : null,

 "balance" : 100000000000000000,

 "metadatas" : null,

 "priv" : {

  "master_weight" : 1,

  "thresholds" : {

 "tx_threshold" : 1

  }

 }

  }

 }

 返回结果中的 address 的值就是创世账号。

 您还可以通过查询账号接口查询任意账号 HTTP GET host:36002/getAccount?address=buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3

 HTTP 接口 生成公私钥对- 测试用 HTTP GET /createKeyPair

 功能:该接口只为方便测试使用, 请勿在生产环境使用该接口(生产环境下请用SDK 或者命令行生成),因为调用该接口后,如果节点服务器作恶会导致账户私钥泄露。该接口仅产生一个公私钥对,不会写入全网区块链。如需要上链,需对该新账号执行任意一次创建账号、转移资产、转移 BU 资产操作。

 返回内容 {

  "error_code" : 0,

  "result" : {

 "address" : "buQqRgkmtckz3U4kX91F2NmZzJ9rkadjYaa2",

 //账户地址

 "private_key" : "privbtnSGRQ46FF3MaqiGiDNytz2soFw4iNHKahTqszR6mRrmq7qhVYh",

 //账户私钥

 "private_key_aes" : "7594a97bc5e6432704cc5f58ff60727ee9bda10a6117915d025553afec7f81527cb857b882b7c775391fe1fe3f7f3ec198ea69ada138b19cbe169a1a3fa2dec8",

 //AES 加密账户私钥之后的数据

 "public_key" : "b00101da11713eaad86ad8ededfc28e86b8cd619ca2d593a21d8b82da34320a7e63b09c279bc", //账户公钥

 "public_key_raw" : "01da11713eaad86ad8ededfc28e86b8cd619ca2d593a21d8b82da34320a7e63b",

 //公钥排除前缀和后缀后的数据

 "sign_type" : "ed25519"

 //账户加密类型

  }

 }

 查询账号 HTTP GET /getAccount?address=buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3&key=hello&code=xxx&issuer=xxx

 功能:返回指定账号的信息及其所有资产、metadata 参数 描述 address 账号地址, 必填

 key 账号的 metadata 中指定的 key 的值,如果不填写,那么返回结果中含有所有的 metadata code, issuer,type 资产代码,资产发行商。这两个变量要么同时填写,要么同时不填写。若不填写,返回的结果中包含所有的资产。若填写,返回的结果中只显示由 code 和 issuer,type 指定的资产。目前 type 只能是0,可以不用填写 返回内容 {

 "error_code" : 0,

 "result" : {

 "address" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3", //该账号的地址

 "assets" : [//该账号的所有资产

 {

 "amount" : 1400,

 "key" :

 {

 "code" : "CNY",

 "issuer" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

 }, {

 "amount" : 1000,

 "key" :

 {

 "code" : "USD",

 "issuer" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

 }

 ],

 "assets_hash" : "9696b03e4c3169380882e0217a986717adfc5877b495068152e6aa25370ecf4a",

 "contract" : null,

 "metadatas" : [//该账号的所有 metadata

 {

 "key" : "123",

 "value" : "123_value",

 "version" : 1

 }, {

 "key" : "456",

 "value" : "456_value",

 "version" : 1

 }, {

 "key" : "abcd",

 "value" : "abcd_value",

 "version" : 1

 }

 ],

 "nonce" : 1, //账号当前作为交易源执行过的交易数量。若 nonce 为 0,该字段不显示

 "priv" : {

 "master_weight" : 1,

 "thresholds" : {

 "tx_threshold" : 1

 }

 },

 "metadatas_hash" : "82c8407cc7cd77897be3100c47ed9d43ec4097ee1c00e2c13447187e5b1ac66c"

 }

 }

 • 如果该账号不存在,则返回内容 {

  "error_code" : 4,

  "result" : null

 }

 查询账号基本信息 HTTP GET /getAccountBase?address=buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3

 • 返回指定账号的基本信息 参数 描述 address 账号地址, 必填 返回内容 {

 "error_code" : 0,

 "result" : {

 "address" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3", //该账号的地址

 "assets_hash" : "9696b03e4c3169380882e0217a986717adfc5877b495068152e6aa25370ecf4a",

 "balance" : 899671600,

 "contract" : null,

 "nonce" : 1, //账号当前作为交易源执行过的交易数量。若 nonce 为 0,该字段不显示

 "priv" : {

 "master_weight" : 1,

 "thresholds" : {

 "tx_threshold" : 1

 }

 },

 "metadatas_hash" : "82c8407cc7cd77897be3100c47ed9d43ec4097ee1c00e2c13447187e5b1ac66c"

 }

 }

 • 如果该账号不存在,则返回内容 {

  "error_code" : 4,

  "result" : null

 }

 查询资产 HTTP GET /getAccountAssets?address=buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3

 • 返回指定账号的资产信息 参数 描述 address 账号地址, 必填 code, issuer issuer 表示资产发行账户地址,code 表示资产代码。只有同时填写正确 code&issuer 才能正确显示指定资产否则默认显示所有资产。type 指定的资产。

 选填 type 目前 type 只能是 0,可以不用填写 返回内容 {

 "error_code" : 0,

 "result": [

 {

 "amount" : 1400,

 "key" :

 {

 "code" : "CNY",

 "issuer" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

 },

 {

 "amount" : 1000,

 "key" :

 {

 "code" : "USD",

 "issuer" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

 }

 ]

 }

 • 如果该账号不存在资产,则返回内容 {

  "error_code" : 0,

  "result" : null

 }

 查询 metadata HTTP GET /getAccountMetaData?address=buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3

 • 返回指定账号的 MetaData 信息 参数 描述 address 账号地址, 必填 key 指定 metadata 中的 key 值。

 选填 返回内容 {

 "error_code" : 0,

 "result": {

 "123": {

 "key" : "123",

 "value" : "123_value",

 "version" : 1

 },

 "456": {

 "key" : "456",

 "value" : "456_value",

 "version" : 1

 },

 "abcd": {

 "key" : "abcd",

 "value" : "abcd_value",

 "version" : 1

 }

 }

 }

 • 如果该账号不存在 metadata,则返回内容 {

  "error_code" : 0,

  "result" : null

 }

 查询交易 GET /getTransactionHistory?ledger_seq=6

 参数 描述 hash 用交易的唯一标识 hash 查询 ledger_seq 查询指定区块中的所有交易

 上述两个参数产生的约束条件是逻辑与的关系,如果您同时指定两个参数,系统将在指定的区块中查询指定的交易

  返回示例 {

 "error_code": 0,

 "result": {

 "total_count": 2,

 "transactions": [{

 "actual_fee": 313000,

 "close_time": 1524031260097214,

 "error_code": 0,

 "error_desc": "",

 "hash": "89a9d6e5d2c0e2b5c4fe58045ab2236d12e9449ef232342a48a2e2628e12014d",

 "ledger_seq": 6,

 "signatures": [{

 "public_key": "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",

 "sign_data": "27866d70a58fc527b1ff1b4a693b8034b0078fc7ac7591fb05679abe5ca660db5c372922bfa8f26e76511e2c33386306ded7593874a6aec5baeeaddbd2012f06"

 }],

 "transaction": {

 "fee_limit": 10000000000,

 "gas_price": 1000,

 "nonce": 1,

 "operations": [{

 "create_account": {

 "dest_address": "buQBAfoMfXZVPpg9DaabMmM2EwUnfoVsTSVV",

 "init_balance": 10000000,

 "priv": {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 1

 }

 }

 },

 "type": 1

 },

 {

 "create_account": {

 "dest_address": "buQj8UyKbN3myVSerLDVXVXH47vWXfqtxKLm",

 "init_balance": 10000000,

 "priv": {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 1

 }

 }

 },

 "type": 1

 }],

 "source_address": "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 },

 "tx_size": 313

 },

 {

 "actual_fee": 313000,

 "close_time": 1524031260097214,

 "error_code": 0,

 "error_desc": "",

 "hash": "7d7cfc860acfd83865d01bb655ac772113833f0769264d6392c6220024b8f93f",

 "ledger_seq": 6,

 "signatures": [{

 "public_key": "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",

 "sign_data": "fb7d9d87f4c9140b6e19a199091c6871e2380ad8e8a8fcada9b42a2911057111dc796d731f3f887e600aa89cc8692300f980723298a93b91db711155670d3e0d"

 }],

 "transaction": {

 "fee_limit": 10000000000,

 "gas_price": 1000,

 "nonce": 2,

 "operations": [{

 "create_account": {

 "dest_address": "buQntAvayDWkAhPh6CSrTWbiEniAL2ys5m2p",

 "init_balance": 10000000,

 "priv": {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 1

 }

 }

 },

 "type": 1

 },

 {

 "create_account": {

 "dest_address": "buQX5X9y59zbmqyFgFPQPcyUPcPnvwsLatsq",

 "init_balance": 10000000,

 "priv": {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 1

 }

 }

 },

 "type": 1

 }],

 "source_address": "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 },

 "tx_size": 313

 }]

 }

 }

 如果没有查到交易则返回 {

 "error_code": 4,

 "result":

 {

 "total_count": 0,

 "transactions": []

 }

 }

 查询缓存队列交易 GET /getTransactionCache?hash=ad545bfc26c440e324076fbbe1d8affbd8a2277858dc35927d425d0fe644e698&limit=100

 参数 描述 hash 用交易的唯一标识 hashlimit 查询交易队列前 N 个正在处理的交易 上述两个参数产生的约束条件是逻辑或的关系,如果您同时指定两个参数,系统将 hash 查询

  返回示例 {

 "error_code": 0,

 "result": {

 "total_count": 1,

 "transactions": [

 {

 "hash": "a336c8f4b49c8b2c5a6c68543368ed3b450b6138a9f878

 892cf982ffb6fe234e",

 "incoming_time": 1521013029435154,

 "signatures": [

 {

 "public_key": "b001882b9d1b5e7019f163d001c85194cface61e294483710f5e66ef40a4d387f5fcb0166f4f",

 "sign_data": "c5885144ffccb0b434b494271258e846c30a4551036e483822ee2b57400576e9e700e8960eb424764d033a2e73af6e6a2bfa5da390f71161732e13beee206107"

 }

 ],

 "status": "processing",

 "transaction": {

 "fee_limit": 100000,

 "gas_price": 1000,

 "nonce": 2,

 "operations": [

 {

 "create_account": {

 "dest_address": "buQWufKdVicxRAqmQs6m1Z9QuFZG2W7LMsi2",

 "init_balance": 300000,

 "metadatas": [

 {

 "key": "key",

 "value": "bubinuo"

 }

 ],

 "priv": {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 2

 }

 }

 },

 "type": 1

 }

 ],

 "source_address": "buQBDf23WtBBC8GySAZHsoBMVGeENWzSRYqB"

 }

 }

 ]

 }

 }

 如果没有查到交易则返回 {

 "error_code": 4,

 "result":

 {

 "total_count": 0,

 "transactions": []

 }

 }

 查询区块头 GET /getLedger?seq=xxxx&with_validator=true&with_consvalue=true&with_fee=true&with_block_reward=true

 参数 描述 seq ledger 的序号, 如果不填写,返回当前 ledger validator 验证节点列表 consvalue 共识值 fee 费用配置 with_block_reward 默认 false,不显示区块奖励和验证节点奖励 • 如果查询到 ledger 则返回内容: {

  "error_code" : 0,

  "result" : {

 "block_reward" : 800000000,

 "consensus_value" : {

  "close_time" : 1524031260097214,

  "ledger_seq" : 6,

  "previous_ledger_hash" : "ef329c7ed761e3065ab08f9e7672fd5f4e3ddd77b0be35598979aff8c21ada9b",

  "previous_proof" : "0ac1010a2c080110022a26080310052220432dde2fd32a2a66da77647231821c87958f56c303bd08003633952d384eb0b61290010a4c623030316435363833363735303137666662633332366538666232303738653532316566383435373234363236353339356536383934633835323434656566643262666130386635393862661240deeb9b782410f0f86d897006cac8ad152e56e4f914e5d718706de84044ef98baef25512a337865772641d57090b5c77e9e2149dbd41910e8d6cd85c3387ea708",

  "previous_proof_plain" : {

 "commits" : [

  {

 "pbft" : {

  "commit" : {

 "sequence" : 5,

 "value_digest" : "432dde2fd32a2a66da77647231821c87958f56c303bd08003633952d384eb0b6",

 "view_number" : 3

  },

  "round_number" : 1,

  "type" : 2

 },

 "signature" : {

  "public_key" : "b001d5683675017ffbc326e8fb2078e521ef8457246265395e6894c85244eefd2bfa08f598bf",

  "sign_data" : "deeb9b782410f0f86d897006cac8ad152e56e4f914e5d718706de84044ef98baef25512a337865772641d57090b5c77e9e2149dbd41910e8d6cd85c3387ea708"

 }

  }

 ]

  },

  "txset" : {

 "txs" : [

  {

 "signatures" : [

  {

 "public_key" : "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",

 "sign_data" : "27866d70a58fc527b1ff1b4a693b8034b0078fc7ac7591fb05679abe5ca660db5c372922bfa8f26e76511e2c33386306ded7593874a6aec5baeeaddbd2012f06"

  }

 ],

 "transaction" : {

  "fee_limit" : 10000000000,

  "gas_price" : 1000,

  "nonce" : 1,

  "operations" : [

 {

  "create_account" : {

 "dest_address" : "buQBAfoMfXZVPpg9DaabMmM2EwUnfoVsTSVV",

 "init_balance" : 10000000,

 "priv" : {

  "master_weight" : 1,

  "thresholds" : {

 "tx_threshold" : 1

  }

 }

  },

  "type" : 1

 },

 {

  "create_account" : {

 "dest_address" : "buQj8UyKbN3myVSerLDVXVXH47vWXfqtxKLm",

 "init_balance" : 10000000,

 "priv" : {

  "master_weight" : 1,

  "thresholds" : {

 "tx_threshold" : 1

  }

 }

  },

  "type" : 1

 }

  ],

  "source_address" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

  },

  {

 "signatures" : [

  {

 "public_key" : "b00180c2007082d1e2519a0f2d08fd65ba607fe3b8be646192a2f18a5fa0bee8f7a810d011ed",

 "sign_data" : "fb7d9d87f4c9140b6e19a199091c6871e2380ad8e8a8fcada9b42a2911057111dc796d731f3f887e600aa89cc8692300f980723298a93b91db711155670d3e0d"

  }

 ],

 "transaction" : {

  "fee_limit" : 10000000000,

  "gas_price" : 1000,

  "nonce" : 2,

  "operations" : [

 {

  "create_account" : {

 "dest_address" : "buQntAvayDWkAhPh6CSrTWbiEniAL2ys5m2p",

 "init_balance" : 10000000,

 "priv" : {

  "master_weight" : 1,

  "thresholds" : {

 "tx_threshold" : 1

  }

 }

  },

  "type" : 1

 },

 {

  "create_account" : {

 "dest_address" : "buQX5X9y59zbmqyFgFPQPcyUPcPnvwsLatsq",

 "init_balance" : 10000000,

 "priv" : {

  "master_weight" : 1,

  "thresholds" : {

 "tx_threshold" : 1

  }

 }

  },

  "type" : 1

 }

  ],

  "source_address" : "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3"

 }

  }

 ]

  }

 },

 "fees" : {

  "base_reserve" : 10000000,

  "gas_price" : 1000

 },

 "header" : {

  "account_tree_hash" : "6aca37dfe83f213942b21d02618b989619cfd7c0e67a8a14b0f7599dd4010aad",

  "close_time" : 1524031260097214,

  "consensus_value_hash" : "14a65d69f619395135da2ff98281d5707494801f12184a4318b9a76383e651a8",

  "fees_hash" : "916daa78d264b3e2d9cff8aac84c943a834f49a62b7354d4fa228dab65515313",

  "hash" : "2cf378b326ab0026625c8d036813aef89a0b383e75055b80cb7cc25a657a9c5d",

  "previous_hash" : "ef329c7ed761e3065ab08f9e7672fd5f4e3ddd77b0be35598979aff8c21ada9b",

  "seq" : 6,

  "tx_count" : 2,

  "validators_hash" : "d857aa40ecdb123415f893159321eb223e4dbc11863daef86f35565dd1633316",

  "version" : 1000

 },

 "validators" : [

  {

 "address" : "buQhmPKU1xTyC3n7zJ8zLQXtuDJmM2zTrJey"

  }

 ],

 "validators_reward" : {

  "buQhmPKU1xTyC3n7zJ8zLQXtuDJmM2zTrJey" : 800000000

 }

  }

 }

 • 如果没有查询到 ledger 返回的内容: {

  "error_code" : 4,

  "result" : null

 }

 提交交易 POST /submitTransaction

 数据格式 {

 "items" : [{

 "transaction_blob" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",//一个交易序列化之后的 16 进制表示

 "signatures" : [{//第一个签名

 "sign_data" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",//签名数据

 "public_key" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"//公钥

 }, {//第二个签名

 "sign_data" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",//签名数据

 "public_key" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"//公钥

 }

 ]

 }

 ]

 }

 参数 描述 transaction_blob 交易序列化之后的 16 进制格式。您可以参照定义交易来组装自己的交易数据 sign_data 签名数据, 16 进制格式。其值为对 transaction_blob 进行签名(动词)得到的签名数据。注意,签名时要先将 注意,签名时要先将 transaction_blob对 转成字节流再签名,不要对 16 进制字符串直接签名 进制字符串直接签名 public_key 公钥, 16 进制格式。

 序列化交易 如果您手中还没有 protocol buffer 工具,您可以使用本接口将交易序列化。

 参数 描述 source_address 的发起方账号地址 nonce 必填,交易序号,必须等于发起方账号的 nonce+1。您可以通过查询账号返回的结果中得到账号的 nonce ceil_ledger_seq 区块高度限制, 如果大于 0,则交易只有在该区块高度之前(包括该高度)才有效,如果为 0,则不判断。

 metadata 可选, 用户自定义交易的备注数据, 必须为 16 进制表示 关于 operations 中的数据格式,参照操作下面各种不同的操作的 json 格式 POST /getTransactionBlob

 {

 "source_address":"xxxxxxxxxxx",//交易源账号,即交易的发起方

 "nonce":2, //nonce 值

 "ceil_ledger_seq": 0, //可选

 "fee_limit":1000, //交易支付的费用

 "gas_price": 1000, //gas 价格(不小于配置的最低值)

 "metadata":"0123456789abcdef", //可选,用户自定义给交易的备注,16 进制格式

 "operations":[

 {

 //根据不同的操作填写

 },

 {

 //根据不同的操作填写

 }

 ......

 ]

 }

 返回内容 {

 "error_code": 0,

 "error_desc": "",

 "result": {

 "hash": "474210d69cf0a797a24be65e187eddc7f15de626d38f8b49446b21ddd12247f8",//交易的 hash

 "transaction_blob": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //交易序列化之后的 16 进制表示

 }

 }

 例如,定义了 1 个 json 格式的交易,该交易只有 1 个操作,创建一个账号 POST /getTransactionBlob

 {

 "source_address": "buQs9npaCq9mNFZG18qu88ZcmXYqd6bqpTU3",

 "nonce": 1,

 "fee_limit": 1000000,

 "gas_price": 1000,

 "operations": [{

 "type": 1,

 "create_account": {

 "dest_address": "buQgmhhxLwhdUvcWijzxumUHaNqZtJpWvNsf",

 "metadatas": [{

 "key": "hello",

 "value": "这是创建账号的过程中设置的一个 metadata"

 }

 ],

 "priv": {

 "master_weight": 10,

 "signers": [],

 "thresholds": {

 "tx_threshold": 7

 }

 },

 "contract": {

 "payload": "function main(inputStr){\n /*这是合约入口函数*/ }"

 }

 }

 }

 ]

 }

 返回 {

  "error_code" : 0,

  "error_desc" : "",

  "result" : {

 "hash" : "106345c939250c26495d461957a17cd58d9f69dc5d21c772e20e1ff337c7c2ce",

 "transaction_blob" : "0a2462755173396e70614371396d4e465a473138717538385a636d5859716436627170545533100122af0108012aaa010a24627551676d6868784c77686455766357696a7a78756d5548614e715a744a7057764e7366123a123866756e6374696f6e206d61696e28696e707574537472297b0a202f2ae8bf99e698afe59088e7baa6e585a5e58fa3e587bde695b02a2f207d1a06080a1a020807223e0a0568656c6c6f1235e8bf99e698afe5889be5bbbae8b4a6e58fb7e79a84e8bf87e7a88be4b8ade8aebee7bdaee79a84e4b880e4b8aa6d65746164617461"

  }

 }

 调用合约 在智能合约模块的设计中,我们提供了沙箱环境来进行调试合约,且调试过程中不会更改区块链和合约的状态。在 BUMO 链上,我们为用户提供了 callContract 接口来帮助用户来调试智能合约,智能合约可以是公链上已存的,也可以是通过参数上传本地的合约代码进行测试,使用 callContract 接口不会发送交易,也就无需支付上链手续费。

 POST /callContract

 • post 内容如下

 {

 "contract_address" : "",

 "code" : "\"use strict\";log(undefined);function query() { return 1; }",

 "input" : "{}",

 "contract_balance" : "100009000000",

 "fee_limit" : 100000000000000000,

 "gas_price": 1000,

 "opt_type" : 2,

 "source_address" : ""

 }

 • contract_address: 调用的智能合约地址,如果从数据库查询不到则返回错误。如果填空,则默认读取 code 字段的内容 • code:需要调试的合约代码,如果 contract_address 为空,则使用 code 字段,如果 code 字段你也为空,则返回错误。

 • input:

 给被调用的合约传参。

 • fee_limit : 手续费。

 • gas_price : Gas 价格。

 • contract_balance : 赋予合约的初始 BU 余额。

 • opt_type: 0: 调用合约的读写接口 init, 1: 调用合约的读写接口 main, 2 :调用只读接口 query。

 • source_address:模拟调用合约的原地址。

 • 返回值如下:

  {

  "error_code" : 0,

  "error_desc" : "",

  "result" : {

 "logs" : {

  "0-buQVkReBYUPUYHBinVDrrb9FQRpo49b9YRXq" : null

 },

 "query_rets" : [

  {

 "result" : {

  "type" : "bool",

  "value" : false

 }

  }

 ],

 "stat" : {

  "apply_time" : 6315,

  "memory_usage" : 886176,

  "stack_usage": 2564,

  "step" : 3

 },

 "txs" : null

  }

 }

 评估费用

 POST /testTransaction

 • post 内容如下 {

 "items": [

 {

 "transaction_json": {

 "source_address": "buQBDf23WtBBC8GySAZHsoBMVGeENWzSRYqB",

 "metadata":"0123456789abcdef", //可选

 "nonce": 6,

 "operations": [

 {

 "type": 7,

 "pay_coin": {

 "dest_address": "buQft4EdxHrtatWUXjTFD7xAbMXACnUyT8vw",

 "amount": 10000

 }

 }

 ]

 },

 "signature_number":1

 }

 ]

 }

 评估费用不改变账号余额基础上进行的评估,交易中涉及的原账号和目标账号都必须在系统中存在,创建账号的目标地址除外。

 • source_address:模拟交易的原地址。

 • nonce : 在原账号基础上加 1。

 • signature_number : 签名个数,默认为 1;不填写系统会设置为 1; • metadata : 可选 • fee_limit : 不用填写 • gas_price : 不用填写

 • operations : 可以是任何一种操作类型。

 • 返回值如下:

 {

 "error_code": 0,

 "error_desc": "",

 "result": {

 "hash": "7f0d9de23d6d8f2964a1efe4a458e02e43e47f60f3c22bb132b676c54a44ba04",

 "logs": null,

 "query_rets": null,

 "stat": null,

 "txs": [

 {

 "actual_fee": 264,

 "gas": 264,

 "transaction_env": {

 "transaction": {

 "fee_limit": 99999999700110000,

 "gas_price": 1,

 "nonce": 1,

 "operations": [

 {

 "pay_coin": {

 "amount": 299890000,

 "dest_address": "buQkBDTfe4tx2Knw9NDKyntVmsYvYtHmAiE7"

 },

 "type": 7

 }

 ],

 "source_address": "buQBDf23WtBBC8GySAZHsoBMVGeENWzSRYqB"

 }

 }

 }

 ]

 }

 }

 gas_price :

 会在 transaction 添加 gas_price,gas_price 为系统的最低 price actual_fee :评估交易的实际费用 • gas :

 评估交易所用 gas

 定义交易 交易的基本结构 • json 格式

  {

 "source_address":"xxxxxxxxxxx",//交易源账号,即交易的发起方

 "nonce":2, //nonce 值

 "fee_limit" : 1000000, //愿为交易花费的手续费

 "gas_price": 1000,//gas 价格(不小于配置的最低值)

 "ceil_ledger_seq": 100, //可选,区块高度限制, 如果大于 0,则交易只有在该区块高度之前(包括该高度)才有效

 "metadata":"0123456789abcdef", //可选,用户自定义给交易的备注,16进制格式

 "operations":[

 {

 //根据不同的操作填写

 },

 {

 //根据不同的操作填写

 }

 ......

 ]

 }

 • protocol buffer 结构

  message Transaction

 {

 enum Limit{

 UNKNOWN = 0;

 OPERATIONS = 1000;

 };

 string source_address = 1;

 int64 nonce = 2;

 int64 fee_limit = 3;

 int64 gas_price =4;

 int64 ceil_ledger_seq = 5;

 bytes metadata = 6;

 repeated Operation operations = 7;

 }

 交易 Transaction 有 7 个关键字段 – source_address: 交易源账号,即交易发起方的账号。当这笔交易成功后,交易源账号的 nonce 字段会自动加 1。账号中的 nonce 意义是本账号作为交易源执行过的交易数量。

 – nonce:其值必须等于交易源账号的当前 nonce+1,这是为了防止重放攻击而设计的。如何查询一个账号的 nonce 可参考查询账号。若查询账号没有显示 nonce 值,说明账号的当前 nonce 是 0. – fee_limit:本交易能接受的最大的手续费。交易首先会按照这个费用收取手续费,若交易执行成功,则会收取实际的花费,否则将收取这个字段的费用。

 gas_price:用于计算每个操作的手续费,还参与交易字节费的计算。

 ceil_ledger_seq:针对本交易的区块高度限制条件,高级功能。

 – operations:操作列表。本交易的有效负载,即本交易想要做什么事情。见操作 – metadata:用户自定义字段,可以不填写,备注用。

  Operation 是所有操作的父类:

  message Operation

 {

 enum Type {

 UNKNOWN = 0;

 CREATE_ACCOUNT = 1;

 ISSUE_ASSET = 2;

 PAY_ASSET = 3;

 SET_METADATA = 4;

 SET_SIGNER_WEIGHT = 5;

 SET_THRESHOLD = 6;

 PAY_COIN = 7;

 LOG = 8;

 };

 Type type = 1;

 string source_address = 2;

 bytes metadata = 3;

  OperationCreateAccount create_account = 4;

 OperationIssueAsset issue_asset = 5;

 OperationPayAsset pay_asset = 6;

 OperationSetMetadata set_metadata = 7;

 OperationSetSignerWeight set_signer_weight = 8;

 OperationSetThreshold set_threshold = 9;

 OperationPayCoin pay_coin = 10;

 OperationLog log = 11;

 }

 – type: 操作类型的枚举。如其值为 ISSUE_ASSET(发行资产),那么本操作中的 issue_asset 字段就会被使用;如果其值为 PAY_ASSET,那么本操作中 pay_asset 字段就会被使用……详见操作码 – source_address:操作源,即本操作针对哪个账号生效。若不填写,则默认本操作源等于本操作源。

 – metadata:本操作的备注,用户自定义,可以不填写 操作 操作码 代码值 枚举名 说明 1 CREATE_ACCOUNT 创建账号 2 ISSUE_ASSET 发行 3 PAY_ASSET 转移资产 4 SET_METADATA 设置 metadata 7 PAY_COIN 支付 BU COIN 9 SET_PRIVILEGE 设置权限 创建账号 参数 描述 dest_address 目标账号的地址。创建普通账号时,不能为空。创建智能合约账号,必须为空。如需创建选举和费用合约,请参考 验证者节点选举 和 费用选举合约 章节 contract 如果不填写,表示普通的账号。如果填写,表示合约账号 priv 该账号的权限信息 balance 初始化账户 BU 值 init_input 给合约传初始化参数 • 功能 在区块链上创建一个新的账号 • 成功条件 各项参数合法 要创建的账号不存在 – 则 注意:如果目标为合约账户,则 priv 配置必须符合 {"master_weight" : 0 , "thresholds": {"tx_threshold":1}} ,如果是普通账号需要配置 {"master_weight" : 1 , "thresholds": {"tx_threshold":1}} • json 格式 创建普通账号

  {

 "type": 1,

 "create_account": {

 "dest_address": "buQgmhhxLwhdUvcWijzxumUHaNqZtJpWvNsf",

 "contract": {

 "payload": ""

 },

 "init_balance": 100000,

 //init_balance to this account

 "init_input" : "",

 // if create contract , then init with this input

 "metadatas": [{

 "key": "111",

 "value": "hello 111!",

 "version": 0

 }, {

 "key": "222",

 "value": "hello 222!",

 "version": 0

 }

 ],

 "priv":

 {

 "master_weight": 1,

 "thresholds": {

 "tx_threshold": 1

 }

 }

 } ...

相关热词搜索: 区块 文档 开发