function createFromJson (rawData) {
            var inst = new NetStats();

            inst.name = rawData.name;
            inst.pollTime = rawData.pollTime;

            inst.endPoints = rawData.sites.map(function (site) {

                var url, httpService, type = site.type.toUpperCase();

                if (type === 'RPC') {
                    url = site.protocol + '://' + site.url;

                    if (site.port) {
                        url += ':' + site.port;
                    }
                    else if (site.protocol === 'http') {
                        url += (inst.name === 'MainNet') ? ':10332' : ':20332';
                    }
                    else {
                        url += (inst.name === 'MainNet') ? ':10331' : ':20331';
                    }

                    httpService = neo.node(url);
                }
                else if (type === 'REST') {

                    url = site.url;

                    if (site.service === 'antChain') {
                        httpService = neo.antChain(url);
                    }
                    else if (site.service === 'neoScan') {
                        httpService = neo.neoScan(url);
                    }
                    else if (site.service === 'neon') {
                        httpService = neo.neon(url);
                    }
                    else {
                        throw new Error('Unknown REST Service: ' + site.service);
                    }
                }
                else {
                    throw new Error('Unknown endpoint type: ' + site.type);
                }

                return {
                    name: url,
                    type: type,
                    isItUp: false,
                    peerCount: ' - ',
                    version: { useragent: ' - ' },
                    location: site.location,
                    url: url,
                    locale: site.locale,
                    httpService: httpService
                };
            });

            return inst;
        }
//Create a new NetStats instance from raw json
Create a new NetStats instance from raw json
Create a new NetStats instance from raw json
function createFromJson (rawData) {
            var inst = new NetStats();
            inst.name = rawData.name;
            inst.pollTime = rawData.pollTime;
            inst.endPoints = rawData.sites.map(function (site) {
                var url, httpService, type = site.type.toUpperCase();
                if (type === 'RPC') {
                    url = site.protocol + '://' + site.url;
                    if (site.port) {
                        url += ':' + site.port;
                    }
                    else if (site.protocol === 'http') {
                        url += (inst.name === 'MainNet') ? ':10332' : ':20332';
                    }
                    else {
                        url += (inst.name === 'MainNet') ? ':10331' : ':20331';
                    }
                    httpService = neo.node(url);
                }
                else if (type === 'REST') {
                    url = site.url;
                    if (site.service === 'antChain') {
                        httpService = neo.antChain(url);
                    }
                    else if (site.service === 'neoScan') {
                        httpService = neo.neoScan(url);
                    }
                    else if (site.service === 'neon') {
                        httpService = neo.neon(url);
                    }
                    else {
                        throw new Error('Unknown REST Service: ' + site.service);
                    }
                }
                else {
                    throw new Error('Unknown endpoint type: ' + site.type);
                }
                return {
                    name: url,
                    type: type,
                    isItUp: false,
                    peerCount: ' - ',
                    version: { useragent: ' - ' },
                    location: site.location,
                    url: url,
                    locale: site.locale,
                    httpService: httpService
                };
            });
            return inst;
        }
function createFromJson ( rawData ) { var inst = new NetStats ( ) ; inst . name = rawData . name ; inst . pollTime = rawData . pollTime ; inst . endPoints = rawData . sites . map ( function ( site ) { var url , httpService , type = site . type . toUpperCase ( ) ; if ( type === 'RPC' ) { url = site . protocol + '://' + site . url ; if ( site . port ) { url += ':' + site . port ; } else if ( site . protocol === 'http' ) { url += ( inst . name === 'MainNet' ) ? ':10332' : ':20332' ; } else { url += ( inst . name === 'MainNet' ) ? ':10331' : ':20331' ; } httpService = neo . node ( url ) ; } else if ( type === 'REST' ) { url = site . url ; if ( site . service === 'antChain' ) { httpService = neo . antChain ( url ) ; } else if ( site . service === 'neoScan' ) { httpService = neo . neoScan ( url ) ; } else if ( site . service === 'neon' ) { httpService = neo . neon ( url ) ; } else { throw new Error ( 'Unknown REST Service: ' + site . service ) ; } } else { throw new Error ( 'Unknown endpoint type: ' + site . type ) ; } return { name : url , type : type , isItUp : false , peerCount : ' - ' , version : { useragent : ' - ' } , location : site . location , url : url , locale : site . locale , httpService : httpService } ; } ) ; return inst ; }
Create a new NetStats instance from raw json
Create a new NetStats instance from raw json