Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getMainAccount(): Promise {
// Get the accounts on the provider
// Throws an error if timeout is reached
const accounts = await Promise.race([
Utils.timeoutPromise(this.timeout, 'Web3 getAccounts connection timeout'),
this.eth.getAccounts(),
]);
if (!accounts || !accounts[0]) {
throw Error('No account found');
}
return accounts[0];
}
public async addHashAndSizeToEthereum(
contentHash: string,
feesParameters: StorageTypes.IFeesParameters,
gasPrice?: number,
): Promise {
// Get the account for the transaction
const account = await this.getMainAccount();
// Handler to get gas price
const gasPriceDefiner = new GasPriceDefiner();
// Get the fee from the size of the content
// Throws an error if timeout is reached
const fee = await Promise.race([
Utils.timeoutPromise(this.timeout, 'Web3 getFeesAmount connection timeout'),
this.requestHashSubmitter.methods.getFeesAmount(feesParameters.contentSize).call(),
]);
// Determines the gas price to use
// If the gas price is provided as a parameter, we use this value
// If the gas price is not provided and we use mainnet, we determine it from gas price api providers
// We use the fast value provided by the api providers
// Otherwise, we use default value from config
const gasPriceToUse =
gasPrice ||
(await gasPriceDefiner.getGasPrice(StorageTypes.GasPriceType.FAST, this.networkName));
// parse the fees parameters to hex bytes
const feesParametersAsBytes = web3Utils.padLeft(
web3Utils.toHex(feesParameters.contentSize),
LENGTH_BYTES32_STRING,
(args: any) =>
Promise.race([
Utils.timeoutPromise(this.timeout, 'Web3 getPastEvents connection timeout'),
this.requestHashStorage.getPastEvents(args),
]),
{