Skip to content

Commit a1e29d6

Browse files
authored
Fix: add missing 'address' param on program and file commands (#432)
1 parent 24766a4 commit a1e29d6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/aleph_client/commands/files.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,21 @@ async def pin(
4848
] = settings.PRIVATE_KEY_FILE,
4949
chain: Annotated[Optional[Chain], typer.Option(help=help_strings.ADDRESS_CHAIN)] = None,
5050
ref: Annotated[Optional[str], typer.Option(help=help_strings.REF)] = None,
51+
address: Annotated[Optional[str], typer.Option(help="Address")] = None,
5152
debug: Annotated[bool, typer.Option()] = False,
5253
):
5354
"""Persist a file from IPFS on Aleph Cloud."""
5455

5556
setup_logging(debug)
5657

5758
account: AccountTypes = load_account(private_key_str=private_key, private_key_file=private_key_file, chain=chain)
59+
address = address or settings.ADDRESS_TO_USE or account.get_address()
5860

5961
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
6062
result: StoreMessage
6163
status: MessageStatus
6264
result, status = await client.create_store(
65+
address=address,
6366
file_hash=item_hash,
6467
storage_engine=StorageEnum.ipfs,
6568
channel=channel,
@@ -80,20 +83,22 @@ async def upload(
8083
] = settings.PRIVATE_KEY_FILE,
8184
chain: Annotated[Optional[Chain], typer.Option(help=help_strings.ADDRESS_CHAIN)] = None,
8285
ref: Annotated[Optional[str], typer.Option(help=help_strings.REF)] = None,
86+
address: Annotated[Optional[str], typer.Option(help="Address")] = None,
8387
debug: Annotated[bool, typer.Option()] = False,
8488
):
8589
"""Upload and store a file or directory on Aleph Cloud."""
8690

8791
setup_logging(debug)
8892

8993
account: AccountTypes = load_account(private_key_str=private_key, private_key_file=private_key_file, chain=chain)
94+
address = address or settings.ADDRESS_TO_USE or account.get_address()
9095

9196
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
9297

93-
async def check_spending_capacity_for_account(storage_size_mib: float, account: AccountTypes):
98+
async def check_spending_capacity_for_account(storage_size_mib: float, address):
9499
# estimate and check before uploading
95100
content = {
96-
"address": account.get_address(),
101+
"address": address,
97102
"time": time.time(),
98103
"item_type": ItemType.storage,
99104
"estimated_size_mib": int(storage_size_mib),
@@ -111,7 +116,7 @@ async def check_spending_capacity_for_account(storage_size_mib: float, account:
111116
price = await response.json()
112117
required_tokens = price["required_tokens"] if price["cost"] is None else Decimal(price["cost"])
113118

114-
balance_response = await client.get_balances(account.get_address())
119+
balance_response = await client.get_balances(address)
115120
available_funds = balance_response.balance - balance_response.locked_amount
116121

117122
try:
@@ -129,7 +134,7 @@ async def check_spending_capacity_for_account(storage_size_mib: float, account:
129134
file_size = len(file_content)
130135

131136
# check spending limit
132-
await check_spending_capacity_for_account(file_size / 1_024 / 1_024, account)
137+
await check_spending_capacity_for_account(file_size / 1_024 / 1_024, address)
133138

134139
storage_limit = 4 * 1024 * 1024 # 4MB
135140
if storage_engine is None:
@@ -143,6 +148,7 @@ async def check_spending_capacity_for_account(storage_size_mib: float, account:
143148
status: MessageStatus
144149
try:
145150
result, status = await client.create_store(
151+
address=address,
146152
file_content=file_content,
147153
storage_engine=storage_engine,
148154
channel=channel,
@@ -193,12 +199,12 @@ async def upload_directory(directory: Path):
193199
if fp.is_file():
194200
total_size += fp.stat().st_size
195201

196-
await check_spending_capacity_for_account(total_size / 1_024 / 1_024, account)
202+
await check_spending_capacity_for_account(total_size / 1_024 / 1_024, address)
197203
cid = await upload_directory(path)
198204
if not cid:
199205
typer.echo("CID not found in response.")
200206
typer.Exit(code=1)
201-
await pin(cid, channel, private_key, private_key_file, chain, ref, debug)
207+
await pin(cid, channel, private_key, private_key_file, chain, ref, address, debug)
202208
else:
203209
typer.echo(f"Error: File not found: '{path}'")
204210
raise typer.Exit(code=1)

src/aleph_client/commands/program.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ async def upload(
162162
user_code: StoreMessage
163163
status: MessageStatus
164164
user_code, status = await client.create_store(
165+
address=address,
165166
file_content=file_content,
166167
storage_engine=storage_engine,
167168
channel=channel,
@@ -330,6 +331,7 @@ async def update(
330331
] = settings.PRIVATE_KEY_FILE,
331332
print_message: Annotated[bool, typer.Option(help="Print the message after creation")] = False,
332333
verbose: Annotated[bool, typer.Option(help="Display additional information")] = True,
334+
address: Annotated[Optional[str], typer.Option(help=help_strings.ADDRESS_PAYER)] = None,
333335
debug: Annotated[bool, typer.Option(help="Enable debug logging")] = False,
334336
):
335337
"""Update the code of an existing program (item hash will not change)"""
@@ -348,6 +350,7 @@ async def update(
348350
raise typer.Exit(code=4) from error
349351

350352
account = _load_account(private_key, private_key_file, chain=chain)
353+
address = address or settings.ADDRESS_TO_USE or account.get_address()
351354

352355
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
353356
try:
@@ -386,6 +389,7 @@ async def update(
386389
logger.debug("Uploading file")
387390
message: StoreMessage
388391
message, status = await client.create_store(
392+
address=address,
389393
file_content=file_content,
390394
storage_engine=StorageEnum(code_message.content.item_type),
391395
channel=code_message.channel,

0 commit comments

Comments
 (0)