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

Function NewClientFromTrustedStore

light/client.go:212–264  ·  view source on GitHub ↗

NewClientFromTrustedStore initializes existing client from the trusted store. See NewClient

(
	chainID string,
	trustingPeriod time.Duration,
	primary provider.Provider,
	witnesses []provider.Provider,
	trustedStore store.Store,
	options ...Option)

Source from the content-addressed store, hash-verified

210//
211// See NewClient
212func NewClientFromTrustedStore(
213 chainID string,
214 trustingPeriod time.Duration,
215 primary provider.Provider,
216 witnesses []provider.Provider,
217 trustedStore store.Store,
218 options ...Option) (*Client, error) {
219
220 c := &Client{
221 chainID: chainID,
222 trustingPeriod: trustingPeriod,
223 verificationMode: skipping,
224 trustLevel: DefaultTrustLevel,
225 maxRetryAttempts: defaultMaxRetryAttempts,
226 maxClockDrift: defaultMaxClockDrift,
227 maxBlockLag: defaultMaxBlockLag,
228 primary: primary,
229 witnesses: witnesses,
230 trustedStore: trustedStore,
231 pruningSize: defaultPruningSize,
232 confirmationFn: func(action string) bool { return true },
233 quit: make(chan struct{}),
234 logger: log.NewNopLogger(),
235 }
236
237 for _, o := range options {
238 o(c)
239 }
240
241 // Validate the number of witnesses.
242 if len(c.witnesses) == 0 {
243 return nil, ErrNoWitnesses
244 }
245
246 // Verify witnesses are all on the same chain.
247 for i, w := range witnesses {
248 if w.ChainID() != chainID {
249 return nil, fmt.Errorf("witness #%d: %v is on another chain %s, expected %s",
250 i, w, w.ChainID(), chainID)
251 }
252 }
253
254 // Validate trust level.
255 if err := ValidateTrustLevel(c.trustLevel); err != nil {
256 return nil, err
257 }
258
259 if err := c.restoreTrustedLightBlock(); err != nil {
260 return nil, err
261 }
262
263 return c, nil
264}
265
266// restoreTrustedLightBlock loads the latest trusted light block from the store
267func (c *Client) restoreTrustedLightBlock() error {

Callers 3

NewClientFunction · 0.85

Calls 4

NewNopLoggerFunction · 0.92
ValidateTrustLevelFunction · 0.85
ChainIDMethod · 0.65

Tested by 1