2017-05-02 63 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。 您可以在每次存儲東西時創建新的智能合同,並存儲您創建的先前合同的地址。它也容易跟蹤。