Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ Use custom addresses & fallback signature to legacy #1772

Merged
merged 7 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/config/ConfigHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-named-default
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
import fs from 'fs'
import { Config } from '.'
import { LoggerInstance } from '../utils'

Expand Down Expand Up @@ -144,9 +145,8 @@ export class ConfigHelper {
public getAddressesFromEnv(network: string, customAddresses?: any): Partial<Config> {
// use the defaults first
let configAddresses: Partial<Config>

// load from custom addresses structure
if (customAddresses) {
if (customAddresses && customAddresses[network]) {
const {
FixedPrice,
Dispenser,
Expand Down Expand Up @@ -180,7 +180,8 @@ export class ConfigHelper {
DFRewards,
DFStrategyV1,
veFeeEstimate,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }),
...(process.env.PROVIDER_URI && { providerUri: process.env.PROVIDER_URI })
}
} else {
// no custom addresses structure was passed, trying to load default
Expand Down Expand Up @@ -218,7 +219,8 @@ export class ConfigHelper {
DFRewards,
DFStrategyV1,
veFeeEstimate,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }),
...(process.env.PROVIDER_URI && { providerUri: process.env.PROVIDER_URI })
}
}
}
Expand All @@ -239,8 +241,16 @@ export class ConfigHelper {
LoggerInstance.error(`No config found for given network '${network}'`)
return null
}

const contractAddressesConfig = this.getAddressesFromEnv(config.network)
const customAddresses = process.env.ADDRESS_FILE
? JSON.parse(
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFileSync(process.env.ADDRESS_FILE, 'utf8')
)
: null
const contractAddressesConfig = this.getAddressesFromEnv(
config.network,
customAddresses
)
config = { ...config, ...contractAddressesConfig }

const nodeUri = infuraProjectId
Expand Down
14 changes: 9 additions & 5 deletions src/services/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,16 @@ export class Provider {
)
const messageHashBytes = ethers.utils.arrayify(consumerMessage)
const chainId = await signer.getChainId()
if (chainId === 8996) {
return await (signer as providers.JsonRpcSigner)._legacySignMessage(
messageHashBytes
)
try {
return await signer.signMessage(messageHashBytes)
} catch (error) {
LoggerInstance.error('Sign provider message error: ', error)
if (chainId === 8996) {
return await (signer as providers.JsonRpcSigner)._legacySignMessage(
messageHashBytes
)
}
}
return await signer.signMessage(messageHashBytes)
}

/**
Expand Down