57
57
)
58
58
59
59
60
- PAYMENT_TYPE_NATIVE = "ba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1"
61
- PAYMENT_TYPE_TOKEN = "3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9"
60
+ # false positives for [B105:hardcoded_password_string] Possible hardcoded password
61
+ PAYMENT_TYPE_NATIVE = (
62
+ "ba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1" # nosec
63
+ )
64
+ PAYMENT_TYPE_TOKEN = (
65
+ "3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9" # nosec
66
+ )
62
67
63
68
CHAIN_TO_OLAS = {
64
69
1 : "0x0001A500A6B18995B03f44bb040A5fFc28E45CB0" ,
@@ -98,6 +103,18 @@ def fetch_mech_info(
98
103
mech_marketplace_contract : Web3Contract ,
99
104
priority_mech_service_id : int ,
100
105
) -> Tuple [str , str ]:
106
+ """
107
+ Fetchs the info of the requested mech.
108
+
109
+ :param ledger_api: The Ethereum API used for interacting with the ledger.
110
+ :type ledger_api: EthereumApi
111
+ :param mech_marketplace_contract: The mech marketplace contract instance.
112
+ :type mech_marketplace_contract: Web3Contract
113
+ :param priority_mech_service_id: Service id of the request mech
114
+ :type priority_mech_service_id: int
115
+ :return: The mech info containing payment_type and mech_payment_balance_tracker.
116
+ :rtype: Tuple[str,str]
117
+ """
101
118
priority_mech_address = mech_marketplace_contract .functions .mapServiceIdMech (
102
119
priority_mech_service_id
103
120
).call ()
@@ -135,7 +152,23 @@ def approve_price_tokens(
135
152
olas : str ,
136
153
mech_payment_balance_tracker : str ,
137
154
price : int ,
138
- ):
155
+ ) -> str :
156
+ """
157
+ Sends the approve tx for olas token of the sender to the requested mech's balance payment tracker contract.
158
+
159
+ :param crypto: The Ethereum crypto object.
160
+ :type crypto: EthereumCrypto
161
+ :param ledger_api: The Ethereum API used for interacting with the ledger.
162
+ :type ledger_api: EthereumApi
163
+ :param olas: The olas token contract address.
164
+ :type olas: str
165
+ :param mech_payment_balance_tracker: Requested mech's balance tracker contract address
166
+ :type mech_payment_balance_tracker: str
167
+ :param price: Amount of olas to approve
168
+ :type price: int
169
+ :return: The transaction digest.
170
+ :rtype: str
171
+ """
139
172
sender = crypto .address
140
173
141
174
with open (Path (__file__ ).parent / "abis" / "IToken.json" , encoding = "utf-8" ) as f :
@@ -149,7 +182,7 @@ def approve_price_tokens(
149
182
f" - Sender Token balance low. Needed: { price } , Actual: { user_token_balance } "
150
183
)
151
184
print (f" - Sender Address: { sender } " )
152
- return None
185
+ sys . exit ( 1 )
153
186
154
187
tx_args = {"sender_address" : sender , "value" : 0 , "gas" : 60000 }
155
188
raw_transaction = ledger_api .build_transaction (
@@ -338,7 +371,7 @@ async def _wait_for_tasks() -> Any: # type: ignore
338
371
return result
339
372
340
373
341
- def marketplace_interact ( # pylint: disable=too-many-arguments, too-many-locals
374
+ def marketplace_interact ( # pylint: disable=too-many-arguments, too-many-locals, too-many-statements
342
375
prompt : str ,
343
376
tool : Optional [str ] = None ,
344
377
extra_attributes : Optional [Dict [str , Any ]] = None ,
@@ -430,10 +463,13 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
430
463
)
431
464
432
465
print ("Fetching Mech Info..." )
466
+ priority_mech_service_id = cast (
467
+ int , mech_marketplace_config .priority_mech_service_id
468
+ )
433
469
(payment_type , mech_payment_balance_tracker ) = fetch_mech_info (
434
470
ledger_api ,
435
471
mech_marketplace_contract ,
436
- mech_marketplace_config . priority_mech_service_id ,
472
+ priority_mech_service_id ,
437
473
)
438
474
439
475
price = mech_config .price or 10_000_000_000_000_000
0 commit comments