Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(logger?: LogTypes.ILogger) {
this.initialized = false;
this.logger = logger || new Utils.SimpleLogger();
const initializationStoragePath = getInitializationStorageFilePath();
const store = initializationStoragePath
? new KeyvFile({
filename: initializationStoragePath,
})
: undefined;
// Use ethereum storage for the storage layer
const ethereumStorage: StorageTypes.IStorage = getEthereumStorage(
getMnemonic(),
this.logger,
store,
);
public constructor(
eth: any,
firstSignificantBlockNumber: number,
retryDelay: number,
maxRetries: number,
getLastBlockNumberMinDelay: number = 0,
logger?: LogTypes.ILogger,
) {
this.eth = eth;
this.firstSignificantBlockNumber = firstSignificantBlockNumber;
this.getLastBlockNumberMinDelay = getLastBlockNumberMinDelay;
this.logger = logger || new Utils.SimpleLogger();
// Get retry parameter values from config
this.retryDelay = retryDelay;
this.maxRetries = maxRetries;
// Setup the throttled and retriable getLastBlockNumber function
this.getLastBlockNumber = Utils.cachedThrottle(
() =>
Utils.retry(
() => {
this.logger.debug(`Getting last block number`, ['ethereum', 'ethereum-blocks']);
return this.eth.getBlockNumber();
},
{
maxRetries: this.maxRetries,
retryDelay: this.retryDelay,
getLastBlockNumberDelay,
logger,
maxRetries,
retryDelay,
}: {
maxConcurrency: number;
logger?: LogTypes.ILogger;
getLastBlockNumberDelay?: number;
maxRetries?: number;
retryDelay?: number;
} = {
maxConcurrency: Number.MAX_SAFE_INTEGER,
},
) {
this.maxConcurrency = maxConcurrency;
this.logger = logger || new Utils.SimpleLogger();
this.maxRetries = maxRetries;
this.retryDelay = retryDelay;
web3Connection = web3Connection || {};
try {
this.eth = new web3Eth(
web3Connection.web3Provider ||
new web3Eth.providers.HttpProvider(config.getDefaultEthereumProvider()),
);
} catch (error) {
throw Error(`Can't initialize web3-eth ${error}`);
}
// Checks if networkId is defined
public constructor(storage: StorageTypes.IStorage, options?: IDataAccessOptions) {
const defaultOptions: IDataAccessOptions = {
logger: new Utils.SimpleLogger(),
synchronizationIntervalTime: DEFAULT_INTERVAL_TIME,
transactionIndex: new TransactionIndex(),
};
options = {
...defaultOptions,
...options,
};
this.storage = storage;
this.lastSyncStorageTimestamp = 0;
this.synchronizationTimer = new IntervalTimer(
(): Promise => this.synchronizeNewDataIds(),
options.synchronizationIntervalTime!,
options.logger!,
5,
);
this.transactionIndex = options.transactionIndex!;
public constructor(logger?: LogTypes.ILogger) {
this.logger = logger || new Utils.SimpleLogger();
}
getLastBlockNumberDelay,
logger,
maxConcurrency,
maxRetries,
retryDelay,
}: {
getLastBlockNumberDelay?: number;
logger?: LogTypes.ILogger;
maxConcurrency?: number;
maxRetries?: number;
retryDelay?: number;
} = {},
metadataStore?: Keyv.Store,
) {
this.maxConcurrency = maxConcurrency || getMaxConcurrency();
this.logger = logger || new Utils.SimpleLogger();
this.ipfsManager = new IpfsManager(ipfsGatewayConnection);
this.smartContractManager = new SmartContractManager(web3Connection, {
getLastBlockNumberDelay,
logger: this.logger,
maxConcurrency: this.maxConcurrency,
maxRetries,
retryDelay,
});
this.ethereumMetadataCache = new EthereumMetadataCache(
this.smartContractManager,
metadataStore,
);
}