I am writing chaincode program in GO on my MacOS. Following is the code:
package main
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
sc "github.com/hyperledger/fabric/protos/peer"
)
//Init and Invoke
type SmartContract struct {
}
type SomeDocument struct {
DocumentID string `json:"docid"`
CreatorID string `json:"uid"`
DocHolder string `json:"doc_holder"`
Location string `json:"location"`
DocumentType string `json:"doc_type"`
Content string `json:"doc_content"`
}
func (s *SmartContract) Init(APIstub shim.ChaincodeStubInterface) sc.Response {
return shim.Success(nil)
}
func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {
return shim.Success(nil)
}
func main() {
first_doc := SomeDocument{"1001", "123456789012", "ABCD EFGH", "New Delhi", "School Form", "I want to enroll in this school"}
theJson, _ := json.Marshal(first_doc) //returns JSON encoding of first_stamp
fmt.Printf("%+v
", string(theJson))
err := shim.Start(new(SmartContract))
if err != nil {
fmt.Printf("Error creating new Smart Document: %s", err)
} else {
fmt.Println("Success")
}
}
It is showing the following error due to this line, shim.Start(new(SmartContract)):
{"docid":"1001","uid":"123456789012","doc_holder":"ABCD EFGH","location":"New Delhi","doc_type":"School Form","doc_content":"I want to enroll in this school"}
2018-04-10 23:34:41.598 IST [shim] SetupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2018-04-10 23:34:41.598 IST [shim] SetupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
Error creating new Smart Document: error chaincode id not provided%
I cannot find any solution.
Is it possible to specify the limit on the length of struct attributes?. For example DocumentID should be length 10.