SDK能做什么
- 创建通道
- 邀请peer节点加入通道
- 在peer节点上安装智能合约
- 在通道上实例化合约
- 调用合约执行交易
- 交易查询,区块查询
fabric上的安全性是用数字证书来保证的的。所有fabric中的操作要求必须由CA证书。
Node.js SDK的功能
Hyperledger Fabric SDK是以面向对象的编程风格进行设计。其模块化结构使应用程序开发人员能够对关键功能实现可插拔的替代实现,例如加密模块,状态存储模块和日志模块。
SDK的功能列表包括:
-
fabric-client:
//加载配置 可以传json对象或者json文件的路径 loadFromConfig(config) addTlsClientCertAndKey(opts) //创建channel 返回一个promise //参数类型 ChannelRequest ![image.png](https://img.haomeiwen.com/i5659111/b8fb4a5a46e7842c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) createChannel(request) //创建User 参数类型UserOpts 返回promise ![image.png](https://img.haomeiwen.com/i5659111/02aa7111abac01ca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) createUser(opts) extractChannelConfig(config_envelope) getCertificateAuthority(name) getChannel(name, throwError) ![image.png](https://img.haomeiwen.com/i5659111/b81d7f0755cb7d5f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) getClientConfig() getCryptoSuite() getEventHub(peer_name) getEventHubsForOrg(org_name) getMspid() getOrderer(name) getPeer(name) getPeersForOrg(org_name) getStateStore() getUserContext(name, checkPersistence) initCredentialStores() installChaincode(request, timeout) ![image.png](https://img.haomeiwen.com/i5659111/dafc384213581ff6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) isDevMode() loadFromConfig(config) loadUserFromStateStore(name) newChannel(name) newEventHub() newOrderer(url, opts) newPeer(url, opts) newTransactionID(admin) queryChannels(peer, useAdmin) queryInstalledChaincodes(peer, useAdmin) saveUserToStateStore() setAdminSigningIdentity(private_key, certificate, mspid) setCryptoSuite(cryptoSuite) setDevMode(devMode) setStateStore(keyValueStore) setTlsClientCertAndKey(clientCert, clientKey) setUserContext(user, skipPersistence) signChannelConfig(config) updateChannel(request)
addOrderer(orderer) addPeer(peer, roles) close() compareProposalResponseResults(The) executeTransaction(request) getChannelConfig(target) getChannelConfigFromOrderer() getChannelEventHub(name) getChannelEventHubsForOrg(org_name) getChannelPeer(name) getGenesisBlock(request) getMSPManager() getName() getOrderer(name) getOrderers() getOrganizations() getPeer(name) getPeers() getPeersForOrg(org_name) initialize(config) joinChannel(request, timeout) newChannelEventHub(peer) queryBlock(blockNumber, target, useAdmin) queryBlockByHash(block, target, useAdmin) queryBlockByTxID(tx_id, target, useAdmin) queryByChaincode(request) queryInfo(target, useAdmin) queryInstantiatedChaincodes(target, useAdmin) queryTransaction(tx_id, target, useAdmin) removeOrderer(orderer) removePeer(peer) sendInstantiateProposal(request, timeout) sendTransaction(request) sendTransactionProposal(request, timeout) sendUpgradeProposal(request, timeout) setMSPManager(msp_manager) toString() verifyProposalResponse(proposal_response)
installChaincode(request, timeout)
sendInstantiateProposal(request, timeout)// sendTransaction(request) //https://fabric-sdk-node.github.io/Channel.html#sendInstantiateProposal
sendTransactionProposal(request, timeout)//https://fabric-sdk-node.github.io/Channel.html#sendTransactionProposal sendTransaction(request)//https://fabric-sdk-node.github.io/Channel.html#sendTransaction
queryByChaincode(request)
-
各种查询功能:
queryInfo(target, useAdmin)
queryBlock(blockNumber, target, useAdmin)//https://fabric-sdk-node.github.io/Channel.html#queryBlock queryBlockByTxID(tx_id, target, useAdmin)//https://fabric-sdk-node.github.io/Channel.html#queryBlockByHash
queryChannels(peer, useAdmin)
queryInstalledChaincodes(peer, useAdmin)
queryInstantiatedChaincodes(target, useAdmin)
queryTransaction(tx_id, target, useAdmin)
getChannelConfig(target)
-
事件:
connect()
registerBlockEvent(onEvent, onError)
registerTxEvent(txid, onEvent, onError)
registerChaincodeEvent(ccid, eventname, onEvent, onError)
-
User对象序列化 签名
fromString() getAffiliation() getCryptoSuite() getIdentity() getName() getRoles() getSigningIdentity() isEnrolled() setAffiliation(affiliation) setEnrollment(privateKey, certificate, mspId) setRoles(roles) toString()
- 多种配置引入方式:文件、环境变量、程序参数、内存设置
- 内置日志模块(winston),可以使用log4js和bunyan等其他日志模块替换
- 可插拔的CryptoSuite接口描述与Fabric成功交互所需的加密操作。提供两种实现方式:
- 可插拔的状态存储接口,用于保存诸如用户的状态缓存
- 可自定义的加密
- 同时支持TLS(grpcs://)或非TLS(grpc://)连接到peer和orderer,请参阅Remote,它是同级和订购者的超类
//https://fabric-sdk-node.github.io/Remote.html //https://fabric-sdk-node.github.io/Orderer.html //https://fabric-sdk-node.github.io/Peer.html //https://fabric-sdk-node.github.io/Orderer.html
-
各种查询功能:
-
fabric-ca-client:
网友评论