首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Blockchain上存储数据

在Blockchain上存储数据
EN

Stack Overflow用户
提问于 2017-05-02 07:28:18
回答 8查看 3.7K关注 0票数 4

我正在开发一个POC,在这里我必须存储一些数据,比如对象的ID、价格、所有者等等。是否有可能使用智能契约将这些东西存储在Blockchain上。如果不是的话,使用Blockchain实现它的方法是什么。(我做了一些研究,人们正在供应链管理行业使用Blockchain。)他们一定存储了这类数据)。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2017-05-03 21:09:25

是的,如果您使用Ethereum智能契约,您可以定义您的合同并将其存储在事务中。

https://www.ethereum.org/greeter

请注意,如果您不加密存储在契约中的数据,那么每个人都可以访问它。

票数 6
EN

Stack Overflow用户

发布于 2017-07-02 20:09:58

考虑从Hyperledger "快速入门“页面中遵循快速入门

基本上,通过利用链码实现所请求的逻辑,就必须实现以下golang接口:

代码语言:javascript
复制
// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
    // Init is called during Instantiate transaction after the chaincode container
    // has been established for the first time, allowing the chaincode to
    // initialize its internal data
    Init(stub ChaincodeStubInterface) pb.Response

    // Invoke is called to update or query the ledger in a proposal transaction.
    // Updated state variables are not committed to the ledger until the
    // transaction is committed.
    Invoke(stub ChaincodeStubInterface) pb.Response
}

例如,类似于此的内容:

代码语言:javascript
复制
type myStoreChaincode struct {
}

func (cc *myStoreChaincode) Init(stub ChaincodeStubInterface) pb.Response {
    return shim.Success(nil)
}

func (cc *myStoreChaincode) Invoke(stub ChaincodeStubInterface) pb.Response {
    action, params = stub.GetFunctionAndParameters()
    if action == "storeItem" {
        cc.StoreItem(stub, params)
    }

    // Handle here other cases and possible parameters combinations
    return shim.Success(nil)
}

func (cc *myStoreChaincode) StoreItem(stub ChaincodeStubInterface, params []string) {
      // Store item on ledger, where params[0] is a key and params[1] actual value
      stub.PutState(params[0], params[1])
}

这只是一个简化的版本,而对于更复杂的,您可以遵循"编写应用程序“教程。

票数 4
EN

Stack Overflow用户

发布于 2017-11-08 01:25:38

是的,您可以在以Hyperledger Fabric实现的Blockchain中存储有关资产的信息(当前版本为1.0)。有关资产的信息通过链码(基于go语言的事务)更新。通过使用HyperLedger作曲家游乐场很容易开始试验这一点。HyperLedger Composer使用HyperLedger Fabric V1作为它的操作基础,它简化了编写过程,特别是原型化,新的Blockchain应用程序。

Composer使用建模语言来定义网络的特性(哪些成员类型、资产类型、事件和事务定义了核心网络)。它有一种健壮的访问控制语言,可以精确地指定谁可以访问哪些资产和哪些事务。它有一种简化的查询语言,在执行查询时会自动调用ACL (这意味着即使您要求获得您不应该看到的信息,您仍然看不到它),最后,它允许您用一种语言编写所有代码--目前的Javascript --包括智能事务的链码。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43732402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档