Hyperledger Fabric 通用放置和获取
Hyperledger Fabric generic put and get
我有一个界面,代表我想用区块链做什么。
public interface IBlockChain {
/**
* Put data on the blockchain
*
* @param key the key being used to put the data on the blockchain
* @param data the data being put on the blockchain
*/
public boolean put(String key, Map<String, Object> data);
/**
* Get data from the blockchain
*
* @param key the key being queried
* @return
*/
public List<Record> get(String key);
/**
* Get all data from the blockchain
* @return
*/
public List<Record> all();
}
我有一个适用于 Multichain 的有效实现。但我现在想开始实施其他区块链技术。
我将如何在 Hyperledger Fabric v1.0 中解决这个问题?我可以将原始数据推送给它吗?或者我是否总是需要调用链代码片段来为我创建一个对象?
您需要编写链代码来放置和获取数据。对应的链码函数为:
PutState(key string, value []byte) error
GetState(key string) ([]byte, error)
有 Hyperledger Fabric v1.0 的链代码教程:
https://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html
然后您的客户端可以调用链代码并提交交易。有一个 Hyperledger Fabric Node.js SDK tutorial 可以帮助您更好地理解。
我有一个界面,代表我想用区块链做什么。
public interface IBlockChain {
/**
* Put data on the blockchain
*
* @param key the key being used to put the data on the blockchain
* @param data the data being put on the blockchain
*/
public boolean put(String key, Map<String, Object> data);
/**
* Get data from the blockchain
*
* @param key the key being queried
* @return
*/
public List<Record> get(String key);
/**
* Get all data from the blockchain
* @return
*/
public List<Record> all();
}
我有一个适用于 Multichain 的有效实现。但我现在想开始实施其他区块链技术。 我将如何在 Hyperledger Fabric v1.0 中解决这个问题?我可以将原始数据推送给它吗?或者我是否总是需要调用链代码片段来为我创建一个对象?
您需要编写链代码来放置和获取数据。对应的链码函数为:
PutState(key string, value []byte) error
GetState(key string) ([]byte, error)
有 Hyperledger Fabric v1.0 的链代码教程:
https://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html
然后您的客户端可以调用链代码并提交交易。有一个 Hyperledger Fabric Node.js SDK tutorial 可以帮助您更好地理解。