代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package samplesyscc
import (
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
// SampleSysCC example simple Chaincode implementation
type SampleSysCC struct {
}
// Init initializes the sample system chaincode by storing the key and value
// arguments passed in as parameters
func (t *SampleSysCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
//as system chaincodes do not take part in consensus and are part of the system,
//best practice to do nothing (or very little) in Init.
return shim.Success(nil)
}
// Invoke gets the supplied key and if it exists, updates the key with the newly
// supplied value.
func (t *SampleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
f, args := stub.GetFunctionAndParameters()
switch f {
case "putval":
if len(args) != 2 {
return shim.Error("need 2 args (key and a value)")
}
// Initialize the chaincode
key := args[0]
val := args[1]
_, err := stub.GetState(key)
if err != nil {
jsonResp := "{\"Error\":\"Failed to get val for " + key + "\"}"
return shim.Error(jsonResp)
}
// Write the state to the ledger
err = stub.PutState(key, []byte(val))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
case "getval":
var err error
if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting key to query")
}
key := args[0]
// Get the state from the ledger
valbytes, err := stub.GetState(key)
if err != nil {
jsonResp := "{\"Error\":\"Failed to get state for " + key + "\"}"
return shim.Error(jsonResp)
}
if valbytes == nil {
jsonResp := "{\"Error\":\"Nil val for " + key + "\"}"
return shim.Error(jsonResp)
}
return shim.Success(valbytes)
default:
jsonResp := "{\"Error\":\"Unknown function " + f + "\"}"
return shim.Error(jsonResp)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。