Filecoin技术架构分析之十二:内部接口层plumbing&porce

目录12.filecoin源码分析之内部接口层plumbing&porcelain接口

12.1 说明

12.2 plumbing&porcelain模式简述

12.3 plumbing底层接口

12.4 porcelain高层接口

12.1 说明目前官方正在将api包解耦,往plumbing、porcelain中迁移

缘由: 原来的api包,依赖于node包,而node包应该属于api之上的,这导致代码耦合性大

node作为一个上帝对象,被api包依赖,对架构扩展性,其他类型节点扩展开发不利

就在笔者写这篇文章的同时,官方应该还在继续迁移,后面api包会逐步都迁移完

porcelain主要依赖于plumbing接口

上一章所述的api包将会被废除

本文分析版本,go-filecoin版本:master 2c87fd59 (2019.3.7)

12.2 plumbing&porcelain模式简述该模式是借鉴git的思路,提供两种接口,porcelain偏高层面对用户更加友好方便;plumbing偏底层,友好度弱于porcelain

porcelain是英文瓷器的意思,类似洗手盆之类;plumbing是水管装置的意思,类似下水管,用户当然直接用洗手盆省心,不用管水管的事情

用户级更偏向用porcelain,协议级更偏向使用plumbing,

12.3 plumbing底层接口说明

plumbing底层接口是为实现协议以及面向网络的必须最小实现

更应用级别的调用更多将会调用到porcelain高层接口

提供的具体功能接口

区块状态读取

配置信息

日志

消息池操作

消息预览,Gas计算

消息查询

消息发送

消息等待

网络操作

Chain状态获取(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(ctxcontext.Context,addraddress.Address):*actor.Actor,error

+ActorGetSignature(ctxcontext.Context,actorAddraddress.Address,methodstring):*exec.FunctionSignature,error

+BlockGet(ctxcontext.Context,idcid.Cid):*types.Block,error

+ChainHead(ctxcontext.Context):types.TipSet

+ChainLs(ctxcontext.Context):chaninterface{}

+ConfigGet(dottedPathstring):interface{},error

+ConfigSet(dottedPathstring,paramJSONstring):error

+MessagePoolGet(cidcid.Cid):*types.SignedMessage,bool

+MessagePoolPending():[]*types.SignedMessage

+MessagePoolRemove(cidcid.Cid)

+MessagePreview(ctxcontext.Context,from,toaddress.Address,methodstring,params...interface{}):types.GasUnits,error

+MessageQuery(ctxcontext.Context,optFrom,toaddress.Address,methodstring,params...interface{}):[][]byte,*exec.FunctionSignature,error

+MessageSend(ctxcontext.Context,from,toaddress.Address,value*types.AttoFIL,gasPricetypes.AttoFIL,gasLimittypes.GasUnits,methodstring,params...interface{}):cid.Cid,error

+MessageWait(ctxcontext.Context,msgCidcid.Cid,cbfunc(*types.Block,*types.SignedMessage,*types.MessageReceipt)error):error

+NetworkFindProvidersAsync(ctxcontext.Context,keycid.Cid,countint):chanpstore.PeerInfo

+NetworkGetPeerID():peer.ID

+PubSubPublish(topicstring,data[]byte):error

+PubSubSubscribe(topicstring):pubsub.Subscription,error

+SignBytes(data[]byte,addraddress.Address):types.Signature,error

+WalletAddresses():[]address.Address

+WalletFind(addressaddress.Address):wallet.Backend,error

+WalletNewAddress():address.Address,error

[functions]

+New(deps*APIDeps):*API

12.4 porcelain高层接口说明

porcelain主要依赖plumbing实现。

主要是面向用户级操作

提供功能

获取区块高度

建立支付通道/多支付通道

获取默认地址

消息池等待未被打包进区块的消息

采用默认地址发送消息

获取指定矿工报价单

获取矿工Owner地址

获取矿工节点ID

创建矿工,预览Gas消耗

矿工报价,预览Gas消耗

矿工报价

获取签名支付凭证

钱包余额查询

▼package

porcelain▶imports▼+API:struct

[embedded]

+*plumbing.API:*plumbing.API

[methods]

+ChainBlockHeight(ctxcontext.Context):*types.BlockHeight,error

+CreatePayments(ctxcontext.Context,configCreatePaymentsParams):*CreatePaymentsReturn,error

+GetAndMaybeSetDefaultSenderAddress():address.Address,error

+MessagePoolWait(ctxcontext.Context,messageCountuint):[]*types.SignedMessage,error

+MessageSendWithDefaultAddress(ctxcontext.Context,from,toaddress.Address,value*types.AttoFIL,gasPricetypes.AttoFIL,gasLimittypes.GasUnits,methodstring,params...interface{}):cid.Cid,error

+MinerGetAsk(ctxcontext.Context,minerAddraddress.Address,askIDuint64):minerActor.Ask,error

+MinerGetOwnerAddress(ctxcontext.Context,minerAddraddress.Address):address.Address,error

+MinerGetPeerID(ctxcontext.Context,minerAddraddress.Address):peer.ID,error

+MinerPreviewCreate(ctxcontext.Context,fromAddraddress.Address,pledgeuint64,pidpeer.ID,collateral*types.AttoFIL):types.GasUnits,error

+MinerPreviewSetPrice(ctxcontext.Context,fromaddress.Address,mineraddress.Address,price*types.AttoFIL,expiry*big.Int):types.GasUnits,error

+MinerSetPrice(ctxcontext.Context,fromaddress.Address,mineraddress.Address,gasPricetypes.AttoFIL,gasLimittypes.GasUnits,price*types.AttoFIL,expiry*big.Int):MinerSetPriceResponse,error

+PaymentChannelLs(ctxcontext.Context,fromAddraddress.Address,payerAddraddress.Address):map[string]*paymentbroker.PaymentChannel,error

+PaymentChannelVoucher(ctxcontext.Context,fromAddraddress.Address,channel*types.ChannelID,amount*types.AttoFIL,validAt*types.BlockHeight):*paymentbroker.PaymentVoucher,error

+WalletBalance(ctxcontext.Context,addressaddress.Address):*types.AttoFIL,error

[functions]

+New(plumbing*plumbing.API):*API

m5js1dhqrsx.png (84.2 KB, 下载次数: 19)

下载附件

m5js1dhqrsx.png

2019-5-5 14:59 上传

版权声明:
作者:bitchina.net
链接:http://www.bitchina.net/archives/642.html
来源:比特中国
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>