コード例 #1
0
    def run(self):
        """
        Run method for account create command
        Generates a secret passphrase using BIP39 mnemonic generator.
        Private and public keys are then calculated using bpl_lib.crypto.Keys and
        the address is generate from the secret passphrase using bpl_lib.address.Address.
        The secret passphrase, private key, public key and address are then displayed in a
        ascii_table.Table object.

        :return: (None)
        """

        NetworkInterface.use(NetworkConfig.get_config_identifier())

        secret_passphrase = Mnemonic("english").generate(256)

        account = SortedDictionary({
            "secret passphrase":
            secret_passphrase,
            "private key":
            Keys(secret_passphrase).get_private_key(),
            "public key":
            Keys(secret_passphrase).get_public_key(),
            "address":
            Address.from_secret(secret_passphrase)
        })

        print("\nAccount")
        print(Table([account.names(), account.values()]))
コード例 #2
0
ファイル: Show.py プロジェクト: DuneRoot/bpl-cli
    def run(self):
        """
        Run method for network config show command.
        Reads the network config and then displays it in a ascii_table.Table object

        :return: (None)
        """

        config = SortedDictionary(NetworkConfig.get_config())

        print("\nNetwork Config ({0})".format(NetworkConfig.get_config_identifier()))
        print(Table([config.names(), config.values()]))
コード例 #3
0
ファイル: Use.py プロジェクト: DuneRoot/bpl-cli
    def run(self):
        """
        Run method for network config use command.
        Prints out a table of valid config identifiers.
        User is then prompted to input the name of a valid config identifier. If input is invalid a
        BPLClientNetworkException is raised. Otherwise the identifier is written to config.json and the new selected
        config is displayed using a ascii_table.Table object.

        :return: (None)
        """

        print("\nConfig Identifiers")
        print(
            Table([{
                "Header": "Configs",
                "Contents": NetworkConfig.get_config_identifiers()
            }]))

        config_identifier = input("\nEnter config identifier: ")

        if not NetworkConfig.validate_identifier(config_identifier):
            print(BPLClientNetworkException({
                "message":
                "invalid config identifier",
                "identifiers":
                NetworkConfig.get_config_identifiers(),
                "identifier":
                config_identifier
            }),
                  file=sys.stderr)
            sys.exit(1)

        write_file(NETWORK_CONFIG,
                   json.dumps({"identifier": config_identifier}))

        config = SortedDictionary(NetworkConfig.get_config())
        print("\nNetwork Config ({0})".format(config_identifier))
        print(Table([config.names(), config.values()]))
コード例 #4
0
    def _get_delegate(self):
        """
        Used to fetch the status of any delegates the account voted for and display them individually using a
        ascii_table.Table object

        :return: (None)
        """

        votes = self._bpl_accounts.votes(self._address)

        if not votes["success"]:
            print(BPLClientAccountsException({
                "message": "Delegate unknown on the blockchain.",
                "error": votes["error"]
            }), file=sys.stderr)
            sys.exit(1)

        for vote in votes["delegates"]:
            delegate = SortedDictionary(vote)
            del delegate["address"]
            del delegate["publicKey"]

            print("\nVoted Delegate ({0})".format(delegate["username"]))
            print(Table([delegate.names(), delegate.values()]))
コード例 #5
0
    def _get_account(self):
        """
        Used to fetch the status of the account and then display it using a ascii_table.Table object

        :return: (None)
        """

        account = self._bpl_accounts.account(self._address)

        if not account["success"]:
            print(BPLClientAccountsException({
                "message": "Address unknown on the blockchain.",
                "address": self._address
            }), file=sys.stderr)
            sys.exit(1)

        account = SortedDictionary({
            str(k): str(v) for k, v in account["account"].items()
            if v and len(str(v)) > 0
        })
        del account["address"]

        print("\nAddress Summary")
        print(Table([account.names(), account.values()]))
コード例 #6
0
    def run(self):
        """
        Run method for network config new command.
        Prints prompt requesting config identifier.
        Prints prompt requesting peer address and port, peer address user input is validated using a regular expression.
        A similar process is applied to the network version and begin epoch prompts.
        If validation fails at a given state then a BPLClientNetworkException is raised.
        Otherwise the nethash is fetch from the peer address the user entered.
        The currently used config identifier is then stored in config.json and the new config is stored in configs.json
        file. The config is then displayed using a ascii_table.Table object

        :return: (None)
        """

        config_identifier = input("Enter config identifier: ")

        if NetworkConfig.validate_identifier(config_identifier):
            print(BPLClientNetworkException({
                "message": "invalid config identifier. config identifier has already been used.",
                "config identifiers": NetworkConfig.get_config_identifiers(),
                "config identifier": config_identifier
            }), file=sys.stderr)
            sys.exit(1)

        peer_address = input("Enter peer address and port: ")

        if not regular_expression.match(PEER_ADDRESS_REGEX, peer_address):
            print(BPLClientNetworkException({
                "message": "invalid peer address.",
                "format": "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}",
                "peer": peer_address
            }), file=sys.stderr)
            sys.exit(1)

        version = input("Enter version: ")

        if not regular_expression.match(VERSION_REGEX, version):
            print(BPLClientNetworkException({
                "message": "invalid network version.",
                "format": "[0-9]{1,3}",
                "version": version
            }), file=sys.stderr)
            sys.exit(1)

        begin_epoch = input("Enter begin epoch: ")

        if not regular_expression.match(EPOCH_REGEX, begin_epoch):
            print(BPLClientNetworkException({
                "message": "invalid begin epoch.",
                "format": "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}",
                "begin epoch": begin_epoch
            }), file=sys.stderr)
            sys.exit(1)

        try:
            nethash = Client(peer_address).api("blocks").nethash()["nethash"]
        except:
            print(BPLClientNetworkException({
                "message": "failed to fetch nethash.",
                "reason": "failed to successfully connect to peer."
            }), file=sys.stderr)
            sys.exit(1)

        configs = NetworkConfig.get_configs()
        configs[config_identifier] = {
            "peer address": peer_address,
            "version": int(version),
            "begin epoch": begin_epoch,
            "nethash": nethash
        }

        write_file(NETWORK_CONFIG, json.dumps({
            "identifier": config_identifier
        }))
        write_file(NETWORK_CONFIGS, json.dumps(configs))

        try:
            Network.use_custom(
                config_identifier, datetime.strptime(begin_epoch, "%Y-%m-%d %H:%M:%S"), int(version)
            )
        except BPLNetworkException:
            pass

        config = SortedDictionary(configs[config_identifier])
        print("\nNetwork Config ({0})".format(config_identifier))
        print(Table([config.names(), config.values()]))