Skip to content

Commit

Permalink
chore: remove purestake code
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Jul 5, 2024
1 parent 3d3a28e commit f13b03a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Bases: {py:obj}`algokit_utils.models.TransactionResponse`, {py:obj}`typing.Gener
:canonical: algokit_utils.models.Account.address
:type: str
:value: >
None
'field(...)'

```{autodoc2-docstring} algokit_utils.models.Account.address
:parser: myst
Expand Down
15 changes: 7 additions & 8 deletions docs/html/_sources/capabilities/client.md.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Client management

Client management is one of the core capabilities provided by AlgoKit Utils.
It allows you to create [algod](https://developer.algorand.org/docs/rest-apis/algod), [indexer](https://developer.algorand.org/docs/rest-apis/indexer)
Client management is one of the core capabilities provided by AlgoKit Utils.
It allows you to create [algod](https://developer.algorand.org/docs/rest-apis/algod), [indexer](https://developer.algorand.org/docs/rest-apis/indexer)
and [kmd](https://developer.algorand.org/docs/rest-apis/kmd) clients against various networks resolved from environment or specified configuration.

Any AlgoKit Utils function that needs one of these clients will take the underlying `algosdk` classes (`algosdk.v2client.algod.AlgodClient`, `algosdk.v2client.indexer.IndexerClient`,
`algosdk.kmd.KMDClient`) so inline with the [Modularity](../index.md#core-principles) principle you can use existing logic to get instances of these clients without needing to use the
Any AlgoKit Utils function that needs one of these clients will take the underlying `algosdk` classes (`algosdk.v2client.algod.AlgodClient`, `algosdk.v2client.indexer.IndexerClient`,
`algosdk.kmd.KMDClient`) so inline with the [Modularity](../index.md#core-principles) principle you can use existing logic to get instances of these clients without needing to use the
Client management capability if you prefer.

To see some usage examples check out the [automated tests](https://github.com/algorandfoundation/algokit-utils-py/blob/main/tests/test_network_clients.py).
Expand All @@ -16,10 +16,9 @@ The network configuration is specified using the `AlgoClientConfig` class. This

There are a number of ways to produce one of these configuration objects:

* Manually creating the object, e.g. `AlgoClientConfig(server="https://myalgodnode.com", token="SECRET_TOKEN")`
* `algokit_utils.get_algonode_config(network, config, token)`: Loads an Algod or indexer config against [AlgoNode](https://algonode.io/api/) to either MainNet or TestNet
* `algokit_utils.get_purestake_config(network, config, token)`: Loads an Algod or indexer config against [PureStake](https://developer.purestake.io/) to either MainNet or TestNet
* `algokit_utils.get_default_localnet_config(configOrPort)`: Loads an Algod, Indexer or Kmd config against [LocalNet](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md) using the default configuration
- Manually creating the object, e.g. `AlgoClientConfig(server="https://myalgodnode.com", token="SECRET_TOKEN")`
- `algokit_utils.get_algonode_config(network, config, token)`: Loads an Algod or indexer config against [Nodely](https://nodely.io/docs/free/start) to either MainNet or TestNet
- `algokit_utils.get_default_localnet_config(configOrPort)`: Loads an Algod, Indexer or Kmd config against [LocalNet](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md) using the default configuration

## Clients

Expand Down
4 changes: 2 additions & 2 deletions docs/html/apidocs/algokit_utils/algokit_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ <h3>API<a class="headerlink" href="#api" title="Permalink to this heading"></
<dl class="py attribute">
<dt class="sig sig-object py" id="algokit_utils.Account.address">
<span class="sig-name descname"><span class="pre">address</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></em><a class="headerlink" href="#algokit_utils.Account.address" title="Permalink to this definition"></a></dt>
<dd><p>None</p>
<dd><p>‘field(…)’</p>
<p>Address for this account</p>
</dd></dl>

Expand Down Expand Up @@ -1508,7 +1508,7 @@ <h3>API<a class="headerlink" href="#api" title="Permalink to this heading"></

<dl class="py function">
<dt class="sig sig-object py" id="algokit_utils.execute_atc_with_logic_error">
<span class="sig-prename descclassname"><span class="pre">algokit_utils.</span></span><span class="sig-name descname"><span class="pre">execute_atc_with_logic_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">atc</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/atomic_transaction_composer.html#algosdk.atomic_transaction_composer.AtomicTransactionComposer" title="(in algosdk)"><span class="pre">algosdk.atomic_transaction_composer.AtomicTransactionComposer</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">algod_client</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient" title="(in algosdk)"><span class="pre">algosdk.v2client.algod.AlgodClient</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">approval_program</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">wait_rounds</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">4</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">approval_source_map</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">algosdk.source_map.SourceMap</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.12)"><span class="pre">Callable</span></a><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">algosdk.source_map.SourceMap</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/atomic_transaction_composer.html#algosdk.atomic_transaction_composer.AtomicTransactionResponse" title="(in algosdk)"><span class="pre">algosdk.atomic_transaction_composer.AtomicTransactionResponse</span></a></span></span><a class="headerlink" href="#algokit_utils.execute_atc_with_logic_error" title="Permalink to this definition"></a></dt>
<span class="sig-prename descclassname"><span class="pre">algokit_utils.</span></span><span class="sig-name descname"><span class="pre">execute_atc_with_logic_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">atc</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/atomic_transaction_composer.html#algosdk.atomic_transaction_composer.AtomicTransactionComposer" title="(in algosdk)"><span class="pre">algosdk.atomic_transaction_composer.AtomicTransactionComposer</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">algod_client</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/v2client/algod.html#algosdk.v2client.algod.AlgodClient" title="(in algosdk)"><span class="pre">algosdk.v2client.algod.AlgodClient</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">approval_program</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">wait_rounds</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">4</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">approval_source_map</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/source_map.html#algosdk.source_map.SourceMap" title="(in algosdk)"><span class="pre">algosdk.source_map.SourceMap</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.12)"><span class="pre">Callable</span></a><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/source_map.html#algosdk.source_map.SourceMap" title="(in algosdk)"><span class="pre">algosdk.source_map.SourceMap</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.12)"><span class="pre">None</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/atomic_transaction_composer.html#algosdk.atomic_transaction_composer.AtomicTransactionResponse" title="(in algosdk)"><span class="pre">algosdk.atomic_transaction_composer.AtomicTransactionResponse</span></a></span></span><a class="headerlink" href="#algokit_utils.execute_atc_with_logic_error" title="Permalink to this definition"></a></dt>
<dd><p>Calls <code class="xref py py-meth docutils literal notranslate"><span class="pre">AtomicTransactionComposer.execute()</span></code> on provided <code class="docutils literal notranslate"><span class="pre">atc</span></code>, but will parse any errors
and raise a <a class="reference internal" href="#algokit_utils.LogicError" title="algokit_utils.LogicError"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogicError</span></code></a> if possible</p>
<div class="admonition note">
Expand Down
3 changes: 1 addition & 2 deletions docs/html/capabilities/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ <h2>Network configuration<a class="headerlink" href="#network-configuration" tit
<p>There are a number of ways to produce one of these configuration objects:</p>
<ul class="simple">
<li><p>Manually creating the object, e.g. <code class="docutils literal notranslate"><span class="pre">AlgoClientConfig(server=&quot;https://myalgodnode.com&quot;,</span> <span class="pre">token=&quot;SECRET_TOKEN&quot;)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">algokit_utils.get_algonode_config(network,</span> <span class="pre">config,</span> <span class="pre">token)</span></code>: Loads an Algod or indexer config against <a class="reference external" href="https://algonode.io/api/">AlgoNode</a> to either MainNet or TestNet</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">algokit_utils.get_purestake_config(network,</span> <span class="pre">config,</span> <span class="pre">token)</span></code>: Loads an Algod or indexer config against <a class="reference external" href="https://developer.purestake.io/">PureStake</a> to either MainNet or TestNet</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">algokit_utils.get_algonode_config(network,</span> <span class="pre">config,</span> <span class="pre">token)</span></code>: Loads an Algod or indexer config against <a class="reference external" href="https://nodely.io/docs/free/start">Nodely</a> to either MainNet or TestNet</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">algokit_utils.get_default_localnet_config(configOrPort)</span></code>: Loads an Algod, Indexer or Kmd config against <a class="reference external" href="https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md">LocalNet</a> using the default configuration</p></li>
</ul>
</section>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h2>Types<a class="headerlink" href="#types" title="Permalink to this heading">
<li><p><a class="reference internal" href="capabilities/app-client.html"><span class="std std-doc"><strong>ARC-0032 Application Spec client</strong></span></a> - Builds on top of the App management and App deployment capabilities to provide a high productivity application client that works with ARC-0032 application spec defined smart contracts (e.g. via Beaker)</p></li>
<li><p><a class="reference internal" href="capabilities/app-deploy.html"><span class="std std-doc"><strong>App deployment</strong></span></a> - Idempotent (safely retryable) deployment of an app, including deploy-time immutability and permanence control and TEAL template substitution</p></li>
<li><p><a class="reference internal" href="capabilities/transfer.html"><span class="std std-doc"><strong>Algo transfers</strong></span></a> - Ability to easily initiate algo transfers between accounts, including dispenser management and idempotent account funding</p></li>
<li><p><span class="xref myst"><strong>Debugger</strong></span> - Provides a set of debugging tools that can be used to simulate and trace transactions on the Algorand blockchain. These tools and methods are optimized for developers who are building applications on Algorand and need to test and debug their smart contracts via <a class="reference internal" href="#link"><span class="xref myst">AVM Debugger extension</span></a>.</p></li>
<li><p><a class="reference internal" href="#capabilities/debugger.md"><span class="xref myst"><strong>Debugger</strong></span></a> - Provides a set of debugging tools that can be used to simulate and trace transactions on the Algorand blockchain. These tools and methods are optimized for developers who are building applications on Algorand and need to test and debug their smart contracts via <a class="reference internal" href="#link"><span class="xref myst">AVM Debugger extension</span></a>.</p></li>
</ul>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/searchindex.js

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,3 @@ INDEXER_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#INDEXER_TOKEN=
#INDEXER_SERVER=https://testnet-idx.algonode.cloud/
#INDEXER_PORT=443

# OR:

# PureStake - https://developer.purestake.io/
# Useful service to target testnet and mainnet without having to run our own node
# You'll need to fund the CREATOR_MNEMONIC and DISPENSER_MNEMONIC accounts via a TestNet dispenser
#ALGOD_TOKEN={token}
#ALGOD_SERVER=https://testnet-algorand.api.purestake.io/ps2
#ALGOD_PORT=443
#INDEXER_TOKEN={token}
#INDEXER_SERVER=https://testnet-algorand.api.purestake.io/idx2
#INDEXER_PORT=443
2 changes: 0 additions & 2 deletions src/algokit_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
get_default_localnet_config,
get_indexer_client,
get_kmd_client_from_algod_client,
get_purestake_config,
is_localnet,
is_mainnet,
is_testnet,
Expand Down Expand Up @@ -160,7 +159,6 @@
"get_default_localnet_config",
"get_indexer_client",
"get_kmd_client_from_algod_client",
"get_purestake_config",
"is_localnet",
"is_mainnet",
"is_testnet",
Expand Down
28 changes: 2 additions & 26 deletions src/algokit_utils/network_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
"get_default_localnet_config",
"get_indexer_client",
"get_kmd_client_from_algod_client",
"get_purestake_config",
"is_localnet",
"is_mainnet",
"is_testnet",
"AlgoClientConfigs",
"get_kmd_client",
]

_PURE_STAKE_HOST = "purestake.io"


@dataclasses.dataclass
class AlgoClientConfig:
Expand Down Expand Up @@ -59,22 +56,12 @@ def get_algonode_config(
)


def get_purestake_config(
network: Literal["testnet", "mainnet"], config: Literal["algod", "indexer"], token: str
) -> AlgoClientConfig:
client = "ps2" if config == "algod" else "idx2"
return AlgoClientConfig(
server=f"https://{network}-algorand.api.purestake.io/{client}",
token=token,
)


def get_algod_client(config: AlgoClientConfig | None = None) -> AlgodClient:
"""Returns an {py:class}`algosdk.v2client.algod.AlgodClient` from `config` or environment
If no configuration provided will use environment variables `ALGOD_SERVER`, `ALGOD_PORT` and `ALGOD_TOKEN`"""
config = config or _get_config_from_environment("ALGOD")
headers = _get_headers(config, "X-Algo-API-Token")
headers = {"X-Algo-API-Token": config.token}
return AlgodClient(config.token, config.server, headers)


Expand All @@ -91,7 +78,7 @@ def get_indexer_client(config: AlgoClientConfig | None = None) -> IndexerClient:
If no configuration provided will use environment variables `INDEXER_SERVER`, `INDEXER_PORT` and `INDEXER_TOKEN`"""
config = config or _get_config_from_environment("INDEXER")
headers = _get_headers(config, "X-Indexer-API-Token")
headers = {"X-Indexer-API-Token": config.token}
return IndexerClient(config.token, config.server, headers) # type: ignore[no-untyped-call]


Expand Down Expand Up @@ -141,14 +128,3 @@ def _get_config_from_environment(environment_prefix: str) -> AlgoClientConfig:
parsed = parse.urlparse(server)
server = parsed._replace(netloc=f"{parsed.hostname}:{port}").geturl()
return AlgoClientConfig(server, os.getenv(f"{environment_prefix}_TOKEN", ""))


def _is_pure_stake_url(url: str) -> bool:
parsed = parse.urlparse(url)
host = parsed.netloc.split(":")[0].lower()
return host.endswith(_PURE_STAKE_HOST)


def _get_headers(config: AlgoClientConfig, default_auth_header: str) -> dict[str, str] | None:
auth_header = "X-API-Key" if _is_pure_stake_url(config.server) else default_auth_header
return {auth_header: config.token}
Loading

0 comments on commit f13b03a

Please sign in to comment.