bitpay / bitcore-p2p

Interface to the bitcoin P2P network for bitcore
MIT License
81 stars 276 forks source link

Peer arguments overloading #46

Closed fanatid closed 9 years ago

fanatid commented 9 years ago

In Peer constructor port, network and relay is optional arguments. When port is Object and network isn't undefined arguments will be overloaded, but only port and network, not relay.

i.e. instead

// overloading stuff
if (port instanceof Object && !network) {
  network = port;
  port = undefined;
}

should be something like this

var test = Function.prototype.call.bind(Object.prototype.toString)

---
if (test(network) === '[object Boolean]' && !relay) {
  relay = network
  network = undefined
  if (test(port) === '[object Object]') {
    network = port
    port = undefined
  }
}
if (test(port) === '[object Object]' && !network && !relay) {
  network = port
  port = relay = undefined
}
if (test(port) === '[object Boolean]' && !network && !relay) {
  relay = network
  port = network = undefined
}

I'm right? Of course it's not simple overloading, so it may be better to use opts as in Pool?

Also @param missing for relay.

maraoz commented 9 years ago

+1 I think we should use an opts object probably

braydonf commented 9 years ago

Agree with the options object.

braydonf commented 9 years ago

Options object for params included in: https://github.com/bitpay/bitcore-p2p/pull/48