state_utils

algofipy.state_utils.format_prefix_state(state)

Format state dict including prefixes.

Parameters:

state (dict) – state dict of base64 key -> dict

Returns:

formatted state dict

Return type:

dict

algofipy.state_utils.format_state(state, decode_byte_values=True)

Format state dict by base64 decoding keys and, optionally, bytes values.

Parameters:
  • state (dict) – state dict of base64 key -> dict

  • decode_byte_values (bool) – whether to decode base64 bytes values to utf-8

Returns:

formatted state dict

Return type:

dict

algofipy.state_utils.get_accounts_opted_into_app(indexer, app_id, exclude=None)

Get list of accounts opted into a given app

Parameters:
  • indexer (IndexerClient) – algorand indexer

  • app_id (int) – app id

  • exclude (str, optional) – comma-delimited list of information to exclude from indexer call

Returns:

formatted global state dict

Return type:

dict

algofipy.state_utils.get_balances(indexer, address, block=None)

Get balances for a given user.

Parameters:
  • indexer (IndexerClient) – algorand indexer client

  • address (str) – user address

  • block (int, optional) – block at which to query balances

Returns:

dict of asset id -> amount

Return type:

dict

algofipy.state_utils.get_global_state(indexer, app_id, decode_byte_values=True, block=None)

Get global state of a given application.

Parameters:
  • indexer (IndexerClient) – algorand indexer

  • app_id (int) – app id

  • decode_byte_values (bool) – whether to base64 decode bytes values

  • block (int, optional) – block at which to query global state

Returns:

formatted global state dict

Return type:

dict

algofipy.state_utils.get_global_state_field(indexer, app_id, field_name, decode_byte_values=True, block=None)

Get global state field of a given application.

Parameters:
  • indexer (IndexerClient) – algorand indexer

  • app_id (int) – app id

  • field_name (str) – name of the global state field

  • decode_byte_values (bool) – whether to base64 decode bytes values

  • block (int, optional) – block at which to query global state

Returns:

global state field

Return type:

int / bytes

algofipy.state_utils.get_local_state_at_app(indexer, address, app_id, decode_byte_values=True, block=None)

Get local state of user for given app.

Parameters:
  • indexer (IndexerClient) – algorand indexer

  • address (str) – user address

  • app_id (int) – app id

  • decode_byte_values (bool) – whether to base64 decode bytes values

  • block (int, optional) – block at which to query local state

Returns:

formatted local state dict

Return type:

dict

algofipy.state_utils.get_local_states(indexer, address, decode_byte_values=True, block=None)

Get local state of user for all opted in apps.

Parameters:
  • indexer (IndexerClient) – algorand indexer

  • address (str) – user address

  • decode_byte_values (bool) – whether to base64 decode bytes values

  • block (int, optional) – block at which to query local state

Returns:

formatted local state dict

Return type:

dict

algofipy.state_utils.get_state_bytes(state, key)

Get bytes value from state dict for given key.

Parameters:
  • state (dict) – state dict of base64 key -> dict

  • key (str) – key of state dict

Returns:

bytes value for given key

Return type:

bytes

algofipy.state_utils.get_state_int(state, key)

Get int value from state dict for given key.

Parameters:
  • state (dict) – state dict of base64 key -> dict

  • key (str) – key of state dict

Returns:

int value for given key

Return type:

int