MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / NewClient

Function NewClient

light/client.go:174–207  ·  view source on GitHub ↗

NewClient returns a new light client. It returns an error if it fails to obtain the light block from the primary or they are invalid (e.g. trust hash does not match with the one from the headers). Witnesses are providers, which will be used for cross-checking the primary provider. At least one witn

(
	ctx context.Context,
	chainID string,
	trustOptions TrustOptions,
	primary provider.Provider,
	witnesses []provider.Provider,
	trustedStore store.Store,
	options ...Option)

Source from the content-addressed store, hash-verified

172//
173// See all Option(s) for the additional configuration.
174func NewClient(
175 ctx context.Context,
176 chainID string,
177 trustOptions TrustOptions,
178 primary provider.Provider,
179 witnesses []provider.Provider,
180 trustedStore store.Store,
181 options ...Option) (*Client, error) {
182
183 if err := trustOptions.ValidateBasic(); err != nil {
184 return nil, fmt.Errorf("invalid TrustOptions: %w", err)
185 }
186
187 c, err := NewClientFromTrustedStore(chainID, trustOptions.Period, primary, witnesses, trustedStore, options...)
188 if err != nil {
189 return nil, err
190 }
191
192 if c.latestTrustedBlock != nil {
193 c.logger.Info("Checking trusted light block using options")
194 if err := c.checkTrustedHeaderUsingOptions(ctx, trustOptions); err != nil {
195 return nil, err
196 }
197 }
198
199 if c.latestTrustedBlock == nil || c.latestTrustedBlock.Height < trustOptions.Height {
200 c.logger.Info("Downloading trusted light block using options")
201 if err := c.initializeWithTrustOptions(ctx, trustOptions); err != nil {
202 return nil, err
203 }
204 }
205
206 return c, err
207}
208
209// NewClientFromTrustedStore initializes existing client from the trusted store.
210//

Calls 5

ValidateBasicMethod · 0.65
InfoMethod · 0.65