本文整理汇总了Golang中github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub.DeleteRow方法的典型用法代码示例。如果您正苦于以下问题:Golang ChaincodeStub.DeleteRow方法的具体用法?Golang ChaincodeStub.DeleteRow怎么用?Golang ChaincodeStub.DeleteRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.DeleteRow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: transfer
func (t *AssetManagementChaincode) transfer(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2")
}
asset := args[0]
newOwner := []byte(args[1])
// Verify the identity of the caller
// Only the owner can transfer one of his assets
var columns []shim.Column
col1 := shim.Column{Value: &shim.Column_String_{String_: asset}}
columns = append(columns, col1)
row, err := stub.GetRow("AssetsOwnership", columns)
if err != nil {
return nil, fmt.Errorf("Failed retrieveing asset [%s]: [%s]", asset, err)
}
prvOwner := row.Columns[1].GetBytes()
myLogger.Debug("Previous owener of [%s] is [% x]", asset, prvOwner)
if len(prvOwner) == 0 {
return nil, fmt.Errorf("Invalid previous owner. Nil")
}
// Verify ownership
ok, err := t.isCaller(stub, prvOwner)
if err != nil {
return nil, errors.New("Failed checking asset owner identity")
}
if !ok {
return nil, errors.New("The caller is not the owner of the asset")
}
// At this point, the proof of ownership is valid, then register transfer
err = stub.DeleteRow(
"AssetsOwnership",
[]shim.Column{shim.Column{Value: &shim.Column_String_{String_: asset}}},
)
if err != nil {
return nil, errors.New("Failed deliting row.")
}
_, err = stub.InsertRow(
"AssetsOwnership",
shim.Row{
Columns: []*shim.Column{
&shim.Column{Value: &shim.Column_String_{String_: asset}},
&shim.Column{Value: &shim.Column_Bytes{Bytes: newOwner}},
},
})
if err != nil {
return nil, errors.New("Failed inserting row.")
}
return nil, nil
}
示例2: Run
//.........这里部分代码省略.........
col2 := shim.Column{Value: &shim.Column_Int32{Int32: col2Val}}
col3 := shim.Column{Value: &shim.Column_Int64{Int64: col3Val}}
col4 := shim.Column{Value: &shim.Column_Uint32{Uint32: col4Val}}
col5 := shim.Column{Value: &shim.Column_Uint64{Uint64: col5Val}}
col6 := shim.Column{Value: &shim.Column_Bytes{Bytes: col6Val}}
col7 := shim.Column{Value: &shim.Column_Bool{Bool: col7Val}}
columns = append(columns, &col1)
columns = append(columns, &col2)
columns = append(columns, &col3)
columns = append(columns, &col4)
columns = append(columns, &col5)
columns = append(columns, &col6)
columns = append(columns, &col7)
row := shim.Row{columns}
ok, err := stub.InsertRow("tableThree", row)
if err != nil {
return nil, fmt.Errorf("insertRowTableThree operation failed. %s", err)
}
if !ok {
return nil, errors.New("insertRowTableThree operation failed. Row with given key already exists")
}
case "deleteRowTableOne":
if len(args) < 1 {
return nil, errors.New("deleteRowTableOne failed. Must include 1 key value")
}
col1Val := args[0]
var columns []shim.Column
col1 := shim.Column{Value: &shim.Column_String_{String_: col1Val}}
columns = append(columns, col1)
err := stub.DeleteRow("tableOne", columns)
if err != nil {
return nil, fmt.Errorf("deleteRowTableOne operation failed. %s", err)
}
case "replaceRowTableOne":
if len(args) < 3 {
return nil, errors.New("replaceRowTableOne failed. Must include 3 column values")
}
col1Val := args[0]
col2Int, err := strconv.ParseInt(args[1], 10, 32)
if err != nil {
return nil, errors.New("replaceRowTableOne failed. arg[1] must be convertable to int32")
}
col2Val := int32(col2Int)
col3Int, err := strconv.ParseInt(args[2], 10, 32)
if err != nil {
return nil, errors.New("replaceRowTableOne failed. arg[2] must be convertable to int32")
}
col3Val := int32(col3Int)
var columns []*shim.Column
col1 := shim.Column{Value: &shim.Column_String_{String_: col1Val}}
col2 := shim.Column{Value: &shim.Column_Int32{Int32: col2Val}}
col3 := shim.Column{Value: &shim.Column_Int32{Int32: col3Val}}
columns = append(columns, &col1)
columns = append(columns, &col2)
columns = append(columns, &col3)
row := shim.Row{columns}
ok, err := stub.ReplaceRow("tableOne", row)
if err != nil {