Пример #1
0
    def test_duplicate_name(self):
        # Create a mock store and put a participant in it
        participant = participant_update.ParticipantObject(
            participantid='0000000000000000', minfo={
                'name': 'participant',
            })
        store = MarketPlaceGlobalStore()
        store[participant.ObjectID] = participant.dump()

        # Because we have not "registered" any assets, the name
        # should not be a duplicate
        update = asset_update.Register(
            update_type=asset_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/asset')
        self.assertTrue(
            global_is_valid_name(store, '/asset',
                                 asset_update.Register.ObjectType,
                                 participant.ObjectID))

        # Add an asset to the store with the creator being the participant
        # we inserted initially
        asset = asset_update.AssetObject(objectid='0000000000000001',
                                         minfo={
                                             'name': '//participant/asset',
                                             'creator': participant.ObjectID
                                         })
        store[asset.ObjectID] = asset.dump()

        # Because the asset name is in the store, trying to register using
        # a relative name based upon creator and a fully-qualified name should
        # not be a valid name as it is a duplicate
        update = asset_update.Register(
            update_type=asset_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/asset')
        self.assertFalse(
            global_is_valid_name(store, '/asset',
                                 asset_update.Register.ObjectType,
                                 participant.ObjectID))

        update = asset_update.Register(
            update_type=asset_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='//participant/asset')
        self.assertFalse(
            global_is_valid_name(store, '//participant/asset',
                                 asset_update.Register.ObjectType,
                                 participant.ObjectID))
Пример #2
0
    def register_asset(self,
                       assettype,
                       name='',
                       description='',
                       consumable=True,
                       restricted=True,
                       divisible=False):
        """
        Register an asset with the ledger.

        :param id assettype: the asset type identifier
        :param str name: an optional name for the asset, unique for the current
            participant
        :param str description: an optional description for the asset

        :return: asset id
        :rtype: id
        """
        update = asset_update.Register()

        update.CreatorID = self.CreatorID
        update.AssetTypeID = assettype
        update.Name = name
        update.Description = description
        update.Consumable = consumable
        update.Restricted = restricted
        update.Divisible = divisible

        return self._register(update)
Пример #3
0
def _prepare_genesis_transactions(journal):
    logger.debug('prepare marketplace transactions for genesis block')

    # Set up a random key for generating the genesis objects, we
    # "trust" that the key is not kept. At some point this should be
    # revisited, suggestions about "burning" the private key
    signingkey = signed_object.generate_signing_key()
    identifier = signed_object.generate_identifier(signingkey)
    signnode = node.Node(identifier=identifier, signingkey=signingkey)

    # Create a participant for the global market
    txn = MarketPlaceTransaction()
    update = participant_update.Register(txn)
    update.Name = 'marketplace'
    update.Description = 'The ROOT participant for the marketplace'

    txn.Update = update

    txn.sign_from_node(signnode)
    journal.add_pending_transaction(txn)
    logger.info('Created market participant: %s', txn.Identifier)
    lasttxn = txn.Identifier

    mktid = update.ObjectID

    # Create an asset type for participants
    txn = MarketPlaceTransaction()
    update = asset_type_update.Register(txn)

    update.CreatorID = mktid

    # anyone can create participant assets for themselves
    update.Restricted = False

    update.Name = '/asset-type/participant'
    update.Description = 'Canonical type for participant assets'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created participant asset type: %s', txn.Identifier)
    lasttxn = txn.Identifier

    assettypeid = update.ObjectID

    # Create an asset type for random tokens
    txn = MarketPlaceTransaction()
    update = asset_type_update.Register(txn)

    update.CreatorID = mktid
    update.Restricted = True  # there is only one asset based on the token type
    update.Name = '/asset-type/token'
    update.Description = 'Canonical type for meaningless tokens that are ' \
                         'very useful for bootstrapping'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created token asset type: %s', txn.Identifier)
    lasttxn = txn.Identifier

    assettypeid = update.ObjectID

    # Create an asset for the tokens
    txn = MarketPlaceTransaction()
    update = asset_update.Register(txn)

    update.CreatorID = mktid
    update.AssetTypeID = assettypeid

    # anyone can create holdings with token instances
    update.Restricted = False

    # and these are infinitely replaceable
    update.Consumable = False

    update.Divisible = False
    update.Name = '/asset/token'
    update.Description = 'Canonical asset for tokens'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created token asset: %s', txn.Identifier)

    # Create an asset for the validation tokens
    txn = MarketPlaceTransaction()
    update = asset_update.Register(txn)

    update.CreatorID = mktid
    update.AssetTypeID = assettypeid
    update.Restricted = True  # these assets are only created by the market
    update.Consumable = True
    update.Divisible = False
    update.Name = '/asset/validation-token'
    update.Description = 'Canonical asset for validation tokens'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created validation token asset: %s', txn.Identifier)