Esempio n. 1
0
File: user.py Progetto: LiTrans/BSMD
    def create_account(self, private_key):
        """
        Create a personal account in the BSMD. In the public domain all your public information is automatically
        populated

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> public = Domain('public', 'default_role')
        >>> user = User('private_key','David', public, '123.456.789', account_information)
        >>> user.create_account('private_key')

        :param str private_key: The private key of the user

        """
        account_id = self.name + '@' + self.domain.name
        iroha = Iroha(account_id)
        tx = iroha.transaction(
            [iroha.command('CreateAccount',
                           account_name=self.name,
                           domain_id=self.domain,
                           public_key=self.public_key)])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)

        if self.domain == 'public':
            self.set_detail('public', self.public_info, private_key)
Esempio n. 2
0
File: user.py Progetto: LiTrans/BSMD
    def create_domain(self, domain, private_key):
        """
        Creates a domain for personal use. You can create a domain for a particular process, e.g., Federated Learning

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> domain = Domain('name', 'default_role')
        >>> user = User('private_key', 'My Name', 'My domain', '123.456.789', account_information)
        >>> user.create_domain(domain, 'private_key')

        :param Domain domain: domain to be created
        :param str private_key: key to sign the transaction

        """
        account_id = self.name + '@' + self.domain.name
        iroha = Iroha(account_id)
        tx = iroha.transaction(
            [iroha.command('CreateDomain',
                           domain_id=domain.name,
                           default_role=domain.default_role)])

        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 3
0
File: user.py Progetto: LiTrans/BSMD
    def set_detail_to(self, user, detail_key, detail_value, private_key):
        """
        Set a detail to a node. The details can be stored in JSON format with limit of 4096 characters per detail.
        You must have the permission from the node to set information on his identification

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> x = { "age": 34, "city": "Mexico" }
        >>> account_information_juan = json.dumps(x)
        >>> domain = Domain('name', 'default_role')
        >>> user = User('private_key','David',domain, account_information)
        >>> juan = User('private_key_juan','Juan',domain, account_information_juan)
        >>> user.set_detail_to(juan, 'Job', 'Bartender', 'private_key')

        :param User user: user you want to set the details
        :param str detail_key: Name of the detail we want to set
        :param str detail_value: Value of the detail
        :param str private_key: key to sign the transaction

        """
        account = self.name + '@' + self.domain.name
        iroha = Iroha(account)
        account_id = user.name + '@' + user.domain
        tx = iroha.transaction([
            iroha.command('SetAccountDetail',
                          account_id=account_id,
                          key=detail_key,
                          value=detail_value)
        ])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 4
0
File: user.py Progetto: LiTrans/BSMD
    def revoke_access_set_details_to(self, user, private_key):
        """
        Revoke permission to a node to set details on your identification

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> x = { "age": 34, "city": "Mexico" }
        >>> account_information_juan = json.dumps(x)
        >>> domain = Domain('name', 'default_role')
        >>> user = User('private_key','David',domain, account_information)
        >>> juan = User('private_key_juan','Juan',domain, account_information_juan)
        >>> user.revoke_access_set_details_to(juan, 'private_key')

        :param User user: User you want to revoke permissions to set details on your behalf
        :param str private_key: Key to sign the transaction

        """
        my_id_account = self.name + '@' + self.domain.name
        grant_account_id = user.name + '@' + user.domain
        iroha = Iroha(my_id_account)
        tx = iroha.transaction([
            iroha.command('RevokePermission',
                          account_id=grant_account_id,
                          permission=can_set_my_account_detail)
        ],
            creator_account=my_id_account)
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 5
0
    def create_user_in_iroha(self, 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)

        :param User user: a user object

        """
        tx = self.iroha.transaction([
            self.iroha.command('CreateAccount',
                               account_name=user.name,
                               domain_id=user.domain,
                               public_key=user.public_key)
        ])
        IrohaCrypto.sign_transaction(tx, self.private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 6
0
File: user.py Progetto: LiTrans/BSMD
    def set_detail(self, detail_key, detail_value, private_key):
        """
        Set a detail in my account. The details can be stored in JSON format with limit of 4096 characters per detail

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "gender": 30, "address": "123 Tennis" }
        >>> account_information = json.dumps(x)
        >>> domain = Domain('name', 'default_role')
        >>> user = User('private_key','David', domain, account_information)
        >>> user.set_detail('personal information', account_information, 'private_key')

        :param str detail_key: Name of the detail we want to set
        :param json detail_value: Value of the detail
        :param str private_key: Key to sign the transaction

        """

        account_id = self.name + '@' + self.domain.name
        iroha = Iroha(account_id)
        tx = iroha.transaction([
            iroha.command('SetAccountDetail',
                          account_id=account_id,
                          key=detail_key,
                          value=detail_value)
        ])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 7
0
    def add_assets_to_user(self, 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)

        :param User user: User receiving the assets
        :param Asset asset: Asset to be transferred
        :param float asset_qty: Quantity of assets the node buy

        """
        # 1. Admin creates the asset for the user
        asset_id = asset.name + '#' + asset.domain.name
        tx = self.iroha.transaction([
            self.iroha.command('AddAssetQuantity',
                               asset_id=asset_id,
                               amount=asset_qty)
        ])
        IrohaCrypto.sign_transaction(tx, self.private_key)
        send_transaction_and_print_status(tx, self.network)

        # 2. Admin transfer the assets to the user
        dest_account_id = user.name + '@' + user.domain
        tx = self.iroha.transaction([
            self.iroha.command('TransferAsset',
                               src_account_id='admin@public',
                               dest_account_id=dest_account_id,
                               asset_id=asset_id,
                               description='asset created for node',
                               amount=asset_qty)
        ])
        IrohaCrypto.sign_transaction(tx, self.private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 8
0
    def create_domain(self, domain):
        """
        Creates a domain

        :Example:
        >>> public = Domain('public', 'default_role')
        >>> admin = Admin('123.456.789')
        >>> admin.create_domain(public)

        :param Domain domain: domain to be created

        """
        tx = self.iroha.transaction([
            self.iroha.command('CreateDomain',
                               domain_id=domain.name,
                               default_role=domain.default_role)
        ])

        IrohaCrypto.sign_transaction(tx, self.private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 9
0
    def create_asset(self, 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)

        :param Asset asset: Asset to be created
        """
        tx = self.iroha.transaction([
            self.iroha.command('CreateAsset',
                               asset_name=asset.name,
                               domain_id=asset.domain,
                               precision=asset.precision)
        ])
        IrohaCrypto.sign_transaction(tx, self.private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 10
0
File: user.py Progetto: LiTrans/BSMD
    def transfer_assets_to(self, user, asset_name, quantity, description, private_key):
        """
        Transfer assets from one account to another. Both users must be in the same domain.

        :Example:
        >>> import json
        >>> from utils.administrator import Domain
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> x = { "age": 34, "city": "Mexico" }
        >>> account_information_dante = json.dumps(x)
        >>> domain = Domain('name', 'default_role')
        >>> user = User('private_key','David',domain, account_information)
        >>> dante = User('dante_private_key','Dante',domain, account_information_dante)
        >>> user.transfer_assets_to(dante, 'coin', '2', 'Shut up and take my money')

        :param User user: User you want to transfer the assets
        :param str asset_name: Name of the asset to be transferred
        :param float quantity: Number of assets we want to transfer
        :param str description: Small message to the receiver of assets
        :param str private_key: Key to sign the transaction

        """

        account_id = self.name + '@' + self.domain.name
        iroha = Iroha(account_id)
        destination_account = user.name + '@' + self.domain.name
        asset_id = asset_name + '#' + self.domain.name
        tx = iroha.transaction([
            iroha.command('TransferAsset',
                          src_account_id=account_id,
                          dest_account_id=destination_account,
                          asset_id=asset_id,
                          description=description,
                          amount=quantity)
        ])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)
Esempio n. 11
0
    def create_account(self, private_key):
        """
        Create a broker account in the BSMD. Brokers are automatically created in the public domain. This function works
        in two steps

        #. The broker account in created in the public domain
        #. 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')

        :param str private_key: The private key of the user

        """
        account_id = self.name + '@public'
        iroha = Iroha(account_id)
        tx = iroha.transaction([
            iroha.command('CreateAccount',
                          account_name=self.name,
                          domain_id='public',
                          public_key=self.public_key)
        ])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)

        tx = iroha.transaction([
            iroha.command('SetAccountDetail',
                          account_id=account_id,
                          key='public information',
                          value=self.public_info)
        ])
        IrohaCrypto.sign_transaction(tx, private_key)
        send_transaction_and_print_status(tx, self.network)