Skip to content

Commit 6d1a427

Browse files
authored
[SDK] Fix SDK docs (#3012)
* fix and sync python sdk docs * fix documentation and comments for ts sdk * update ts docs * Add force_complete to create_bulk_payout_transaction * Fix pyhton tests * use txid parameter in SDK and fix tests * add txid to payout
1 parent 2eeb21b commit 6d1a427

File tree

108 files changed

+1054
-956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1054
-956
lines changed

docs/sdk/python/human_protocol_sdk.encryption.encryption.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# human_protocol_sdk.encryption.encryption module
22

3-
This class allows to sign, verify, encrypt and
4-
decrypt messages at all levels of escrow processing.
3+
This class allows signing, verifying, encrypting, and
4+
decrypting messages at all levels of escrow processing.
55

66
The algorithm includes the implementation of the
77
[PGP encryption algorithm]([https://github.com/openpgpjs/openpgpjs](https://github.com/openpgpjs/openpgpjs))
8-
multi-public key encryption on python.
8+
multi-public key encryption in Python.
99
Using the vanilla [ed25519]([https://en.wikipedia.org/wiki/EdDSA#Ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519))
1010
implementation Schnorr signatures for signature and
1111
[curve25519]([https://en.wikipedia.org/wiki/Curve25519](https://en.wikipedia.org/wiki/Curve25519)) for encryption.

docs/sdk/python/human_protocol_sdk.escrow.escrow_client.md

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Represents the result of an escrow cancellation transaction.
6464

6565
Bases: `object`
6666

67-
A class used to manage escrow on the HUMAN network.
67+
A client class to interact with the escrow smart contract.
6868

6969
#### \_\_init_\_(web3)
7070

@@ -127,7 +127,7 @@ Pays out the amounts specified to the workers and sets the URL of the final resu
127127
* **escrow_address** (`str`) – Address of the escrow
128128
* **recipients** (`List`[`str`]) – Array of recipient addresses
129129
* **amounts** (`List`[`Decimal`]) – Array of amounts the recipients will receive
130-
* **final_results_url** (`str`) – Final results file url
130+
* **final_results_url** (`str`) – Final results file URL
131131
* **final_results_hash** (`str`) – Final results file hash
132132
* **txId** (`Decimal`) – Serial number of the bulks
133133
* **force_complete** (`Optional`[`bool`]) – (Optional) Indicates if remaining balance should be transferred to the escrow creator
@@ -148,8 +148,7 @@ Pays out the amounts specified to the workers and sets the URL of the final resu
148148
from human_protocol_sdk.escrow import EscrowClient
149149

150150
def get_w3_with_priv_key(priv_key: str):
151-
w3 = Web3(load_provider_from_uri(
152-
URI("http://localhost:8545")))
151+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
153152
gas_payer = w3.eth.account.from_key(priv_key)
154153
w3.eth.default_account = gas_payer.address
155154
w3.middleware_onion.add(
@@ -249,8 +248,7 @@ Sets the status of an escrow to completed.
249248
from human_protocol_sdk.escrow import EscrowClient
250249

251250
def get_w3_with_priv_key(priv_key: str):
252-
w3 = Web3(load_provider_from_uri(
253-
URI("http://localhost:8545")))
251+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
254252
gas_payer = w3.eth.account.from_key(priv_key)
255253
w3.eth.default_account = gas_payer.address
256254
w3.middleware_onion.add(
@@ -265,15 +263,15 @@ Sets the status of an escrow to completed.
265263
escrow_client.complete("0x62dD51230A30401C455c8398d06F85e4EaB6309f")
266264
```
267265

268-
#### create_bulk_payout_transaction(escrow_address, recipients, amounts, final_results_url, final_results_hash, txId, tx_options=None)
266+
#### create_bulk_payout_transaction(escrow_address, recipients, amounts, final_results_url, final_results_hash, txId, force_complete=False, tx_options=None)
269267

270268
Creates a prepared transaction for bulk payout without signing or sending it.
271269

272270
* **Parameters:**
273271
* **escrow_address** (`str`) – Address of the escrow
274272
* **recipients** (`List`[`str`]) – Array of recipient addresses
275273
* **amounts** (`List`[`Decimal`]) – Array of amounts the recipients will receive
276-
* **final_results_url** (`str`) – Final results file url
274+
* **final_results_url** (`str`) – Final results file URL
277275
* **final_results_hash** (`str`) – Final results file hash
278276
* **txId** (`Decimal`) – Serial number of the bulks
279277
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
@@ -293,8 +291,7 @@ Creates a prepared transaction for bulk payout without signing or sending it.
293291
from human_protocol_sdk.escrow import EscrowClient
294292

295293
def get_w3_with_priv_key(priv_key: str):
296-
w3 = Web3(load_provider_from_uri(
297-
URI("http://localhost:8545")))
294+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
298295
gas_payer = w3.eth.account.from_key(priv_key)
299296
w3.eth.default_account = gas_payer.address
300297
w3.middleware_onion.add(
@@ -323,35 +320,36 @@ Creates a prepared transaction for bulk payout without signing or sending it.
323320
amounts,
324321
results_url,
325322
results_hash,
326-
1
323+
1,
324+
false
327325
)
328326

329327
print(f"Transaction: {transaction}")
330328

331329
signed_transaction = w3.eth.account.sign_transaction(
332-
transaction, private_key)
330+
transaction, private_key
331+
)
333332
tx_hash = w3.eth.send_raw_transaction(
334-
signed_transaction.raw_transaction)
333+
signed_transaction.raw_transaction
334+
)
335335
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
336336
print(f"Transaction sent with hash: {tx_hash.hex()}")
337337
print(f"Transaction receipt: {tx_receipt}")
338338
```
339339

340340
#### create_escrow(token_address, trusted_handlers, job_requester_id, tx_options=None)
341341

342-
Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
342+
Creates a new escrow contract.
343343

344344
* **Parameters:**
345-
* **tokenAddress** – The address of the token to use for payouts
346-
* **trusted_handlers** (`List`[`str`]) – Array of addresses that can perform actions on the contract
347-
* **job_requester_id** (`str`) – The id of the job requester
348-
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
345+
* **token_address** (`str`) – Address of the token to be used in the escrow
346+
* **trusted_handlers** (`List`[`str`]) – List of trusted handler addresses
347+
* **job_requester_id** (`str`) – ID of the job requester
348+
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Transaction options
349349
* **Return type:**
350350
`str`
351351
* **Returns:**
352-
The address of the escrow created
353-
* **Raises:**
354-
[**EscrowClientError**](#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an error occurs while checking the parameters
352+
Address of the created escrow contract
355353
* **Example:**
356354
```python
357355
from eth_typing import URI
@@ -375,10 +373,10 @@ Creates an escrow contract that uses the token passed to pay oracle fees and rew
375373
(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
376374
escrow_client = EscrowClient(w3)
377375

378-
token_address = '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4'
376+
token_address = '0x1234567890abcdef1234567890abcdef12345678'
379377
trusted_handlers = [
380-
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
381-
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
378+
'0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
379+
'0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef'
382380
]
383381
job_requester_id = 'job-requester'
384382
escrow_address = escrow_client.create_escrow(
@@ -396,7 +394,7 @@ Validates input parameters for bulk payout operations.
396394
* **escrow_address** (`str`) – Address of the escrow
397395
* **recipients** (`List`[`str`]) – Array of recipient addresses
398396
* **amounts** (`List`[`Decimal`]) – Array of amounts the recipients will receive
399-
* **final_results_url** (`str`) – Final results file url
397+
* **final_results_url** (`str`) – Final results file URL
400398
* **final_results_hash** (`str`) – Final results file hash
401399
* **Return type:**
402400
`None`
@@ -410,7 +408,7 @@ Validates input parameters for bulk payout operations.
410408
Adds funds to the escrow.
411409

412410
* **Parameters:**
413-
* **escrow_address** (`str`) – Address of the escrow to setup
411+
* **escrow_address** (`str`) – Address of the escrow to fund
414412
* **amount** (`Decimal`) – Amount to be added as funds
415413
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
416414
* **Return type:**
@@ -429,8 +427,7 @@ Adds funds to the escrow.
429427
from human_protocol_sdk.escrow import EscrowClient
430428

431429
def get_w3_with_priv_key(priv_key: str):
432-
w3 = Web3(load_provider_from_uri(
433-
URI("http://localhost:8545")))
430+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
434431
gas_payer = w3.eth.account.from_key(priv_key)
435432
w3.eth.default_account = gas_payer.address
436433
w3.middleware_onion.add(
@@ -442,9 +439,10 @@ Adds funds to the escrow.
442439
(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
443440
escrow_client = EscrowClient(w3)
444441

445-
amount = Web3.to_wei(5, 'ether') # convert from ETH to WEI
442+
amount = Web3.to_wei(5, 'ether') # convert from ETH to WEI
446443
escrow_client.fund(
447-
"0x62dD51230A30401C455c8398d06F85e4EaB6309f", amount)
444+
"0x62dD51230A30401C455c8398d06F85e4EaB6309f", amount
445+
)
448446
```
449447

450448
#### get_balance(escrow_address)
@@ -788,15 +786,9 @@ Gets the address of the token used to fund the escrow.
788786
Sets up the parameters of the escrow.
789787

790788
* **Parameters:**
791-
* **escrow_address** (`str`) – Address of the escrow to setup
792-
* **escrow_config** ([`EscrowConfig`](#human_protocol_sdk.escrow.escrow_client.EscrowConfig)) – Object containing all the necessary information to setup an escrow
793-
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
794-
* **Return type:**
795-
`None`
796-
* **Returns:**
797-
None
798-
* **Raises:**
799-
[**EscrowClientError**](#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an error occurs while checking the parameters
789+
* **escrow_address** (`str`) – Address of the escrow contract
790+
* **escrow_config** ([`EscrowConfig`](#human_protocol_sdk.escrow.escrow_client.EscrowConfig)) – Configuration parameters for the escrow
791+
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Transaction options
800792
* **Example:**
801793
```python
802794
from eth_typing import URI
@@ -820,27 +812,35 @@ Sets up the parameters of the escrow.
820812
(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
821813
escrow_client = EscrowClient(w3)
822814

823-
escrow_address = "0x62dD51230A30401C455c8398d06F85e4EaB6309f"
815+
escrow_address = "0x1234567890abcdef1234567890abcdef12345678"
824816
escrow_config = EscrowConfig(
825-
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
826-
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
827-
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
828-
10,
829-
10,
830-
10,
831-
"htttp://localhost/manifest.json",
832-
"b5dad76bf6772c0f07fd5e048f6e75a5f86ee079",
817+
recording_oracle_address='0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
818+
reputation_oracle_address='0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
819+
exchange_oracle_address='0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
820+
recording_oracle_fee=100,
821+
reputation_oracle_fee=100,
822+
exchange_oracle_fee=100,
823+
recording_oracle_url='https://example.com/recording',
824+
reputation_oracle_url='https://example.com/reputation',
825+
exchange_oracle_url='https://example.com/exchange',
826+
manifest_url='https://example.com/manifest',
827+
manifest_hash='0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef'
828+
)
829+
escrow_client.setup(
830+
escrow_address,
831+
escrow_config
833832
)
834-
escrow_client.setup(escrow_address, escrow_config)
835833
```
834+
* **Return type:**
835+
`None`
836836

837837
#### store_results(escrow_address, url, hash, tx_options=None)
838838

839-
Stores the results url.
839+
Stores the results URL.
840840

841841
* **Parameters:**
842842
* **escrow_address** (`str`) – Address of the escrow
843-
* **url** (`str`) – Results file url
843+
* **url** (`str`) – Results file URL
844844
* **hash** (`str`) – Results file hash
845845
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
846846
* **Return type:**
@@ -859,8 +859,7 @@ Stores the results url.
859859
from human_protocol_sdk.escrow import EscrowClient
860860

861861
def get_w3_with_priv_key(priv_key: str):
862-
w3 = Web3(load_provider_from_uri(
863-
URI("http://localhost:8545")))
862+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
864863
gas_payer = w3.eth.account.from_key(priv_key)
865864
w3.eth.default_account = gas_payer.address
866865
w3.middleware_onion.add(

docs/sdk/python/human_protocol_sdk.escrow.escrow_utils.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Utility class for escrow-related operations.
66

77
```python
88
from human_protocol_sdk.constants import ChainId
9-
from human_protocol_sdk.escrow import EscrowUtils, EscorwFilter, Status
9+
from human_protocol_sdk.escrow import EscrowUtils, EscrowFilter, Status
1010

1111
print(
1212
EscrowUtils.get_escrows(
@@ -133,7 +133,7 @@ Retrieve status events for specified networks and statuses within a date range.
133133

134134
print(
135135
EscrowUtils.get_status_events(
136-
networks=[ChainId.POLYGON_AMOY, ChainId.ETHEREUM],
136+
chain_id=ChainId.POLYGON_AMOY,
137137
statuses=[Status.Pending, Status.Paid],
138138
date_from=datetime(2023, 1, 1),
139139
date_to=datetime(2023, 12, 31),

docs/sdk/python/human_protocol_sdk.filter.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,33 @@ Initializes a PayoutFilter instance.
4646
* **date_from** (`Optional`[`datetime`]) – Created from date
4747
* **date_to** (`Optional`[`datetime`]) – Created to date
4848

49-
### *class* human_protocol_sdk.filter.StatisticsFilter(date_from=None, date_to=None, first=10, skip=0, order_direction=OrderDirection.ASC)
49+
### *class* human_protocol_sdk.filter.StatisticsFilter(date_from=None, date_to=None, first=10, skip=0, order_direction=OrderDirection.DESC)
5050

5151
Bases: `object`
5252

53-
A class used to filter statistics requests.
54-
55-
#### \_\_init_\_(date_from=None, date_to=None, first=10, skip=0, order_direction=OrderDirection.ASC)
56-
57-
Initializes a StatisticsFilter instance.
53+
A class used to filter statistical data.
5854

5955
* **Parameters:**
60-
* **date_from** (`Optional`[`datetime`]) – Created from date
61-
* **date_to** (`Optional`[`datetime`]) – Created to date
62-
* **first** (`int`) – Number of items per page
63-
* **skip** (`int`) – Page number to retrieve
64-
* **order_direction** ([`OrderDirection`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.OrderDirection)) – Order of results, “asc” or “desc”
56+
* **date_from** (`Optional`[`datetime`]) – Start date for the query range.
57+
* **date_to** (`Optional`[`datetime`]) – End date for the query range.
58+
* **first** (`int`) – Number of items per page.
59+
* **skip** (`int`) – Page number to retrieve.
60+
* **order_direction** ([`OrderDirection`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.OrderDirection)) – Order of results, “asc” or “desc”.
61+
* **Example:**
62+
```python
63+
from datetime import datetime
64+
from human_protocol_sdk.filter import StatisticsFilter
65+
66+
filter = StatisticsFilter(
67+
date_from=datetime(2023, 1, 1),
68+
date_to=datetime(2023, 12, 31),
69+
first=10,
70+
skip=0,
71+
order_direction=OrderDirection.DESC
72+
)
73+
```
74+
75+
#### \_\_init_\_(date_from=None, date_to=None, first=10, skip=0, order_direction=OrderDirection.DESC)
6576

6677
### *class* human_protocol_sdk.filter.TransactionFilter(chain_id, from_address=None, to_address=None, start_date=None, end_date=None, start_block=None, end_block=None, first=10, skip=0, order_direction=OrderDirection.DESC)
6778

docs/sdk/python/human_protocol_sdk.kvstore.kvstore_client.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# human_protocol_sdk.kvstore.kvstore_client module
22

3-
This client enables to perform actions on KVStore contract and
4-
obtain information from both the contracts and subgraph.
3+
This client enables performing actions on the KVStore contract and
4+
obtaining information from both the contracts and subgraph.
55

66
Internally, the SDK will use one network or another according to the network ID of the web3.
7-
To use this client, you need to create Web3 instance, and configure default account,
7+
To use this client, you need to create a Web3 instance and configure the default account,
88
as well as some middlewares.
99

1010
## Code Example
@@ -59,7 +59,8 @@ A class used to manage kvstore on the HUMAN network.
5959
Initializes a KVStore instance.
6060

6161
* **Parameters:**
62-
**web3** (`Web3`) – The Web3 object
62+
* **web3** (`Web3`) – The Web3 object
63+
* **gas_limit** (`Optional`[`int`]) – (Optional) Gas limit for transactions
6364

6465
#### set(key, value, tx_options=None)
6566

@@ -131,8 +132,8 @@ Sets multiple key-value pairs in the contract.
131132
(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
132133
kvstore_client = KVStoreClient(w3)
133134

134-
keys = ['Role', 'Webhook_url'];
135-
values = ['RecordingOracle', 'http://localhost'];
135+
keys = ['Role', 'Webhook_url']
136+
values = ['RecordingOracle', 'http://localhost']
136137
kvstore_client.set_bulk(keys, values)
137138
```
138139

docs/sdk/python/human_protocol_sdk.kvstore.kvstore_utils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from human_protocol_sdk.constants import ChainId
99
from human_protocol_sdk.kvstore import KVStoreUtils
1010

1111
print(
12-
KVStoreUtils.get_data(
12+
KVStoreUtils.get_kvstore_data(
1313
ChainId.POLYGON_AMOY,
1414
"0x15d34aaf54267db7d7c367839aaf71a00a2c6a65"
1515
)

0 commit comments

Comments
 (0)