|
| 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 | + |
0 commit comments