storage

get(key: ByteString, context: Optional[StorageContext] = None) bytes

Gets a value from the persistent store based on the given key.

Parameters
  • key (str or bytes) – value identifier in the store

  • context (StorageContext) – storage context to be used

Returns

the value corresponding to given key for current storage context

Return type

bytes

get_context() StorageContext

Gets current storage context.

Returns

the current storage context

Return type

StorageContext

get_read_only_context() StorageContext

Gets current read only storage context.

Returns

the current read only storage context

Return type

StorageContext

put(key: ByteString, value: Union[int, ByteString], context: Optional[StorageContext] = None)

Inserts a given value in the key-value format into the persistent storage.

Parameters
  • key (str or bytes) – the identifier in the store for the new value

  • value (int or str or bytes) – value to be stored

  • context (StorageContext) – storage context to be used

delete(key: ByteString, context: Optional[StorageContext] = None)

Removes a given key from the persistent storage if exists.

Parameters
  • key (str or bytes) – the identifier in the store for the new value

  • context (StorageContext) – storage context to be used

find(prefix: ByteString, context: Optional[StorageContext] = None, options: FindOptions = FindOptions.NONE) Iterator

Searches in the storage for keys that start with the given prefix.

Parameters
  • prefix (str or bytes) – prefix to find the storage keys

  • context (StorageContext) – storage context to be used

  • options (FindOptions) – the options of the search

Returns

an iterator with the search results

Return type

Iterator

StorageContext

class StorageContext

Bases: object

The storage context used to read and write data in smart contracts.

create_map(prefix: ByteString) StorageMap

Creates a storage map with the given prefix.

Parameters

prefix (str or bytes) – the identifier of the storage map

Returns

a map with the key-values in the storage that match with the given prefix

Return type

StorageMap

as_read_only() StorageContext

Converts the specified storage context to a new readonly storage context.

Returns

current StorageContext as ReadOnly

Return type

StorageContext

StorageMap

class StorageMap(context, prefix: ByteString)

Bases: object

The key-value storage for the specific prefix in the given storage context.

get(key: ByteString) bytes

Gets a value from the map based on the given key.

Parameters

key (str or bytes) – value identifier in the store

Returns

the value corresponding to given key for current storage context

Return type

bytes

put(key: ByteString, value: Union[int, ByteString])

Inserts a given value in the key-value format into the map.

Parameters
  • key (str or bytes) – the identifier in the store for the new value

  • value (int or str or bytes) – value to be stored

delete(key: ByteString)

Removes a given key from the map if exists.

Parameters

key (str or bytes) – the identifier in the store for the new value