import axios from 'axios' ; import RadixNodeDiscovery from './RadixNodeDiscovery' ; import { RadixSerializer } from '../atommodel' ; import { RadixNode , RadixNodeSystem } from '../..' ; /**
 * Radix node discovery from a fixed list
 */ export default class RadixNodeDiscoveryHardcoded implements RadixNodeDiscovery { private readonly httpProtocol : string ; private readonly wsProtocol : string ; param bootstrapNodes param ssl constructor ( readonly bootstrapNodes , readonly ssl = false ) { if ( bootstrapNodes . length < 1 ) { throw new Error ( 'ERROR: List of bootstrap nodes cannot be empty.' ) ; } this . httpProtocol = ssl ? 'https' : 'http' ; this . wsProtocol = ssl ? 'wss' : 'ws' ; } public async loadNodes ( ) { return Promise . all ( this . bootstrapNodes . map ( async ( address ) => { const response = await axios . get ( `${ this . httpProtocol }://${ address }/api/system` ) ; const nodeInfo = RadixSerializer . fromJSON ( response . data ) ; const node = new RadixNode ( nodeInfo , `${ this . wsProtocol }://${ address }/rpc` , `${ this . httpProtocol }://${ address }/rpc` ) ; return node ; } ) ) ; } }