peerplays.amount module¶
-
class
peerplays.amount.
Amount
(*args, **kwargs)¶ Bases:
peerplays.instance.BlockchainInstance
,peerplays.amount.Amount
This class deals with Amounts of any asset to simplify dealing with the tuple:
(amount, asset)
Parameters: - args (list) – Allows to deal with different representations of an amount
- amount (float) – Let’s create an instance with a specific amount
- asset (str) – Let’s you create an instance with a specific asset (symbol)
- blockchain_instance (peerplays.peerplays.peerplays) – peerplays instance
Returns: All data required to represent an Amount/Asset
Return type: dict
Raises: ValueError – if the data provided is not recognized
from peerplays.amount import Amount from peerplays.asset import Asset a = Amount("1 USD") b = Amount(1, "USD") c = Amount("20", Asset("USD")) a + b a * 2 a += b a /= 2.0
Way to obtain a proper instance:
args
can be a string, e.g.: “1 USD”args
can be a dictionary containingamount
andasset_id
args
can be a dictionary containingamount
andasset
args
can be a list of afloat
andstr
(symbol)args
can be a list of afloat
and apeerplays.asset.Asset
amount
andasset
are defined manually
An instance is a dictionary and comes with the following keys:
amount
(float)symbol
(str)asset
(instance ofpeerplays.asset.Asset
)
Instances of this class can be used in regular mathematical expressions (
+-*/%
) such as:Amount("1 USD") * 2 Amount("15 GOLD") + Amount("0.5 GOLD")
-
amount
¶ Returns the amount as float
-
asset
¶ Returns the asset as instance of
asset.Asset
-
blockchain
¶
-
blockchain_instance_class
¶
-
chain
¶ Short form for blockchain (for the lazy)
-
clear
() → None. Remove all items from D.¶
-
copy
()¶ Copy the instance and make sure not to use a reference
-
define_classes
()¶ Needs to define instance variables that provide classes
-
fromkeys
()¶ Create a new dictionary with keys from iterable and values set to value.
-
get
()¶ Return the value for key if key is in the dictionary, else default.
-
get_instance_class
()¶ Should return the Chain instance class, e.g. peerplays.PeerPlays
-
classmethod
inject
(cls)¶
-
items
() → a set-like object providing a view on D's items¶
-
json
()¶
-
keys
() → a set-like object providing a view on D's keys¶
-
peerplays
¶ Alias for the specific blockchain
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
This method allows us to override default instance for all users of
SharedInstance.instance
.Parameters: instance (chaininstance) – Chain instance
This allows to set a config that will be used when calling
shared_blockchain_instance
and allows to define the configuration without requiring to actually create an instance
This method allows to set the current instance as default
-
setdefault
()¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
This method will initialize
SharedInstance.instance
and return it. The purpose of this method is to have offer single default instance that can be reused by multiple classes.
-
symbol
¶ Returns the symbol of the asset
-
tuple
()¶
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D's values¶