Skip to content

Commit 3d7f098

Browse files
Merge pull request #6 from renlabs-dev/feat/faucet
feat: implement faucet command [TOR-30]
2 parents ee63350 + 2e0cef0 commit 3d7f098

File tree

5 files changed

+143
-97
lines changed

5 files changed

+143
-97
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
"python.autoComplete.extraPaths": [
1818
"/home/manjairo/tcheco/torustrate-interface"
1919
]
20-
}
20+
}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ poetry add torusdk
4747
## Installation with Nix
4848

4949
To install `torus` the torus cli with Nix
50+
5051
```sh
5152
nix profile install .
5253
```
@@ -61,7 +62,6 @@ The `torus` offers a variety of features for token management and agent interact
6162
- Agent management for registration, curation and updates
6263
- Participation in governance processes
6364

64-
6565
## CLI Usage
6666

6767
The CLI commands are structured as follows:
@@ -140,6 +140,14 @@ torus network params
140140
torus misc circulating-supply
141141
```
142142

143+
### Acquiring Tokens from a Testnet Faucet
144+
145+
```sh
146+
# This command will send 15 TOR to the key-name address.
147+
# This command is only available on testnet.
148+
torus --testnet balance run-faucet <key-name>
149+
```
150+
143151
## Completions
144152

145153
You can enable completions for your shell by running:

src/torusdk/cli/balance.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import time
12
from typing import Optional
23

34
import typer
45
from typer import Context
56

67
from torusdk.balance import BalanceUnit, format_balance, to_rems
78
from torusdk.cli._common import (
8-
NOT_IMPLEMENTED_MESSAGE,
99
make_custom_context,
1010
print_table_from_plain_dict,
1111
)
@@ -229,14 +229,17 @@ def unstake(ctx: Context, key: str, amount: float, dest: str):
229229
raise ChainTransactionError(response.error_message) # type: ignore
230230

231231

232+
# Ammount of seconds to wait between faucet executions
233+
SLEEP_BETWEEN_FAUCET_EXECUTIONS = 8
234+
235+
232236
@balance_app.command()
233237
def run_faucet(
234238
ctx: Context,
235239
key: str,
236-
num_processes: Optional[int] = None,
237-
num_executions: int = 1,
240+
jobs: Optional[int] = None,
241+
repeat: int = 1,
238242
):
239-
raise NotImplementedError("Faucet " + NOT_IMPLEMENTED_MESSAGE)
240243
context = make_custom_context(ctx)
241244
use_testnet = ctx.obj.use_testnet
242245

@@ -247,13 +250,13 @@ def run_faucet(
247250
resolved_key = context.load_key(key, None)
248251

249252
client = context.com_client()
250-
for _ in range(num_executions):
253+
for _i in range(repeat):
251254
with context.progress_status("Solving PoW..."):
252255
solution = solve_for_difficulty_fast(
253256
client,
254257
resolved_key,
255258
client.url,
256-
num_processes=num_processes,
259+
num_processes=jobs,
257260
)
258261
with context.progress_status("Sending solution to blockchain"):
259262
params = {
@@ -262,10 +265,17 @@ def run_faucet(
262265
"work": solution.seal,
263266
"key": resolved_key.ss58_address,
264267
}
268+
265269
client.compose_call(
266270
"faucet",
267271
params=params,
268272
unsigned=True,
269-
module="FaucetModule",
270-
key=resolved_key.ss58_address, # type: ignore
273+
module="Faucet",
274+
key=resolved_key,
275+
wait_for_inclusion=False,
271276
)
277+
278+
context.info(
279+
f"Waiting {SLEEP_BETWEEN_FAUCET_EXECUTIONS} seconds before next execution..."
280+
)
281+
time.sleep(SLEEP_BETWEEN_FAUCET_EXECUTIONS)

0 commit comments

Comments
 (0)