该智能合约实现一个简单的商业应用案例,即数字货币的发行与转账。在这之中一共分为三种角色:中央银行,商业银行,企业。其中中央银行可以发行一定数量的货币,企业之间可以进行相互的转账。主要实现如下的功能:
init
invoke
query
createBank
createCompany
issueCoin
issueCoinToBank
issueCoinToCp
transfer
getCompanys
getBanks
getTransactions
getCompanyById
getBankById
getTransactionBy
writeCenterBank
writeBank
writeCompany
writeTransaction
request 参数:
args[0] 银行名称 args[1] 初始化发布金额
response 参数:
{"Name":"XXX","TotalNumber":"0","RestNumber":"0","ID":"XX"}
args[0] 银行名称
args[0] 公司名称
{"Name":"XXX","Number":"0","ID":"XX"}
args[0] 再次发行货币数额
{"FromType":"0","FromID":"0","ToType":"0","ToID":"0","Time":"XX","Number":"XX","ID":"XX"}
args[0] 商业银行ID args[1] 转账数额
{"FromType":"0","FromID":"0","ToType":"1","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"}
args[0] 商业银行ID args[1] 企业ID args[2] 转账数额
{"FromType":"1","FromID":"XX","ToType":"2","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"}
args[0] 转账用户ID args[1] 被转账用户ID args[2] 转账余额
{"FromType":"2","FromID":"XX","ToType":"2","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"}
response 参数
[{"Name":"XXX","Number":"XX","ID":"XX"},{"Name":"XXX","Number":"XX","ID":"XX"},...]
[{"Name":"XXX","TotalNumber":"XX","RestNumber":"XX","ID":"XX"},{"Name":"XXX","TotalNumber":"XX","RestNumber":"XX","ID":"XX"},...]
[{"FromType":"XX","FromID":"XX","ToType":"XX","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"},{"FromType":"XX","FromID":"XX","ToType":"XX","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"},...]
getCenterBank
[{"Name":"XX","TotalNumber":"XX","RestNumber":"XX","ID":"XX"}]
request 参数
args[0] 商业银行ID
args[0] 企业ID
[{"Name":"XXX","Number":"XX","ID":"XX"}]
getTransactionById
args[0] 交易ID
{"FromType":"XX","FromID":"XX","ToType":"XX","ToID":"XX","Time":"XX","Number":"XX","ID":"XX"}
CenterBank
err nil 为成功
Bank
Company
Transaction
err nil 为成功 ··· #### 其它 查询时为了兼顾读速率,将一些信息备份存放在非区块链数据库上也是一个较好的选择。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8