-
Notifications
You must be signed in to change notification settings - Fork 272
/
main.go
65 lines (55 loc) · 1.58 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
/*
* Copyright IBM Corp. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"fmt"
"os"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
am "github.com/hyperledger/cacti/weaver/core/network/fabric-interop-cc/interfaces/asset-mgmt/v2"
)
// SmartContract provides functions for managing an BondAsset and TokenAsset
type SmartContract struct {
contractapi.Contract
amc am.AssetManagementContract
}
func (s *SmartContract) ConfigureInterop(interopChaincodeId string) {
s.amc.Configure(interopChaincodeId)
}
func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface, ccType string, interopChaincodeId string) error {
s.ConfigureInterop(interopChaincodeId)
if ccType == "Bond" {
return s.InitBondAssetLedger(ctx)
} else if ccType == "Token" {
return s.InitTokenAssetLedger(ctx)
}
return fmt.Errorf("only Bond and Token are accepted as ccType.")
}
func main() {
chaincode, err := contractapi.NewChaincode(new(SmartContract))
if err != nil {
fmt.Printf("Error creating chaincode: %s", err.Error())
return
}
_, ok := os.LookupEnv("EXTERNAL_SERVICE")
if ok {
server := &shim.ChaincodeServer{
CCID: os.Getenv("CHAINCODE_CCID"),
Address: os.Getenv("CHAINCODE_ADDRESS"),
CC: chaincode,
TLSProps: shim.TLSProperties{
Disabled: true,
},
}
// Start the chaincode external server
err = server.Start()
} else {
err = chaincode.Start()
}
if err != nil {
fmt.Printf("Error starting chaincode: %s", err.Error())
}
}