2017-05-02 51 views
2

我正在处理POC,我必须存储一些数据,例如对象的ID,价格,所有者等等。是否可以使用智能合约将这些内容存储在区块链中。如果不是,使用区块链实现它的方法是什么。 (我做了一些研究,人们在SCM行业使用区块链,他们必须存储这些数据)。在区块链上存储数据

回答

1

是的,如果您使用以太坊智能合约,您可以定义您的合约并将其与交易一起存储。

https://www.ethereum.org/greeter

需要注意的是,如果你不加密存储在合同中的数据将是每个人都可以访问。

1

是的,你可以使用合约来存储你想要的东西。当然,你必须加密你的记录。但是,我认为这不是问题。

您可以定义合同并将其部署到同行。您的合同应该定义如何存储交易。另外,它应该定义如何验证它们。

1

您可以通过使用合同中相应的数据结构,然后进行交易产生的散列,你需要保存访问时随时

2

考虑从Hyperledger面料“Getting Started”页以下tutorial存储数据。

基本上您实现要求逻辑上通过利用chaincodes,你将必须实现以下golang接口:

// 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 
} 

例如一些与此类似:

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]) 
} 

这只是一个简化版本,而对于更复杂的你可以按照“Writing Your Application”教程。

2

是的,您可以在Hyperledger Fabric(当前版本为1.0)中存储实施区块链中资产的信息。关于资产的信息通过chaincode更新(去基于语言的交易)。通过使用HyperLedger Composer Playground来开始试验,这相当容易。 HyperLedger Composer使用HyperLedger Fabric V1作为操作基础,简化了新的Blockchain应用程序的编写过程,特别是原型。

Composer使用建模语言来定义网络的特征(成员类型,资产类型,事件和事务定义了核心网络)。它具有强大的访问控制语言,可以准确指定谁可以访问哪些资产和哪些事务。它有一个简化的查询语言,在执行查询时自动调用ACL(这意味着即使您要求提供您不应该看到的信息,您仍然无法看到它),最后,允许您编写所有的代码采用单一语言 - 目前使用Javascript - 包括智能交易的链式代码。

1

是的,可以将数据存储在智能合约中,您可以使用松露框架来创建智能合约和UI。 您可以在每次存储东西时创建新的智能合同,并存储您创建的先前合同的地址。它也容易跟踪。