本文整理汇总了Golang中github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub.CreateTable方法的典型用法代码示例。如果您正苦于以下问题:Golang ChaincodeStub.CreateTable方法的具体用法?Golang ChaincodeStub.CreateTable怎么用?Golang ChaincodeStub.CreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.CreateTable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
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: 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)
}
示例3: 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)
}
示例4: 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)
}