pylibsimba.simba.Simbachain¶
-
class
pylibsimba.simba.
Simbachain
(endpoint: str, wallet)¶ Main object to interact with the PyLibSIMBA API
-
__init__
(endpoint: str, wallet)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(endpoint, wallet)Initialize self.
Add funds to the attached Wallet.
api_auth_headers
()call_method
(method, parameters)Call a method on the API
call_method_with_file
(method, parameters, files)Call a method on the API with files
Check if the transaction is complete
check_transaction_status
(txn_id)Gets the status of a transaction by ID
Gets the status of a transaction
Get the balance for the attached Wallet
get_bundle_for_transaction
(…[, stream])Gets the bundle for a transaction
Gets the bundle metadata for a transaction
Gets a file from the bundle for a transaction
Gets a file from the bundle for a transaction
get_method_transactions
(method, parameters)Gets a paged list of transactions for the method
get_transaction
(transaction_id_or_hash)Gets a specific transaction
get_transaction_status
(transaction_id_or_hash)Gets the status of a specific transaction
get_transactions
(parameters)Gets a paged list of transactions
management_auth_headers
()Internal function for sending transaction GET requests
set_api_key
(api_key)set_management_key
(management_key)set_wallet
(wallet)validate_any_get_call
()Validate the method call against the app metadata
validate_call
(method_name, parameters[, files])Validate the method call against the app metadata
validate_get_call
(method_name, parameters)Validate the method call against the app metadata
wait_for_success_or_error
(txn_id[, …])-
add_funds
() → dict¶ Add funds to the attached Wallet. Please check the output of this method. It is of the form
return { 'txnId': None, 'faucet_url': None, 'poa': True }
If successful, txnId will be populated.
If the network is PoA, then poa will be true, and txnId will be null.
If the faucet for the network is external (e.g. Rinkeby, Ropsten, etc), then txnId will be null, and faucet_url will be populated with a URL.
You should present this URL to your users to direct them to request funds there.
- Returns
Details of the txn
- Raises
MissingMetadataException – If the App Metadata not yet retrieved.
WalletNotFoundException – If there is no Wallet found.
-
call_method
(method: str, parameters: dict)¶ Call a method on the API
- Parameters
method – the method to call
parameters – the parameters for the method
- Returns
A transaction id
- Raises
WalletNotFoundException – If a wallet has not yet been initialised.
-
call_method_with_file
(method: str, parameters: dict, files: list) → dict¶ Call a method on the API with files
- Parameters
method – the method to call
parameters – the parameters for the method
files – a list of file paths to be submitted with the API call
- Returns
A transaction id
-
check_transaction_done
(txn: dict) → bool¶ Check if the transaction is complete
- Parameters
txn – the transaction object
- Returns
Is the transaction complete?
-
check_transaction_status
(txn_id) → dict¶ Gets the status of a transaction by ID
- Parameters
txn_id – a transaction ID
- Returns
An object with status details
-
check_transaction_status_from_object
(txn: dict) → dict¶ Gets the status of a transaction
- Parameters
txn – A transaction object
- Returns
An object with status details
-
get_balance
() → dict¶ Get the balance for the attached Wallet
- Parameters
txn_id – a transaction ID
- Returns
An object with the balance
- Raises
MissingMetadataException – If the App Metadata not yet retrieved.
WalletNotFoundException – If there is no Wallet found.
TransactionStatusCheckException – If the server response is not ok.
-
get_bundle_for_transaction
(transaction_id_or_hash: str, stream: bool = True) → requests.models.Response¶ Gets the bundle for a transaction
- Parameters
transaction_id_or_hash – Either a transaction ID or a transaction hash
stream – A boolean to indicate if the file should be downloaded into memory or streamed
- Returns
a response type object which can be read, eg requests.models.Response
In this case, using “stream=True” avoids downloading the file into memory first.
- Raises
GetRequestException – If there is a problem getting the bundle
-
get_bundle_metadata_for_transaction
(transaction_id_or_hash: str)¶ Gets the bundle metadata for a transaction
- Parameters
transaction_id_or_hash – Either a transaction ID or a transaction hash
- Returns
The bundle metadata
- Raises
GetRequestException – If there is a problem getting the bundle
-
get_file_from_bundle_by_name_for_transaction
(transaction_id_or_hash: str, file_name: str, stream: bool) → requests.models.Response¶ Gets a file from the bundle for a transaction
- Parameters
transaction_id_or_hash – Either a transaction ID or a transaction hash
file_name – The name of the file in the bundle metadata
stream – A boolean to indicate if the file should be downloaded into memory or streamed
- Returns
A response type object which can be read, eg requests.models.Response
In this case, using “stream=True” avoids downloading the file into memory first.
- Raises
GetRequestException – If there is a problem getting the bundle
-
get_file_from_bundle_for_transaction
(transaction_id_or_hash: str, file_idx: int, stream=False) → requests.models.Response¶ Gets a file from the bundle for a transaction
- Parameters
transaction_id_or_hash – Either a transaction ID or a transaction hash
file_idx – The index of the file in the bundle metadata
stream – A boolean to indicate if the file should be downloaded into memory or streamed
- Returns
A response type object which can be read, eg requests.models.Response
In this case, using “stream=True” avoids downloading the file into memory first.
- Raises
GetRequestException – If there is a problem getting the bundle
-
get_method_transactions
(method: str, parameters: dict) → Optional[pylibsimba.pages.PagedResponse]¶ Gets a paged list of transactions for the method
- Parameters
method – The method
parameters – The query parameters
- Returns
A response wrapped in a PagedResponse helper
-
get_transaction
(transaction_id_or_hash)¶ Gets a specific transaction
- Parameters
transaction_id_or_hash – Either a transaction ID or a transaction hash
- Returns
The transaction details
- Raises
GetTransactionsException – If there is a problem getting the transaction
-
get_transaction_status
(transaction_id_or_hash: str) → dict¶ Gets the status of a specific transaction
- Parameters
transaction_id_or_hash – the id of the transaction
- Returns
A transaction id
- Raises
TransactionStatusCheckException – If the server response is not ok.
-
get_transactions
(parameters: dict) → pylibsimba.pages.PagedResponse¶ Gets a paged list of transactions
- Parameters
parameters – The query parameters
- Returns
A response wrapped in a PagedResponse helper
-
send_transaction_request
(url: str) → pylibsimba.pages.PagedResponse¶ Internal function for sending transaction GET requests
- Parameters
url – The URL
- Returns
A response wrapped in a PagedResponse helper
- Raises
GetTransactionsException – If there is a problem getting the transaction
-