提交 2c28ef19 作者: Łukasz Magiera

coreapi: FetchBlocks option

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 7efffc35
......@@ -210,7 +210,9 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
subApi.peerstore = nil
subApi.peerHost = nil
subApi.recordValidator = nil
}
if settings.Offline || !settings.FetchBlocks {
subApi.exchange = offlinexch.Exchange(subApi.blockstore)
subApi.blocks = bserv.New(subApi.blockstore, subApi.exchange)
subApi.dag = dag.NewDAGService(subApi.blocks)
......
package options
type ApiSettings struct {
Offline bool
Offline bool
FetchBlocks bool
}
type ApiOption func(*ApiSettings) error
func ApiOptions(opts ...ApiOption) (*ApiSettings, error) {
options := &ApiSettings{
Offline: false,
Offline: false,
FetchBlocks: true,
}
return ApiOptionsTo(options, opts...)
......@@ -34,3 +36,12 @@ func (apiOpts) Offline(offline bool) ApiOption {
return nil
}
}
// FetchBlocks when set to false prevents api from fetching blocks from the
// network while allowing other services such as IPNS to still be online
func (apiOpts) FetchBlocks(fetch bool) ApiOption {
return func(settings *ApiSettings) error {
settings.FetchBlocks = fetch
return nil
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论