@@ -383,11 +383,11 @@ def getblockheader(self, block_hash, verbose=False):
383383
384384 Raises IndexError if block_hash is not valid.
385385 """
386- if type (block_hash ) != str :
386+ if not isinstance (block_hash , str ) :
387387 try :
388388 block_hash = b2lx (block_hash )
389389 except TypeError :
390- raise TypeError ('%s.getblockheader(): block_hash must be bytes; got %r instance' %
390+ raise TypeError ('%s.getblockheader(): block_hash must be bytes or str ; got %r instance' %
391391 (self .__class__ .__name__ , block_hash .__class__ ))
392392 try :
393393 r = self ._call ('getblockheader' , block_hash , verbose )
@@ -418,8 +418,7 @@ def getblockfilter(self, block_hash, filter_type="basic"):
418418 Default filter_type must be changed
419419 #UNTESTED
420420 """
421- # ALLOWED FOR str blockhash as well
422- if type (block_hash ) != str :
421+ if not isinstance (block_hash , str ):
423422 try :
424423 block_hash = b2lx (block_hash )
425424 except TypeError :
@@ -441,7 +440,7 @@ def getblock(self, block_hash):
441440
442441 Raises IndexError if block_hash is not valid.
443442 """
444- if type (block_hash ) != str :
443+ if not isinstance (block_hash , str ) :
445444 try :
446445 block_hash = b2lx (block_hash )
447446 except TypeError :
@@ -476,9 +475,9 @@ def getblockstats(self, hash_or_height, *args):
476475 # On clients before PR #17831, passing hash as bytes will result in Block not found
477476 """Return a JSON object containing block stats"""
478477
479- try :
478+ if isinstance ( hash_or_height , bytes ):
480479 hval = b2lx (hash_or_height )
481- except TypeError :
480+ else : #int or str of block_hash or height
482481 hval = hash_or_height
483482 try :
484483 r = self ._call ('getblockstats' , hval , args )
@@ -494,7 +493,7 @@ def getchaintips(self):
494493 def getchaintxstats (self , nblocks = None , block_hash = None ):
495494 """Compute stats about transactions in chain"""
496495 if block_hash is not None :
497- if type (block_hash ) != str :
496+ if not isinstance (block_hash , str ) :
498497 block_hash = b2lx (block_hash )
499498 return self ._call ('getchaintxstats' , nblocks , block_hash )
500499
@@ -503,7 +502,7 @@ def getdifficulty(self):
503502
504503 def getmempoolancestors (self , txid , verbose = False ):
505504 """Returns a list of txids for ancestor transactions"""
506- if type (txid ) != str :
505+ if not isinstance (txid , str ) :
507506 try :
508507 txid = b2lx (txid )
509508 except TypeError :
@@ -517,8 +516,7 @@ def getmempoolancestors(self, txid, verbose=False):
517516
518517 def getmempooldescendants (self , txid , verbose = False ):
519518 """Returns a list of txids for descendant transactions"""
520- # Added str capacity
521- if type (txid ) != str :
519+ if not isinstance (txid , str ):
522520 try :
523521 txid = b2lx (txid )
524522 except TypeError :
@@ -532,7 +530,7 @@ def getmempooldescendants(self, txid, verbose=False):
532530
533531 def getmempoolentry (self , txid ):
534532 """Returns a JSON object for mempool transaction"""
535- if type (txid ) != str :
533+ if not isinstance (txid , str ) :
536534 try :
537535 txid = b2lx (txid )
538536 except TypeError :
@@ -561,12 +559,11 @@ def getrawmempool(self, verbose=False):
561559
562560 def gettxout (self , outpoint , includemempool = True ):
563561 """Return details about an unspent transaction output.
564-
562+ outpoint - COutPoint or tuple (<txid>, n)
565563 Raises IndexError if outpoint is not found or was spent.
566564
567565 includemempool - Include mempool txouts
568566 """
569- # CHANGED TO ALLOW TUPLE (str(<txid>), n)
570567 if isinstance (outpoint , COutPoint ):
571568 r = self ._call ('gettxout' , b2lx (outpoint .hash ), outpoint .n , includemempool )
572569 else :
@@ -583,9 +580,9 @@ def gettxout(self, outpoint, includemempool=True):
583580
584581 def gettxoutproof (self , txids , block_hash = None ):
585582 """Returns a hex string object of proof of inclusion in block"""
586- if type (txids [0 ]) != str :
583+ if not isinstance (txids [0 ], str ) :
587584 txids = [b2lx (txid ) for txid in txids ]
588- if type (block_hash ) != str :
585+ if not isinstance (block_hash , str ) :
589586 block_hash = b2lx (block_hash )
590587 return self ._call ('gettxoutproof' , txids , block_hash )
591588
@@ -597,7 +594,7 @@ def gettxoutsetinfo(self):
597594 #Untested
598595 def preciousblock (self , block_hash ):
599596 """Marks a block as precious. No return"""
600- if type (block_hash ) != str :
597+ if not isinstance (block_hash , str ) :
601598 block_hash = b2lx (block_hash )
602599 self ._call ('preciousblock' , block_hash )
603600
@@ -633,7 +630,7 @@ def verifytxoutproof(self, proof):
633630 returns [] on fail
634631 """
635632 #Had several timeouts on this function. Might be natural
636- if type (proof ) != str :
633+ if not isinstance (proof , str ) :
637634 proof = proof .hex ()
638635 r = self ._call ('verifytxoutproof' , proof )
639636 return [lx (txid ) for txid in r ]
@@ -727,7 +724,7 @@ def getnetworkhashps(self, nblocks=None, height=None):
727724
728725 def prioritisetransaction (self , txid , fee_delta , dummy = "" ):
729726 """Returns true. Prioritises transaction for mining"""
730- if type (txid ) != str :
727+ if not isinstance (txid , str ) :
731728 txid = b2lx (txid )
732729 return self ._call ('prioritisetransaction' , txid , dummy , fee_delta )
733730
@@ -737,8 +734,7 @@ def submitblock(self, block, params=None):
737734 params is optional and is currently ignored by bitcoind. See
738735 https://en.bitcoin.it/wiki/BIP_0022 for full specification.
739736 """
740- # Allow for hex directly
741- if type (block ) == str :
737+ if not isinstance (block , str ):
742738 hexblock = block
743739 else :
744740 hexblock = hexlify (block .serialize ())
@@ -838,7 +834,7 @@ def combinepsbt(self, psbt_b64s):
838834
839835 def converttopsbt (self , tx , permitsigdata = None , iswitness = None ):
840836 """Returns a base64 encoded PSBT"""
841- if type (tx ) != str :
837+ if not isinstance (tx , str ) :
842838 tx = hexlify (tx .serialize ())
843839 return self ._call ('converttopsbt' , tx , permitsigdata , iswitness )
844840
@@ -858,7 +854,7 @@ def createpsbt(self, vins, vouts, data="", locktime=0, replaceable=False):
858854 vout = i .prevout .n
859855 sequence = i .nSequence
860856 ins .append ({"txid" : txid , "vout" : vout , "sequence" : sequence })
861- vins = ins #Allow for JSON data to be passed straight to vins
857+ vins = ins
862858 if isinstance (vouts [0 ], COutPoint ):
863859 outs = []
864860 for o in vouts :
@@ -908,7 +904,7 @@ def utxoupdatepsbt(self, psbt_b64, data):
908904 #RAW TX
909905 def combinerawtransaction (self , hextxs ):
910906 """Return raw hex of combined transaction"""
911- if type (hextxs [0 ]) != str :
907+ if not isinstance (hextxs [0 ], str ) :
912908 hextxs = [hexlify (tx .serialize ()) for tx in hextxs ]
913909 return self ._call ('combinerawtransaction' , hextxs )
914910
@@ -931,10 +927,9 @@ def getrawtransaction(self, txid, verbose=False, block_hash=None):
931927 enabled the transaction may not be available.
932928 """
933929 #Timeout issues depending on tx / machine
934- # Allow handling strings. Desirable?
935- if type (txid ) != str :
930+ if not isinstance (txid , str ):
936931 txid = b2lx (txid )
937- if type (block_hash ) != str :
932+ if not isinstance (block_hash , str ) :
938933 block_hash = b2lx (block_hash )
939934 try :
940935 r = self ._call ('getrawtransaction' , txid , 1 if verbose else 0 , block_hash )
@@ -973,7 +968,7 @@ def sendrawtransactionv0_19(self, tx, maxfeerate=None):
973968
974969 maxfeerate - numeric or string for max fee rate
975970 """
976- if type (tx ) != str :
971+ if not isinstance (tx , str ) :
977972 tx = hexlify (tx .serialize ())
978973 r = self ._call ('sendrawtransaction' , tx , maxfeerate )
979974 return lx (r )
@@ -1029,7 +1024,7 @@ def fundrawtransactionv0_19(self, tx, options=None, iswitness=None):
10291024 'changepos': Position of added change output, or -1,
10301025 }
10311026 """
1032- if type (tx ) != str :
1027+ if not isinstance (tx , str ) :
10331028 tx = hexlify (tx .serialize ())
10341029 r = self ._call ('fundrawtransaction' , tx , options , iswitness )
10351030 r ['tx' ] = CTransaction .deserialize (unhexlify (r ['hex' ]))
@@ -1043,12 +1038,11 @@ def signrawtransactionwithkey(self, tx, privkeys, prevtxs=None, sighashtype=None
10431038 prevtxs - JSON object containing info
10441039 sighashtype - numeric sighashtype default=SIGHASH_ALL
10451040 """
1046- # THIS ALLOWS FOR str, bytes, and CBitcoinSecret. desirable?
1047- if type (tx ) != str :
1041+ if not isinstance (tx , str ):
10481042 tx = hexlify (tx .serialize ())
1049- if isinstance (privkeys [0 ], CBitcoinSecret ): # IS THIS CORRECT
1043+ if isinstance (privkeys [0 ], CBitcoinSecret ):
10501044 privkeys = [str (sk ) for sk in privkeys ]
1051- elif isinstance (privkeys [0 ], bytes ): # ALLOW FOR BYTES
1045+ elif isinstance (privkeys [0 ], bytes ):
10521046 privkeys = [sk .hex () for sk in privkeys ]
10531047 r = self ._call ('signrawtransactionwithkey' , privkeys , prevtxs , )
10541048 r ['tx' ] = CTransaction .deserialize (unhexlify (r ['hex' ]))
@@ -1057,7 +1051,7 @@ def signrawtransactionwithkey(self, tx, privkeys, prevtxs=None, sighashtype=None
10571051
10581052 def testmempoolaccept (self , txs , maxfeerate = None ):
10591053 """Return a JSON object of each transaction's acceptance info"""
1060- if type (txs [0 ]) != str :
1054+ if not isinstance (txs [0 ], str ) :
10611055 txs = [hexlify (tx .serialize ()) for tx in txs ]
10621056 return self ._call ('testmempoolaccept' , txs , maxfeerate )
10631057
@@ -1085,7 +1079,7 @@ def createmultisig(self, nrequired, keys, address_type=None):
10851079 }
10861080
10871081 """
1088- if type (keys [0 ]) != str :
1082+ if not isinstance (keys [0 ], str ) :
10891083 keys = [str (k ) for k in keys ]
10901084 r = self ._call ('createmultisig' , nrequired , keys , address_type )
10911085 # PLEASE CHECK
@@ -1098,12 +1092,11 @@ def deriveaddresses(self, descriptor, _range=None):
10981092 """Returns addresses from descriptor
10991093
11001094 """
1101- #TODODescriptors need Implementing
1095+ #TODO Descriptors need Implementing
11021096 return self ._call ('deriveaddresses' , descriptor , _range )
11031097
11041098 def estimatesmartfee (self , conf_target , estimate_mode = None ):
11051099 """Returns a JSON object with feerate, errors, and block estimate
1106- #Fix description?
11071100 conf_target - attempted number of blocks from current tip to place tx
11081101 estimate_mode:
11091102 "UNSET"
@@ -1150,7 +1143,6 @@ def addmultisigaddress(self, nrequired, keys, label=None, address_type=None):
11501143 #TODO see if CPubKey.__str__() is used elsewhere or can be changed.
11511144 if isinstance (keys [0 ], CBitcoinAddress ):
11521145 keys = [str (k ) for k in keys ]
1153- #included CPubKey for clarity. Could possibly remove
11541146 elif isinstance (keys [0 ], (CPubKey , bytes )):
11551147 keys = [k .hex () for k in keys ]
11561148 r = self ._call ('addmultisigaddress' , nrequired , keys , label , address_type )
@@ -1166,7 +1158,7 @@ def backupwallet(self, destination):
11661158
11671159 def bumpfee (self , txid , options = None ):
11681160 """Bump fee of transation in mempool"""
1169- if type (txid ) != str :
1161+ if not isinstance (txid , str ) :
11701162 txid = b2lx (txid )
11711163 return self ._call ('bumpfee' , txid , options )
11721164
@@ -1215,8 +1207,7 @@ def getaccountaddress(self, account=None):
12151207
12161208 def getaddressinfo (self , address ):
12171209 """Return a JSON object of info about address"""
1218- if type (address ) != str :
1219- address = str (address )
1210+ address = str (address )
12201211 r = self ._call ('getaddressinfo' , address )
12211212 if r ['script' ] == 'scripthash' :
12221213 r ['redeemScript' ] = CScript .fromhex (r ['hex' ])
@@ -1362,13 +1353,13 @@ def importprunedfunds(self, tx, txout_proof):
13621353
13631354 #TODO should txout_proof be an obj?
13641355 """
1365- if type (tx ) != str :
1356+ if not isinstance (tx , str ) :
13661357 tx = hexlify (tx .serialize ())
13671358 return self ._call ('importprunedfunds' , tx , txout_proof )
13681359
13691360 def importpubkey (self , pubkey , label = None , rescan = None ):
13701361 """Import pubkey as watchonly"""
1371- if type (pubkey ) != str :
1362+ if not isinstance (pubkey , str ) :
13721363 pubkey = pubkey .hex ()
13731364 self ._call ('importpubkey' , pubkey , label , rescan )
13741365
@@ -1527,7 +1518,7 @@ def lockunspent(self, unlock, outpoints):
15271518
15281519 def removeprunedfunds (self , txid ):
15291520 """Remove pruned utxos from wallet"""
1530- if type (txid ) != str :
1521+ if not isinstance (txid , str ) :
15311522 txid = b2lx (txid )
15321523 self ._call ('removeprunedfunds' , txid )
15331524
0 commit comments