示例#1
0
func (t *AssetManagementChaincode) init(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
	myLogger.Info("[AssetManagementChaincode] Init")
	if len(args) != 0 {
		return nil, errors.New("Incorrect number of arguments. Expecting 0")
	}

	// Create ownership table
	err := stub.CreateTable("AssetsOwnership", []*shim.ColumnDefinition{
		&shim.ColumnDefinition{"Asset", shim.ColumnDefinition_STRING, true},
		&shim.ColumnDefinition{"Owner", shim.ColumnDefinition_BYTES, false},
	})
	if err != nil {
		return nil, errors.New("Failed creating AssetsOnwership table.")
	}

	// Set the admin
	// The metadata will contain the certificate of the administrator
	adminCert, err := stub.GetCallerMetadata()
	if err != nil {
		return nil, errors.New("Failed getting metadata.")
	}
	if len(adminCert) == 0 {
		return nil, errors.New("Invalid admin certificate. Empty.")
	}

	stub.PutState("admin", adminCert)

	return nil, nil
}
示例#2
0
func createTableThree(stub *shim.ChaincodeStub) error {
	var columnDefsTableThree []*shim.ColumnDefinition
	columnOneTableThreeDef := shim.ColumnDefinition{Name: "colOneTableThree",
		Type: shim.ColumnDefinition_STRING, Key: true}
	columnTwoTableThreeDef := shim.ColumnDefinition{Name: "colTwoTableThree",
		Type: shim.ColumnDefinition_INT32, Key: false}
	columnThreeTableThreeDef := shim.ColumnDefinition{Name: "colThreeTableThree",
		Type: shim.ColumnDefinition_INT64, Key: false}
	columnFourTableThreeDef := shim.ColumnDefinition{Name: "colFourTableFour",
		Type: shim.ColumnDefinition_UINT32, Key: false}
	columnFiveTableThreeDef := shim.ColumnDefinition{Name: "colFourTableFive",
		Type: shim.ColumnDefinition_UINT64, Key: false}
	columnSixTableThreeDef := shim.ColumnDefinition{Name: "colFourTableSix",
		Type: shim.ColumnDefinition_BYTES, Key: false}
	columnSevenTableThreeDef := shim.ColumnDefinition{Name: "colFourTableSeven",
		Type: shim.ColumnDefinition_BOOL, Key: false}
	columnDefsTableThree = append(columnDefsTableThree, &columnOneTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnTwoTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnThreeTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnFourTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnFiveTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnSixTableThreeDef)
	columnDefsTableThree = append(columnDefsTableThree, &columnSevenTableThreeDef)
	return stub.CreateTable("tableThree", columnDefsTableThree)
}
示例#3
0
func createTableOne(stub *shim.ChaincodeStub) error {
	// Create table one
	var columnDefsTableOne []*shim.ColumnDefinition
	columnOneTableOneDef := shim.ColumnDefinition{Name: "colOneTableOne",
		Type: shim.ColumnDefinition_STRING, Key: true}
	columnTwoTableOneDef := shim.ColumnDefinition{Name: "colTwoTableOne",
		Type: shim.ColumnDefinition_INT32, Key: false}
	columnThreeTableOneDef := shim.ColumnDefinition{Name: "colThreeTableOne",
		Type: shim.ColumnDefinition_INT32, Key: false}
	columnDefsTableOne = append(columnDefsTableOne, &columnOneTableOneDef)
	columnDefsTableOne = append(columnDefsTableOne, &columnTwoTableOneDef)
	columnDefsTableOne = append(columnDefsTableOne, &columnThreeTableOneDef)
	return stub.CreateTable("tableOne", columnDefsTableOne)
}
示例#4
0
func createTableTwo(stub *shim.ChaincodeStub) error {
	var columnDefsTableTwo []*shim.ColumnDefinition
	columnOneTableTwoDef := shim.ColumnDefinition{Name: "colOneTableTwo",
		Type: shim.ColumnDefinition_STRING, Key: true}
	columnTwoTableTwoDef := shim.ColumnDefinition{Name: "colTwoTableTwo",
		Type: shim.ColumnDefinition_INT32, Key: false}
	columnThreeTableTwoDef := shim.ColumnDefinition{Name: "colThreeTableThree",
		Type: shim.ColumnDefinition_INT32, Key: true}
	columnFourTableTwoDef := shim.ColumnDefinition{Name: "colFourTableFour",
		Type: shim.ColumnDefinition_STRING, Key: true}
	columnDefsTableTwo = append(columnDefsTableTwo, &columnOneTableTwoDef)
	columnDefsTableTwo = append(columnDefsTableTwo, &columnTwoTableTwoDef)
	columnDefsTableTwo = append(columnDefsTableTwo, &columnThreeTableTwoDef)
	columnDefsTableTwo = append(columnDefsTableTwo, &columnFourTableTwoDef)
	return stub.CreateTable("tableTwo", columnDefsTableTwo)
}