Пример #1
0
def _transform_NetworkValues_to_Network(nv):
    from pycoin.ecdsa.secp256k1 import secp256k1_generator
    from pycoin.ui.uiclass import UI
    from pycoin.vm.ScriptInfo import ScriptInfo
    from pycoin.coins.bitcoin.ScriptTools import BitcoinScriptTools

    defaults = dict(tx=None,
                    block=None,
                    magic_header=None,
                    dns_bootstrap=[],
                    default_port=None)
    puzzle_script = ScriptInfo(BitcoinScriptTools)
    ui = UI(puzzle_script,
            secp256k1_generator,
            bip32_prv_prefix=nv.prv32,
            bip32_pub_prefix=nv.pub32,
            wif_prefix=nv.wif,
            sec_prefix="%sSEC" % nv.code,
            address_prefix=nv.address,
            pay_to_script_prefix=nv.pay_to_script)
    defaults["ui"] = ui
    u = nv._asdict()
    for k in ['wif', 'address', 'pay_to_script', 'prv32', 'pub32']:
        if k in u:
            del u[k]
    defaults.update(u)
    return Network(**defaults)
Пример #2
0
def create_bitcoinish_network(symbol, network_name, subnet_name, **kwargs):
    # potential kwargs:
    #   tx, block, magic_header_hex, default_port, dns_bootstrap,
    #   wif_prefix_hex, address_prefix_hex, pay_to_script_prefix_hex
    #   bip32_prv_prefix_hex, bip32_pub_prefix_hex, sec_prefix, scriptTools

    network = Network(symbol, network_name, subnet_name)

    generator = kwargs.get("generator", secp256k1_generator)
    kwargs.setdefault("sec_prefix", "%sSEC" % symbol.upper())
    KEYS_TO_H2B = (
        "bip32_prv_prefix bip32_pub_prefix wif_prefix address_prefix "
        "pay_to_script_prefix sec_prefix magic_header").split()
    for k in KEYS_TO_H2B:
        k_hex = "%s_hex" % k
        if k_hex in kwargs:
            kwargs[k] = h2b(kwargs[k_hex])

    network.script_tools = kwargs.get("scriptTools", BitcoinScriptTools)
    network.script_info = ScriptInfo(network.script_tools)

    UI_KEYS = ("bip32_prv_prefix bip32_pub_prefix wif_prefix sec_prefix "
               "address_prefix pay_to_script_prefix bech32_hrp").split()
    ui_kwargs = {k: kwargs[k] for k in UI_KEYS if k in kwargs}

    network.ui = UI(network.script_info, generator, **ui_kwargs)
    network.extras = Extras(network.script_tools, network.ui)

    NETWORK_KEYS = "network_name subnet_name dns_bootstrap default_port magic_header".split(
    )
    network_kwargs = {k: kwargs.get(k) for k in NETWORK_KEYS if k in kwargs}
    for k in NETWORK_KEYS:
        if k in kwargs:
            setattr(network, k, kwargs[k])

    network.Tx = network.tx = kwargs.get("tx") or Tx
    network.Block = network.block = kwargs.get("block") or Block.make_subclass(
        network.tx)

    streamer = standard_streamer(
        standard_parsing_functions(network.block, network.tx))
    network.parse_message, network.pack_message = make_parser_and_packer(
        streamer, standard_messages(), standard_message_post_unpacks(streamer))

    network.output_for_hwif = make_output_for_hwif(network)
    network.output_for_secret_exponent = make_output_for_secret_exponent(
        network.extras.Key)
    network.output_for_public_pair = make_output_for_public_pair(
        network.extras.Key, network)
    network.output_for_h160 = make_output_for_h160(network)
    network.BIP32Node = network.extras.BIP32Node
    network.Key = network.extras.Key
    network.ElectrumKey = network.extras.ElectrumKey
    network.Keychain = Keychain
    return network
Пример #3
0
def create_bitcoinish_network(**kwargs):
    # potential kwargs:
    #   netcode, network_name, subnet_name, tx, block, magic_header_hex, default_port, dns_bootstrap,
    #   wif_prefix_hex, address_prefix_hex, pay_to_script_prefix_hex
    #   bip32_prv_prefix_hex, bip32_pub_prefix_hex, sec_prefix, scriptTools

    kwargs.setdefault("sec_prefix", "%sSEC" % kwargs["netcode"].upper())
    KEYS_TO_H2B = (
        "bip32_prv_prefix bip32_pub_prefix wif_prefix address_prefix "
        "pay_to_script_prefix sec_prefix magic_header").split()
    for k in KEYS_TO_H2B:
        k_hex = "%s_hex" % k
        if k_hex in kwargs:
            kwargs[k] = h2b(kwargs[k_hex])

    scriptTools = kwargs.get("scriptTools", BitcoinScriptTools)
    _script_info = ScriptInfo(scriptTools)
    UI_KEYS = ("bip32_prv_prefix bip32_pub_prefix wif_prefix sec_prefix "
               "address_prefix pay_to_script_prefix bech32_hrp").split()
    ui_kwargs = {k: kwargs[k] for k in UI_KEYS if k in kwargs}
    ui = UI(_script_info, kwargs.get("generator", secp256k1_generator),
            **ui_kwargs)
    extras = Extras(scriptTools, ui)
    kwargs["ui"] = ui
    kwargs["extras"] = extras
    kwargs.setdefault("tx", Tx)
    kwargs.setdefault("block", Block.make_subclass(kwargs["tx"]))

    NETWORK_KEYS = ("network_name subnet_name tx block ui extras "
                    "dns_bootstrap default_port magic_header").split()
    network_kwargs = {k: kwargs.get(k) for k in NETWORK_KEYS if k in kwargs}
    network_kwargs["code"] = kwargs["netcode"]  # BRAIN DAMAGE
    network = Network(**network_kwargs)

    streamer = standard_streamer(
        standard_parsing_functions(network.block, network.tx))
    network.parse_message, network.pack_message = make_parser_and_packer(
        streamer, standard_messages(), standard_message_post_unpacks(streamer))

    return network
Пример #4
0
from pycoin.serialize import h2b

from .ScriptTools import BitcoinScriptTools
from .Tx import Tx as BitcoinTx
from .extras import Extras
from pycoin.block import Block as BitcoinBlock

from pycoin.ecdsa.secp256k1 import secp256k1_generator
from pycoin.networks.network import Network
from pycoin.ui.uiclass import UI
from pycoin.vm.ScriptInfo import ScriptInfo

# BRAIN DAMAGE
_script_info = ScriptInfo(BitcoinScriptTools)

# BRAIN DAMAGE
mainnet_ui = UI(
    _script_info, secp256k1_generator,
    bip32_prv_prefix=h2b("0488ade4"), bip32_pub_prefix=h2b("0488B21E"),
    wif_prefix=h2b("80"), sec_prefix="BTCSEC:", address_prefix=h2b("00"),
    pay_to_script_prefix=h2b("05"), bech32_hrp='bc')

mainnet_extras = Extras(BitcoinScriptTools, mainnet_ui)

BitcoinMainnet = Network(
    'BTC', "Bitcoin", "mainnet",
    BitcoinTx, BitcoinBlock,
    h2b('F9BEB4D9'), 8333, [
        "seed.bitcoin.sipa.be", "dnsseed.bitcoin.dashjr.org",
        "bitseed.xf2.org", "dnsseed.bluematt.me",