use node util.inherits

This commit is contained in:
Manuel Araoz 2014-07-10 15:55:32 -03:00
parent 6e346d067c
commit 557e9ae2a4
8 changed files with 23 additions and 20 deletions

View File

@ -32,8 +32,10 @@
'use strict'; 'use strict';
var coinUtil = require('../util'); var coinUtil = require('../util');
var VersionedData = require('../util/VersionedData'); var VersionedData = require('../util/VersionedData');
var EncodedData = require('../util/EncodedData');
var networks = require('../networks'); var networks = require('../networks');
var Script = require('./Script'); var Script = require('./Script');
var util = require('util');
function Address(version, hash) { function Address(version, hash) {
if (hash && hash.length && hash.length != 20) if (hash && hash.length && hash.length != 20)
@ -41,8 +43,8 @@ function Address(version, hash) {
Address.super(this, arguments); Address.super(this, arguments);
} }
Address.prototype = Object.create(VersionedData.prototype) util.inherits(Address, VersionedData);
VersionedData.applyEncodingsTo(Address); EncodedData.applyEncodingsTo(Address);
// create a pubKeyHash address // create a pubKeyHash address
Address.fromPubKey = function(pubKey, network) { Address.fromPubKey = function(pubKey, network) {

View File

@ -17,6 +17,7 @@ var buffertools = require('buffertools');
var doubleSha256 = util.twoSha256; var doubleSha256 = util.twoSha256;
var SecureRandom = require('./SecureRandom'); var SecureRandom = require('./SecureRandom');
var nonce = SecureRandom.getPseudoRandomBuffer(8); var nonce = SecureRandom.getPseudoRandomBuffer(8);
var nodeUtil = require('util');
var BIP0031_VERSION = 60000; var BIP0031_VERSION = 60000;
@ -61,7 +62,7 @@ function Connection(socket, peer, opts) {
this.setupHandlers(); this.setupHandlers();
} }
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
Connection.prototype = Object.create(EventEmitter.prototype) nodeUtil.inherits(Connection, EventEmitter);
Connection.prototype.open = function(callback) { Connection.prototype.open = function(callback) {
if (typeof callback === 'function') this.once('connect', callback); if (typeof callback === 'function') this.once('connect', callback);
this.socket.connect(this.peer.port, this.peer.host); this.socket.connect(this.peer.port, this.peer.host);

View File

@ -5,6 +5,7 @@ var Peer = require('./Peer');
var async = require('async'); var async = require('async');
var dns = require('dns'); var dns = require('dns');
var networks = require('../networks'); var networks = require('../networks');
var util = require('util');
GetAdjustedTime = function() { GetAdjustedTime = function() {
// TODO: Implement actual adjustment // TODO: Implement actual adjustment
@ -40,7 +41,7 @@ function PeerManager(config) {
} }
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
PeerManager.prototype = Object.create(EventEmitter.prototype) util.inherits(PeerManager, EventEmitter);
PeerManager.Connection = Connection; PeerManager.Connection = Connection;
PeerManager.prototype.start = function() { PeerManager.prototype.start = function() {

View File

@ -1,6 +1,8 @@
var VersionedData = require('../util/VersionedData'); var VersionedData = require('../util/VersionedData');
var EncodedData = require('../util/EncodedData');
var networks = require('../networks'); var networks = require('../networks');
var util = require('util');
//compressed is true if public key is compressed; false otherwise //compressed is true if public key is compressed; false otherwise
function PrivateKey(version, buf, compressed) { function PrivateKey(version, buf, compressed) {
@ -8,9 +10,8 @@ function PrivateKey(version, buf, compressed) {
if (compressed !== undefined) if (compressed !== undefined)
this.compressed(compressed); this.compressed(compressed);
}; };
util.inherits(PrivateKey, VersionedData);
PrivateKey.prototype = Object.create(VersionedData.prototype) EncodedData.applyEncodingsTo(PrivateKey);
VersionedData.applyEncodingsTo(PrivateKey);
PrivateKey.prototype.validate = function() { PrivateKey.prototype.validate = function() {
this.doAsBinary(function() { this.doAsBinary(function() {

View File

@ -1,4 +1,6 @@
var VersionedData = require('../util/VersionedData'); var VersionedData = require('../util/VersionedData');
var EncodedData = require('../util/EncodedData');
var util = require('util');
function SIN(type, payload) { function SIN(type, payload) {
if (typeof type != 'number') { if (typeof type != 'number') {
@ -12,8 +14,8 @@ function SIN(type, payload) {
this.payload(payload); this.payload(payload);
}; };
SIN.prototype = Object.create(VersionedData.prototype) util.inherits(SIN, VersionedData);
VersionedData.applyEncodingsTo(SIN); EncodedData.applyEncodingsTo(SIN);
SIN.SIN_PERSIST_MAINNET = 0x01; // associated with sacrifice TX SIN.SIN_PERSIST_MAINNET = 0x01; // associated with sacrifice TX
SIN.SIN_PERSIST_TESTNET = 0x11; // associated with sacrifice TX SIN.SIN_PERSIST_TESTNET = 0x11; // associated with sacrifice TX

View File

@ -2,8 +2,6 @@
* Simple synchronous parser based on node-binary. * Simple synchronous parser based on node-binary.
*/ */
var imports = require('soop').imports();
function Parser(buffer) { function Parser(buffer) {
this.subject = buffer; this.subject = buffer;
this.pos = 0; this.pos = 0;

View File

@ -1,6 +1,4 @@
var imports = require('soop').imports(); var base58 = require('../lib/Base58').base58Check;
var base58 = imports.base58 || require('../lib/Base58').base58Check;
// Constructor. Takes the following forms: // Constructor. Takes the following forms:
// new EncodedData(<base58_address_string>) // new EncodedData(<base58_address_string>)
@ -32,7 +30,7 @@ EncodedData.prototype.withEncoding = function(encoding) {
// answer the data in the given encoding // answer the data in the given encoding
EncodedData.prototype.as = function(encoding) { EncodedData.prototype.as = function(encoding) {
if (!encodings[encoding]) throw new Error('invalid encoding'); if (!encodings[encoding]) throw new Error('invalid encoding: '+encoding);
return this.converters[encoding].call(this); return this.converters[encoding].call(this);
}; };

View File

@ -1,6 +1,6 @@
var imports = require('soop').imports(); var base58 = require('../lib/Base58').base58Check;
var base58 = imports.base58 || require('../lib/Base58').base58Check; var util = require('util');
var parent = imports.parent || require('./EncodedData'); var EncodedData = require('./EncodedData');
function VersionedData(version, payload) { function VersionedData(version, payload) {
@ -14,8 +14,8 @@ function VersionedData(version, payload) {
this.payload(payload); this.payload(payload);
}; };
VersionedData.parent = parent; util.inherits(VersionedData, EncodedData);
parent.applyEncodingsTo(VersionedData); EncodedData.applyEncodingsTo(VersionedData);
// get or set the version data (the first byte of the address) // get or set the version data (the first byte of the address)
VersionedData.prototype.version = function(num) { VersionedData.prototype.version = function(num) {