当前位置: 首页>>代码示例>>Golang>>正文


Golang ChaincodeStub.ReplaceRow方法代码示例

本文整理汇总了Golang中github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub.ReplaceRow方法的典型用法代码示例。如果您正苦于以下问题:Golang ChaincodeStub.ReplaceRow方法的具体用法?Golang ChaincodeStub.ReplaceRow怎么用?Golang ChaincodeStub.ReplaceRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub的用法示例。


在下文中一共展示了ChaincodeStub.ReplaceRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run


//.........这里部分代码省略.........
		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 {
			return nil, fmt.Errorf("replaceRowTableOne operation failed. %s", err)
		}
		if !ok {
			return nil, errors.New("replaceRowTableOne operation failed. Row with given key does not exist")
		}

	case "deleteAndRecreateTableOne":

		err := stub.DeleteTable("tableOne")
		if err != nil {
			return nil, fmt.Errorf("deleteAndRecreateTableOne operation failed. Error deleting table. %s", err)
		}

		err = createTableOne(stub)
		if err != nil {
			return nil, fmt.Errorf("deleteAndRecreateTableOne operation failed. Error creating table. %s", err)
		}

		return nil, nil

	case "init":

		// Create table one
		err := createTableOne(stub)
		if err != nil {
			return nil, fmt.Errorf("Error creating table one during init. %s", err)
		}

		// Create table two
		err = createTableTwo(stub)
		if err != nil {
			return nil, fmt.Errorf("Error creating table two during init. %s", err)
		}

		// Create table three
		err = createTableThree(stub)
		if err != nil {
			return nil, fmt.Errorf("Error creating table three during init. %s", err)
		}

	default:
		return nil, errors.New("Unsupported operation")
	}
	return nil, nil
}
开发者ID:tanyakchoon,项目名称:obc-peer,代码行数:101,代码来源:table.go


注:本文中的github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub.ReplaceRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。