refactor: remove all duck typing.

This commit is contained in:
Christopher Jeffrey 2017-09-02 21:29:38 -07:00
parent bc25bdb016
commit e0eb1cdbe3
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
16 changed files with 16 additions and 55 deletions

View File

@ -538,9 +538,7 @@ ChainEntry.prototype.inspect = function inspect() {
*/
ChainEntry.isChainEntry = function isChainEntry(obj) {
return obj
&& BN.isBN(obj.chainwork)
&& typeof obj.getMedianTime === 'function';
return obj instanceof ChainEntry;
};
/*

View File

@ -554,9 +554,7 @@ Mnemonic.prototype.inspect = function inspect() {
*/
Mnemonic.isMnemonic = function isMnemonic(obj) {
return obj
&& typeof obj.bits === 'number'
&& typeof obj.toSeed === 'function';
return obj instanceof Mnemonic;
};
/**

View File

@ -742,10 +742,7 @@ HDPrivateKey.fromJSON = function fromJSON(json, network) {
*/
HDPrivateKey.isHDPrivateKey = function isHDPrivateKey(obj) {
return obj
&& typeof obj.derive === 'function'
&& typeof obj.fromMnemonic === 'function'
&& Buffer.isBuffer(obj.chainCode);
return obj instanceof HDPrivateKey;
};
/*

View File

@ -561,10 +561,7 @@ HDPublicKey.fromRaw = function fromRaw(data, network) {
*/
HDPublicKey.isHDPublicKey = function isHDPublicKey(obj) {
return obj
&& typeof obj.derive === 'function'
&& obj.fromMnemonic === undefined
&& Buffer.isBuffer(obj.chainCode);
return obj instanceof HDPublicKey;
};
/*

View File

@ -818,9 +818,7 @@ Block.prototype.getWitnessSizes = function getWitnessSizes() {
*/
Block.isBlock = function isBlock(obj) {
return obj
&& typeof obj.merkleRoot === 'string'
&& typeof obj.getClaimed === 'function';
return obj instanceof Block;
};
/*

View File

@ -424,10 +424,7 @@ Coin.fromTX = function fromTX(tx, index, height) {
*/
Coin.isCoin = function isCoin(obj) {
return obj
&& typeof obj.version === 'number'
&& typeof obj.script === 'object'
&& typeof obj.getDepth === 'function';
return obj instanceof Coin;
};
/*

View File

@ -266,10 +266,7 @@ Headers.prototype.format = function format(view, height) {
*/
Headers.isHeaders = function isHeaders(obj) {
return obj
&& !obj.txs
&& typeof obj.toHead === 'function'
&& typeof obj.toBlock !== 'function';
return obj instanceof Headers;
};
/*

View File

@ -950,9 +950,7 @@ KeyRing.fromRaw = function fromRaw(data) {
*/
KeyRing.isKeyRing = function isKeyRing(obj) {
return obj
&& Buffer.isBuffer(obj.publicKey)
&& typeof obj.toSecret === 'function';
return obj instanceof KeyRing;
};
/*

View File

@ -211,10 +211,7 @@ MemBlock.prototype.toHeaders = function toHeaders() {
*/
MemBlock.isMemBlock = function isMemBlock(obj) {
return obj
&& typeof obj.toBlock === 'function'
&& typeof obj.isMemory === 'function'
&& obj.isMemory();
return obj instanceof MemBlock;
};
/*

View File

@ -637,9 +637,7 @@ MerkleBlock.fromMatches = function fromMatches(block, matches) {
*/
MerkleBlock.isMerkleBlock = function isMerkleBlock(obj) {
return obj
&& Buffer.isBuffer(obj.flags)
&& typeof obj.verifyBody === 'function';
return obj instanceof MerkleBlock;
};
/**

View File

@ -292,10 +292,7 @@ TXMeta.fromRaw = function fromRaw(data, enc) {
*/
TXMeta.isTXMeta = function isTXMeta(obj) {
return obj
&& Array.isArray(obj.inputs)
&& typeof obj.locktime === 'number'
&& typeof obj.mtime === 'number';
return obj instanceof TXMeta;
};
/*

View File

@ -367,9 +367,7 @@ Network.prototype.inspect = function inspect() {
*/
Network.isNetwork = function isNetwork(obj) {
return obj
&& typeof obj.genesisBlock === 'string'
&& typeof obj.pow === 'object';
return obj instanceof Network;
};
/*

View File

@ -994,9 +994,7 @@ Account.fromRaw = function fromRaw(db, data) {
*/
Account.isAccount = function isAccount(obj) {
return obj
&& typeof obj.receiveDepth === 'number'
&& obj.deriveKey === 'function';
return obj instanceof Account;
};
/*

View File

@ -692,9 +692,7 @@ MasterKey.prototype.inspect = function inspect() {
*/
MasterKey.isMasterKey = function isMasterKey(obj) {
return obj
&& typeof obj.encrypted === 'boolean'
&& typeof obj.decrypt === 'function';
return obj instanceof MasterKey;
};
/*

View File

@ -2584,9 +2584,7 @@ Wallet.fromRaw = function fromRaw(db, data) {
*/
Wallet.isWallet = function isWallet(obj) {
return obj
&& typeof obj.accountDepth === 'number'
&& obj.template === 'function';
return obj instanceof Wallet;
};
/*

View File

@ -294,10 +294,7 @@ WalletKey.prototype.toPath = function toPath() {
*/
WalletKey.isWalletKey = function isWalletKey(obj) {
return obj
&& Buffer.isBuffer(obj.publicKey)
&& typeof obj.index === 'number'
&& typeof obj.toPath === 'function';
return obj instanceof WalletKey;
};
/*