@@ -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 )
0 commit comments