This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.go
91 lines (72 loc) · 2.28 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright 2020 Telefónica Digital España. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
log "TrustID/fabric-chaincode/log"
"encoding/json"
"github.com/hyperledger/fabric-chaincode-go/shim"
sc "github.com/hyperledger/fabric-protos-go/peer"
)
// Chaincode struct
type Chaincode struct {
}
const logLevel string = "DEBUG"
// CHANNEL_ENV
var CHANNEL_ENV string
// Init is called when the chaincode is instantiated by the blockchain network.
func (cc *Chaincode) Init(stub shim.ChaincodeStubInterface) sc.Response {
log.Init("DEBUG")
CHANNEL_ENV = stub.GetChannelID()
log.Infof("[%s][IdentityCC][Init] Initializing identity root", CHANNEL_ENV)
idReq := IdentityRequest{}
_, args := stub.GetFunctionAndParameters()
err := json.Unmarshal([]byte(args[0]), &idReq)
if err != nil {
log.Errorf("[%s][IdentityGateway][CreateIdentity] Error parsing: %v", CHANNEL_ENV, err.Error())
}
identityStore := Identity{PublicKey: idReq.PublicKey, Controller: idReq.Controller, Access: 4}
_, err = cc.createIDRegistry(stub, idReq.Did, identityStore)
if err != nil {
log.Errorf("[%s][IdentityGateway][CreateIdentity] Error parsing: %v", CHANNEL_ENV, err.Error())
return shim.Error(err.Error())
}
log.Infof("[%s][IdentityCC][Init] Chaincode initialized", CHANNEL_ENV)
return shim.Success(nil)
}
// Invoke is called as a result of an application request to run the chaincode.
func (cc *Chaincode) Invoke(stub shim.ChaincodeStubInterface) sc.Response {
log.Init("DEBUG")
fcn, params := stub.GetFunctionAndParameters()
var err error
var result string
CHANNEL_ENV = stub.GetChannelID()
if fcn == "proxy" {
result, err = cc.checkArgs(stub, params)
}
if err != nil {
log.Errorf("[%s][IdentityCC][Init] Errror %v", CHANNEL_ENV, err)
return shim.Error(err.Error())
}
return shim.Success([]byte(result))
}
func main() {
// server := &shim.ChaincodeServer{
// CCID: os.Getenv("CHAINCODE_CCID"),
// Address: os.Getenv("CHAINCODE_ADDRESS"),
// CC: new(Chaincode),
// TLSProps: shim.TLSProperties{
// Disabled: true,
// },
// }
// // Start the chaincode external server
// err := server.Start()
// if err != nil {
// log.Errorf("Error starting chaincode: %s", err)
// }
err := shim.Start(new(Chaincode))
if err != nil {
panic(err)
}
}