Skip to content

Commit

Permalink
Update SDKs with the new transaction format
Browse files Browse the repository at this point in the history
  • Loading branch information
flopez7 committed Oct 21, 2024
1 parent c89cf66 commit 8d48b54
Show file tree
Hide file tree
Showing 78 changed files with 453 additions and 764 deletions.
4 changes: 1 addition & 3 deletions docs/sdk/python/human_protocol_sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
* [human_protocol_sdk.staking.staking_client module](human_protocol_sdk.staking.staking_client.md)
* [Code Example](human_protocol_sdk.staking.staking_client.md#code-example)
* [Module](human_protocol_sdk.staking.staking_client.md#module)
* [`AllocationData`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.AllocationData)
* [`StakingClient`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient)
* [`StakingClientError`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClientError)
* [human_protocol_sdk.statistics package](human_protocol_sdk.statistics.md)
Expand Down Expand Up @@ -111,10 +110,10 @@
* [human_protocol_sdk.transaction.transaction_utils module](human_protocol_sdk.transaction.transaction_utils.md)
* [Code Example](human_protocol_sdk.transaction.transaction_utils.md#code-example)
* [Module](human_protocol_sdk.transaction.transaction_utils.md#module)
* [`InternalTransaction`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.InternalTransaction)
* [`TransactionData`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionData)
* [`TransactionUtils`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils)
* [`TransactionUtilsError`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtilsError)
* [`Transfer`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.Transfer)

## Submodules

Expand Down Expand Up @@ -195,7 +194,6 @@
* [`get_factory_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_factory_interface)
* [`get_hmt_balance()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_hmt_balance)
* [`get_kvstore_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_kvstore_interface)
* [`get_reward_pool_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_reward_pool_interface)
* [`get_staking_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_staking_interface)
* [`handle_transaction()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.handle_transaction)
* [`parse_transfer_transaction()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.parse_transfer_transaction)
Expand Down
6 changes: 0 additions & 6 deletions docs/sdk/python/human_protocol_sdk.staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ obtain staking information from both the contracts and subgraph.
* [human_protocol_sdk.staking.staking_client module](human_protocol_sdk.staking.staking_client.md)
* [Code Example](human_protocol_sdk.staking.staking_client.md#code-example)
* [Module](human_protocol_sdk.staking.staking_client.md#module)
* [`AllocationData`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.AllocationData)
* [`AllocationData.__init__()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.AllocationData.__init__)
* [`StakingClient`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient)
* [`StakingClient.__init__()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.__init__)
* [`StakingClient.allocate()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.allocate)
* [`StakingClient.approve_stake()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.approve_stake)
* [`StakingClient.close_allocation()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.close_allocation)
* [`StakingClient.distribute_reward()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.distribute_reward)
* [`StakingClient.get_allocation()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.get_allocation)
* [`StakingClient.slash()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.slash)
* [`StakingClient.stake()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.stake)
* [`StakingClient.unstake()`](human_protocol_sdk.staking.staking_client.md#human_protocol_sdk.staking.staking_client.StakingClient.unstake)
Expand Down
160 changes: 0 additions & 160 deletions docs/sdk/python/human_protocol_sdk.staking.staking_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ staking_client = StakingClient(w3)

## Module

### *class* human_protocol_sdk.staking.staking_client.AllocationData(escrow_address, staker, tokens, created_at, closed_at)

Bases: `object`

#### \_\_init_\_(escrow_address, staker, tokens, created_at, closed_at)

Initializes an AllocationData instance.

* **Parameters:**
* **escrow_address** (`str`) – Escrow address
* **staker** (`str`) – Staker address
* **tokens** (`str`) – Amount allocated
* **created_at** (`str`) – Creation date
* **closed_at** (`str`) – Closing date

### *class* human_protocol_sdk.staking.staking_client.StakingClient(w3)

Bases: `object`
Expand All @@ -76,48 +61,6 @@ Initializes a Staking instance
* **Parameters:**
**w3** (`Web3`) – Web3 instance

#### allocate(escrow_address, amount, tx_options=None)

Allocates HMT token to the escrow.

* **Parameters:**
* **escrow_address** (`str`) – Address of the escrow
* **amount** (`Decimal`) – Amount to allocate
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
* **Return type:**
`None`
* **Returns:**
None
* **Validate:**
- Amount must be greater than 0
- Escrow address must be valid
- Amount must be less than or equal to the staked amount (on-chain)
* **Example:**
```python
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.providers.auto import load_provider_from_uri

from human_protocol_sdk.staking import StakingClient

def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
)
return (w3, gas_payer)

(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
staking_client = StakingClient(w3)

amount = Web3.to_wei(5, 'ether') # convert from ETH to WEI
staking_client.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount)
```

#### approve_stake(amount, tx_options=None)

Approves HMT token for Staking.
Expand Down Expand Up @@ -157,109 +100,6 @@ Approves HMT token for Staking.
staking_client.approve_stake(amount)
```

#### close_allocation(escrow_address, tx_options=None)

Closes allocated HMT token from the escrow.

* **Parameters:**
* **escrow_address** (`str`) – Address of the escrow
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
* **Return type:**
`None`
* **Returns:**
None
* **Validate:**
- Escrow address must be valid
- Escrow should be cancelled / completed (on-chain)
* **Example:**
```python
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.providers.auto import load_provider_from_uri

from human_protocol_sdk.staking import StakingClient

def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
)
return (w3, gas_payer)

(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
staking_client = StakingClient(w3)

staking_client.close_allocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f')
```

#### distribute_reward(escrow_address, tx_options=None)

Pays out rewards to the slashers for the specified escrow address.

* **Parameters:**
* **escrow_address** (`str`) – Address of the escrow
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
* **Return type:**
`None`
* **Returns:**
None
* **Validate:**
- Escrow address must be valid
* **Example:**
```python
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.providers.auto import load_provider_from_uri

from human_protocol_sdk.staking import StakingClient

def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
)
return (w3, gas_payer)

(w3, gas_payer) = get_w3_with_priv_key('YOUR_PRIVATE_KEY')
staking_client = StakingClient(w3)

staking_client.distribute_reward('0x62dD51230A30401C455c8398d06F85e4EaB6309f')
```

#### get_allocation(escrow_address)

Gets the allocation info for the specified escrow.

* **Parameters:**
**escrow_address** (`str`) – Address of the escrow
* **Return type:**
`Optional`[[`AllocationData`](#human_protocol_sdk.staking.staking_client.AllocationData)]
* **Returns:**
Allocation info if escrow exists, otherwise None
* **Example:**
```python
from eth_typing import URI
from web3 import Web3
from web3.providers.auto import load_provider_from_uri

from human_protocol_sdk.staking import StakingClient

w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
staking_client = StakingClient(w3)

allocation = staking_client.get_allocation(
'0x62dD51230A30401C455c8398d06F85e4EaB6309f'
)
```

#### slash(slasher, staker, escrow_address, amount, tx_options=None)

Slashes HMT token.
Expand Down
4 changes: 2 additions & 2 deletions docs/sdk/python/human_protocol_sdk.transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ both the contracts and subgraph.
* [human_protocol_sdk.transaction.transaction_utils module](human_protocol_sdk.transaction.transaction_utils.md)
* [Code Example](human_protocol_sdk.transaction.transaction_utils.md#code-example)
* [Module](human_protocol_sdk.transaction.transaction_utils.md#module)
* [`InternalTransaction`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.InternalTransaction)
* [`InternalTransaction.__init__()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.InternalTransaction.__init__)
* [`TransactionData`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionData)
* [`TransactionData.__init__()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionData.__init__)
* [`TransactionUtils`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils)
* [`TransactionUtils.get_transaction()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils.get_transaction)
* [`TransactionUtils.get_transactions()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils.get_transactions)
* [`TransactionUtilsError`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtilsError)
* [`Transfer`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.Transfer)
* [`Transfer.__init__()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.Transfer.__init__)
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ print(

## Module

### *class* human_protocol_sdk.transaction.transaction_utils.TransactionData(chain_id, block, tx_hash, from_address, to_address, timestamp, value, method, transfers)
### *class* human_protocol_sdk.transaction.transaction_utils.InternalTransaction(from_address, to_address, value, method, receiver, escrow, token)

Bases: `object`

#### \_\_init_\_(chain_id, block, tx_hash, from_address, to_address, timestamp, value, method, transfers)
#### \_\_init_\_(from_address, to_address, value, method, receiver, escrow, token)

### *class* human_protocol_sdk.transaction.transaction_utils.TransactionData(chain_id, block, tx_hash, from_address, to_address, timestamp, value, method, receiver, escrow, token, internal_transactions)

Bases: `object`

#### \_\_init_\_(chain_id, block, tx_hash, from_address, to_address, timestamp, value, method, receiver, escrow, token, internal_transactions)

### *class* human_protocol_sdk.transaction.transaction_utils.TransactionUtils

Expand Down Expand Up @@ -92,9 +98,3 @@ Get an array of transactions based on the specified filter parameters.
Bases: `Exception`

Raises when some error happens when getting data from subgraph.

### *class* human_protocol_sdk.transaction.transaction_utils.Transfer(from_address, to_address, value)

Bases: `object`

#### \_\_init_\_(from_address, to_address, value)
7 changes: 0 additions & 7 deletions docs/sdk/python/human_protocol_sdk.utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ Retrieve the KVStore interface.
* **Returns:**
The KVStore interface of smart contract.

### human_protocol_sdk.utils.get_reward_pool_interface()

Retrieve the RewardPool interface.

* **Returns:**
The RewardPool interface of smart contract.

### human_protocol_sdk.utils.get_staking_interface()

Retrieve the Staking interface.
Expand Down
1 change: 0 additions & 1 deletion docs/sdk/python/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pip install human-protocol-sdk[agreement]
* [`get_factory_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_factory_interface)
* [`get_hmt_balance()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_hmt_balance)
* [`get_kvstore_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_kvstore_interface)
* [`get_reward_pool_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_reward_pool_interface)
* [`get_staking_interface()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.get_staking_interface)
* [`handle_transaction()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.handle_transaction)
* [`parse_transfer_transaction()`](human_protocol_sdk.utils.md#human_protocol_sdk.utils.parse_transfer_transaction)
Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/typescript/base/classes/BaseEthersClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The network information required to connect to the contracts

#### Defined in

[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20)
[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20)

## Properties

Expand All @@ -50,7 +50,7 @@ The network information required to connect to the contracts
#### Defined in

[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12)
[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12)

***

Expand All @@ -60,4 +60,4 @@ The network information required to connect to the contracts
#### Defined in

[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11)
[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11)
10 changes: 5 additions & 5 deletions docs/sdk/typescript/encryption/classes/Encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The private key.

#### Defined in

[encryption.ts:52](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L52)
[encryption.ts:52](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L52)

## Methods

Expand Down Expand Up @@ -117,7 +117,7 @@ const resultMessage = await encription.decrypt('message');

#### Defined in

[encryption.ts:179](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L179)
[encryption.ts:179](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L179)

***

Expand Down Expand Up @@ -153,7 +153,7 @@ const resultMessage = await encription.sign('message');

#### Defined in

[encryption.ts:216](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L216)
[encryption.ts:216](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L216)

***

Expand Down Expand Up @@ -218,7 +218,7 @@ const resultMessage = await encription.signAndEncrypt('message', publicKeys);

#### Defined in

[encryption.ts:128](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L128)
[encryption.ts:128](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L128)

***

Expand Down Expand Up @@ -246,4 +246,4 @@ Optional: The passphrase for the private key.

#### Defined in

[encryption.ts:63](https://github.com/humanprotocol/human-protocol/blob/9ddd51f9c9a3ec97c56d6ffbca5fe9048b9ea0f8/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L63)
[encryption.ts:63](https://github.com/humanprotocol/human-protocol/blob/c89cf662f1f49999499468fbc2c62e830c1f474a/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L63)
Loading

0 comments on commit 8d48b54

Please sign in to comment.