Skip to content

Commit 0c327ce

Browse files
committed
networks
1 parent 33990d8 commit 0c327ce

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/networks.js renamed to src/networks.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
/* eslint-disable */
2+
13
'use strict';
24
var _ = require('lodash');
35

46
var BufferUtil = require('./util/buffer');
57
var JSUtil = require('./util/js');
6-
var networks = [];
7-
var networkMaps = {};
8+
var networks:networkType[] = [];
9+
var networkMaps:any = {};
810

911
/**
1012
* A network is merely a map containing values that correspond to version
1113
* numbers for each bitcoin network. Currently only supporting "livenet"
1214
* (a.k.a. "mainnet") and "testnet".
1315
* @constructor
1416
*/
15-
function Network() {}
17+
export const Network:any = () => {}
1618

1719
Network.prototype.toString = function toString() {
1820
return this.name;
@@ -26,17 +28,15 @@ Network.prototype.toString = function toString() {
2628
* @param {string|Array} keys - if set, only check if the magic number associated with this name matches
2729
* @return Network
2830
*/
29-
function get(arg, keys) {
31+
function get(arg?:networkType, keys?:keyType) {
3032
if (~networks.indexOf(arg)) {
3133
return arg;
3234
}
3335
if (keys) {
3436
if (!_.isArray(keys)) {
3537
keys = [keys];
3638
}
37-
var containsArg = function(key) {
38-
return networks[index][key] === arg;
39-
};
39+
var containsArg = (key: keyType, index:number) => networks[index][key] === arg;
4040
for (var index in networks) {
4141
if (_.some(keys, containsArg)) {
4242
return networks[index];
@@ -69,9 +69,9 @@ function get(arg, keys) {
6969
* @param {Array} data.dnsSeeds - An array of dns seeds
7070
* @return Network
7171
*/
72-
function addNetwork(data) {
72+
function addNetwork(data:any) {
7373

74-
var network = new Network();
74+
var network:any = new Network();
7575

7676
JSUtil.defineImmutable(network, {
7777
name: data.name,
@@ -101,7 +101,7 @@ function addNetwork(data) {
101101
dnsSeeds: data.dnsSeeds
102102
});
103103
}
104-
_.each(network, function(value) {
104+
_.each(network, function(value:any) {
105105
if (!_.isUndefined(value) && !_.isObject(value)) {
106106
if(!networkMaps[value]) {
107107
networkMaps[value] = [];
@@ -122,7 +122,7 @@ function addNetwork(data) {
122122
* Will remove a custom network
123123
* @param {Network} network
124124
*/
125-
function removeNetwork(network) {
125+
function removeNetwork(network:networkType) {
126126
for (var i = 0; i < networks.length; i++) {
127127
if (networks[i] === network) {
128128
networks.splice(i, 1);

src/type.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type stringNumberType = string | number;
33
type dataType = string | Buffer;
44

55
type networkType = string | number | Network;
6+
7+
type keyType = string | Array;

0 commit comments

Comments
 (0)