Skip to content

Commit

Permalink
chore: require node below 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 28, 2021
1 parent ebb36f0 commit ae1a5ef
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,33 @@ async function getConsensusProtocolVersion (protocols = [], height) {
* @example Node({url: 'https://testnet.aeternity.io'})
*/
const Node = AsyncInit.compose({
async init ({ url, internalUrl }) {
async init ({ url, internalUrl, ignoreVersion }) {
if (!url) throw new Error('"url" required')
this.url = url.replace(/\/$/, '')
this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url
let client = await genSwaggerClient(`${this.url}/api`, { internalUrl: this.internalUrl })
if (client.spec.info.version.split('-')[0] === '0.0.0') {
this.version = client.spec.info.version
const isIrisPrereleaseNode = semverSatisfies(this.version, '0.0.0', '0.0.1') // TODO: Remove after Iris node release
if (
!isIrisPrereleaseNode &&
!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
!ignoreVersion
) {
throw new Error(
`Unsupported node version ${this.version}. ` +
`Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
)
}
if (isIrisPrereleaseNode || semverSatisfies(this.version, IRIS_NODE_GE_VERSION, NODE_LT_VERSION)) {
client = await genSwaggerClient(`${this.url}/api?oas3`, { internalUrl: this.internalUrl })
this._isIrisNode = true
}
this.version = client.spec.info.version
this.api = client.api

const { nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId, protocols } = await this.api.getStatus()
this.consensusProtocolVersion = await this.getConsensusProtocolVersion(protocols)
this.nodeNetworkId = networkId
return Object.assign(this, { revision, genesisHash })
},
methods: {
getNodeInfo () {
Expand All @@ -102,26 +118,10 @@ const Node = AsyncInit.compose({
consensusProtocolVersion: null,
nodeNetworkId: null
}
}, {
async init ({ ignoreVersion = false }) {
const { nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId, protocols } = await this.api.getStatus()
this.consensusProtocolVersion = await this.getConsensusProtocolVersion(protocols)
if (
!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
!ignoreVersion
) {
throw new Error(
`Unsupported node version ${this.version}. ` +
`Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
)
}

this.nodeNetworkId = networkId
return Object.assign(this, { revision, genesisHash })
}
})

const NODE_GE_VERSION = '5.2.0'
const NODE_LT_VERSION = '6.0.0'
const IRIS_NODE_GE_VERSION = '6.0.0'
const NODE_LT_VERSION = '7.0.0'

export default Node

0 comments on commit ae1a5ef

Please sign in to comment.