架构
分为五个部分:
区块链(核心部分,其中又以区块、交易为重点)
API/客户端/服务端(通过RPC交互)
网络传输(一般就是P2P)
数据存储(运用数据库,保存、管理数据)
数学/密码学
模块间调用
模块之间,可通过创建其关联对象进行互相调用。
API/客户端 - 调用 chain::Chain、p2p::Peers、pool::TransactionPool、pool::BlockChain、store::Store
区块链 - 调用 store::ChainStore(store::Store)、ChainAdapter、PMMRBackend(PMMR)
网络传输 - 调用 grin_store::Store,自调用 ChainAdapter、NetAdapter
交易池 - 调用 BlockChain、PoolAdapter
其它模块之间事件处理 - NetToChainAdapter(p2p::ChainAdapter)、ChainToPoolAndNetAdapter(chain::ChainAdapter)、PoolToNetAdapter(pool::PoolAdapter)、PoolToChainAdapter(pool::BlockChain)
目录结构
After checking out grin, building and using, these are the folders you'll have:
apiCode for ApiEndpoints accessible over REST.
chainThe blockchain implementation. Accepts a block (see pipe.rs) and adds it to the chain, or reject it.
configCode for handling configuration.
coreAll core types: Hash, Block, Input, Output, and how to serialize them. Core mining algorithm, and more.
docAll documentation.
serversMany parts (adapters, lib, miner, seed, server, sync, types) that the
grinserver needs, including mining server.keychainCode for working safely with keys and doing blinding.
p2pAll peer to peer connection and protocol-related logic (handshake, block propagation, etc.).
poolCode for the transaction pool implementation.
serverA folder you're supposed to create , before starting your server: cd to project root; mkdir server; cd server; grin server start (or run) and it will create a subfolder .grin
.grinchain- a database with the blockchain blocks and related information
peers- a database with the list of Grin peers you're connected to
txhashset- contains folders kernel, rangeproof and output that each have a pmmr_dat.bin
srcCode for the
grinbinary.storeData store - Grin uses near-zero-cost Rust wrapper around LMDB, key-value embedded data store.
targetWhere the grin binary ends up, after the compile and build process finishes. In case of trouble, see troubleshooting
utilLow-level rust utilities.
walletSimple command line wallet implementation. Will generate:
wallet_data- a database storing your "outputs", that once confirmed and matured, can be spent with the
grin wallet sendcommand. (locally created, _not _in git)
- a database storing your "outputs", that once confirmed and matured, can be spent with the
wallet.seed- your secret wallet seed. (locally created, _not _in git)