Altering fabcar example hyperledger-fabric -
i have been playing around hyperledger-fabric samples/fabcar example while , able add more fields , functions in fabcar.go when change fields entirely. getting errors in deployment.
here example of changes have made in fabcar.go.
type car struct { name string `json:"name"` college string `json:"college"` dob string `json:"dob"` secretcode string `json:"secretcode"` } func (s *smartcontract) initledger(apistub shim.chaincodestubinterface) sc.response { cars := []car{ car{name: "name1", college: "college1", dob: "dob1", secretcode: "secretcode1"}, car{name: "name2", college: "college2", dob: "dob2", secretcode: "secretcode2"}, car{name: "name3", college: "college3", dob: "dob3", secretcode: "secretcode3"}, car{name: "name4", college: "college4", dob: "dob4", secretcode: "secretcode4"}, } := 0 < len(cars) { fmt.println("i ", i) carasbytes, _ := json.marshal(cars[i]) apistub.putstate("car"+strconv.itoa(i), carasbytes) fmt.println("added", cars[i]) = + 1 } return shim.success(nil) }
here error when run startfabric.sh
error: error endorsing chaincode: rpc error: code = unknown desc = error starting container: failed generate platform-specific docker build: error returned build: 2 "# github.com/fabcar chaincode/input/src/github.com/fabcar/fabcar.go:132: unknown car field 'make' in struct literal chaincode/input/src/github.com/fabcar/fabcar.go:132: unknown car field 'model' in struct literal chaincode/input/src/github.com/fabcar/fabcar.go:132: unknown car field 'colour' in struct literal chaincode/input/src/github.com/fabcar/fabcar.go:132: unknown car field 'owner' in struct literal chaincode/input/src/github.com/fabcar/fabcar.go:193: car.owner undefined (type car has no field or method owner) chaincode/input/src/github.com/fabcar/fabcar.go:211: car.colour undefined (type car has no field or method colour) "
i using mac osx yosemite , have tried cleaning docker removing data , starting again , have tried renaming go file nothing works. doing wrong here?
output of go build command:
go build ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/admin.pb.go:74:8: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/admin.pb.go:77:8: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/chaincode.pb.go:9:8: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/init.go:21:2: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/bccsp/pkcs11/conf.go:25:2: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/admin.pb.go:80:2: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/protos/peer/admin.pb.go:81:2: use of vendored package not allowed ../../../../../go/src/github.com/hyperledger/fabric/common/flogging/grpclogger.go:21:2: use of vendored package not allowed
it seems having compilation error, while changed structure of car
be
type car struct { name string `json:"name"` college string `json:"college"` dob string `json:"dob"` secretcode string `json:"secretcode"` }
while many function remained in fabcar.go
still trying use struct "old fashion" way, assuming previous model:
type car struct { make string `json:"make"` model string `json:"model"` colour string `json:"colour"` owner string `json:"owner"` }
for example:
func (s *smartcontract) createcar(apistub shim.chaincodestubinterface, args []string) sc.response { if len(args) != 5 { return shim.error("incorrect number of arguments. expecting 5") } var car = car{make: args[1], model: args[2], colour: args[3], owner: args[4]} carasbytes, _ := json.marshal(car) apistub.putstate(args[0], carasbytes) return shim.success(nil) }
i suggest instead reusing declaration of car
struct create own , use properly:
type student struct { name string `json:"name"` college string `json:"college"` dob string `json:"dob"` secretcode string `json:"secretcode"` }
and
func (s *smartcontract) initledger(apistub shim.chaincodestubinterface) sc.response { cars := []student{ student{name: "name1", college: "college1", dob: "dob1", secretcode: "secretcode1"}, student{name: "name2", college: "college2", dob: "dob2", secretcode: "secretcode2"}, student{name: "name3", college: "college3", dob: "dob3", secretcode: "secretcode3"}, student{name: "name4", college: "college4", dob: "dob4", secretcode: "secretcode4"}, } := 0 < len(cars) { fmt.println("i ", i) carasbytes, _ := json.marshal(cars[i]) apistub.putstate("car"+strconv.itoa(i), carasbytes) fmt.println("added", cars[i]) = + 1 } return shim.success(nil) }
Comments
Post a Comment