-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfabric-payment.go
More file actions
70 lines (58 loc) · 1.98 KB
/
fabric-payment.go
File metadata and controls
70 lines (58 loc) · 1.98 KB
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
/*
Package main provides the entrypoint of this chaincode.
Copyright Nobuyuki Matsui<nobuyuki.matsui>.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
sc "github.com/hyperledger/fabric/protos/peer"
"github.com/nmatsui/fabric-payment-sample-chaincode/contracts"
)
var logger = shim.NewLogger("main")
var accountContract = new(contracts.AccountContract)
var eventContract = new(contracts.EventContract)
var historyContract = new(contracts.HistoryContract)
// EntryPoint : a struct to hadle shim.Chaincode interface.
type EntryPoint struct {
}
// Init : implementation for shim.Chaincode interface.
func (s *EntryPoint) Init(APIstub shim.ChaincodeStubInterface) sc.Response {
logger.Info("instantiated chaincode")
return shim.Success(nil)
}
// Invoke : implementation for shim.Chaincode interface.
func (s *EntryPoint) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {
function, args := APIstub.GetFunctionAndParameters()
switch function {
case "listAccount":
return accountContract.ListAccount(APIstub, args)
case "createAccount":
return accountContract.CreateAccount(APIstub, args)
case "retrieveAccount":
return accountContract.RetrieveAccount(APIstub, args)
case "updateAccountName":
return accountContract.UpdateAccountName(APIstub, args)
case "deleteAccount":
return accountContract.DeleteAccount(APIstub, args)
case "listEvent":
return eventContract.ListEvent(APIstub, args)
case "deposit":
return eventContract.Deposit(APIstub, args)
case "remit":
return eventContract.Remit(APIstub, args)
case "withdraw":
return eventContract.Withdraw(APIstub, args)
case "listHistory":
return historyContract.ListHistory(APIstub, args)
}
msg := fmt.Sprintf("No such function. function = %s, args = %s", function, args)
logger.Error(msg)
return shim.Error(msg)
}
func main() {
if err := shim.Start(new(EntryPoint)); err != nil {
logger.Errorf("Error creating new Chaincode. Error = %s\n", err)
}
}