コード例 #1
0
    def test_duplicate_name(self):
        # Create a mock store
        store = MockMarketPlaceGlobalStore()

        # Because we have not "registered" any participants, the name
        # should not be a duplicate
        update = participant_update.Register(minfo={'Name': 'participant'})
        self.assertTrue(update.is_valid_name(store))

        #  Put a participant in the store
        participant = participant_update.ParticipantObject(
            participantid='0000000000000000', minfo={
                'name': 'participant',
            })
        store[participant.ObjectID] = participant.dump()
        store.bind(store.i2n(participant.ObjectID), participant.ObjectID)

        # Because the participant name is in the store, the name should
        # not be a valid name as it is a duplicate
        update = participant_update.Register(minfo={'Name': 'participant'})
        self.assertFalse(update.is_valid_name(store))
コード例 #2
0
    def register_participant(self, name='', description=''):
        """
        Register a participant with the ledger.

        :param str name: an optional name for the asset, unique for the current
            participant
        :param str description: an optional description for the asset

        :return: participant id
        :rtype: id
        """
        update = participant_update.Register()

        update.Name = name
        update.Description = description

        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)