@@ -383,11 +383,11 @@ def getblockheader(self, block_hash, verbose=False):
383
383
384
384
Raises IndexError if block_hash is not valid.
385
385
"""
386
- if type (block_hash ) != str :
386
+ if not isinstance (block_hash , str ) :
387
387
try :
388
388
block_hash = b2lx (block_hash )
389
389
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' %
391
391
(self .__class__ .__name__ , block_hash .__class__ ))
392
392
try :
393
393
r = self ._call ('getblockheader' , block_hash , verbose )
@@ -418,8 +418,7 @@ def getblockfilter(self, block_hash, filter_type="basic"):
418
418
Default filter_type must be changed
419
419
#UNTESTED
420
420
"""
421
- # ALLOWED FOR str blockhash as well
422
- if type (block_hash ) != str :
421
+ if not isinstance (block_hash , str ):
423
422
try :
424
423
block_hash = b2lx (block_hash )
425
424
except TypeError :
@@ -441,7 +440,7 @@ def getblock(self, block_hash):
441
440
442
441
Raises IndexError if block_hash is not valid.
443
442
"""
444
- if type (block_hash ) != str :
443
+ if not isinstance (block_hash , str ) :
445
444
try :
446
445
block_hash = b2lx (block_hash )
447
446
except TypeError :
@@ -476,9 +475,9 @@ def getblockstats(self, hash_or_height, *args):
476
475
# On clients before PR #17831, passing hash as bytes will result in Block not found
477
476
"""Return a JSON object containing block stats"""
478
477
479
- try :
478
+ if isinstance ( hash_or_height , bytes ):
480
479
hval = b2lx (hash_or_height )
481
- except TypeError :
480
+ else : #int or str of block_hash or height
482
481
hval = hash_or_height
483
482
try :
484
483
r = self ._call ('getblockstats' , hval , args )
@@ -494,7 +493,7 @@ def getchaintips(self):
494
493
def getchaintxstats (self , nblocks = None , block_hash = None ):
495
494
"""Compute stats about transactions in chain"""
496
495
if block_hash is not None :
497
- if type (block_hash ) != str :
496
+ if not isinstance (block_hash , str ) :
498
497
block_hash = b2lx (block_hash )
499
498
return self ._call ('getchaintxstats' , nblocks , block_hash )
500
499
@@ -503,7 +502,7 @@ def getdifficulty(self):
503
502
504
503
def getmempoolancestors (self , txid , verbose = False ):
505
504
"""Returns a list of txids for ancestor transactions"""
506
- if type (txid ) != str :
505
+ if not isinstance (txid , str ) :
507
506
try :
508
507
txid = b2lx (txid )
509
508
except TypeError :
@@ -517,8 +516,7 @@ def getmempoolancestors(self, txid, verbose=False):
517
516
518
517
def getmempooldescendants (self , txid , verbose = False ):
519
518
"""Returns a list of txids for descendant transactions"""
520
- # Added str capacity
521
- if type (txid ) != str :
519
+ if not isinstance (txid , str ):
522
520
try :
523
521
txid = b2lx (txid )
524
522
except TypeError :
@@ -532,7 +530,7 @@ def getmempooldescendants(self, txid, verbose=False):
532
530
533
531
def getmempoolentry (self , txid ):
534
532
"""Returns a JSON object for mempool transaction"""
535
- if type (txid ) != str :
533
+ if not isinstance (txid , str ) :
536
534
try :
537
535
txid = b2lx (txid )
538
536
except TypeError :
@@ -561,12 +559,11 @@ def getrawmempool(self, verbose=False):
561
559
562
560
def gettxout (self , outpoint , includemempool = True ):
563
561
"""Return details about an unspent transaction output.
564
-
562
+ outpoint - COutPoint or tuple (<txid>, n)
565
563
Raises IndexError if outpoint is not found or was spent.
566
564
567
565
includemempool - Include mempool txouts
568
566
"""
569
- # CHANGED TO ALLOW TUPLE (str(<txid>), n)
570
567
if isinstance (outpoint , COutPoint ):
571
568
r = self ._call ('gettxout' , b2lx (outpoint .hash ), outpoint .n , includemempool )
572
569
else :
@@ -583,9 +580,9 @@ def gettxout(self, outpoint, includemempool=True):
583
580
584
581
def gettxoutproof (self , txids , block_hash = None ):
585
582
"""Returns a hex string object of proof of inclusion in block"""
586
- if type (txids [0 ]) != str :
583
+ if not isinstance (txids [0 ], str ) :
587
584
txids = [b2lx (txid ) for txid in txids ]
588
- if type (block_hash ) != str :
585
+ if not isinstance (block_hash , str ) :
589
586
block_hash = b2lx (block_hash )
590
587
return self ._call ('gettxoutproof' , txids , block_hash )
591
588
@@ -597,7 +594,7 @@ def gettxoutsetinfo(self):
597
594
#Untested
598
595
def preciousblock (self , block_hash ):
599
596
"""Marks a block as precious. No return"""
600
- if type (block_hash ) != str :
597
+ if not isinstance (block_hash , str ) :
601
598
block_hash = b2lx (block_hash )
602
599
self ._call ('preciousblock' , block_hash )
603
600
@@ -633,7 +630,7 @@ def verifytxoutproof(self, proof):
633
630
returns [] on fail
634
631
"""
635
632
#Had several timeouts on this function. Might be natural
636
- if type (proof ) != str :
633
+ if not isinstance (proof , str ) :
637
634
proof = proof .hex ()
638
635
r = self ._call ('verifytxoutproof' , proof )
639
636
return [lx (txid ) for txid in r ]
@@ -727,7 +724,7 @@ def getnetworkhashps(self, nblocks=None, height=None):
727
724
728
725
def prioritisetransaction (self , txid , fee_delta , dummy = "" ):
729
726
"""Returns true. Prioritises transaction for mining"""
730
- if type (txid ) != str :
727
+ if not isinstance (txid , str ) :
731
728
txid = b2lx (txid )
732
729
return self ._call ('prioritisetransaction' , txid , dummy , fee_delta )
733
730
@@ -737,8 +734,7 @@ def submitblock(self, block, params=None):
737
734
params is optional and is currently ignored by bitcoind. See
738
735
https://en.bitcoin.it/wiki/BIP_0022 for full specification.
739
736
"""
740
- # Allow for hex directly
741
- if type (block ) == str :
737
+ if not isinstance (block , str ):
742
738
hexblock = block
743
739
else :
744
740
hexblock = hexlify (block .serialize ())
@@ -838,7 +834,7 @@ def combinepsbt(self, psbt_b64s):
838
834
839
835
def converttopsbt (self , tx , permitsigdata = None , iswitness = None ):
840
836
"""Returns a base64 encoded PSBT"""
841
- if type (tx ) != str :
837
+ if not isinstance (tx , str ) :
842
838
tx = hexlify (tx .serialize ())
843
839
return self ._call ('converttopsbt' , tx , permitsigdata , iswitness )
844
840
@@ -858,7 +854,7 @@ def createpsbt(self, vins, vouts, data="", locktime=0, replaceable=False):
858
854
vout = i .prevout .n
859
855
sequence = i .nSequence
860
856
ins .append ({"txid" : txid , "vout" : vout , "sequence" : sequence })
861
- vins = ins #Allow for JSON data to be passed straight to vins
857
+ vins = ins
862
858
if isinstance (vouts [0 ], COutPoint ):
863
859
outs = []
864
860
for o in vouts :
@@ -908,7 +904,7 @@ def utxoupdatepsbt(self, psbt_b64, data):
908
904
#RAW TX
909
905
def combinerawtransaction (self , hextxs ):
910
906
"""Return raw hex of combined transaction"""
911
- if type (hextxs [0 ]) != str :
907
+ if not isinstance (hextxs [0 ], str ) :
912
908
hextxs = [hexlify (tx .serialize ()) for tx in hextxs ]
913
909
return self ._call ('combinerawtransaction' , hextxs )
914
910
@@ -931,10 +927,9 @@ def getrawtransaction(self, txid, verbose=False, block_hash=None):
931
927
enabled the transaction may not be available.
932
928
"""
933
929
#Timeout issues depending on tx / machine
934
- # Allow handling strings. Desirable?
935
- if type (txid ) != str :
930
+ if not isinstance (txid , str ):
936
931
txid = b2lx (txid )
937
- if type (block_hash ) != str :
932
+ if not isinstance (block_hash , str ) :
938
933
block_hash = b2lx (block_hash )
939
934
try :
940
935
r = self ._call ('getrawtransaction' , txid , 1 if verbose else 0 , block_hash )
@@ -973,7 +968,7 @@ def sendrawtransactionv0_19(self, tx, maxfeerate=None):
973
968
974
969
maxfeerate - numeric or string for max fee rate
975
970
"""
976
- if type (tx ) != str :
971
+ if not isinstance (tx , str ) :
977
972
tx = hexlify (tx .serialize ())
978
973
r = self ._call ('sendrawtransaction' , tx , maxfeerate )
979
974
return lx (r )
@@ -1029,7 +1024,7 @@ def fundrawtransactionv0_19(self, tx, options=None, iswitness=None):
1029
1024
'changepos': Position of added change output, or -1,
1030
1025
}
1031
1026
"""
1032
- if type (tx ) != str :
1027
+ if not isinstance (tx , str ) :
1033
1028
tx = hexlify (tx .serialize ())
1034
1029
r = self ._call ('fundrawtransaction' , tx , options , iswitness )
1035
1030
r ['tx' ] = CTransaction .deserialize (unhexlify (r ['hex' ]))
@@ -1043,12 +1038,11 @@ def signrawtransactionwithkey(self, tx, privkeys, prevtxs=None, sighashtype=None
1043
1038
prevtxs - JSON object containing info
1044
1039
sighashtype - numeric sighashtype default=SIGHASH_ALL
1045
1040
"""
1046
- # THIS ALLOWS FOR str, bytes, and CBitcoinSecret. desirable?
1047
- if type (tx ) != str :
1041
+ if not isinstance (tx , str ):
1048
1042
tx = hexlify (tx .serialize ())
1049
- if isinstance (privkeys [0 ], CBitcoinSecret ): # IS THIS CORRECT
1043
+ if isinstance (privkeys [0 ], CBitcoinSecret ):
1050
1044
privkeys = [str (sk ) for sk in privkeys ]
1051
- elif isinstance (privkeys [0 ], bytes ): # ALLOW FOR BYTES
1045
+ elif isinstance (privkeys [0 ], bytes ):
1052
1046
privkeys = [sk .hex () for sk in privkeys ]
1053
1047
r = self ._call ('signrawtransactionwithkey' , privkeys , prevtxs , )
1054
1048
r ['tx' ] = CTransaction .deserialize (unhexlify (r ['hex' ]))
@@ -1057,7 +1051,7 @@ def signrawtransactionwithkey(self, tx, privkeys, prevtxs=None, sighashtype=None
1057
1051
1058
1052
def testmempoolaccept (self , txs , maxfeerate = None ):
1059
1053
"""Return a JSON object of each transaction's acceptance info"""
1060
- if type (txs [0 ]) != str :
1054
+ if not isinstance (txs [0 ], str ) :
1061
1055
txs = [hexlify (tx .serialize ()) for tx in txs ]
1062
1056
return self ._call ('testmempoolaccept' , txs , maxfeerate )
1063
1057
@@ -1085,7 +1079,7 @@ def createmultisig(self, nrequired, keys, address_type=None):
1085
1079
}
1086
1080
1087
1081
"""
1088
- if type (keys [0 ]) != str :
1082
+ if not isinstance (keys [0 ], str ) :
1089
1083
keys = [str (k ) for k in keys ]
1090
1084
r = self ._call ('createmultisig' , nrequired , keys , address_type )
1091
1085
# PLEASE CHECK
@@ -1098,12 +1092,11 @@ def deriveaddresses(self, descriptor, _range=None):
1098
1092
"""Returns addresses from descriptor
1099
1093
1100
1094
"""
1101
- #TODODescriptors need Implementing
1095
+ #TODO Descriptors need Implementing
1102
1096
return self ._call ('deriveaddresses' , descriptor , _range )
1103
1097
1104
1098
def estimatesmartfee (self , conf_target , estimate_mode = None ):
1105
1099
"""Returns a JSON object with feerate, errors, and block estimate
1106
- #Fix description?
1107
1100
conf_target - attempted number of blocks from current tip to place tx
1108
1101
estimate_mode:
1109
1102
"UNSET"
@@ -1150,7 +1143,6 @@ def addmultisigaddress(self, nrequired, keys, label=None, address_type=None):
1150
1143
#TODO see if CPubKey.__str__() is used elsewhere or can be changed.
1151
1144
if isinstance (keys [0 ], CBitcoinAddress ):
1152
1145
keys = [str (k ) for k in keys ]
1153
- #included CPubKey for clarity. Could possibly remove
1154
1146
elif isinstance (keys [0 ], (CPubKey , bytes )):
1155
1147
keys = [k .hex () for k in keys ]
1156
1148
r = self ._call ('addmultisigaddress' , nrequired , keys , label , address_type )
@@ -1166,7 +1158,7 @@ def backupwallet(self, destination):
1166
1158
1167
1159
def bumpfee (self , txid , options = None ):
1168
1160
"""Bump fee of transation in mempool"""
1169
- if type (txid ) != str :
1161
+ if not isinstance (txid , str ) :
1170
1162
txid = b2lx (txid )
1171
1163
return self ._call ('bumpfee' , txid , options )
1172
1164
@@ -1215,8 +1207,7 @@ def getaccountaddress(self, account=None):
1215
1207
1216
1208
def getaddressinfo (self , address ):
1217
1209
"""Return a JSON object of info about address"""
1218
- if type (address ) != str :
1219
- address = str (address )
1210
+ address = str (address )
1220
1211
r = self ._call ('getaddressinfo' , address )
1221
1212
if r ['script' ] == 'scripthash' :
1222
1213
r ['redeemScript' ] = CScript .fromhex (r ['hex' ])
@@ -1362,13 +1353,13 @@ def importprunedfunds(self, tx, txout_proof):
1362
1353
1363
1354
#TODO should txout_proof be an obj?
1364
1355
"""
1365
- if type (tx ) != str :
1356
+ if not isinstance (tx , str ) :
1366
1357
tx = hexlify (tx .serialize ())
1367
1358
return self ._call ('importprunedfunds' , tx , txout_proof )
1368
1359
1369
1360
def importpubkey (self , pubkey , label = None , rescan = None ):
1370
1361
"""Import pubkey as watchonly"""
1371
- if type (pubkey ) != str :
1362
+ if not isinstance (pubkey , str ) :
1372
1363
pubkey = pubkey .hex ()
1373
1364
self ._call ('importpubkey' , pubkey , label , rescan )
1374
1365
@@ -1527,7 +1518,7 @@ def lockunspent(self, unlock, outpoints):
1527
1518
1528
1519
def removeprunedfunds (self , txid ):
1529
1520
"""Remove pruned utxos from wallet"""
1530
- if type (txid ) != str :
1521
+ if not isinstance (txid , str ) :
1531
1522
txid = b2lx (txid )
1532
1523
self ._call ('removeprunedfunds' , txid )
1533
1524
0 commit comments