当前位置: 首页>>代码示例>>Python>>正文


Python BtcTxStore.validate_address方法代码示例

本文整理汇总了Python中btctxstore.BtcTxStore.validate_address方法的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore.validate_address方法的具体用法?Python BtcTxStore.validate_address怎么用?Python BtcTxStore.validate_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在btctxstore.BtcTxStore的用法示例。


在下文中一共展示了BtcTxStore.validate_address方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestValidateAddressMainnet

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import validate_address [as 别名]
class TestValidateAddressMainnet(unittest.TestCase):

    def setUp(self):
        self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
        self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)

    def test_valid_string(self):
        address = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc'
        self.assertTrue(self.mainnet_api.validate_address(address))

    def test_valid_network(self):
        address = self.mainnet_api.get_address(self.mainnet_api.create_key())
        self.assertTrue(self.mainnet_api.validate_address(address))

    def test_invalid_network(self):
        address = self.testnet_api.get_address(self.testnet_api.create_key())
        self.assertFalse(self.mainnet_api.validate_address(address))

    def test_invalid_data(self):
        self.assertFalse(self.mainnet_api.validate_address("f483"))

    def test_invalid_type(self):
        self.assertFalse(self.mainnet_api.validate_address(None))
开发者ID:F483,项目名称:btctxstore,代码行数:25,代码来源:other.py

示例2: TestValidateAddressTestnet

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import validate_address [as 别名]
class TestValidateAddressTestnet(unittest.TestCase):

    def setUp(self):
        self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
        self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)

    def test_valid_string(self):
        address = 'migiScBNvVKYwEiCFhgBNGtZ87cdygtuSQ'
        self.assertTrue(self.testnet_api.validate_address(address))

    def test_valid_network(self):
        address = self.testnet_api.get_address(self.testnet_api.create_key())
        self.assertTrue(self.testnet_api.validate_address(address))

    def test_invalid_network(self):
        address = self.mainnet_api.get_address(self.mainnet_api.create_key())
        self.assertFalse(self.testnet_api.validate_address(address))

    def test_invalid_data(self):
        self.assertFalse(self.testnet_api.validate_address("f483"))

    def test_invalid_type(self):
        self.assertFalse(self.testnet_api.validate_address(None))
开发者ID:F483,项目名称:btctxstore,代码行数:25,代码来源:other.py

示例3: Client

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import validate_address [as 别名]
class Client(object):

    def __init__(self, url=common.DEFAULT_URL, debug=False,
                 max_size=common.DEFAULT_MAX_SIZE,
                 store_path=common.DEFAULT_STORE_PATH,
                 config_path=common.DEFAULT_CONFIG_PATH,
                 set_master_secret=None, set_payout_address=None,
                 connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT,
                 connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY):

        # FIXME validate master_secret

        self.url = url
        self.config = None  # lazy
        self.messanger = None  # lazy
        self.debug = debug  # TODO validate
        self.retry_limit = deserialize.positive_integer(connection_retry_limit)
        self.retry_delay = deserialize.positive_integer(connection_retry_delay)
        self.max_size = deserialize.byte_count(max_size)

        # paths
        self.config_path = os.path.realpath(config_path)  # TODO validate
        self._ensure_path_exists(os.path.dirname(self.config_path))
        self.store_path = os.path.realpath(store_path)
        self._ensure_path_exists(self.store_path)

        # validate payout address
        self.btctxstore = BtcTxStore()
        if set_payout_address and (not self.btctxstore.validate_address(set_payout_address)):
            raise exceptions.InvalidAddress(set_payout_address)

        self._initialize_config(set_master_secret, set_payout_address)

    def _initialize_config(self, set_master_secret, set_payout_address):
        if os.path.exists(self.config_path):
            self._load_config()
        else:  # initialize config
            if not set_master_secret:  # create random master secret
                secret_data = base64.b64encode(os.urandom(256))
                set_master_secret = secret_data.decode('utf-8')
            if not set_payout_address:  # use root address if not given
                set_payout_address = self._get_root_address(set_master_secret)

        if set_master_secret or set_payout_address:
            self.config = {
                "version": __version__,
                "master_secret": set_master_secret,
                "payout_address": set_payout_address,
            }
            config.save(self.config_path, self.config)

    def _ensure_path_exists(self, path):
        if not os.path.exists(path):
            os.makedirs(path)

    def _load_config(self):
        if self.config is None:
            if not os.path.exists(self.config_path):
                raise exceptions.ConfigNotFound(self.config_path)
            self.config = config.load(self.config_path)

    def _get_root_wif(self, master_secret):
        master_secret = base64.b64decode(master_secret)
        hwif = self.btctxstore.create_wallet(master_secret=master_secret)
        return self.btctxstore.get_key(hwif)

    def _get_root_address(self, master_secret):
            wif = self._get_root_wif(master_secret)
            return self.btctxstore.get_address(wif)

    def _init_messanger(self):
        if self.messanger is None:
            wif = self._get_root_wif(self.config["master_secret"])
            self.messanger = messaging.Messaging(self.url, wif,
                                                 self.retry_limit,
                                                 self.retry_delay)

    def version(self):
        print(__version__)
        return __version__

    def register(self):
        """Attempt to register the config address."""
        self._init_messanger()
        registered = self.messanger.register(self.config["payout_address"])
        auth_addr = self.messanger.auth_address()
        if registered:
            print("Address {0} now registered on {1}.".format(auth_addr,
                                                              self.url))
        else:
            print("Failed to register address {0} on {1}.".format(auth_addr,
                                                                  self.url))
        return True

    def show_config(self):
        """Display saved config."""
        print(json.dumps(self.config, indent=2))
        return self.config

    def ping(self):
#.........这里部分代码省略.........
开发者ID:F483,项目名称:dataserv-client,代码行数:103,代码来源:api.py

示例4: Client

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import validate_address [as 别名]
class Client(object):

    def __init__(self, url=common.DEFAULT_URL, debug=False, quiet=False,
                 use_folder_tree=False, max_size=common.DEFAULT_MAX_SIZE,
                 min_free_size=common.DEFAULT_MIN_FREE_SIZE,
                 store_path=common.DEFAULT_STORE_PATH,
                 config_path=common.DEFAULT_CONFIG_PATH,
                 connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT,
                 connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY):

        debug = deserialize.flag(debug)
        quiet = deserialize.flag(quiet)

        self.url = deserialize.url(url)
        self.use_folder_tree = deserialize.flag(use_folder_tree)
        self.max_size = deserialize.byte_count(max_size)
        self.min_free_size = deserialize.byte_count(min_free_size)

        self.messenger = None  # lazy
        self.btctxstore = BtcTxStore()
        self.retry_limit = deserialize.positive_integer(connection_retry_limit)
        self.retry_delay = deserialize.positive_integer(connection_retry_delay)

        # paths
        self.cfg_path = os.path.realpath(config_path)
        storjnode.util.ensure_path_exists(os.path.dirname(self.cfg_path))
        self.store_path = os.path.realpath(store_path)
        storjnode.util.ensure_path_exists(self.store_path)

        # check for vfat partions
        try:
            fstype = storjnode.util.get_fs_type(self.store_path)

        # FileNotFoundError: [Errno 2] No such file or directory: '/etc/mtab'
        # psutil: https://code.google.com/p/psutil/issues/detail?id=434
        except EnvironmentError as e:
            logger.warning(e)
            fstype = None

        if fstype == "vfat":
            logger.info("Detected vfat partition, using folder tree.")
            self.use_folder_tree = True
        if fstype is None:
            msg = "Couldn't detected partition type for '{0}'"
            logger.warning(msg.format(self.store_path))

        self.cfg = storjnode.config.get(self.btctxstore, self.cfg_path)

    @staticmethod
    def version():
        print(__version__)
        return __version__

    def _init_messenger(self):
        """Make sure messenger exists."""
        if self.messenger is None:
            wif = self.btctxstore.get_key(self.cfg["wallet"])
            self.messenger = messaging.Messaging(self.url, wif,
                                                 self.retry_limit,
                                                 self.retry_delay)

    def register(self):
        """Attempt to register the config address."""
        self._init_messenger()
        payout_address = self.cfg["payout_address"]
        self.messenger.register(payout_address)
        logger.info("Registered on server '{0}'.".format(self.url))
        return True

    def config(self, set_wallet=None, set_payout_address=None):
        """
        Set and then show the config settings.

        :param set_wallet: Set the HWIF for registration/auth address.
        :param set_payout_address:  Set the payout address.
        :return: Configuation object.
        """
        if((set_payout_address is not None) and
                (not self.btctxstore.validate_address(set_payout_address))):
            raise exceptions.InvalidAddress(set_payout_address)
        if((set_wallet is not None) and
                (not self.btctxstore.validate_wallet(set_wallet))):
            raise exceptions.InvalidHWIF(set_wallet)

        self._init_messenger()
        config_updated = False

        # update payout address if requested
        if set_payout_address:
            self.cfg["payout_address"] = set_payout_address
            config_updated = True

        # update wallet if requested
        if set_wallet:
            self.cfg["wallet"] = set_wallet
            config_updated = True

        # save config if updated
        if config_updated:
            storjnode.config.save(self.btctxstore, self.cfg_path, self.cfg)
#.........这里部分代码省略.........
开发者ID:StorjOld,项目名称:dataserv-client,代码行数:103,代码来源:api.py

示例5: Client

# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import validate_address [as 别名]
class Client(object):

    def __init__(self, url=common.DEFAULT_URL, debug=False, quiet=False,
                 use_folder_tree=False, max_size=common.DEFAULT_MAX_SIZE,
                 store_path=common.DEFAULT_STORE_PATH,
                 config_path=common.DEFAULT_CONFIG_PATH,
                 connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT,
                 connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY):

        debug = deserialize.flag(debug)
        quiet = deserialize.flag(quiet)

        self.url = deserialize.url(url)
        self.use_folder_tree = deserialize.flag(use_folder_tree)
        self.max_size = deserialize.byte_count(max_size)

        self.messenger = None  # lazy
        self.btctxstore = BtcTxStore()
        self.retry_limit = deserialize.positive_integer(connection_retry_limit)
        self.retry_delay = deserialize.positive_integer(connection_retry_delay)

        # paths
        self.cfg_path = os.path.realpath(config_path)
        control.util.ensure_path_exists(os.path.dirname(self.cfg_path))
        self.store_path = os.path.realpath(store_path)
        control.util.ensure_path_exists(self.store_path)

        # check for vfat partions
        if control.util.get_fs_type(self.store_path) == "vfat":
            self.use_folder_tree = True

        self.cfg = control.config.get(self.btctxstore, self.cfg_path)

    @staticmethod
    def version():
        print(__version__)
        return __version__

    def _init_messenger(self):
        """Make sure messenger exists."""
        if self.messenger is None:
            wif = self.btctxstore.get_key(self.cfg["wallet"])
            self.messenger = messaging.Messaging(self.url, wif,
                                                 self.retry_limit,
                                                 self.retry_delay)

    def register(self):
        """Attempt to register the config address."""
        self._init_messenger()
        payout_address = self.cfg["payout_address"]
        self.messenger.register(payout_address)
        logger.info("Registered on server '{0}'.".format(self.url))
        return True

    def config(self, set_wallet=None, set_payout_address=None):
        """
        Set and then show the config settings.

        :param set_wallet: Set the HWIF for registration/auth address.
        :param set_payout_address:  Set the payout address.
        :return: Configuation object.
        """
        if((set_payout_address is not None) and
                (not self.btctxstore.validate_address(set_payout_address))):
            raise exceptions.InvalidAddress(set_payout_address)
        if((set_wallet is not None) and
                (not self.btctxstore.validate_wallet(set_wallet))):
            raise exceptions.InvalidHWIF(set_wallet)

        self._init_messenger()
        config_updated = False

        # update payout address if requested
        if set_payout_address:
            self.cfg["payout_address"] = set_payout_address
            config_updated = True

        # update wallet if requested
        if set_wallet:
            self.cfg["wallet"] = set_wallet
            config_updated = True

        # save config if updated
        if config_updated:
            control.config.save(self.btctxstore, self.cfg_path, self.cfg)

        # display config
        print(SHOW_CONFIG_TEMPLATE.format(
            self.messenger.auth_address(),
            self.cfg["payout_address"]
        ))
        return self.cfg

    def ping(self):
        """Attempt one keep-alive with the server."""
        self._init_messenger()

        msg = "Pinging server '{0}' at {1:%Y-%m-%d %H:%M:%S}."
        logger.info(msg.format(self.messenger.server_url(), datetime.now()))
        self.messenger.ping()
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:dataserv-client,代码行数:103,代码来源:api.py


注:本文中的btctxstore.BtcTxStore.validate_address方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。