Python bitcoin.SelectParams() Examples

The following are 7 code examples of bitcoin.SelectParams(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bitcoin , or try the search function .
Example #1
Source File: bitcoin_signer.py    From hermit with Apache License 2.0 6 votes vote down vote up
def generate_multisig_address(redeemscript: str, testnet: bool = False) -> str:
    """
    Generates a P2SH-multisig Bitcoin address from a redeem script

    Args:
        redeemscript: hex-encoded redeem script
                      use generate_multisig_redeem_script to create
                      the redeem script from three compressed public keys
         testnet: Should the address be testnet or mainnet?

    Example:
        TODO
    """

    if testnet:
        bitcoin.SelectParams('testnet')

    redeem_script = CScript(bitcoin.core.x(redeemscript))

    addr = P2SHBitcoinAddress.from_redeemScript(redeem_script)

    return str(addr) 
Example #2
Source File: bitcoin_signer.py    From hermit with Apache License 2.0 6 votes vote down vote up
def validate_request(self) -> None:
        """Validates a signature request

        Validates

        * the redeem script
        * inputs & outputs
        * fee
        """
        if self.testnet:
            SelectParams('testnet')
        else:
            SelectParams('mainnet')
        self._validate_input_groups()
        self._validate_outputs()
        self._validate_fee() 
Example #3
Source File: checks.py    From cert-verifier with MIT License 5 votes vote down vote up
def do_execute(self):

        if self.signing_key is None or self.content_to_verify is None or self.signature_value is None:
            return False
        message = BitcoinMessage(self.content_to_verify)
        try:
            lock.acquire()
            # obtain lock while modifying global state
            bitcoin.SelectParams(chain_to_bitcoin_network(self.chain))
            return VerifyMessage(self.signing_key, message, self.signature_value)
        finally:
            lock.release() 
Example #4
Source File: test_network.py    From clove with GNU General Public License v3.0 5 votes vote down vote up
def test_auto_switch_params_decorator(network):

    if network.name == 'bitcoin':
        assert simple_params_name_return(network) == 'mainnet'
    elif network.name == 'test-bitcoin':
        assert simple_params_name_return(network) == 'testnet'
    else:
        assert simple_params_name_return(network) == network.name

    bitcoin.SelectParams('mainnet') 
Example #5
Source File: config.py    From cert-issuer with MIT License 5 votes vote down vote up
def get_config():
    configure_logger()
    p = configargparse.getArgumentParser(default_config_files=[os.path.join(PATH, 'conf.ini'),
                                                               '/etc/cert-issuer/conf.ini'])
    add_arguments(p)
    parsed_config, _ = p.parse_known_args()

    if not parsed_config.safe_mode:
        logging.warning('Your app is configured to skip the wifi check when the USB is plugged in. Read the '
                        'documentation to ensure this is what you want, since this is less secure')

    # overwrite with enum
    parsed_config.chain = Chain.parse_from_chain(parsed_config.chain)

    # ensure it's a supported chain
    if parsed_config.chain.blockchain_type != BlockchainType.bitcoin and \
                    parsed_config.chain.blockchain_type != BlockchainType.ethereum and \
                    parsed_config.chain.blockchain_type != BlockchainType.mock:
        raise UnknownChainError(parsed_config.chain.name)

    logging.info('This run will try to issue on the %s chain', parsed_config.chain.name)

    if parsed_config.chain.blockchain_type == BlockchainType.bitcoin:
        bitcoin_chain_for_python_bitcoinlib = parsed_config.chain
        if parsed_config.chain == Chain.bitcoin_regtest:
            bitcoin_chain_for_python_bitcoinlib = Chain.bitcoin_regtest
        bitcoin.SelectParams(chain_to_bitcoin_network(bitcoin_chain_for_python_bitcoinlib))

    global CONFIG
    CONFIG = parsed_config
    return parsed_config 
Example #6
Source File: test_prepare.py    From simcoin with MIT License 5 votes vote down vote up
def setUp(self):
        self.context = Mock()
        self.prepare = Prepare(self.context)

        bitcoin.SelectParams('regtest') 
Example #7
Source File: simcoin.py    From simcoin with MIT License 4 votes vote down vote up
def main():
    cmd_parser = argparse.ArgumentParser(
        description='Simcoin a cryptocurrency simulator.',
        usage='''<command> [<args>]

        The commands are:
        nodes       creates the {} for a simulation
        network     creates the {} for a simulation
        ticks       creates the {} for a simulation
        simulate    executes a simulation based on the {}, {} and {}
        run         runs all above commands
        multi-run   run the simulation multiple times
        '''.format(
            config.nodes_csv_file_name,
            config.network_csv_file_name,
            config.ticks_csv_file_name,
            config.nodes_csv_file_name,
            config.network_csv_file_name,
            config.ticks_csv_file_name,
        ))

    cmd_parser.add_argument('command', help='Subcommand to run')

    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    args = cmd_parser.parse_args(sys.argv[1:2])
    command = args.command
    if command not in commands:
        print('Unrecognized command')
        cmd_parser.print_help()
        exit(1)
    # use dispatch pattern to invoke method with same name

    if not os.path.exists(config.data_dir):
        os.makedirs(config.data_dir)

    bitcoin.SelectParams('regtest')

    args = _parse_args()
    utils.config_logger(args.verbose)
    logging.info("Arguments called with: {}".format(sys.argv))
    logging.info("Parsed arguments in simcoin.py: {}".format(args))

    logging.info('Executing command={}'.format(command))
    commands[command]()