- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 139字
- 2021-06-24 14:59:38
The Init function
The implementation of our Init function is as follows:
func (c *AssetMgr) Init(stub shim.ChaincodeStubInterface) pb.Response {
args := stub.GetStringArgs()
if len(args) != 3 {
return shim.Error("Incorrect arguments. Expecting a key and a value")
}
assetId := args[0]
assetType := args[1]
deviceId := args[2]
//create asset
assetData := OrgAsset{
Id: assetId,
AssetType: assetType,
Status: "START",
Location: "N/A",
DeviceId: deviceId,
Comment: "Initialized asset",
From: "N/A",
To: "N/A"}
assetBytes, _ := json.Marshal(assetData)
assetErr := stub.PutState(assetId, assetBytes)
if assetErr != nil {
return shim.Error(fmt.Sprintf("Failed to create asset: %s", args[0]))
}
return shim.Success(nil)
}
func (c *AssetMgr) Init(stub shim.ChaincodeStubInterface) pb.Response {
args := stub.GetStringArgs()
assetId := args[0] assetType := args[1] deviceId := args[2]
//create asset
assetData := OrgAsset{Id: assetId,AssetType:
assetType, Status: "START",Location: "N/A",DeviceId:
deviceId,Comment: "Initialized asset",From: "N/A", To: "N/A"}
assetBytes, _ := json.Marshal(assetData)
assetErr := stub.PutState(assetId, assetBytes)
…
return shim.Success(nil)
}
推薦閱讀
- Blockchain for Business 2019
- 世界是隨機(jī)的:大數(shù)據(jù)時(shí)代的概率統(tǒng)計(jì)學(xué)
- 妙趣橫生博弈論:事業(yè)與人生的成功之道(白金版)
- 數(shù)學(xué)教學(xué)論
- The Modern C# Challenge
- 數(shù)學(xué)建模33講:數(shù)學(xué)與繽紛的世界
- 別說(shuō)你不懂?dāng)?shù)學(xué)
- 數(shù)獨(dú)游戲全集
- Abaqus有限元分析從入門到精通(2022版)
- 數(shù)學(xué)的力量
- 數(shù)學(xué)與決策:數(shù)學(xué)教你做決定
- Hands-On Blockchain with Hyperledger
- Mastering Ethereum
- Blockchain for Decision Makers
- 排序問(wèn)題的數(shù)學(xué)規(guī)劃松弛方法