Esempio n. 1
0
func createTableFour(stub *shim.ChaincodeStub) error {
	var columnDefsTableFour []*shim.ColumnDefinition
	columnOneTableFourDef := shim.ColumnDefinition{Name: "colOneTableFour",
		Type: shim.ColumnDefinition_STRING, Key: true}
	columnDefsTableFour = append(columnDefsTableFour, &columnOneTableFourDef)
	return stub.CreateTable("tableFour", columnDefsTableFour)
}
func (t *AssetManagementChaincode) Init(stub *shim.ChaincodeStub, function string, 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 role of the users that are allowed to assign assets
	// The metadata will contain the role of the users that are allowed to assign assets
	assignerRole, err := stub.GetCallerMetadata()
	if err != nil {
		return nil, errors.New("Failed getting metadata.")
	}
	if len(assignerRole) == 0 {
		return nil, errors.New("Invalid assigner role. Empty.")
	}

	stub.PutState("assignerRole", assignerRole)

	return nil, nil
}
Esempio n. 3
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)
}
Esempio n. 4
0
// Init method will be called during deployment.
// The deploy transaction metadata is supposed to contain the administrator cert
func (t *AssetManagementChaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	myLogger.Debug("Init Chaincode...")
	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{Name: "Asset", Type: shim.ColumnDefinition_STRING, Key: true},
		&shim.ColumnDefinition{Name: "Owner", Type: shim.ColumnDefinition_BYTES, Key: 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 {
		myLogger.Debug("Failed getting metadata")
		return nil, errors.New("Failed getting metadata.")
	}
	if len(adminCert) == 0 {
		myLogger.Debug("Invalid admin certificate. Empty.")
		return nil, errors.New("Invalid admin certificate. Empty.")
	}

	myLogger.Debug("The administrator is [%x]", adminCert)

	stub.PutState("admin", adminCert)

	myLogger.Debug("Init Chaincode...done")

	return nil, nil
}
Esempio n. 5
0
// createTable initiates a new asset depository table in the chaincode state
// stub: chaincodestub
func (t *depositoryHandler) createTable(stub *shim.ChaincodeStub) error {

	// Create asset depository table
	return stub.CreateTable(tableColumn, []*shim.ColumnDefinition{
		&shim.ColumnDefinition{Name: columnAccountID, Type: shim.ColumnDefinition_STRING, Key: true},
		&shim.ColumnDefinition{Name: columnContactInfo, Type: shim.ColumnDefinition_STRING, Key: false},
		&shim.ColumnDefinition{Name: columnAmount, Type: shim.ColumnDefinition_UINT64, Key: false},
	})

}
Esempio n. 6
0
// Init method will be called during deployment
func (t *RBACChaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {

	// Init the crypto layer
	if err := crypto.Init(); err != nil {
		panic(fmt.Errorf("Failed initializing the crypto layer [%s]", err))
	}

	myLogger.Info("Init")
	// if len(args) != 0 {
	// 	return nil, errors.New("Incorrect number of arguments. Expecting 0")
	// }

	myLogger.Debug("Creating RBAC Table...")

	// Create RBAC table
	err := stub.CreateTable("RBAC", []*shim.ColumnDefinition{
		&shim.ColumnDefinition{Name: "ID", Type: shim.ColumnDefinition_BYTES, Key: true},
		&shim.ColumnDefinition{Name: "Roles", Type: shim.ColumnDefinition_STRING, Key: false},
	})
	if err != nil {
		return nil, errors.New("Failed creating RBAC table.")
	}

	myLogger.Debug("Assign 'admin' role...")

	// Give to the deployer the role 'admin'
	deployer, err := stub.GetCallerMetadata()
	if err != nil {
		return nil, errors.New("Failed getting metadata.")
	}
	if len(deployer) == 0 {
		return nil, errors.New("Invalid admin certificate. Empty.")
	}

	myLogger.Debug("Add admin [% x][%s]", deployer, "admin")
	ok, err := stub.InsertRow("RBAC", shim.Row{
		Columns: []*shim.Column{
			&shim.Column{Value: &shim.Column_Bytes{Bytes: deployer}},
			&shim.Column{Value: &shim.Column_String_{String_: "admin"}},
		},
	})
	if !ok && err == nil {
		return nil, fmt.Errorf("Failed initiliazing RBAC entries.")
	}
	if err != nil {
		return nil, fmt.Errorf("Failed initiliazing RBAC entries [%s]", err)
	}

	myLogger.Debug("Done.")

	return nil, nil
}
Esempio n. 7
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)
}
Esempio n. 8
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)
}