refactor: remove all duck typing.
This commit is contained in:
parent
bc25bdb016
commit
e0eb1cdbe3
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -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';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user