Browse Source

fix int assertions

master
undeath 7 years ago
parent
commit
59a998fda0
  1. 2
      jmclient/jmclient/taker_utils.py
  2. 13
      jmclient/jmclient/wallet.py
  3. 3
      jmclient/jmclient/wallet_utils.py
  4. 4
      jmdaemon/jmdaemon/daemon_protocol.py
  5. 4
      jmdaemon/jmdaemon/orderbookwatch.py

2
jmclient/jmclient/taker_utils.py

@ -39,7 +39,7 @@ def direct_send(wallet, amount, mixdepth, destaddr, answeryes=False,
""" """
#Sanity checks #Sanity checks
assert validate_address(destaddr)[0] assert validate_address(destaddr)[0]
assert isinstance(mixdepth, int) assert isinstance(mixdepth, numbers.Integral)
assert mixdepth >= 0 assert mixdepth >= 0
assert isinstance(amount, numbers.Integral) assert isinstance(amount, numbers.Integral)
assert amount >=0 assert amount >=0

13
jmclient/jmclient/wallet.py

@ -12,6 +12,7 @@ from mnemonic import Mnemonic
from hashlib import sha256 from hashlib import sha256
from itertools import chain from itertools import chain
from decimal import Decimal from decimal import Decimal
from numbers import Integral
from .configure import jm_single from .configure import jm_single
@ -489,9 +490,9 @@ class BaseWallet(object):
def add_utxo(self, txid, index, script, value): def add_utxo(self, txid, index, script, value):
assert isinstance(txid, bytes) assert isinstance(txid, bytes)
assert isinstance(index, int) assert isinstance(index, Integral)
assert isinstance(script, bytes) assert isinstance(script, bytes)
assert isinstance(value, int) assert isinstance(value, Integral)
if script not in self._script_map: if script not in self._script_map:
raise WalletError("Tried to add UTXO for unknown key to wallet.") raise WalletError("Tried to add UTXO for unknown key to wallet.")
@ -1136,7 +1137,7 @@ class BIP32Wallet(BaseWallet):
def get_path(self, mixdepth=None, internal=None, index=None): def get_path(self, mixdepth=None, internal=None, index=None):
if mixdepth is not None: if mixdepth is not None:
assert isinstance(mixdepth, int) assert isinstance(mixdepth, Integral)
if not 0 <= mixdepth <= self.max_mixdepth: if not 0 <= mixdepth <= self.max_mixdepth:
raise WalletError("Mixdepth outside of wallet's range.") raise WalletError("Mixdepth outside of wallet's range.")
@ -1146,7 +1147,7 @@ class BIP32Wallet(BaseWallet):
int_type = self._get_internal_type(internal) int_type = self._get_internal_type(internal)
if index is not None: if index is not None:
assert isinstance(index, int) assert isinstance(index, Integral)
if internal is None: if internal is None:
raise Exception("internal must be set if index is set") raise Exception("internal must be set if index is set")
assert index <= self._index_cache[mixdepth][int_type] assert index <= self._index_cache[mixdepth][int_type]
@ -1164,7 +1165,7 @@ class BIP32Wallet(BaseWallet):
@classmethod @classmethod
def _harden_path_level(cls, lvl): def _harden_path_level(cls, lvl):
assert isinstance(lvl, int) assert isinstance(lvl, Integral)
if not 0 <= lvl < cls.BIP32_MAX_PATH_LEVEL: if not 0 <= lvl < cls.BIP32_MAX_PATH_LEVEL:
raise WalletError("Unable to derive hardened path level from {}." raise WalletError("Unable to derive hardened path level from {}."
"".format(lvl)) "".format(lvl))
@ -1172,7 +1173,7 @@ class BIP32Wallet(BaseWallet):
@classmethod @classmethod
def _path_level_to_repr(cls, lvl): def _path_level_to_repr(cls, lvl):
assert isinstance(lvl, int) assert isinstance(lvl, Integral)
if not 0 <= lvl < cls.BIP32_MAX_PATH_LEVEL * 2: if not 0 <= lvl < cls.BIP32_MAX_PATH_LEVEL * 2:
raise WalletError("Invalid path level {}.".format(lvl)) raise WalletError("Invalid path level {}.".format(lvl))
if lvl < cls.BIP32_MAX_PATH_LEVEL: if lvl < cls.BIP32_MAX_PATH_LEVEL:

3
jmclient/jmclient/wallet_utils.py

@ -6,6 +6,7 @@ import sqlite3
import binascii import binascii
from datetime import datetime from datetime import datetime
from optparse import OptionParser from optparse import OptionParser
from numbers import Integral
from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle, from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle,
jm_single, BitcoinCoreInterface, JsonRpcError, sync_wallet, WalletError, jm_single, BitcoinCoreInterface, JsonRpcError, sync_wallet, WalletError,
VolatileStorage, StoragePasswordError, VolatileStorage, StoragePasswordError,
@ -167,7 +168,7 @@ class WalletViewEntry(WalletViewBase):
self.account = account self.account = account
assert forchange in [0, 1, -1] assert forchange in [0, 1, -1]
self.forchange =forchange self.forchange =forchange
assert isinstance(aindex, int) assert isinstance(aindex, Integral)
assert aindex >= 0 assert aindex >= 0
self.aindex = aindex self.aindex = aindex
self.address = addr self.address = addr

4
jmdaemon/jmdaemon/daemon_protocol.py

@ -23,6 +23,7 @@ import threading
import os import os
import copy import copy
from functools import wraps from functools import wraps
from numbers import Integral
"""Joinmarket application protocol control flow. """Joinmarket application protocol control flow.
For documentation on protocol (formats, message sequence) see For documentation on protocol (formats, message sequence) see
@ -230,7 +231,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
"""Takes the necessary data from the Taker and initiates the Stage 1 """Takes the necessary data from the Taker and initiates the Stage 1
interaction with the Makers. interaction with the Makers.
""" """
if not (self.jm_state == 1 and isinstance(amount, int) and amount >=0): if not (self.jm_state == 1 and isinstance(amount, Integral)
and amount >= 0):
return {'accepted': False} return {'accepted': False}
self.cjamount = amount self.cjamount = amount
self.commitment = commitment self.commitment = commitment

4
jmdaemon/jmdaemon/orderbookwatch.py

@ -10,6 +10,7 @@ import time
import threading import threading
import json import json
from decimal import InvalidOperation, Decimal from decimal import InvalidOperation, Decimal
from numbers import Integral
from jmdaemon.protocol import JM_VERSION from jmdaemon.protocol import JM_VERSION
from jmbase.support import get_log, joinmarket_alert, DUST_THRESHOLD from jmbase.support import get_log, joinmarket_alert, DUST_THRESHOLD
@ -95,7 +96,8 @@ class OrderbookWatch(object):
"from {}").format "from {}").format
log.debug(fmt(minsize, maxsize, counterparty)) log.debug(fmt(minsize, maxsize, counterparty))
return return
if ordertype in ['swabsoffer', 'absoffer'] and not isinstance(cjfee, int): if ordertype in ['swabsoffer', 'absoffer']\
and not isinstance(cjfee, Integral):
try: try:
cjfee = int(cjfee) cjfee = int(cjfee)
except ValueError: except ValueError:

Loading…
Cancel
Save