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)
| 210 | // |
| 211 | // See NewClient |
| 212 | func 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 |
| 267 | func (c *Client) restoreTrustedLightBlock() error { |