Skip to content

Commit 45b9ea3

Browse files
authored
Merge pull request #68 from singnet/development
Release 3.5.0
2 parents 847ff18 + a9ab0d0 commit 45b9ea3

68 files changed

Lines changed: 6507 additions & 168 deletions

Some content is hidden

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

README.md

Lines changed: 210 additions & 57 deletions
Large diffs are not rendered by default.

docs/main/account.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
## module: sdk.account
2+
3+
[Link](https://github.com/singnet/snet-sdk-python/blob/master/snet/sdk/account.py) to GitHub
4+
5+
Entities:
6+
1. [TransactionError](#class-transactionerror)
7+
- [\_\_init\_\_](#__init__)
8+
- [\_\_str\_\_](#__str__)
9+
2. [Account](#class-account)
10+
- [\_\_init\_\_](#__init__-1)
11+
- [_get_nonce](#_get_nonce)
12+
- [_get_gas_price](#_get_gas_price)
13+
- [_send_signed_transaction](#_send_signed_transaction)
14+
- [send_transaction](#send_transaction)
15+
- [_parse_receipt](#_parse_receipt)
16+
- [escrow_balance](#escrow_balance)
17+
- [deposit_to_escrow_account](#deposit_to_escrow_account)
18+
- [approve_transfer](#approve_transfer)
19+
- [allowance](#allowance)
20+
21+
### Class `TransactionError`
22+
23+
extends: `Exception`
24+
25+
is extended by: -
26+
27+
#### description
28+
29+
`TransactionError` is a custom exception class that is raised when an Ethereum transaction receipt has a status of 0.
30+
This indicates that the transaction failed. Can provide a custom message. Optionally includes receipt
31+
32+
#### attributes
33+
34+
- `message` (str): The exception message.
35+
- `receipt` (dict): The transaction receipt.
36+
37+
#### methods
38+
39+
#### `__init__`
40+
41+
Initializes the exception with the provided message and receipt.
42+
43+
###### args:
44+
45+
- `message` (str): The exception message.
46+
- `receipt` (dict): The transaction receipt. Defaults to _None_.
47+
48+
###### returns:
49+
50+
- _None_
51+
52+
#### `__str__`
53+
54+
Returns a string representation of the `TransactionError` object.
55+
56+
###### returns:
57+
58+
- A string containing the `message` attribute of the TransactionError object. (str)
59+
60+
### Class `Account`
61+
62+
extends: -
63+
64+
is extended by: -
65+
66+
#### description
67+
68+
`Account` is responsible for managing the Ethereum account associated with the SingularityNET platform.
69+
It provides methods for interacting with the MultiPartyEscrow contract, the SingularityNetToken contract, and
70+
the Ethereum blockchain.
71+
72+
#### attributes
73+
74+
- `config` (dict): The configuration settings for the account. _Note_: In fact, this is the same config
75+
from `SnetSDK`.
76+
- `web3` (Web3): An instance of the `Web3` class for interacting with the Ethereum blockchain.
77+
- `mpe_contract` (MPEContract): An instance of the `MPEContract` class for interacting with
78+
the MultiPartyEscrow contract.
79+
- `token_contract` (Contract): An instance of the `Contract` class from the `web3` library for interacting
80+
with the SingularityNET AGIX Token contract.
81+
- `private_key` (str): The private key associated with the account.
82+
- `signer_private_key` (str): The private key used for signing transactions.
83+
- `address` (str): The Ethereum address associated with the account.
84+
- `signer_address` (str): The Ethereum address used for signing transactions.
85+
- `nonce` (int): The nonce value for the account.
86+
87+
#### methods
88+
89+
#### `__init__`
90+
91+
Initializes a new instance of the `Account` class.
92+
93+
###### args:
94+
95+
- `w3` (Web3): An instance of the `Web3` class.
96+
- `config` (dict): A dictionary containing the configuration settings.
97+
- `mpe_contract` (MPEContract): An instance of the `MPEContract` class.
98+
99+
###### returns:
100+
101+
- _None_
102+
103+
#### `_get_nonce`
104+
105+
Returns the next nonce for a transaction.
106+
107+
###### returns:
108+
109+
- The next nonce for a transaction. (int)
110+
111+
#### `_get_gas_price`
112+
113+
Calculates the gas price for a transaction.
114+
115+
Retrieves the current gas price from the Ethereum network using the web3 and increases it
116+
according to a certain algorithm so that the transaction goes faster.
117+
118+
###### returns:
119+
120+
- The calculated gas price. (int)
121+
122+
#### `_send_signed_transaction`
123+
124+
Sends a signed transaction to the Ethereum blockchain.
125+
126+
Builds a transaction using the given contract function and arguments, signs it with the private key of the account,
127+
and sends it to the Ethereum blockchain.
128+
129+
###### args:
130+
131+
- `contract_fn`: The contract function to be called.
132+
- `*args`: The arguments to pass to the contract function.
133+
134+
###### returns:
135+
136+
- Hash of the sent transaction. (HexStr | str)
137+
138+
#### `send_transaction`
139+
140+
Sends a transaction by calling the given contract function with the provided arguments.
141+
142+
###### args:
143+
144+
- `contract_fn`: The contract function to be called.
145+
- `*args`: The arguments to pass to the contract function.
146+
147+
###### returns:
148+
149+
- The transaction receipt indicating the success or failure of the transaction. (TxReceipt)
150+
151+
#### `_parse_receipt`
152+
153+
Parses the receipt of a transaction and returns the result as a JSON string.
154+
155+
###### args:
156+
157+
- `receipt` (TxReceipt): The receipt of the transaction.
158+
- `event` (Event): The event to process the receipt with.
159+
- `encoder` (JSONEncoder): The JSON encoder to use. Defaults to json.JSONEncoder.
160+
161+
###### returns:
162+
163+
- The result of processing the receipt as a JSON string. (str)
164+
165+
###### raises:
166+
167+
- TransactionError: If the transaction status is 0, indicating a failed transaction.
168+
169+
#### `escrow_balance`
170+
171+
Retrieves the escrow balance for the current account.
172+
173+
###### returns:
174+
175+
- The escrow balance in cogs. (int)
176+
177+
#### `deposit_to_escrow_account`
178+
179+
Deposit the specified amount of AGIX tokens in cogs into the MPE account.
180+
181+
###### args:
182+
183+
- `amount_in_cogs` (int): The amount of AGIX tokens in cogs to deposit.
184+
185+
###### returns:
186+
187+
- The transaction receipt of the transaction. (TxReceipt)
188+
189+
#### `approve_transfer`
190+
191+
Approves a transfer of a specified amount of AGIX tokens in cogs to the MPE contract.
192+
193+
###### args:
194+
195+
- `amount_in_cogs` (int): The amount of AGIX tokens in cogs to approve for transfer.
196+
197+
###### returns:
198+
199+
- The transaction receipt of the transaction. (TxReceipt)
200+
201+
#### `allowance`
202+
203+
Retrieves the allowance of the current account for the MPE contract.
204+
205+
###### returns:
206+
207+
- The allowance in cogs. (int)
208+

docs/main/client_lib_generator.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## module: sdk.client_lib_generator
2+
3+
[Link](https://github.com/singnet/snet-sdk-python/blob/master/snet/sdk/client_lib_generator.py) to GitHub
4+
5+
Entities:
6+
1. [ClientLibGenerator](#class-clientlibgenerator)
7+
- [\_\_init\_\_](#__init__)
8+
- [generate_client_library](#generate_client_library)
9+
- [_get_service_metadata_from_registry](#_get_service_metadata_from_registry)
10+
- [_get_service_registration](#_get_service_registration)
11+
12+
### Class `ClientLibGenerator`
13+
14+
extends: -
15+
16+
is extended by: -
17+
18+
#### description
19+
20+
This class is used to generate client library files for a given service.
21+
22+
#### attributes
23+
24+
- `sdk_config` (Config): An instance of the `Config` class
25+
- `registry_contract` (web3.contract.Contract): An instance of the `Contract` class (from `snet.cli`) for interacting with the Registry contract.
26+
- `org_id` (str): The organization ID of the service.
27+
- `service_id` (str): The service ID.
28+
- `language` (str): The language of the client library. Default is `python`.
29+
- `protodir` (str): The directory where the .proto files are located. Default is `~/.snet`.
30+
31+
#### methods
32+
33+
#### `__init__`
34+
35+
Initializes a new instance of the class. Initializes the attributes by arguments values.
36+
37+
###### args:
38+
39+
- `sdk_config` (Config): An instance of the `Config` class
40+
- `registry_contract` (web3.contract.Contract): An instance of the `Contract` class (from `snet.cli`) for interacting with the Registry contract.
41+
- `org_id` (str): The organization ID of the service.
42+
- `service_id` (str): The service ID.
43+
44+
###### returns:
45+
46+
- _None_
47+
48+
#### `generate_client_library`
49+
50+
Generates client library stub files based on specified organization and service ids, including:
51+
- getting service metadata from Registry
52+
- getting .proto file from IPFS
53+
- compiling .proto file to stub file and saving it in a given directory
54+
55+
#### `_get_service_metadata_from_registry`
56+
57+
Retrieves service metadata. Fetches the service registration from the Registry contract, extracts the metadata URI,
58+
downloads the metadata from IPFS, and parses it into a `MPEServiceMetadata` object.
59+
60+
###### returns:
61+
62+
- The service metadata. (MPEServiceMetadata)
63+
64+
#### `_get_service_registration`
65+
66+
Retrieves the service registration from the Registry contract using the `getServiceRegistrationById` function of it.
67+
68+
###### returns:
69+
70+
- Dictionary containing the service registration. (dict[str, Any])
71+
72+
###### raises:
73+
74+
- `Exception`: If the service with the specified ID is not found in the organization.
75+

0 commit comments

Comments
 (0)