# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['cardano_tools', 'cardano_tools.utils']

package_data = \
{'': ['*']}

setup_kwargs = {
    'name': 'cardano-tools',
    'version': '2.0.1',
    'description': 'A collection of tools to enable development in the Cardano ecosystem using the Python programming language.',
    'long_description': '# Cardano Tools\nA python module for interacting with the [Cardano](https://www.cardano.org/) \nblockchain.\n\n## Installation\n\nYou can install Cardano Tools from PyPI:\n\n```\npip install cardano-tools\n```\n\nThe Cardano Tools package supports Python 3.9 and above.\n\n## Usage\n\nThe library provides objects for interfacing with different parts of the Cardano ecosystem: the node, the node CLI, and the wallet server. The basic usage is outlined below. For more help see the [example scripts](https://gitlab.com/viper-staking/cardano-tools/-/tree/master/examples) and browse through the code.\n\n### The Cardano-Node\n\nA cardano-node may be started in passive mode from a Python script using the code:\n\n    node = CardanoNode(\n        binary="/usr/local/bin/cardano-node",\n        topology=base_path / "mainnet-topology.json",\n        database=base_path / "db",\n        socket=base_path / "db" / "node.socket",\n        config=base_path / "mainnet-config.json",\n        show_output=True,  # Optionally print node output to the terminal.\n    )\n    node.start()\n\nTo run the node as a block producer, supply the additional parameters to the `CardanoNode` object constructor before starting.\n\n    node = CardanoNode(\n        binary="/usr/local/bin/cardano-node",\n        topology="mainnet-topology.json",\n        database="db",\n        socket="node.socket",\n        config="mainnet-config.json",\n        kes_key="pool_kes.skey",\n        vrf_key="pool_vrf.skey",\n        cert="pool.cert",\n        port=3002,  # defaults to 3001\n    )\n    node.start()\n\nA running node may then be later stopped by calling `node.stop()` which sends the `SIGINT` signal to the node process. This allows the node to shutdown gracefully by closing the database files and results in faster startup times during the next run. This feature may be useful for using Python to automate node restarts.\n\nSee the [official cardano-node GitHub repository](https://github.com/input-output-hk/cardano-node) for details on the necessary arguments and files needed for operating the node as well as how to install the binary.\n\n### The Cardano-Node CLI\nThe Cardano-Tools `NodeCLI` object provides a wrapped interface to functionality within the Cardano CLI. Raw methods are wrapped and provide a simple way to get results from CLI commands into your Python scripts. Also, common tasks that require multiple CLI commands are combined into easy to call methods.\n\n    cli = NodeCLI(\n        binary="/usr/local/bin/cardano-cli",\n        socket="/home/nalyd88/ViperStaking/cardano-node/db/node.socket",\n        working_dir=os.getcwd(),\n        ttl_buffer=1000,          # optional (default 1000)\n        network="--mainnet",      # optional (default --mainnet)\n        era="--mary-era",         # optional (default --mary-era)\n    )\n\n    print(f"Tip = {cli.get_tip()}")\n\n#### Managing Wallets\nMany common tasks like checking balances and sending ADA are provided.\n\n    # Get and print the ADA balance in an address\n    addr = open(working_dir + "/mywallet.addr", \'r\').read()\n    print(cli.query_balance(addr))\n\n    # Get and display all the UTxOs currently in a address\n    print(json.dumps(cli.get_utxos(addr), indent=4, sort_keys=True))\n\n    # Send ADA\n    key_file = "/home/lovelace/cardano-node/owner.skey"\n    to_addr = "addr_test1qpzft..."\n    from_addr = "addr_test1qrjpd..."\n    amt_ada = 10\n    cli.send_payment(amt_ada, to_addr, from_addr, key_file)\n\n#### Stake Pool Management\nThe Cardano-Tools library provides tools to help Cardano Stake-Pool Operators (SPOs) setup and maintain pools.\n\n    # Generate a new set of pool keys.\n    pool_id = cli.create_block_producing_keys(\n        "/home/lovelace/cardano-node/mainnet-shelley-genesis.json",\n        pool_name="TESTS"\n    )\n\nRemember to keep your cold keys in a secure, off-line, location!\n\n    # Stakepool registration inputs\n    pledges = {\n        "owner1": 110_000,\n        "owner2": 340_000,\n    } # ADA\n    pmt_addr = "addr1..."\n    args = {\n        "pool_name": "TESTS",\n        "pool_pledge": sum(pledges.values())*1_000_000,\n        "pool_cost": 340*1_000_000,\n        "pool_margin": 1.0,\n        "pool_cold_vkey":   "keys/TESTS_cold.vkey",\n        "pool_vrf_key":     "keys/TESTS_vrf.vkey",\n        "pool_reward_vkey": "owner1_pledge_stake.vkey",\n        "owner_stake_vkeys": [\n            "owner1_pledge_stake.vkey",\n            "owner2_pledge_stake.vkey",\n        ],\n        "pool_relays": [\n            {\n                "port": "3001",\n                "host": "myrelay.testspool.io",\n                "host-type": "single"\n            }\n        ],\n        "pool_metadata_url": "https://testspool.io/files/TESTS_metadata.json",\n        "folder": working_dir\n    }\n\n    # Signatures required (must be present during signing).\n    witness_files = [\n        working_dir / "cold_witness.json",\n        working_dir / "fees_witness.json",\n        working_dir / "owner1_witness.json",\n        working_dir / "owner2_witness.json",\n    ]\n\n    # Create the stake pool registration certificate and the transaction to be \n    # signed.\n    raw_tx = cli.build_raw_transaction(\n        pool_addr, \n        witness_count=len(witness_files),\n        certs=[\n            cli.generate_stake_pool_cert(**args)\n        ]\n    )\n\nAfter the registration transaction is successfully signed by all the required keys (hardware wallets and cold keys), collect the witness files and then sign and send the stake pool registration transaction. \n\n    # Apply witness signatures\n    signed_tx = cli.witness_transaction(raw_tx, witness_files)\n\n    # Send the transaction\n    cli.submit_transaction(signed_tx)\n\n#### Minting and Burning Non-Fungible Tokens (NFTs)\n\nThe first step in minting an NFT, other than the art work 😉, is to create a policy ID. \n\n    # Get hashes of the verification keys from the signing keys.\n    vkey_hash = cli.get_key_hash("./payment.vkey")\n\n    # Time until policy ID closes\n    genesis = "/home/lovelace/cardano-node/mainnet-shelley-genesis.json"\n    slots_till_close = cli.days2slots(365, genesis)  # 1 yr\n    closing_slot = cli.get_tip() + slots_till_close\n\n    # Create the minting script\n    multi_script = cli.build_multisignature_scripts(\n        "policyid-name-multisig",\n        [vkey_hash],  # Supports multiple signing keys\n        "all",\n        end_slot=closing_slot,\n    )\n\n    # Generate the policy ID\n    policy_id = cli.generate_policy(multi_script)\n\nNext, we must create the asset metadata and then store it in a JSON file.\nThis is not specific to the Cardano-Tools library.\n\n    metadata = {\n        "721": {\n            policy_id: policy_id,\n            "version": "1.0"\n            "COOL_NFT_00": {\n                "image": "ipfs://...",\n                ...\n            }\n        }\n    }\n\n    with open("my_nft_metadata.json", \'w\') as outfile:\n        json.dump(metadata, outfile, indent=4)\n\nThen all we have to do is simply build and send the minting transaction.\n\n    # Address that will own the NFT when it is minted. \n    addr = "addr1..."\n\n    # You can mint more than one NFT at a time but we will do just one here.\n    asset_names = ["COOL_NFT_00",]\n\n    # Since we are minting NFTs and not FTs, set the amounts to 1.\n    asset_amounts = [1 for i in asset_names]\n\n    # Build the minting transaction\n    tx_file = cli.build_mint_transaction(\n        policy_id,\n        asset_names, \n        asset_amounts,\n        addr,\n        n_wit := 1,  # Number of signing keys in multi-sig script\n        tx_metadata="my_nft_metadata.json",\n        minting_script="policyid-name-multisig.json",\n        ada=3  # Optionally specify some ADA to exist in the UTxO with the NFT\n    )\n\n    # Sign the transaction\n    skey = "payment.skey"\n    signed_tx = cli.sign_transaction(tx_file, [skey,])\n\n    # Send the transaction\n    cli.submit_transaction(signed_tx)\n\nIf you need to burn an NFT, the process is similar.\n\n    tx_file = cli.build_burn_transaction(\n        policy_id, \n        asset_names, \n        asset_amounts,\n        addr, \n        n_wit := 1,\n        minting_script="policyid-name-multisig.json",\n    )\n\nSending an NFT is also covered.\n\n\n    # Address that currently owns the UTxOs \n    from_addr = open("payment.addr", \'r\').read().strip()\n\n    # Address to receive the token\n    to_addr = "addr1..."\n\n    # Asset name to send\n    asset_name = "COOL_NFT_00"\n\n    # Build the sending transaction\n    tx_file = cli.build_send_tx(\n        to_addr,\n        from_addr,\n        quantity := 1,\n        policy_id,\n        asset_name=asset_name,\n    )\n\n    # Sign the transaction\n    skey1 = "payment.skey"\n    signed_tx = cli.sign_transaction(tx_file, [skey1])\n\n# Send the transaction\nif click.confirm("Do you want to send?", abort=True):\n    txid = cli.submit_transaction(signed_tx)\n    logging.info(f"Send transaction: {txid}")\n\n### The Cardano Wallet\nThe Cardano-Tools library contains an interface to the [Cardano wallet back end](https://github.com/input-output-hk/cardano-wallet), which may be accessed via either the CLI or through HTTP requests.\n\n#### CLI\n\n    cw_cli = WalletCLI(\n        path_to_cli="/usr/local/bin/cardano-wallet"\n    )\n\n    logging.basicConfig(level=logging.DEBUG)\n\n    # Find the wallet\n    wallet = cw_cli.get_wallet_by_name("ADDER_Rewards")\n  \n    # Print the balance (ADA)\n    print(int(wallet["balance"]["total"]["quantity"])/1_000_000)\n\n    # Use the built-in method\n    print(cw_cli.get_wallet_balance(wallet["id"]))\n\n#### HTTP Server\n\n    cw_http = WalletHTTP(\n        wallet_server="http://127.0.0.1",\n        wallet_server_port=8090\n    )\n\n    ada_amt = 100.5\n    rx_address = "addr1...."\n\n    wallet = cw_http.get_wallet_by_name("ExampleWallet")\n\n    # Get the passphrase from an env variable. DO NOT store in script.\n    # Example ZSH shell command to save the password in a local variable\n    # without it being stored in the command history:\n    #\n    #     $ read "?Enter password: " WALLET_PASS\n    #     $ export WALLET_PASS\n    #\n    passphrase = os.getenv(\'WALLET_PASS\')\n\n    cw_http.send_ada(\n        wallet.get("id"),\n        rx_address,\n        ada_amt,\n        passphrase,\n        wait=True\n    )\n\n## Logging\n\nThe modules include detailed logging for debugging. To enable most log messages, import the logging module and include the following at the beginning of your scripts.\n\n    logging.basicConfig(level=logging.DEBUG)\n\nThe [example scripts](https://gitlab.com/viper-staking/cardano-tools/-/tree/master/examples) illustrate how to enable logging.\n\n## Contributors\n\nThis project is developed and maintained by the team at [Viper Staking](https://viperstaking.com/).\n\n## Related Projects\n\nThe Cardano-Tools library is also used in the official [Viper Staking Docker containers](https://gitlab.com/viper-staking/docker-containers).\n',
    'author': 'Viper Science LLC',
    'author_email': 'viperstakepool@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://gitlab.com/viper-staking/cardano-tools',
    'packages': packages,
    'package_data': package_data,
    'python_requires': '>=3.9,<4.0',
}


setup(**setup_kwargs)
