Utils¶
The Iroha module have functions to post transactions in the BSMD and functions to node details manipulation.
The Administrator. module have functions to perform task such as domain, node and peer creation. This module is intended for the maintenance of the BSMD.
Iroha¶
Functions to post transactions in the iroha implementation of the BSMD
-
utils.iroha.get_a_detail_written_by(name, writer, private_key, detail_key, domain, ip)¶ This function can be use when the User object is no available. Consult a details of the node writen by other node
- Example
>>> juan_detail = get_a_detail_written_by('David', 'Juan', 'private key of david', 'detail_key of Juan', 'domain', 'ip') >>> print(juan_detail) { "nodeA@domain":{ "Age":"35" }
- Parameters
name (str) – Name of the node consulting the information
writer (str) – Name of the node who write the detail
private_key (str) – Private key of the user
detail_key (str) – Name of the detail we want to consult
domain (str) – Name of the domain
ip (str) – Address for connecting to the BSMD
- Returns
returns the detail writen by “the writer”
- Return type
json
-
utils.iroha.set_detail_to_node(sender, receiver, private_key, detail_key, detail_value, domain, ip)¶ This function can be use when the User object is no available. The sender must have permission to write in the details of the receiver.
In federated learning the details are in JSON format and contains the address (location) where the weight is stored if the weight is small enough it can be embedded to the block if needed)
- Example
>>> set_detail_to_node('David', 'Juan', 'private key of david', 'detail key of Juan', 'detail value', 'domain' 'ip')
- Parameters
sender (str) – Name of the node sending the information
receiver (str) – Name of the node receiving the information
private_key (str) – Private key of the user
detail_key (str) – Name of the detail we want to set
detail_value (str) – Value of the detail
domain (str) – Name of the domain
ip (str) – address for connecting to the BSMD
-
utils.iroha.trace(func)¶ A decorator for tracing methods’ begin/end execution points
Administrator¶
Defines an Admin of the BSMD. This module also defines the domains
-
class
utils.administrator.Admin(ip)¶ The administrator object of the BSMD. This object can create assets, add active nodes, add passive nodes and creates de public domain in the BSMD
- Parameters
ip (str) – ip address of one node hosting the Blockchain
- Example
>>> Admin('123.456.789')
-
add_assets_to_user(user, asset, asset_qty)¶ The admin creates credit for a user. Users can buy credit in the BSMD to pay for services. This functions works in two step:
admin add assets to his own wallet
admin transfers the asset to the user
- Example
>>> import json >>> from layers.identification.user import User >>> from layers.incentive.asset import Asset >>> x = { "age": 30, "city": "Cartagena" } >>> account_information = json.dumps(x) >>> public = Domain('public', 'default_role') >>> user = User('private_key','David',public, account_information) >>> asset = Asset('coin', public, 3) >>> asset.domain >>> admin = Admin('123.456.789') >>> admin.add_assets_to_user(user, asset, 330.2)
-
create_asset(asset)¶ Creates an asset
- Example
>>> from layers.incentive.asset import Asset >>> public = Domain('public', 'default_role') >>> asset = Asset('coin', public, 3) >>> admin = Admin('123.456.789') >>> admin.create_asset(asset)
- Parameters
asset (Asset) – Asset to be created
-
create_domain(domain)¶ Creates a domain
- Example
>>> public = Domain('public', 'default_role') >>> admin = Admin('123.456.789') >>> admin.create_domain(public)
- Parameters
domain (Domain) – domain to be created
-
create_user_in_iroha(user)¶ Creates a personal account in a domain
- Example
>>> import json >>> from layers.identification.user import User >>> x = { "age": 30, "city": "New York" } >>> account_information = json.dumps(x) >>> public = Domain('public', 'default_role') >>> user = User('private_key','David',public, account_information) >>> admin = Admin('123.456.789') >>> admin.create_user_in_iroha(user)
- Parameters
user (User) – a user object
-
class
utils.administrator.Domain(name, default_role)¶ The domain can be use to run distributed processes. Or to constantly share information of an specific type
- Example
>>> Domain('public', 'default_role')
- Parameters
name (str) – name of the domain
default_role (str) – default role in the domain