graphenecommon.blockchainobject module

class graphenecommon.blockchainobject.BlockchainObject(data, klass=None, lazy=False, use_cache=True, *args, **kwargs)

Bases: graphenecommon.blockchainobject.Caching, dict

This class deals with objects from graphene-based blockchains. It is used to validate object ids, store entire objects in the cache and deal with indexing thereof.

classmethod cache_object(data, key=None)

This classmethod allows to feed an object into the cache is is mostly used for testing

identifier = None
static objectid_valid(i)

Test if a string looks like a regular object id of the form::

xxxx.yyyyy.zzzz

with those being numbers.

perform_id_tests = True
space_id = 1
store(data, key='id')

Cache the list

Parameters:data (list) – List of objects to cache
test_valid_objectid(i)

Alias for objectid_valid

testid(id)

In contrast to validity, this method tests if the objectid matches the type_id provided in self.type_id or self.type_ids

type_id = None
type_ids = []
class graphenecommon.blockchainobject.BlockchainObjects(*args, **kwargs)

Bases: graphenecommon.blockchainobject.Caching, list

This class is used internally to store lists of objects and deal with the cache and indexing thereof.

cache(key)

(legacy) store the current object with key key.

classmethod cache_objects(data, key=None)

This classmethod allows to feed multiple objects into the cache is is mostly used for testing

identifier = None
refresh(*args, **kwargs)

Interface that needs to be implemented. This method is called when an object is requested that has not yet been fetched/stored

store(data, key=None, *args, **kwargs)

Cache the list

Parameters:data (list) – List of objects to cache
class graphenecommon.blockchainobject.Caching(*args, **kwargs)

Bases: object

This class implements a few common methods that are used to either cache lists or dicts

classmethod clear_cache()

Clear/Reset the entire Cache

getfromcache(id)

Get an element from the cache explicitly

incached(id)

Is an element cached?

items()

This overwrites items() so that refresh() is called it the object is not already fetched

class graphenecommon.blockchainobject.Object(data, klass=None, lazy=False, use_cache=True, *args, **kwargs)

Bases: graphenecommon.blockchainobject.BlockchainObject, graphenecommon.instance.AbstractBlockchainInstanceProvider

This class is a basic class that allows to obtain any object from the blockchyin by fetching it through the API

refresh()

This is the refresh method that overloads the prototype in BlockchainObject.

class graphenecommon.blockchainobject.ObjectCache(initial_data={}, default_expiration=60, no_overwrite=False)

Bases: dict

This class implements an object/dict cache that comes with an expiration. Expired items are removed from the cache.

The class implements/extends:

  • __setitem__()
  • __getitem__()
  • __contains__
  • __str__()
  • get()

and provides a method to define the default expiration time.

get(key, default=None)

Returns an element from the cache if available, else returns the value provided as default or None

set_expiration(expiration)

Set new default expiration time in seconds (default: 10s)