ApiUtils
Helpers for working with GridWorks specific Algorand certificates and Smart Contracts. Heavily used in API Type validation.
- gridworks.api_utils.alias_from_deed_idx(asset_idx)
Returns the TerminalAsset’s GNodeAlias from the the TaDeed unique identifer (when the AlgoCertType is ASA, and the identifier is an integer). Returns None if the asset_idx is not in fact the identifier for a TaDeed [more info](https://gridworks.readthedocs.io/en/latest/ta-deed.html#tadeed)
- Parameters:
asset_idx (int) – the ASA id in question
- Return type:
str | None
- gridworks.api_utils.check_mtx_subsig(mtx, signer_addr)
Throws a SchemaError if the signer_addr is not a signer for mtx or did not sign. TODO: add error if the signature does not match the txn.
- Parameters:
mtx (MultisigTransaction) –
- Return type:
None
- gridworks.api_utils.check_validator_multi_has_enough_algos(ta_validator_addr)
Raises exception if the 2-sig multi [GNfAdminAddr, ta_validator_addr] insufficiently funded. Set publicly by the GNodeFactory. [More info](https://gridworks.readthedocs.io/en/latest/g-node-factory.html#tavalidatorfundingthresholdalgos)
- Parameters:
validator_addr – the public address of the pending validator
ta_validator_addr (str) –
- Raises:
SchemaError if joint account does not have Public().gnf_validator_funding_threshold_algos. –
- Return type:
None
- gridworks.api_utils.get_discoverer_account_with_admin(discoverer_addr)
Returns the 2-sig multi [discoverer, gnf_admin_addr] address for a GridWorks Discoverer.
- Parameters:
discoverer_addr (str) – The Algorand address of the Discoverer
- Raises:
Exception SchemaError – Returned if discoverer_addr has wrong format.
- Return type:
- gridworks.api_utils.get_tadeed_id(terminal_asset_alias, validator_addr)
- Looks for an asset created in the 2-sig [Gnf Admin, validator_addr] account
that is a tadeed for terminal_asset_alias.
[more info](https://gridworks.readthedocs.io/en/latest/ta-deed.html#tadeed-technical-details) [GwCertId.Type](https://gridworks.readthedocs.io/en/latest/enums.html#gridworks.enums.AlgoCertType)
- Parameters:
terminal_asset_alias (str) – the alias of the Terminal Asset
validator_addr (str) – the AlgoAddress of the Validator
- Returns:
returns None if no TaDeed for this alias was created by the two-sig Multi [GnfAdminAddr, validator_addr]. Otherwise returns the unique identifier of the TaDeed, which is an AlgoAddress string if the GwCertId.Type=SmartSig, and is an integer if the GwCertId.Type=ASA
- Return type:
Optional[GwCertId]
- gridworks.api_utils.get_tatrading_rights_id(terminal_asset_alias)
Returns unique identifier for TaTradingRights [more info](https://gridworks.readthedocs.io/en/latest/ta-trading-rights.html#tatradingrights-technical-details) [GwCertId.Type](https://gridworks.readthedocs.io/en/latest/enums.html#gridworks.enums.AlgoCertType)
- Parameters:
terminal_asset_alias (str) – The GNodeAlias of the TerminalAsset that
for (the TaTradingRights are) –
- Returns:
returns None if no TaTradingRights are found. Otherwise returns the unique identifier of the TaTradingRights, which is an AlgoAddress string if the GwCertId.Type==SmartSig, and is an integer if the GwCertId.Type==ASA
- Return type:
Optional[GwCertId]
- gridworks.api_utils.get_validator_account_with_admin(validator_addr)
Returns the 2-sig multi [gnf_admin_addr, validator_addr] address for a GridWorks Validator.
- Parameters:
validator_addr (str) – The Algorand address of the Discoverer
- Raises:
Exception SchemaError – Returned if discoverer_addr has wrong format.
- Return type:
- gridworks.api_utils.get_validator_cert_idx(validator_addr)
Looks for an asset in the validatorMsig account that is a validator certificate (based on unit name). [More info](https://gridworks.readthedocs.io/en/latest/ta-validator.html#tavalidator-certificate)
- Parameters:
validator_addr (str) – the public address of the validator (NOT the multi)
- Returns:
returns None if no Validator Certificate is found, otherwise the unique identifier of the certificate. Since Validator certificates are always ASA, this identifier is an int.
- Return type:
Optional[int]
- gridworks.api_utils.is_ta_deed(asset_idx)
Returns True if the asset_idx is the unique identifier for a TaDeed certificate. Note that the AlgoCertType must be ASA [more info](https://gridworks.readthedocs.io/en/latest/ta-deed.html#tadeed-technical-details)
- Parameters:
asset_idx (int) – the ASA id in question
- Return type:
bool
- gridworks.api_utils.is_ta_validator(acct_addr)
Returns True if the account_addr is the TaValidatorAddr for a TaValidator False otherwise [more info](https://gridworks.readthedocs.io/en/latest/ta-validator.html)
- Parameters:
acct_addr (str) –
- Return type:
bool
- gridworks.api_utils.is_validator_addr(validator_addr)
Checks if Validator Multi has a single valid TaValidator certificate
- Parameters:
validator_addr (str) –
- Return type:
bool