本文整理匯總了Golang中github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub.CreateTable方法的典型用法代碼示例。如果您正苦於以下問題:Golang ChaincodeStub.CreateTable方法的具體用法?Golang ChaincodeStub.CreateTable怎麽用?Golang ChaincodeStub.CreateTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.CreateTable方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createTableFour
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)
}
示例2: Init
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
}
示例3: createTableThree
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)
}
示例4: Init
// 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
}
示例5: createTable
// 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},
})
}
示例6: Init
// 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
}
示例7: createTableOne
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)
}
示例8: createTableTwo
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)
}