Skip to content

Latest commit

 

History

History

simulation

Configuration

In the file iroha_config.py set all configuration variables

NETWORK: setup the IP of one active node
ADMIN_PRIVATE_KEY: hardcoded key of the administrator of the network
IROHA_ADMIN: local address of the administrator of the cBSMD
DEFAULT_ROLE: default privileges of new users
DOMAIN_CARBON_TAX = domain where user pay carbon tokens for each trip
DOMAIN_CARBON_PAYMENTS = domain where user buy carbon coins that can be exchanged for carbon coins
ASSET_CARBON_TAX = name of the asset for paying trips
ASSET_CARBON_PAYMENTS = name of the asset for paying carbon tokens
ASSET_PRECISION = presicion of both assets
CARBON_TAX_INIT = initial amount of carbon takes every user starts with
CARBON_COIN_INIT = initial amount of carbon coins every user starts with
GOVERNMENT_ID: id for government
GOVERNMENT_PK_TAX = hardcoded key of the goverment in the domain carbon tax
GOVERNMENT_PK_PAYMENTS = hardcoded key of the goverment in the domain carbon payments
SIMULATION_STARTS_AT = initial time of the simulation
LENGTH = total running time in seconds of the simulation \

See iroha_config.py for a deeper understanding.

Simulation

We have a simulation over the BSMD and a local simulation (off-blockchain). Both simulation get to the same results is just easy to run the local simulation since you don't need a blockchain. However the local simulation accounts for all the blockchain transactions

To run the local simulation do:

python3 simulation.py

The result of this simulation are the file economics.csv and statistics.csv. In the first file is the breakdown of all token and coins transactions. In the former file is the count all the transactions per second

To run the BSMD simulation first setup a blockchain (see network). The run

python3 create_populationBSMD.py

python3 simulationBSMD.py

To see the result you can query the blockchain using functions in the file iroha_functions.py

Single transactions examples

In the examples.py you will find some examples of the cBSMD operations. Before start exploring the example run python3 setup.py to setup the cBSMD.

In the first part we create two individual nodes (David and Johannes) and one vehicle node (Fiesta.. as in Ford Fiesta). We create nodes with the function:

create_account_with_assets(domain, node_name, node_private_key, asset_name, asset_quantity)
  1. domain: name of the domain in where you want to create a node. The domain must be previously create by the setup.py file
  2. node_name: name of the node you want to create. The name must be small-caps
  3. node_private_key: private key of the node. Create private key with IrohaCrypto.private_key()
  4. asset_name: name of the asset you want to add to the node. The asset must be previously create by the setup.py file.
  5. asset_quantity: number of assets you want to assing to the node

After the creation of the passive nodes, we make a transaction of assets. You can only transfer assets in the same domain, i.e., only nodes that lives in the same domain can transfer the assets of the domain

transfer_assets(domain, name, private_key, to_name, asset_name, asset_quantity, message)
  1. domain name of the domain from where the node is sending the assets
  2. name name of the node who is sending the assets
  3. private_key: private key of the node for sign the transaction
  4. to_name: name of the node receiving the assets
  5. asset_name: name of the asset to be transferred
  6. quantity: Number of assets we want to transfer
  7. description: Message to explain the transactions (e.g. pay debt, pay carbon credits)

In the cBSMD users can record his own information. In the example Johannes records a trip with the emitted CO2.

set_detail(domain, name, private_key, detail_key, detail_value)
  1. domain: name of the domain where the node wants to set a detail
  2. name: name of the node doing the trip
  3. private_key: Private key of the node
  4. detail_key: Name of the detail we want to set
  5. detail_value: Characteristics of the detail. This can store a Json with at most 4096 characters

The cBSMD also admits other passive nodes make transactions on your behalf. This is useful for transfer information that was not generated by you but is related to you. For example, if you made a taxi trip, the taxi can set in your profile the carbon you expend on the trip.

Before letting a node record a transaction on your behalf you must grant him permissions

grants_access_to_set_details(your_domain, your_name, private_key, grant_domain, grant_account)
  1. your_domain: Domain of the node granting the permission
  2. your_name: Name of the node granting the permission
  3. private_key: private key of the node granting the permission
  4. param grant_domain: domain of the node how will have the permission
  5. param grant_account: name of the node how will have the permission

Once you grant the permission, the other node can record transactions on your behalf with:

set_detail_to_node(domain, name, private_key, to_domain, to_name, detail_key, detail_value)
  1. domain: name of the domain where the node wants to set a detail
  2. name: name of the node who is doing the record on your behalf
  3. private_key: private key of the node doing the transactions
  4. to_domain: name of domain where is the receptor of the information
  5. to_name: name of the receptor
  6. detail_key: Name of the detail we want to set
  7. detail_value: Characteristics of the detail. This can store a Json with at most 4096 characters