Contract

Broker

Defines a Broker class

class layers.contract.broker.Broker(private_key, name, ip, public_info)

Brokers look for users (passive nodes) in the BSMD and arrange transactions. Brokers are created in the public domain and can get the public details of all passive nodes

Parameters
  • private_key (str) – Private key of the broker. This is not save in the class is just used to generate a public_key. In other functions the private_key must be used to sign transactions. You can generate private keys with IrohaCrypto.private_key()

  • name (str) – name of the user (lower case)

  • ip (str) – ip of one node hosting the blockchain

  • public_info (json) – public information of the broker, e.g., type of node: broker

create_account(private_key)

Create a broker account in the BSMD. Brokers are automatically created in the public domain. This function works in two steps

  1. The broker account in created in the public domain

  2. Set the public details of the broker

Example

>>> import json
>>> from admin.administrator import Domain
>>> x = { "address": "123 Street, City", "type": "broker" }
>>> public_info = json.dumps(x)
>>> broker = Broker('private_key','broker', '123.456.789', public_info)
>>> broker.create_account('private_key')
Parameters

private_key (str) – The private key of the user

get_details_from(user, private_key)

Consult all details of the node. Broker can only consult details in the ‘public’ domain

Example

>>> import json
>>> from admin.administrator import Domain
>>> from layers.identification.identification import User
>>> x = { "gender": 30, "address": "123 Tennis" }
>>> user_info = json.dumps(x)
>>> x = { "address": "123 Street, City", "type": "broker" }
>>> broker_info = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David', domain, user_info)
>>> broker = Broker('private_key','broker', '123.456.789', broker_info)
>>> user_public_details = broker.get_details_from(user, 'private_key')
>>> print(user_public_details)
{
    "node@domain":{
        "Type":"user"
    }
}
Parameters
  • private_key (str) – Key to sign the transaction

  • user (User) – The user the broker want to consult

Returns

solicited details of the user

Return type

json