Skip to content

Commit

Permalink
Merge branch 'main' into feat/docker-image-build-update
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Sep 19, 2024
2 parents 15306d9 + eae33b9 commit d9109bb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
19 changes: 17 additions & 2 deletions docs/userguides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def handle_on_shutdown():

*Changed in 0.2.0*: The behavior of the `@app.on_startup()` decorator and handler signature have changed. It is now executed only once upon application startup and worker events have moved on `@app.on_worker_startup()`.

### Signing Transactions

If configured, your bot with have `app.signer` which is an Ape account that can sign arbitrary transactions you ask it to.
To learn more about signing transactions with Ape, see the [documentation](https://docs.apeworx.io/ape/stable/userguides/transactions.html).

```{warning}
While not recommended, you can use keyfile accounts for automated signing.
See [this guide](https://docs.apeworx.io/ape/stable/userguides/accounts.html#automation) to learn more about how to do that.
```

## Running your Application

Once you have programmed your bot, it's really useful to be able to run it locally and validate that it does what you expect it to do.
Expand All @@ -141,9 +151,14 @@ else:
# Log what the transaction *would* have done, had a signer been enabled
```

```{note}
```{warning}
If you configure your application to use a signer, and that signer signs anything given to it, remember that you can lose substational amounts of funds if you deploy this to a production network.
Always test your applications throughly before deploying.
Always test your applications throughly before deploying, and always use a dedicated key for production signing with your application in a remote setting.
```

```{note}
It is highly suggested to use a dedicated cloud signer plugin, such as [`ape-aws`](https://github.com/ApeWorX/ape-aws) for signing transactions in a cloud environment.
Use segregated keys and limit your risk by controlling the amount of funds that key has access to at any given time.
```

### Distributed Execution
Expand Down
9 changes: 8 additions & 1 deletion silverback/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ape.api import AccountAPI, ProviderContextManager
from ape.utils import ManagerAccessMixin
from ape_accounts import KeyfileAccount
from pydantic_settings import BaseSettings, SettingsConfigDict
from taskiq import (
AsyncBroker,
Expand Down Expand Up @@ -122,4 +123,10 @@ def get_signer(self) -> AccountAPI | None:
return self.account_manager.test_accounts[acct_idx]

# NOTE: Will only have a signer if assigned one here (or in app)
return self.account_manager.load(alias)
signer = self.account_manager.load(alias)

# NOTE: Set autosign if it's a keyfile account (for local testing)
if isinstance(signer, KeyfileAccount):
signer.set_autosign(True)

return signer
2 changes: 1 addition & 1 deletion silverback/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def get_subscription_data_nowait(
try:
await self._receive(timeout=timeout)
except TimeoutError:
logger.debug("Receive call timed out.")
logger.warning(f"Receive call timed out ({sub_id}).")
return
else:
try:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
({"a": 1}, {"a": {"type": "scalar", "data": 1}}),
# max INT96 value
(
{"a": 2**96 - 1},
{"a": {"type": "scalar", "data": 79228162514264337593543950335}},
{"a": 2**95 - 1},
{"a": {"type": "scalar", "data": 39614081257132168796771975167}},
),
# int over INT96 max parses as Decimal
(
{"a": 2**96},
{"a": {"type": "scalar", "data": Decimal("79228162514264337593543950336")}},
{"a": 2**95},
{"a": {"type": "scalar", "data": Decimal("39614081257132168796771975168")}},
),
# Decimal parses as Decimal
(
Expand Down

0 comments on commit d9109bb

Please sign in to comment.