hippius 0.2.9__py3-none-any.whl → 0.2.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hippius-0.2.9.dist-info → hippius-0.2.11.dist-info}/METADATA +1 -1
- hippius-0.2.11.dist-info/RECORD +17 -0
- hippius_sdk/__init__.py +1 -1
- hippius_sdk/cli_handlers.py +77 -51
- hippius_sdk/client.py +63 -15
- hippius_sdk/config.py +14 -2
- hippius_sdk/ipfs.py +159 -114
- hippius_sdk/ipfs_core.py +1 -1
- hippius_sdk/substrate.py +123 -79
- hippius_sdk/utils.py +14 -8
- hippius-0.2.9.dist-info/RECORD +0 -17
- {hippius-0.2.9.dist-info → hippius-0.2.11.dist-info}/WHEEL +0 -0
- {hippius-0.2.9.dist-info → hippius-0.2.11.dist-info}/entry_points.txt +0 -0
hippius_sdk/substrate.py
CHANGED
@@ -67,7 +67,6 @@ class SubstrateClient:
|
|
67
67
|
def __init__(
|
68
68
|
self,
|
69
69
|
url: Optional[str] = None,
|
70
|
-
seed_phrase: Optional[str] = None,
|
71
70
|
password: Optional[str] = None,
|
72
71
|
account_name: Optional[str] = None,
|
73
72
|
):
|
@@ -76,7 +75,6 @@ class SubstrateClient:
|
|
76
75
|
|
77
76
|
Args:
|
78
77
|
url: WebSocket URL of the Hippius substrate node (from config if None)
|
79
|
-
seed_phrase: Seed phrase for the account (mnemonic) (from config if None)
|
80
78
|
password: Optional password to decrypt the seed phrase if it's encrypted
|
81
79
|
account_name: Optional name of the account to use (uses active account if None)
|
82
80
|
"""
|
@@ -91,29 +89,27 @@ class SubstrateClient:
|
|
91
89
|
self._account_name = account_name or get_active_account()
|
92
90
|
self._account_address = None
|
93
91
|
self._read_only = False
|
92
|
+
self._seed_phrase_password = password
|
94
93
|
|
95
94
|
# Get the account address for read-only operations
|
96
95
|
addr = get_account_address(self._account_name)
|
97
96
|
if addr:
|
98
97
|
self._account_address = addr
|
99
98
|
|
100
|
-
#
|
101
|
-
|
102
|
-
self.set_seed_phrase(seed_phrase)
|
103
|
-
else:
|
104
|
-
# Only try to get the seed phrase if we need it for the current operation
|
105
|
-
# We'll defer this to when it's actually needed
|
106
|
-
self._seed_phrase = None
|
107
|
-
self._seed_phrase_password = password
|
99
|
+
# For backward compatibility - storing the seed phrase is deprecated but needed for older code
|
100
|
+
self._seed_phrase = None
|
108
101
|
|
109
102
|
# Don't connect immediately to avoid exceptions during initialization
|
110
103
|
# Connection will happen lazily when needed
|
111
104
|
|
112
|
-
def connect(self) -> None:
|
105
|
+
def connect(self, seed_phrase: Optional[str] = None) -> None:
|
113
106
|
"""
|
114
107
|
Connect to the Substrate node.
|
115
108
|
|
116
109
|
Initializes the connection to the Substrate node and creates a keypair from the seed phrase.
|
110
|
+
|
111
|
+
Args:
|
112
|
+
seed_phrase: Optional seed phrase for the connection
|
117
113
|
"""
|
118
114
|
try:
|
119
115
|
print(f"Connecting to Substrate node at {self.url}...")
|
@@ -123,10 +119,8 @@ class SubstrateClient:
|
|
123
119
|
type_registry_preset="substrate-node-template",
|
124
120
|
)
|
125
121
|
|
126
|
-
#
|
127
|
-
if
|
128
|
-
self._keypair = Keypair.create_from_mnemonic(self._seed_phrase)
|
129
|
-
self._account_address = self._keypair.ss58_address
|
122
|
+
# Create keypair if seed_phrase is provided or try to get from config
|
123
|
+
if self._ensure_keypair(seed_phrase):
|
130
124
|
print(
|
131
125
|
f"Connected successfully. Account address: {self._keypair.ss58_address}"
|
132
126
|
)
|
@@ -146,36 +140,45 @@ class SubstrateClient:
|
|
146
140
|
f"Could not connect to Substrate node at {self.url}: {e}"
|
147
141
|
)
|
148
142
|
|
149
|
-
def _ensure_keypair(self) -> bool:
|
143
|
+
def _ensure_keypair(self, seed_phrase: Optional[str] = None) -> bool:
|
150
144
|
"""
|
151
145
|
Ensure we have a keypair for signing transactions.
|
152
|
-
Will
|
146
|
+
Will use the provided seed_phrase if given, otherwise get it from config.
|
147
|
+
|
148
|
+
Args:
|
149
|
+
seed_phrase: Optional seed phrase to use for creating keypair
|
153
150
|
|
154
151
|
Returns:
|
155
152
|
bool: True if keypair is available, False if it couldn't be created
|
156
153
|
"""
|
157
|
-
|
154
|
+
# If we already have a keypair and no new seed phrase was provided, use existing keypair
|
155
|
+
if self._keypair and not seed_phrase:
|
158
156
|
return True
|
159
157
|
|
160
|
-
# If
|
161
|
-
if
|
158
|
+
# If a seed phrase was provided, use it to create a keypair
|
159
|
+
if seed_phrase:
|
162
160
|
try:
|
163
|
-
self._keypair = Keypair.create_from_mnemonic(
|
161
|
+
self._keypair = Keypair.create_from_mnemonic(seed_phrase)
|
164
162
|
self._account_address = self._keypair.ss58_address
|
165
163
|
self._read_only = False
|
166
164
|
return True
|
167
165
|
except Exception as e:
|
168
|
-
print(
|
166
|
+
print(
|
167
|
+
f"Warning: Could not create keypair from provided seed phrase: {e}"
|
168
|
+
)
|
169
169
|
return False
|
170
170
|
|
171
171
|
# Otherwise, try to get the seed phrase from config
|
172
172
|
config_seed = get_seed_phrase(self._seed_phrase_password, self._account_name)
|
173
173
|
if config_seed:
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
174
|
+
try:
|
175
|
+
self._keypair = Keypair.create_from_mnemonic(config_seed)
|
176
|
+
self._account_address = self._keypair.ss58_address
|
177
|
+
self._read_only = False
|
178
|
+
return True
|
179
|
+
except Exception as e:
|
180
|
+
print(f"Warning: Could not create keypair from config seed phrase: {e}")
|
181
|
+
return False
|
179
182
|
else:
|
180
183
|
return False
|
181
184
|
|
@@ -201,6 +204,25 @@ class SubstrateClient:
|
|
201
204
|
"""
|
202
205
|
return self.generate_mnemonic()
|
203
206
|
|
207
|
+
def set_seed_phrase(self, seed_phrase: str) -> None:
|
208
|
+
"""
|
209
|
+
Set or update the seed phrase used for signing transactions.
|
210
|
+
|
211
|
+
Note: This method is kept for backward compatibility.
|
212
|
+
The preferred approach is to pass seed_phrase to individual methods.
|
213
|
+
|
214
|
+
Args:
|
215
|
+
seed_phrase: Mnemonic seed phrase for the account
|
216
|
+
"""
|
217
|
+
if not seed_phrase or not seed_phrase.strip():
|
218
|
+
raise ValueError("Seed phrase cannot be empty")
|
219
|
+
|
220
|
+
# Store the seed phrase in memory for this session (deprecated)
|
221
|
+
self._seed_phrase = seed_phrase.strip()
|
222
|
+
|
223
|
+
# Create the keypair for future operations
|
224
|
+
self._ensure_keypair(seed_phrase)
|
225
|
+
|
204
226
|
def create_account(
|
205
227
|
self, name: str, encode: bool = False, password: Optional[str] = None
|
206
228
|
) -> Dict[str, Any]:
|
@@ -244,8 +266,8 @@ class SubstrateClient:
|
|
244
266
|
# Update the client's state to use this account
|
245
267
|
self._account_name = name
|
246
268
|
self._account_address = ss58_address
|
247
|
-
|
248
|
-
self.
|
269
|
+
# Set seed phrase using the method to ensure proper state update
|
270
|
+
self.set_seed_phrase(mnemonic)
|
249
271
|
self._read_only = False
|
250
272
|
|
251
273
|
# Return the new account details
|
@@ -372,8 +394,8 @@ class SubstrateClient:
|
|
372
394
|
# Update the client's state to use this account
|
373
395
|
self._account_name = name
|
374
396
|
self._account_address = address
|
375
|
-
|
376
|
-
self.
|
397
|
+
# Set seed phrase using the method to ensure proper state update
|
398
|
+
self.set_seed_phrase(mnemonic)
|
377
399
|
self._read_only = False
|
378
400
|
|
379
401
|
# Return the imported account details
|
@@ -471,29 +493,11 @@ class SubstrateClient:
|
|
471
493
|
|
472
494
|
return account_info
|
473
495
|
|
474
|
-
def set_seed_phrase(self, seed_phrase: str) -> None:
|
475
|
-
"""
|
476
|
-
Set or update the seed phrase used for signing transactions.
|
477
|
-
|
478
|
-
Args:
|
479
|
-
seed_phrase: Mnemonic seed phrase for the account
|
480
|
-
"""
|
481
|
-
if not seed_phrase or not seed_phrase.strip():
|
482
|
-
raise ValueError("Seed phrase cannot be empty")
|
483
|
-
|
484
|
-
# Store the seed phrase in memory for this session
|
485
|
-
self._seed_phrase = seed_phrase.strip()
|
486
|
-
self._read_only = False
|
487
|
-
|
488
|
-
# Try to create the keypair if possible
|
489
|
-
try:
|
490
|
-
self._keypair = Keypair.create_from_mnemonic(self._seed_phrase)
|
491
|
-
self._account_address = self._keypair.ss58_address
|
492
|
-
except Exception as e:
|
493
|
-
raise ValueError(f"Could not create keypair from seed phrase: {e}")
|
494
|
-
|
495
496
|
async def storage_request(
|
496
|
-
self,
|
497
|
+
self,
|
498
|
+
files: List[Union[FileInput, Dict[str, str]]],
|
499
|
+
miner_ids: List[str] = None,
|
500
|
+
seed_phrase: Optional[str] = None,
|
497
501
|
) -> str:
|
498
502
|
"""
|
499
503
|
Submit a storage request for IPFS files to the marketplace.
|
@@ -504,6 +508,7 @@ class SubstrateClient:
|
|
504
508
|
Args:
|
505
509
|
files: List of FileInput objects or dictionaries with fileHash and fileName
|
506
510
|
miner_ids: List of miner IDs to store the files (optional)
|
511
|
+
seed_phrase: Optional seed phrase to use for this transaction (uses config if None)
|
507
512
|
|
508
513
|
Returns:
|
509
514
|
str: Transaction hash
|
@@ -515,8 +520,10 @@ class SubstrateClient:
|
|
515
520
|
... ])
|
516
521
|
"""
|
517
522
|
# Check if we have a keypair for signing transactions
|
518
|
-
if not self._ensure_keypair():
|
519
|
-
raise ValueError(
|
523
|
+
if not self._ensure_keypair(seed_phrase):
|
524
|
+
raise ValueError(
|
525
|
+
"Valid seed phrase must be provided or available in config"
|
526
|
+
)
|
520
527
|
|
521
528
|
# Convert any dict inputs to FileInput objects
|
522
529
|
file_inputs = []
|
@@ -537,8 +544,9 @@ class SubstrateClient:
|
|
537
544
|
for file in file_inputs:
|
538
545
|
print(f" - {file.file_name}: {file.file_hash}")
|
539
546
|
|
540
|
-
# Initialize Substrate connection
|
541
|
-
|
547
|
+
# Initialize Substrate connection with seed phrase
|
548
|
+
if not self._substrate:
|
549
|
+
self.connect(seed_phrase)
|
542
550
|
|
543
551
|
# Step 1: Create a JSON file with the list of files to pin
|
544
552
|
file_list = []
|
@@ -647,6 +655,7 @@ class SubstrateClient:
|
|
647
655
|
self,
|
648
656
|
cid: str,
|
649
657
|
filename: str = None,
|
658
|
+
seed_phrase: Optional[str] = None,
|
650
659
|
) -> str:
|
651
660
|
"""
|
652
661
|
Store a CID on the blockchain.
|
@@ -654,28 +663,32 @@ class SubstrateClient:
|
|
654
663
|
Args:
|
655
664
|
cid: Content Identifier (CID) to store
|
656
665
|
filename: Original filename (optional)
|
666
|
+
seed_phrase: Optional seed phrase to use for this transaction (uses config if None)
|
657
667
|
|
658
668
|
Returns:
|
659
669
|
str: Transaction hash
|
660
670
|
"""
|
661
671
|
file_input = FileInput(file_hash=cid, file_name=filename or "unnamed_file")
|
662
|
-
return await self.storage_request([file_input])
|
672
|
+
return await self.storage_request([file_input], seed_phrase=seed_phrase)
|
663
673
|
|
664
674
|
async def get_account_balance(
|
665
|
-
self, account_address: Optional[str] = None
|
675
|
+
self, account_address: Optional[str] = None, seed_phrase: Optional[str] = None
|
666
676
|
) -> Dict[str, float]:
|
667
677
|
"""
|
668
678
|
Get the balance of an account.
|
669
679
|
|
670
680
|
Args:
|
671
681
|
account_address: Substrate account address (uses keypair address if not specified)
|
682
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
672
683
|
|
673
684
|
Returns:
|
674
685
|
Dict[str, float]: Account balances (free, reserved, total)
|
675
686
|
"""
|
676
687
|
try:
|
677
688
|
# Initialize Substrate connection and get account address
|
678
|
-
substrate, derived_address = initialize_substrate_connection(
|
689
|
+
substrate, derived_address = initialize_substrate_connection(
|
690
|
+
self, seed_phrase
|
691
|
+
)
|
679
692
|
|
680
693
|
# Use provided account address or the one derived from initialization
|
681
694
|
if not account_address:
|
@@ -733,7 +746,10 @@ class SubstrateClient:
|
|
733
746
|
raise ValueError(f"Error querying account balance: {str(e)}")
|
734
747
|
|
735
748
|
async def watch_account_balance(
|
736
|
-
self,
|
749
|
+
self,
|
750
|
+
account_address: Optional[str] = None,
|
751
|
+
interval: int = 5,
|
752
|
+
seed_phrase: Optional[str] = None,
|
737
753
|
) -> None:
|
738
754
|
"""
|
739
755
|
Watch account balance in real-time, updating at specified intervals.
|
@@ -743,6 +759,7 @@ class SubstrateClient:
|
|
743
759
|
Args:
|
744
760
|
account_address: Substrate account address (uses keypair address if not specified)
|
745
761
|
interval: Polling interval in seconds (default: 5)
|
762
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
746
763
|
"""
|
747
764
|
try:
|
748
765
|
# Use provided account address or default to keypair/configured address
|
@@ -750,8 +767,8 @@ class SubstrateClient:
|
|
750
767
|
if self._account_address:
|
751
768
|
account_address = self._account_address
|
752
769
|
else:
|
753
|
-
# Try to get the address from the keypair (
|
754
|
-
if not self._ensure_keypair():
|
770
|
+
# Try to get the address from the keypair (with seed phrase if provided)
|
771
|
+
if not self._ensure_keypair(seed_phrase):
|
755
772
|
raise ValueError("No account address available")
|
756
773
|
account_address = self._keypair.ss58_address
|
757
774
|
|
@@ -765,7 +782,9 @@ class SubstrateClient:
|
|
765
782
|
|
766
783
|
# Get current balance
|
767
784
|
try:
|
768
|
-
balance = await self.get_account_balance(
|
785
|
+
balance = await self.get_account_balance(
|
786
|
+
account_address, seed_phrase
|
787
|
+
)
|
769
788
|
|
770
789
|
# Clear screen (ANSI escape sequence)
|
771
790
|
print("\033c", end="")
|
@@ -819,13 +838,16 @@ class SubstrateClient:
|
|
819
838
|
except Exception as e:
|
820
839
|
print(f"Error in watch_account_balance: {e}")
|
821
840
|
|
822
|
-
async def get_free_credits(
|
841
|
+
async def get_free_credits(
|
842
|
+
self, account_address: Optional[str] = None, seed_phrase: Optional[str] = None
|
843
|
+
) -> float:
|
823
844
|
"""
|
824
845
|
Get the free credits available for an account in the marketplace.
|
825
846
|
|
826
847
|
Args:
|
827
848
|
account_address: Substrate account address (uses keypair address if not specified)
|
828
849
|
Format: 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
850
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
829
851
|
|
830
852
|
Returns:
|
831
853
|
float: Free credits amount (with 18 decimal places)
|
@@ -836,7 +858,9 @@ class SubstrateClient:
|
|
836
858
|
"""
|
837
859
|
try:
|
838
860
|
# Initialize Substrate connection and get account address
|
839
|
-
substrate, derived_address = initialize_substrate_connection(
|
861
|
+
substrate, derived_address = initialize_substrate_connection(
|
862
|
+
self, seed_phrase
|
863
|
+
)
|
840
864
|
|
841
865
|
# Use provided account address or the one derived from initialization
|
842
866
|
if not account_address:
|
@@ -871,13 +895,16 @@ class SubstrateClient:
|
|
871
895
|
print(error_msg)
|
872
896
|
raise ValueError(error_msg)
|
873
897
|
|
874
|
-
def get_user_file_hashes(
|
898
|
+
def get_user_file_hashes(
|
899
|
+
self, account_address: Optional[str] = None, seed_phrase: Optional[str] = None
|
900
|
+
) -> List[str]:
|
875
901
|
"""
|
876
902
|
Get all file hashes (CIDs) stored by a user in the marketplace.
|
877
903
|
|
878
904
|
Args:
|
879
905
|
account_address: Substrate account address (uses keypair address if not specified)
|
880
906
|
Format: 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
907
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
881
908
|
|
882
909
|
Returns:
|
883
910
|
List[str]: List of CIDs stored by the user
|
@@ -888,7 +915,9 @@ class SubstrateClient:
|
|
888
915
|
"""
|
889
916
|
try:
|
890
917
|
# Initialize Substrate connection and get account address
|
891
|
-
substrate, derived_address = initialize_substrate_connection(
|
918
|
+
substrate, derived_address = initialize_substrate_connection(
|
919
|
+
self, seed_phrase
|
920
|
+
)
|
892
921
|
|
893
922
|
# Use provided account address or the one derived from initialization
|
894
923
|
if not account_address:
|
@@ -920,6 +949,7 @@ class SubstrateClient:
|
|
920
949
|
account_address: Optional[str] = None,
|
921
950
|
truncate_miners: bool = True,
|
922
951
|
max_miners: int = 3,
|
952
|
+
seed_phrase: Optional[str] = None,
|
923
953
|
) -> List[Dict[str, Any]]:
|
924
954
|
"""
|
925
955
|
Get detailed information about all files stored by a user in the marketplace.
|
@@ -931,6 +961,7 @@ class SubstrateClient:
|
|
931
961
|
Format: 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
932
962
|
truncate_miners: Whether to truncate long miner IDs for display (default: True)
|
933
963
|
max_miners: Maximum number of miners to include in the response (default: 3, 0 for all)
|
964
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
934
965
|
|
935
966
|
Returns:
|
936
967
|
List[Dict[str, Any]]: List of file objects with the following structure:
|
@@ -949,11 +980,12 @@ class SubstrateClient:
|
|
949
980
|
"""
|
950
981
|
# For backward compatibility, this method now calls get_user_files_from_profile
|
951
982
|
# with appropriate conversions
|
952
|
-
return await self.get_user_files_from_profile(account_address)
|
983
|
+
return await self.get_user_files_from_profile(account_address, seed_phrase)
|
953
984
|
|
954
985
|
async def get_user_files_from_profile(
|
955
986
|
self,
|
956
987
|
account_address: Optional[str] = None,
|
988
|
+
seed_phrase: Optional[str] = None,
|
957
989
|
) -> List[Dict[str, Any]]:
|
958
990
|
"""
|
959
991
|
Get user files by fetching the user profile CID from ipfsPallet and then retrieving
|
@@ -962,6 +994,7 @@ class SubstrateClient:
|
|
962
994
|
Args:
|
963
995
|
account_address: Substrate account address (uses keypair address if not specified)
|
964
996
|
Format: 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
997
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
965
998
|
|
966
999
|
Returns:
|
967
1000
|
List[Dict[str, Any]]: List of file objects from the user profile
|
@@ -972,7 +1005,9 @@ class SubstrateClient:
|
|
972
1005
|
"""
|
973
1006
|
try:
|
974
1007
|
# Initialize Substrate connection and get account address
|
975
|
-
substrate, derived_address = initialize_substrate_connection(
|
1008
|
+
substrate, derived_address = initialize_substrate_connection(
|
1009
|
+
self, seed_phrase
|
1010
|
+
)
|
976
1011
|
|
977
1012
|
# Use provided account address or the one derived from initialization
|
978
1013
|
if not account_address:
|
@@ -1055,7 +1090,7 @@ class SubstrateClient:
|
|
1055
1090
|
raise ValueError(f"Error retrieving user files from profile: {str(e)}")
|
1056
1091
|
|
1057
1092
|
def get_pinning_status(
|
1058
|
-
self, account_address: Optional[str] = None
|
1093
|
+
self, account_address: Optional[str] = None, seed_phrase: Optional[str] = None
|
1059
1094
|
) -> List[Dict[str, Any]]:
|
1060
1095
|
"""
|
1061
1096
|
Get the status of file pinning requests for an account.
|
@@ -1066,6 +1101,7 @@ class SubstrateClient:
|
|
1066
1101
|
Args:
|
1067
1102
|
account_address: Substrate account address (uses keypair address if not specified)
|
1068
1103
|
Format: 5HoreGVb17XhY3wanDvzoAWS7yHYbc5uMteXqRNTiZ6Txkqq
|
1104
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
1069
1105
|
|
1070
1106
|
Returns:
|
1071
1107
|
List[Dict[str, Any]]: List of storage requests with their status information:
|
@@ -1086,7 +1122,7 @@ class SubstrateClient:
|
|
1086
1122
|
ValueError: If query fails or no requests found
|
1087
1123
|
"""
|
1088
1124
|
# Initialize Substrate connection and get account address
|
1089
|
-
substrate, derived_address = initialize_substrate_connection(self)
|
1125
|
+
substrate, derived_address = initialize_substrate_connection(self, seed_phrase)
|
1090
1126
|
|
1091
1127
|
# Use provided account address or the one derived from initialization
|
1092
1128
|
if not account_address:
|
@@ -1140,21 +1176,24 @@ class SubstrateClient:
|
|
1140
1176
|
"""
|
1141
1177
|
return hex_to_ipfs_cid(hex_string)
|
1142
1178
|
|
1143
|
-
async def check_storage_request_exists(
|
1179
|
+
async def check_storage_request_exists(
|
1180
|
+
self, cid: str, seed_phrase: Optional[str] = None
|
1181
|
+
) -> bool:
|
1144
1182
|
"""
|
1145
1183
|
Check if a storage request exists for the given CID in the user's storage requests.
|
1146
1184
|
|
1147
1185
|
Args:
|
1148
1186
|
cid: Content Identifier (CID) to check
|
1187
|
+
seed_phrase: Optional seed phrase to use for this operation (uses config if None)
|
1149
1188
|
|
1150
1189
|
Returns:
|
1151
1190
|
bool: True if the CID exists in the user's storage requests, False otherwise
|
1152
1191
|
"""
|
1153
|
-
substrate, derived_address = initialize_substrate_connection(self)
|
1192
|
+
substrate, derived_address = initialize_substrate_connection(self, seed_phrase)
|
1154
1193
|
|
1155
1194
|
if not derived_address:
|
1156
1195
|
# If we don't have a derived address, try to get the keypair
|
1157
|
-
if not self._ensure_keypair():
|
1196
|
+
if not self._ensure_keypair(seed_phrase):
|
1158
1197
|
raise ValueError("No account address available")
|
1159
1198
|
derived_address = self._keypair.ss58_address
|
1160
1199
|
|
@@ -1184,12 +1223,15 @@ class SubstrateClient:
|
|
1184
1223
|
# If we encounter an error checking, we'll assume it exists to be safe
|
1185
1224
|
return True
|
1186
1225
|
|
1187
|
-
async def cancel_storage_request(
|
1226
|
+
async def cancel_storage_request(
|
1227
|
+
self, cid: str, seed_phrase: Optional[str] = None
|
1228
|
+
) -> str:
|
1188
1229
|
"""
|
1189
1230
|
Cancel a storage request by CID from the Hippius blockchain.
|
1190
1231
|
|
1191
1232
|
Args:
|
1192
1233
|
cid: Content Identifier (CID) of the file to cancel
|
1234
|
+
seed_phrase: Optional seed phrase to use for this transaction (uses config if None)
|
1193
1235
|
|
1194
1236
|
Returns:
|
1195
1237
|
str: Transaction hash or status message
|
@@ -1212,12 +1254,14 @@ class SubstrateClient:
|
|
1212
1254
|
raise
|
1213
1255
|
|
1214
1256
|
# Continue with cancellation if it exists
|
1215
|
-
if not self._ensure_keypair():
|
1257
|
+
if not self._ensure_keypair(seed_phrase):
|
1216
1258
|
raise HippiusSubstrateAuthError(
|
1217
|
-
"
|
1259
|
+
"Valid seed phrase must be provided or available in config"
|
1218
1260
|
)
|
1219
1261
|
|
1220
|
-
|
1262
|
+
# Initialize Substrate connection with seed phrase if needed
|
1263
|
+
if not self._substrate:
|
1264
|
+
self.connect(seed_phrase)
|
1221
1265
|
|
1222
1266
|
call = self._substrate.compose_call(
|
1223
1267
|
call_module="Marketplace",
|
hippius_sdk/utils.py
CHANGED
@@ -193,6 +193,7 @@ def generate_key() -> str:
|
|
193
193
|
|
194
194
|
def initialize_substrate_connection(
|
195
195
|
self_obj: Any,
|
196
|
+
seed_phrase: Optional[str] = None,
|
196
197
|
) -> Tuple[SubstrateInterface, Optional[str]]:
|
197
198
|
"""
|
198
199
|
Initialize a Substrate connection if not already connected and set up the account.
|
@@ -201,6 +202,7 @@ def initialize_substrate_connection(
|
|
201
202
|
|
202
203
|
Args:
|
203
204
|
self_obj: The object (usually SubstrateClient instance) with required attributes
|
205
|
+
seed_phrase: Optional seed phrase to use for the connection
|
204
206
|
|
205
207
|
Returns:
|
206
208
|
Tuple[SubstrateInterface, Optional[str]]: A tuple containing the Substrate interface
|
@@ -216,19 +218,23 @@ def initialize_substrate_connection(
|
|
216
218
|
)
|
217
219
|
print(f"Connected to Substrate node at {self_obj.url}")
|
218
220
|
|
219
|
-
# Use provided account address or
|
221
|
+
# Use provided account address or create keypair from seed_phrase
|
220
222
|
account_address = None
|
221
|
-
if hasattr(self_obj, "_account_address") and self_obj._account_address:
|
222
|
-
account_address = self_obj._account_address
|
223
223
|
|
224
|
-
|
225
|
-
# Try to get the address from the keypair (
|
226
|
-
if not self_obj._ensure_keypair():
|
227
|
-
#
|
228
|
-
|
224
|
+
if hasattr(self_obj, "_ensure_keypair") and callable(self_obj._ensure_keypair):
|
225
|
+
# Try to get the address from the keypair (using seed_phrase if provided)
|
226
|
+
if not self_obj._ensure_keypair(seed_phrase):
|
227
|
+
# If we have an account address already, use that
|
228
|
+
if hasattr(self_obj, "_account_address") and self_obj._account_address:
|
229
|
+
account_address = self_obj._account_address
|
230
|
+
else:
|
231
|
+
# No keypair or address available
|
232
|
+
return self_obj._substrate, None
|
229
233
|
|
230
234
|
if hasattr(self_obj, "_keypair") and self_obj._keypair:
|
231
235
|
account_address = self_obj._keypair.ss58_address
|
232
236
|
print(f"Using keypair address: {account_address}")
|
237
|
+
elif hasattr(self_obj, "_account_address") and self_obj._account_address:
|
238
|
+
account_address = self_obj._account_address
|
233
239
|
|
234
240
|
return self_obj._substrate, account_address
|
hippius-0.2.9.dist-info/RECORD
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
hippius_sdk/__init__.py,sha256=fqaCct4J_4JlfpFmTtc2TrG3fqQaiDU9Yl4tsgvqcBI,1391
|
2
|
-
hippius_sdk/cli.py,sha256=pzwoa-X5cwdA_pM-fqUyXZKHgcZODrLe4qHZuCqQMtQ,18210
|
3
|
-
hippius_sdk/cli_assets.py,sha256=V3MX63QTiex6mCp0VDXQJ7cagm5v1s4xtsu8c1O4G_k,371
|
4
|
-
hippius_sdk/cli_handlers.py,sha256=LUS-BPPMfvXCLsHiN225nMTlBEHXKxZmUf1YpC-Xyqc,127905
|
5
|
-
hippius_sdk/cli_parser.py,sha256=Qh2wgkFBUTPldvGoTQuoNKQl5Vo0x6fPEsPBU5oymP4,20242
|
6
|
-
hippius_sdk/cli_rich.py,sha256=_jTBYMdHi2--fIVwoeNi-EtkdOb6Zy_O2TUiGvU3O7s,7324
|
7
|
-
hippius_sdk/client.py,sha256=eYURsq_so3WlEt_JY_u7J0iECFVOKDf5vsnGyR9Kngw,16974
|
8
|
-
hippius_sdk/config.py,sha256=sCWD2remLa-FodvxC2O45tiNSJD7gzv9idIStX9sF_k,21240
|
9
|
-
hippius_sdk/errors.py,sha256=LScJJmawVAx7aRzqqQguYSkf9iazSjEQEBNlD_GXZ6Y,1589
|
10
|
-
hippius_sdk/ipfs.py,sha256=xq0y87dyKvbwf52OjEAlqFNrl4Ej1Zp5g2rZa75qfN8,71706
|
11
|
-
hippius_sdk/ipfs_core.py,sha256=Dzfmty7SzHW1GNjjLpp9u0JSf0f2g2FB-78nDtTUt3I,12820
|
12
|
-
hippius_sdk/substrate.py,sha256=HqR2-_9njZZ5UCKgiaGr5L5TGQ_wtj7oyA3sA5sGGyE,47525
|
13
|
-
hippius_sdk/utils.py,sha256=Ur7P_7iVnXXYvbg7a0aVrdN_8NkVxjhdngn8NzR_zpc,7066
|
14
|
-
hippius-0.2.9.dist-info/METADATA,sha256=Br0pN49dYq3fhG3bjl5lVj-yOjPAHM1pFk7PGxF7wYk,29992
|
15
|
-
hippius-0.2.9.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
16
|
-
hippius-0.2.9.dist-info/entry_points.txt,sha256=b1lo60zRXmv1ud-c5BC-cJcAfGE5FD4qM_nia6XeQtM,98
|
17
|
-
hippius-0.2.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|