官术网_书友最值得收藏!

  • 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)
}
主站蜘蛛池模板: 繁峙县| 定兴县| 兴隆县| 湖北省| 巫溪县| 三门峡市| 德化县| 漠河县| 策勒县| 霍林郭勒市| 滦平县| 华安县| 沽源县| 龙州县| 上饶县| 秀山| 黄梅县| 张北县| 商水县| 石渠县| 绥德县| 股票| 大宁县| 丰县| 额敏县| 哈尔滨市| 阿尔山市| 佛冈县| 嵩明县| 西藏| 安义县| 武义县| 衢州市| 潞城市| 新宾| 本溪| 开平市| 蓬莱市| 鄂州市| 曲阜市| 长春市|