mktplace.mktplace_client module

Helper functions for creating and submitting marketplace transactions

mktplace.mktplace_client.interactive_client(url=None, name=None, keyfile=None)[source]

InterativeClient – utility function to simplify initialization of the MarketPlaceClient class in an interactive python shell.

Parameters:
  • -- base url for a validator (url) –
  • -- simple name of a player, e.g. 'market' (name) –
  • -- the name of the file from which keys should be retreived (keyfile) –
mktplace.mktplace_client.sign_message_with_transaction(transaction, key)[source]

Signs a transaction message or transaction :param transaction dict: :param key str: A signing key returns message, txnid tuple: The first 16 characters of a sha256 hexdigest.

class mktplace.mktplace_client.MarketPlaceClient(baseurl, creator=None, name='txnclient', keystring=None, keyfile=None, state=None, tokenstore=None, session=False)[source]

Bases: mktplace.mktplace_communication.MarketPlaceCommunication

The MarketPlaceClient class wraps transaction generation and submission for the Sawtooth Lake Digital Market.

Parameters:
  • baseurl (url) – the base URL for a Sawtooth Lake validator that supports an HTTP interface
  • creator (id) – the identifier for the participant generating transactions
  • keystring (str) – the wif format key used to sign transactions
  • keyfile (str) – the name of a file that contains the wif format key
  • state (MarketPlaceState) – ledger state used to test correctness of transactions prior to submission
create_session()[source]
delete_session()[source]
waitforcommit(txnid=None, timetowait=5, iterations=12)[source]

Wait until a specified transaction shows up in the ledger’s committed transaction list

Parameters:
  • txnid (id) – the transaction to wait for, the last transaction by default
  • timetowait (int) – time to wait between polling the ledger
  • iterations (int) – number of iterations to wait before giving up
exchange(payer, payee, count, offerids=None)[source]

Generate an exchange transaction for moving assets amongst holdings

Parameters:
  • payer (id) – the holding/liability from which assets will be transferred
  • payee (id) – the holding/liability into which assets will be transferred
  • count (int) – the number of assets that will be transferred from the payer holding/liability
  • offerids (list of id) – a list of offer identifiers that transform payer to payee transaction
Returns:

exchange transaction id

Return type:

id

register_asset(assettype, name='', description='', consumable=True, restricted=True, divisible=False)[source]

Register an asset with the ledger.

Parameters:
  • assettype (id) – the asset type identifier
  • name (str) – an optional name for the asset, unique for the current participant
  • description (str) – an optional description for the asset
Returns:

asset id

Return type:

id

unregister_asset(objectid)[source]

Unregister an asset.

Parameters:objectid (id) – the identifier for the asset object
Returns:unregister transaction identifier
Return type:id
update_asset_name(objectid, name)[source]
update_asset_description(objectid, description)[source]
register_assettype(name='', description='', restricted=True)[source]

Register an asset type.

Parameters:
  • name (str) – an optional name for the asset type, unique for the current participant
  • description (str) – an optional description for the asset type
Returns:

asset type id

Return type:

id

unregister_assettype(objectid)[source]

Unregister an asset type.

Parameters:objectid (id) – the identifier for the asset type object
Returns:unregister transaction identifier
Return type:id
update_assettype_name(objectid, name)[source]
update_assettype_description(objectid, description)[source]
register_exchangeoffer(iliability, oliability, ratio, **kwargs)[source]

Construct and post a transaction to register an exchange offer.

Parameters:
  • iliability (id) – identifier for the input liability (where payment is made)
  • oliability (id) – identifier for the output liability (where goods are given)
  • name (str) – an optional name for the asset type, unique for the current participant
  • description (str) – an optional description for the asset type
  • minimum (int) – an optional parameter noting the smallest number of input assets
  • maximum (int) – an optional parameter noting the largest number of input assets
  • execution (one of 'Any', 'ExecuteOnce', 'ExecuteOncePerParticipant') – optional flag indicating offer execution modifiers
Returns:

exchange offer id

Return type:

id

unregister_exchangeoffer(objectid)[source]

Revoke an exchange offer.

Parameters:objectid (id) – the identifier for the exchange offer
Returns:unregister transaction identifier
Return type:id
update_exchangeoffer_name(objectid, name)[source]
update_exchangeoffer_description(objectid, description)[source]
register_holding(account, asset, count, name='', description='')[source]

Register a holding.

Parameters:
  • account (id) – the identifier the account that scopes the holding
  • asset (id) – the identifier for the asset to store in the holding
  • count (int) – the initial number of assets to store in the holding
  • name (str) – an optional name for the holding, unique for the current participant
  • description (str) – an optional description for the holding
Returns:

holding id

Return type:

id

unregister_holding(objectid)[source]

Unregister a holding.

Parameters:objectid (id) – the identifier for the holding
Returns:unregister transaction identifier
Return type:id
update_holding_name(objectid, name)[source]
update_holding_description(objectid, description)[source]
register_liability(account, assettype, guarantor, count, name='', description='')[source]

Register a liability.

Parameters:
  • account (id) – the identifier the account that scopes the liability
  • assettype (id) – the identifier for the asset type to store in the liability
  • count (int) – the initial number of assets to store in the liability
  • name (str) – an optional name for the liability, unique for the current participant
  • description (str) – an optional description for the liability
Returns:

liability id

Return type:

id

unregister_liability(objectid)[source]

Unregister a liability.

Parameters:objectid (id) – the identifier for the liability
Returns:unregister transaction identifier
Return type:id
update_liability_name(objectid, name)[source]
update_liability_description(objectid, description)[source]
register_participant(name='', description='')[source]

Register a participant with the ledger.

Parameters:
  • name (str) – an optional name for the asset, unique for the current participant
  • description (str) – an optional description for the asset
Returns:

participant id

Return type:

id

unregister_participant(objectid)[source]

Unregister a participant.

Parameters:objectid (id) – the identifier for the participant
Returns:unregister transaction identifier
Return type:id
update_participant_name(objectid, name)[source]
update_participant_description(objectid, description)[source]
register_selloffer(iliability, oholding, ratio, **kwargs)[source]

Construct and post a transaction to register an SellOffer object

Parameters:
  • iliability (id) – identifier for the input liability (where payment is made)
  • oholding (id) – identifier for the output holding (where goods are given)
  • name (str) – an optional name for the asset type, unique for the current participant
  • description (str) – an optional description for the asset type
  • minimum (int) – an optional parameter noting the smallest number of input assets
  • maximum (int) – an optional parameter noting the largest number of input assets
  • execution (one of 'Any', 'ExecuteOnce', 'ExecuteOncePerParticipant') – optional flag indicating offer execution modifiers
Returns:

exchange offer id

Return type:

id

unregister_selloffer(objectid)[source]

Revoke a sell offer.

Parameters:objectid (id) – the identifier for the sell offer
Returns:unregister transaction identifier
Return type:id
update_selloffer_name(objectid, name)[source]
update_selloffer_description(objectid, description)[source]
register_account(name='', description='')[source]

Register an account with the ledger.

Parameters:
  • name (str) – an optional name for the asset, unique for the current participant
  • description (str) – an optional description for the asset
Returns:

account id

Return type:

id

unregister_account(objectid)[source]

Unregister an account.

Parameters:objectid (id) – the identifier for the account
Returns:unregister transaction identifier
Return type:id
update_account_name(objectid, name)[source]
update_account_description(objectid, description)[source]