github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/creative/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strconv" 6 . "github.com/inklabsfoundation/inkchain/examples/creative/conf" 7 . "github.com/inklabsfoundation/inkchain/examples/creative/invoke" 8 "github.com/inklabsfoundation/inkchain/core/chaincode/shim" 9 pb "github.com/inklabsfoundation/inkchain/protos/peer" 10 ) 11 12 type mainChaincode struct { 13 UserInvoke 14 ArtistInvoke 15 ProductionInvoke 16 } 17 18 func main() { 19 err := shim.Start(&mainChaincode{}) 20 if err != nil { 21 fmt.Printf("Error starting assetChaincode: %s", err) 22 } 23 } 24 25 func (c *mainChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { 26 fmt.Println("mainChaincode Init.") 27 return shim.Success([]byte("Init success.")) 28 } 29 30 func (c *mainChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { 31 fmt.Println("mainChaincode Invoke.") 32 function, args := stub.GetFunctionAndParameters() 33 switch function { 34 case AddUser: 35 parameter_length := 2 36 if len(args) != parameter_length { 37 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length) + ":" + strconv.Itoa(len(args))) 38 } 39 return c.AddUser(stub, args) 40 case ModifyUser: 41 parameter_length := 2 42 if len(args) <= parameter_length { 43 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 44 } 45 return c.ModifyUser(stub, args) 46 case DeleteUser: 47 parameter_length := 1 48 if len(args) != parameter_length { 49 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 50 } 51 return c.DeleteUser(stub, args) 52 case QueryUser: 53 parameter_length := 1 54 if len(args) != parameter_length { 55 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 56 } 57 return c.QueryUser(stub, args) 58 case ListOfUser: 59 parameter_length := 0 60 if len(args) != parameter_length { 61 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 62 } 63 return c.ListOfUser(stub, args) 64 case AddArtist: 65 parameter_length := 3 66 if len(args) != parameter_length { 67 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 68 } 69 return c.AddArtist(stub, args) 70 case DeleteArtist: 71 parameter_length := 1 72 if len(args) != parameter_length { 73 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 74 } 75 return c.DeleteArtist(stub, args) 76 case ModifyArtist: 77 parameter_length := 1 78 if len(args) <= parameter_length { 79 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 80 } 81 return c.ModifyArtist(stub, args) 82 case QueryArtist: 83 parameter_length := 1 84 if len(args) != parameter_length { 85 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 86 } 87 return c.QueryArtist(stub, args) 88 case ListOfArtist: 89 parameter_length := 0 90 if len(args) != parameter_length { 91 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 92 } 93 return c.ListOfArtist(stub, args) 94 case AddProduction: 95 parameter_length := 9 96 if len(args) != parameter_length { 97 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 98 } 99 return c.AddProduction(stub, args) 100 case DeleteProduction: 101 parameter_length := 3 102 if len(args) != parameter_length { 103 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 104 } 105 return c.DeleteProduction(stub, args) 106 case ModifyProduction: 107 parameter_length := 3 108 if len(args) <= parameter_length { 109 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 110 } 111 return c.ModifyProduction(stub, args) 112 case QueryProduction: 113 parameter_length := 3 114 if len(args) != parameter_length { 115 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 116 } 117 return c.QueryProduction(stub, args) 118 case ListOfProduction: 119 parameter_length := 2 120 if len(args) > parameter_length { 121 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 122 } 123 return c.ListOfProduction(stub, args) 124 case ListOfSupporter: 125 parameter_length := 3 126 if len(args) <= 1 && len(args) > parameter_length { 127 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 128 } 129 return c.ListOfSupporter(stub, args) 130 case ListOfBuyer: 131 parameter_length := 3 132 if len(args) <= 1 && len(args) > parameter_length { 133 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 134 } 135 return c.ListOfBuyer(stub, args) 136 case AddSupporter: 137 parameter_length := 6 138 if len(args) != parameter_length { 139 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 140 } 141 return c.AddSupporter(stub, args) 142 case AddBuyer: 143 parameter_length := 6 144 if len(args) != parameter_length { 145 return shim.Error("Incorrect number of arguments. Expecting " + strconv.Itoa(parameter_length)) 146 } 147 return c.AddBuyer(stub, args) 148 case ModifyBuyer: 149 // TODO 150 return c.ModifyBuyer(stub, args) 151 case DeleteBuyer: 152 // TODO 153 return c.DeleteBuyer(stub, args) 154 } 155 return shim.Error("Invalid invoke function name.") 156 }