本文作者:楊尉;原創(chuàng)作品茸俭,轉(zhuǎn)載請注明出處
[上一篇鏈接] filecoin技術(shù)架構(gòu)分析之十一:filecoin源碼分析之內(nèi)部接口層api包分析
[下一篇鏈接] filecoin技術(shù)架構(gòu)分析之十三:filecoin源碼分析之服務(wù)層actor及vm
目錄
- 12.filecoin源碼分析之內(nèi)部接口層plumbing&porcelain接口
- 12.1 說明
- 12.2 plumbing&porcelain模式簡述
- 12.3 plumbing底層接口
- 12.4 porcelain高層接口
12.1 說明
-
目前官方正在將api包解耦有梆,往plumbing报强、porcelain中遷移
- 緣由: 原來的api包懒鉴,依賴于node包犬性,而node包應(yīng)該屬于api之上的瞻离,這導(dǎo)致代碼耦合性大
- node作為一個(gè)上帝對象,被api包依賴乒裆,對架構(gòu)擴(kuò)展性套利,其他類型節(jié)點(diǎn)擴(kuò)展開發(fā)不利
- 就在筆者寫這篇文章的同時(shí),官方應(yīng)該還在繼續(xù)遷移鹤耍,后面api包會逐步都遷移完
porcelain主要依賴于plumbing接口
上一章所述的api包將會被廢除
本文分析版本肉迫,go-filecoin版本:master 2c87fd59 (2019.3.7)
12.2 plumbing&porcelain模式簡述
- 該模式是借鑒git的思路,提供兩種接口稿黄,porcelain偏高層面對用戶更加友好方便喊衫;plumbing偏底層,友好度弱于porcelain
- porcelain是英文瓷器的意思,類似洗手盆之類杆怕;plumbing是水管裝置的意思族购,類似下水管,用戶當(dāng)然直接用洗手盆省心,不用管水管的事情
- 用戶級更偏向用porcelain陵珍,協(xié)議級更偏向使用plumbing寝杖,
12.3 plumbing底層接口
-
說明
- plumbing底層接口是為實(shí)現(xiàn)協(xié)議以及面向網(wǎng)絡(luò)的必須最小實(shí)現(xiàn)
- 更應(yīng)用級別的調(diào)用更多將會調(diào)用到porcelain高層接口
-
提供的具體功能接口
- 區(qū)塊狀態(tài)讀取
- 配置信息
- 日志
- 消息池操作
- 消息預(yù)覽,Gas計(jì)算
- 消息查詢
- 消息發(fā)送
- 消息等待
- 網(wǎng)絡(luò)操作
- Chain狀態(tài)獲然ゴ俊(actor信息)
- 錢包底層操作
具體的方法如下
▼ package
plumbing
? imports
▼+API : struct
[fields]
-chain : chain.ReadStore
-config : *cfg.Config
-logger : logging.EventLogger
-msgPool : *core.MessagePool
-msgPreviewer : *msg.Previewer
-msgQueryer : *msg.Queryer
-msgSender : *msg.Sender
-msgWaiter : *msg.Waiter
-network : *ntwk.Network
-sigGetter : *mthdsig.Getter
-wallet : *wallet.Wallet
[methods]
+ActorGet(ctx context.Context, addr address.Address) : *actor.Actor, error
+ActorGetSignature(ctx context.Context, actorAddr address.Address, method string) : *exec.FunctionSignature, error
+BlockGet(ctx context.Context, id cid.Cid) : *types.Block, error
+ChainHead(ctx context.Context) : types.TipSet
+ChainLs(ctx context.Context) : chan interface{}
+ConfigGet(dottedPath string) : interface{}, error
+ConfigSet(dottedPath string, paramJSON string) : error
+MessagePoolGet(cid cid.Cid) : *types.SignedMessage, bool
+MessagePoolPending() : []*types.SignedMessage
+MessagePoolRemove(cid cid.Cid)
+MessagePreview(ctx context.Context, from, to address.Address, method string, params ...interface{}) : types.GasUnits, error
+MessageQuery(ctx context.Context, optFrom, to address.Address, method string, params ...interface{}) : [][]byte, *exec.FunctionSignature, error
+MessageSend(ctx context.Context, from, to address.Address, value *types.AttoFIL, gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) : cid.Cid, error
+MessageWait(ctx context.Context, msgCid cid.Cid, cb func(*types.Block, *types.SignedMessage, *types.MessageReceipt) error) : error
+NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) : chan pstore.PeerInfo
+NetworkGetPeerID() : peer.ID
+PubSubPublish(topic string, data []byte) : error
+PubSubSubscribe(topic string) : pubsub.Subscription, error
+SignBytes(data []byte, addr address.Address) : types.Signature, error
+WalletAddresses() : []address.Address
+WalletFind(address address.Address) : wallet.Backend, error
+WalletNewAddress() : address.Address, error
[functions]
+New(deps *APIDeps) : *API
12.4 porcelain高層接口
-
說明
- porcelain主要依賴plumbing實(shí)現(xiàn)瑟幕。
- 主要是面向用戶級操作
-
提供功能
- 獲取區(qū)塊高度
- 建立支付通道/多支付通道
- 獲取默認(rèn)地址
- 消息池等待未被打包進(jìn)區(qū)塊的消息
- 采用默認(rèn)地址發(fā)送消息
- 獲取指定礦工報(bào)價(jià)單
- 獲取礦工Owner地址
- 獲取礦工節(jié)點(diǎn)ID
- 創(chuàng)建礦工,預(yù)覽Gas消耗
- 礦工報(bào)價(jià)留潦,預(yù)覽Gas消耗
- 礦工報(bào)價(jià)
- 獲取簽名支付憑證
- 錢包余額查詢
▼ package
porcelain
? imports
▼+API : struct
[embedded]
+*plumbing.API : *plumbing.API
[methods]
+ChainBlockHeight(ctx context.Context) : *types.BlockHeight, error
+CreatePayments(ctx context.Context, config CreatePaymentsParams) : *CreatePaymentsReturn, error
+GetAndMaybeSetDefaultSenderAddress() : address.Address, error
+MessagePoolWait(ctx context.Context, messageCount uint) : []*types.SignedMessage, error
+MessageSendWithDefaultAddress(ctx context.Context, from, to address.Address, value *types.AttoFIL, gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) : cid.Cid, error
+MinerGetAsk(ctx context.Context, minerAddr address.Address, askID uint64) : minerActor.Ask, error
+MinerGetOwnerAddress(ctx context.Context, minerAddr address.Address) : address.Address, error
+MinerGetPeerID(ctx context.Context, minerAddr address.Address) : peer.ID, error
+MinerPreviewCreate(ctx context.Context, fromAddr address.Address, pledge uint64, pid peer.ID, collateral *types.AttoFIL) : types.GasUnits, error
+MinerPreviewSetPrice(ctx context.Context, from address.Address, miner address.Address, price *types.AttoFIL, expiry *big.Int) : types.GasUnits, error
+MinerSetPrice(ctx context.Context, from address.Address, miner address.Address, gasPrice types.AttoFIL, gasLimit types.GasUnits, price *types.AttoFIL, expiry *big.Int) : MinerSetPriceResponse, error
+PaymentChannelLs(ctx context.Context, fromAddr address.Address, payerAddr address.Address) : map[string]*paymentbroker.PaymentChannel, error
+PaymentChannelVoucher(ctx context.Context, fromAddr address.Address, channel *types.ChannelID, amount *types.AttoFIL, validAt *types.BlockHeight) : *paymentbroker.PaymentVoucher, error
+WalletBalance(ctx context.Context, address address.Address) : *types.AttoFIL, error
[functions]
+New(plumbing *plumbing.API) : *API
[上一篇鏈接] filecoin技術(shù)架構(gòu)分析之十一:filecoin源碼分析之內(nèi)部接口層api包分析
[下一篇鏈接] filecoin技術(shù)架構(gòu)分析之十三:filecoin源碼分析之服務(wù)層actor及vm