Пример #1
0
// initParms handles the initialization of `parms`.
func (c *counters) initParms(stub *shim.ChaincodeStub, args []string) (val []byte, err error) {

	c.infof("initParms : Command-line arguments : %v", args)

	// Define and parse the parameters
	flags := flag.NewFlagSet("initParms", flag.ContinueOnError)
	flags.StringVar(&c.id, "id", "", "A unique identifier; Allows multiple copies of this chaincode to be deployed")
	loggingLevel := flags.String("loggingLevel", "default", "The logging level of the chaincode logger. Defaults to INFO.")
	shimLoggingLevel := flags.String("shimLoggingLevel", "default", "The logging level of the chaincode 'shim' interface. Defaults to WARNING.")
	flags.BoolVar(&c.checkCounters, "checkCounters", false, "Default false. If true, consistency checks are made on counter states during increment/decrement.")
	flags.BoolVar(&c.checkStatus, "checkStatus", true, "Default true; If false, no error/consistency checks are made in the 'status' method.")
	err = flags.Parse(args)
	if err != nil {
		c.errorf("initParms : Error during option processing : %s", err)
	}

	// Replace the original logger logging as "counters", with a new logger,
	// then set its logging level and the logging level of the shim.
	c.logger = shim.NewLogger("counters:" + c.id)
	if *loggingLevel == "default" {
		c.logger.SetLevel(shim.LogInfo)
	} else {
		level, _ := shim.LogLevel(*loggingLevel)
		c.logger.SetLevel(level)
	}
	if *shimLoggingLevel != "default" {
		level, _ := shim.LogLevel(*shimLoggingLevel)
		shim.SetLoggingLevel(level)
	}
	return
}
Пример #2
0
// initParms handles the initialization of `parms`.
func (c *counters) initParms(args []string) (val []byte, err error) {

	c.infof("initParms : Command-line arguments : %v", args)

	// Define and parse the parameters
	flags := flag.NewFlagSet("initParms", flag.ContinueOnError)
	flags.StringVar(&c.id, "id", "", "A unique identifier; Allows multiple copies of this chaincode to be deployed")
	loggingLevel := flags.String("loggingLevel", "default", "The logging level of the chaincode logger. Defaults to INFO.")
	shimLoggingLevel := flags.String("shimLoggingLevel", "default", "The logging level of the chaincode 'shim' interface. Defaults to WARNING.")
	err = flags.Parse(args)
	if err != nil {
		c.errorf("initParms : Error during option processing : %s", err)
	}

	// Replace the original logger, logging as "counters", with a new logger
	// logging as "counters:<id>", then set its logging level and the logging
	// level of the shim.
	c.logger = shim.NewLogger("counters:" + c.id)
	if *loggingLevel == "default" {
		c.logger.SetLevel(shim.LogInfo)
	} else {
		level, _ := shim.LogLevel(*loggingLevel)
		c.logger.SetLevel(level)
	}
	if *shimLoggingLevel != "default" {
		level, _ := shim.LogLevel(*shimLoggingLevel)
		shim.SetLoggingLevel(level)
	}
	return
}
Пример #3
0
func main() {

	c := newCounters()

	c.logger.SetLevel(shim.LogInfo)
	shim.SetLoggingLevel(shim.LogWarning)

	// This is required because we need the lengths (len()) of our arrays to
	// support large (> 2^32) byte arrays.
	c.assert(busy.SizeOfInt() == 8, "The 'counters' chaincode is only supported on platforms where Go integers are 8-byte integers")

	err := shim.Start(c)
	if err != nil {
		c.logger.Criticalf("main : Error starting counters chaincode: %s", err)
		os.Exit(1)
	}
}