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) { ChainEntry.isChainEntry = function isChainEntry(obj) {
return obj return obj instanceof ChainEntry;
&& BN.isBN(obj.chainwork)
&& typeof obj.getMedianTime === 'function';
}; };
/* /*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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