Skip to content

Commit c086074

Browse files
authored
Refactor: replace VoucherManager by voucher service from sdk (#390)
* to revert: pointing sdk to aleph-sdk-python@1yam-voucher-service * Refactor: Remove Vouchers code from aleph-client * Fix: replace voucher Manager from cli to use new client service 'vouchers' * fix: linting issue on pyproject.toml * fix: mypy issue * Feature: proper unit test case for voucher * (unit test): test case for aleph account vouchers
1 parent 30375f1 commit c086074

File tree

9 files changed

+232
-664
lines changed

9 files changed

+232
-664
lines changed

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ dependencies = [
3131
"aiodns==3.2",
3232
"aiohttp==3.11.13",
3333
"aleph-message>=1.0.1",
34-
"aleph-sdk-python>=2.0.5",
35-
"base58==2.1.1", # Needed now as default with _load_account changement
34+
"aleph-sdk-python @ git+https://github.com/aleph-im/aleph-sdk-python@1yam-voucher-service",
35+
"base58==2.1.1", # Needed now as default with _load_account changement
3636
"click<8.2",
37-
"py-sr25519-bindings==0.2", # Needed for DOT signatures
37+
"py-sr25519-bindings==0.2", # Needed for DOT signatures
3838
"pydantic>=2",
3939
"pygments==2.19.1",
40-
"pynacl==1.5", # Needed now as default with _load_account changement
40+
"pynacl==1.5", # Needed now as default with _load_account changement
4141
"python-magic==0.4.27",
4242
"rich==13.9.*",
4343
"setuptools>=65.5",
44-
"substrate-interface==1.7.11", # Needed for DOT signatures
44+
"substrate-interface==1.7.11", # Needed for DOT signatures
4545
"textual==0.73",
4646
"typer==0.15.2",
4747
]

src/aleph_client/commands/account.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import aiohttp
1111
import typer
12+
from aleph.sdk import AuthenticatedAlephHttpClient
1213
from aleph.sdk.account import _load_account
1314
from aleph.sdk.chains.common import generate_key
1415
from aleph.sdk.chains.solana import parse_private_key as parse_solana_private_key
@@ -42,7 +43,6 @@
4243
yes_no_input,
4344
)
4445
from aleph_client.utils import AsyncTyper, list_unlinked_keys
45-
from aleph_client.voucher import VoucherManager
4646

4747
logger = logging.getLogger(__name__)
4848
app = AsyncTyper(no_args_is_help=True)
@@ -301,8 +301,6 @@ async def balance(
301301
if account and not address:
302302
address = account.get_address()
303303

304-
voucher_manager = VoucherManager(account=account, chain=chain)
305-
306304
if address:
307305
try:
308306
balance_data = await get_balance(address)
@@ -335,7 +333,8 @@ async def balance(
335333
]
336334

337335
# Get vouchers and add them to Account Info panel
338-
vouchers = await voucher_manager.get_all(address=address)
336+
async with AuthenticatedAlephHttpClient(account=account) as client:
337+
vouchers = await client.voucher.get_vouchers(address=address)
339338
if vouchers:
340339
voucher_names = [voucher.name for voucher in vouchers]
341340
infos += [
@@ -422,11 +421,10 @@ async def vouchers(
422421
if account and not address:
423422
address = account.get_address()
424423

425-
voucher_manager = VoucherManager(account=account, chain=chain)
426-
427424
if address:
428425
try:
429-
vouchers = await voucher_manager.get_all(address=address)
426+
async with AuthenticatedAlephHttpClient(account=account) as client:
427+
vouchers = await client.voucher.get_vouchers(address=address)
430428
if vouchers:
431429
voucher_table = Table(title="", show_header=True, box=box.ROUNDED)
432430
voucher_table.add_column("Name", style="bright_cyan")

src/aleph_client/commands/instance/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
yes_no_input,
8686
)
8787
from aleph_client.utils import AsyncTyper, sanitize_url
88-
from aleph_client.voucher import VoucherManager
8988

9089
logger = logging.getLogger(__name__)
9190
app = AsyncTyper(no_args_is_help=True)
@@ -193,9 +192,7 @@ async def create(
193192
# Force-switches if NFT payment-type
194193
nft_chains = [Chain.AVAX, Chain.BASE, Chain.SOL]
195194
if payment_type == "nft":
196-
voucher_manager = VoucherManager(account=account, chain=Chain(account.CHAIN))
197195
payment_type = PaymentType.hold
198-
199196
if payment_chain is None or payment_chain not in nft_chains:
200197
if payment_chain:
201198
console.print(
@@ -210,11 +207,11 @@ async def create(
210207
default=Chain.AVAX.value,
211208
)
212209
)
213-
214-
vouchers = await voucher_manager.fetch_vouchers_by_chain(payment_chain)
215-
if len(vouchers) == 0:
216-
console.print("No NFT vouchers find on this account")
217-
raise typer.Exit(code=1)
210+
async with AuthenticatedAlephHttpClient(account=account) as client:
211+
vouchers = await client.voucher.fetch_vouchers_by_chain(chain=Chain(account.CHAIN))
212+
if len(vouchers) == 0:
213+
console.print("No NFT vouchers find on this account")
214+
raise typer.Exit(code=1)
218215

219216
elif payment_type in [ptype.value for ptype in PaymentType]:
220217
payment_type = PaymentType(payment_type)

src/aleph_client/commands/instance/display.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,15 @@ def _prepare_allocation_column(self):
344344
color_allocation = "magenta3"
345345
crn_hash = safe_getattr(self.message.content.requirements, "node.node_hash") or ""
346346
else:
347-
crn_url = self.allocation.allocations.node.url
347+
allocation_node = (
348+
self.allocation.allocations.node
349+
if self.allocation.allocations and self.allocation.allocations.node
350+
else None
351+
)
352+
crn_url = allocation_node.url if allocation_node else ""
348353
allocation_str = ALLOCATION_AUTO
349354
color_allocation = "deep_sky_blue1"
350-
crn_hash = self.allocation.allocations.node.node_id
355+
crn_hash = allocation_node.node_id if allocation_node else ""
351356

352357
# Assemble the complete allocation column
353358
self.allocation_column = cast(

src/aleph_client/voucher.py

Lines changed: 0 additions & 213 deletions
This file was deleted.

0 commit comments

Comments
 (0)