forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaincode.go
47 lines (38 loc) · 945 Bytes
/
chaincode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package callee
import (
"github.com/hyperledger/fabric-chaincode-go/shim"
pb "github.com/hyperledger/fabric-protos-go/peer"
)
// CC example simple Chaincode implementation
type CC struct {
}
func (t *CC) Init(stub shim.ChaincodeStubInterface) pb.Response {
err := stub.PutState("foo", []byte("callee:foo"))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}
func (t *CC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
fn, _ := stub.GetFunctionAndParameters()
switch fn {
case "INVOKE":
err := stub.PutState("foo", []byte("callee:bar"))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
case "QUERY":
val, err := stub.GetState("foo")
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(val)
default:
return shim.Error("unknown function")
}
}