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

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)
}
主站蜘蛛池模板: 杂多县| 碌曲县| 东明县| 雷波县| 榆中县| 大英县| 兴山县| 横峰县| 房山区| 定西市| 海丰县| 盐城市| 丘北县| 无锡市| 观塘区| 普安县| 通江县| 牡丹江市| 石阡县| 龙江县| 泽普县| 浦东新区| 荆州市| 陆良县| 扎鲁特旗| 灵璧县| 青浦区| 涟水县| 庐江县| 海丰县| 府谷县| 饶河县| 商城县| 略阳县| 镶黄旗| 望江县| 芦溪县| 泰州市| 法库县| 综艺| 依兰县|