PolySwarm Client Source-Based Documentation

API Reference

This page contains auto-generated API reference documentation 1.

balancemanager

Submodules

balancemanager.__main__
Module Contents
balancemanager.__main__.logger[source]
balancemanager.__main__.validate_optional_transfer_amount(ctx, param, value)[source]
balancemanager.__main__.validate_transfer_amount(ctx, param, value)[source]
balancemanager.__main__.polyswarm_client(func)[source]
balancemanager.__main__.cli(log, client_log, log_format)[source]
Entrypoint for the balance manager driver
Parameters
  • log (str) – Log level for balancemanger module logs

  • client_log (str) – Log level for all polyswarmclient module logs

  • log_format (str) – Choose either json, or text log format

balancemanager.__main__.deposit(polyswarmd_addr, keyfile, password, api_key, testing, insecure_transport, denomination, all, amount)[source]
Entrypoint to deposit NCT into a sidechain
Parameters
  • polyswarmd_addr (str) – Address for the polyswarmd server

  • keyfile (str) – Path to the keyfile

  • password (str) – Password to unlock keyfile

  • api_key (str) – ApiKey to access polyswarmd

  • testing (int) – Number of tests to run

  • insecure_transport (bool) – Flag to allow use of http instead of https

  • denomination (str) – Choose to interpret amount as nct, nct-gwei, or nct-wei

  • all (bool) – Choose to deposit the entire homechain balance

  • amount (float) – Amount of Nectar (NCT) to transfer

balancemanager.__main__.withdraw(polyswarmd_addr, keyfile, password, api_key, testing, insecure_transport, denomination, all, amount)[source]
Entrypoint to withdraw NCT from a sidechain into the homechain
Parameters
  • polyswarmd_addr (str) – Address for the polyswarmd server

  • keyfile (str) – Path to the keyfile

  • password (str) – Password to unlock keyfile

  • api_key (str) – ApiKey to access polyswarmd

  • testing (int) – Number of tests to run

  • insecure_transport (bool) – Flag to allow use of http instead of https

  • denomination (str) – Choose to interpret amount as nct, nct-gwei, or nct-wei

  • all (bool) – Choose to withdraw the entire sidechain balance

  • amount (float) – Amount of Nectar (NCT) to transfer (if not all)

balancemanager.__main__.maintain(polyswarmd_addr, keyfile, password, api_key, testing, insecure_transport, denomination, maximum, withdraw_target, confirmations, minimum, refill_amount)[source]
Entrypoint to withdraw NCT from a sidechain into the homechain
Parameters
  • polyswarmd_addr (str) – Address for the polyswarmd server

  • keyfile (str) – Path to the keyfile

  • password (str) – Password to unlock keyfile

  • api_key (str) – ApiKey to access polyswarmd

  • testing (int) – Number of tests to run

  • insecure_transport (bool) – Flag to allow use of http instead of https

  • denomination (str) – Choose to interpret amount as nct, nct-gwei, or nct-wei

  • maximum (int) – Maximum balance to before starting a withdrawal from sidechain

  • withdraw_target (int) – Target value after performing a withdrawal

  • confirmations (int) – Number of confirmations to wait to confirm a transfer occurred

  • minimum (float) – Value of NCT on sidechain where you want to transfer more NCT

  • refill_amount (float) – Value of NCT to transfer anytime the balance falls below the minimum

Package Contents

balancemanager.logger[source]
balancemanager.RELAY_LEEWAY = 5[source]
balancemanager.convert(client, denomination, amount)[source]
Convert the amount from it's original precision to 18 decimals
class balancemanager.BalanceManager(client, denomination, transfer_all, amount, testing=0, chains=None)[source]

Bases: object

Balance manager is used for single transfer events in either direction. Create a client, choose a chain and amount then run it.

run(self)[source]

Starts the client on whichever chain this uses.

run_oneshot(self)[source]

Runs run_task once

class balancemanager.Deposit(client, denomination, transfer_all, amount, testing=0)[source]

Bases: balancemanager.BalanceManager

Deposit only version of Balance Manager

class balancemanager.Withdraw(client, denomination, transfer_all, amount, testing=0)[source]

Bases: balancemanager.BalanceManager

Withdraw only version of Balance Manager

class balancemanager.Maintainer(client, denomination, confirmations, minimum, refill_amount, maximum, withdraw_target, testing=0)[source]

Bases: object

This class maintains a balance on the sidechain. It requires a base setup of a minimum balance. Optionally, it can take a maximum balance, so that earnings can automatically be transferred back to the homechain.

run(self)[source]

Starts the client. Have to run with both chains, or lots of nonce errors

polyswarmclient

Submodules

polyswarmclient.abstractambassador
Module Contents
polyswarmclient.abstractambassador.logger[source]
polyswarmclient.abstractambassador.MAX_TRIES = 10[source]
polyswarmclient.abstractambassador.BOUNTY_QUEUE_SIZE = 10[source]
polyswarmclient.abstractambassador.MAX_BOUNTIES_IN_FLIGHT = 10[source]
polyswarmclient.abstractambassador.MAX_BOUNTIES_PER_BLOCK = 1[source]
polyswarmclient.abstractambassador.BLOCK_DIVISOR = 1[source]
class polyswarmclient.abstractambassador.QueuedBounty(artifact_type, amount, ipfs_uri, duration, api_key=None)[source]

Bases: object

__repr__(self)[source]
class polyswarmclient.abstractambassador.AbstractAmbassador(client, testing=0, chains=None, watchdog=0, submission_rate=0)[source]

Bases: abc.ABC

classmethod connect(cls, polyswarmd_addr, keyfile, password, api_key=None, testing=0, insecure_transport=False, chains=None, watchdog=0, submission_rate=0)[source]

Connect the Ambassador to a Client.

Parameters
  • polyswarmd_addr (str) – URL of polyswarmd you are referring to.

  • keyfile (str) – Keyfile filename.

  • password (str) – Password associated with Keyfile.

  • api_key (str) – Your PolySwarm API key.

  • testing (int) – Number of testing bounties to use.

  • insecure_transport (bool) – Allow insecure transport such as HTTP?

  • chains (set(str)) – Set of chains you are acting on.

Returns

Ambassador instantiated with a Client.

Return type

AbstractAmbassador

run(self)[source]

Run the Client on all of our chains.

polyswarmclient.abstractarbiter
Module Contents
polyswarmclient.abstractarbiter.logger[source]
polyswarmclient.abstractarbiter.MAX_STAKE_RETRIES = 10[source]
class polyswarmclient.abstractarbiter.AbstractArbiter(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: object

classmethod connect(cls, polyswarmd_addr, keyfile, password, api_key=None, testing=0, insecure_transport=False, scanner=None, chains=None, artifact_types=None)[source]

Connect the Arbiter to a Client.

Parameters
  • polyswarmd_addr (str) – URL of polyswarmd you are referring to.

  • keyfile (str) – Keyfile filename.

  • password (str) – Password associated with Keyfile.

  • api_key (str) – Your PolySwarm API key.

  • testing (int) – Number of testing bounties to use.

  • insecure_transport (bool) – Allow insecure transport such as HTTP?

  • scanner (AbstractScanner) – Scanner for scanning artifacts

  • chains (set(str)) – Set of chains you are acting on.

  • artifact_types (list(ArtifactType)) – List of artifact types you support

Returns

Arbiter instantiated with a Client.

Return type

AbstractArbiter

run(self)[source]

Run the Client on the Arbiter’s chains.

polyswarmclient.abstractmicroengine
Module Contents
polyswarmclient.abstractmicroengine.logger[source]
class polyswarmclient.abstractmicroengine.AbstractMicroengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: object

classmethod connect(cls, polyswarmd_addr, keyfile, password, api_key=None, testing=0, insecure_transport=False, scanner=None, chains=None, artifact_types=None)[source]

Connect the Microengine to a Client.

Parameters
  • polyswarmd_addr (str) – URL of polyswarmd you are referring to.

  • keyfile (str) – Keyfile filename.

  • password (str) – Password associated with Keyfile.

  • api_key (str) – Your PolySwarm API key.

  • testing (int) – Number of testing bounties to use.

  • insecure_transport (bool) – Allow insecure transport such as HTTP?

  • scanner (Scanner) – Scanner instance to use.

  • chains (set(str)) – Set of chains you are acting on.

  • artifact_types (list(ArtifactType)) – List of artifact types you support

Returns

Microengine instantiated with a Client.

Return type

AbstractMicroengine

run(self)[source]

Run the Client on the Microengine’s chains.

polyswarmclient.abstractscanner
Module Contents
polyswarmclient.abstractscanner.logger[source]
class polyswarmclient.abstractscanner.ScanResult(bit=False, verdict=False, confidence=1.0, metadata='')[source]

Bases: object

Results from scanning one artifact

__repr__(self)[source]
class polyswarmclient.abstractscanner.AbstractScanner[source]

Bases: abc.ABC

Base Scanner class. To be overwritten with other scanning logic.

polyswarmclient.balanceclient
Module Contents
polyswarmclient.balanceclient.logger[source]
class polyswarmclient.balanceclient.BalanceClient(client)[source]

Bases: object

polyswarmclient.bloom
Module Contents
polyswarmclient.bloom.FILTER_BITS[source]
polyswarmclient.bloom.HASH_FUNCS = 8[source]
polyswarmclient.bloom.logger[source]
polyswarmclient.bloom.w3[source]
polyswarmclient.bloom.get_chunks_for_bloom(value_hash)[source]
Bloom filter helper function. Turn a value hash into
a series of chunks.
Parameters

value_hash (bytes) – Hash of to be encoded into the Bloom filter.

Yields

chunk (bytes) – Chunks of the value hash.

polyswarmclient.bloom.chunk_to_bloom_bits(chunk)[source]
Bloom filter helper function. Turn a chunk into a series of
actual bytes.
Parameters

chunk (bytes) – Byte encoded chunk.

polyswarmclient.bloom.get_bloom_bits(value)[source]
Bloom filter helper function. Get the Bloom bits of a
given value.
Parameters

value (bytes) – Value to be encoded into the Bloom filter.

class polyswarmclient.bloom.BloomFilter(value=0)[source]

Bases: numbers.Number

value[source]
__int__(self)[source]
add(self, value)[source]

Add a single byte value to the Bloom filter.

Parameters

value (bytes) – Byte encoded value to add to Bloom filter.

extend(self, iterable)[source]

Add an iterable of byte values to the bloom filter.

Parameters

iterable (Iterable[bytes]) – Iterable of byte values.

classmethod from_iterable(cls, iterable)[source]

Instantiate a bloom filter from a given iterable.

Parameters

iterable (Iterable[bytes]) – Iterable of byte values.

Returns

Instantiated BloomFilter.

Return type

BloomFilter

__contains__(self, value)[source]
__index__(self)[source]
_combine(self, other)[source]
__or__(self, other)[source]
__add__(self, other)[source]
_icombine(self, other)[source]
__ior__(self, other)[source]
__iadd__(self, other)[source]
polyswarmclient.bountiesclient
Module Contents
polyswarmclient.bountiesclient.logger[source]
class polyswarmclient.bountiesclient.PostBountyTransaction(client, artifact_type, amount, bounty_fee, artifact_uri, num_artifacts, duration, bloom)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.bountiesclient.PostAssertionTransaction(client, bounty_guid, bid, assertion_fee, mask, commitment)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_body(self)[source]
get_path(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.bountiesclient.RevealAssertionTransaction(client, bounty_guid, index, nonce, verdicts, metadata)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.bountiesclient.PostVoteTransaction(client, bounty_guid, votes, valid_bloom)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.bountiesclient.SettleBountyTransaction(client, bounty_guid)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.bountiesclient.BountiesClient(client)[source]

Bases: object

polyswarmclient.config
Module Contents
polyswarmclient.config.logger[source]
polyswarmclient.config.validate_apikey(ctx, param, value)[source]
Validates the API key passed in through click parameters
polyswarmclient.config.init_logging(loggers, log_format, loglevel=logging.WARNING)[source]
Logic to support JSON logging.
class polyswarmclient.config.LoggerConfig(loggers, log_format, log_level=logging.WARNING)[source]
LEVELS[source]
configure(self)[source]
set_level(self, new_level)[source]
polyswarmclient.corpus
Module Contents
polyswarmclient.corpus.logger[source]
polyswarmclient.corpus.MALICIOUS_BOOTSTRAP_URL[source]
polyswarmclient.corpus.ARCHIVE_PASSWORD[source]
class polyswarmclient.corpus.DownloadToFileSystemCorpus(base_dir=None)[source]

Bases: object

mal_path[source]
benign_path[source]
download_and_unpack(self)[source]
_get_pth_listing(self, p)[source]
get_malicious_file_list(self)[source]
get_benign_file_list(self)[source]
download_truth(self)[source]
polyswarmclient.events
Module Contents
polyswarmclient.events.logger[source]
class polyswarmclient.events.Callback[source]

Bases: object

Abstract callback class which is the parent to a number of child callback classes to be used in different scenarios.

Note

Classes which extend Callback are expected to impliment the run method.

register(self, f)[source]

Register a function to this Callback.

Parameters

f (function) – Function to register.

remove(self, f)[source]

Remove a function previously assigned to this Callback.

Parameters

f (function) – Function to remove.

class polyswarmclient.events.OnRunCallback[source]

Bases: polyswarmclient.events.Callback

Called upon entering the event loop for the first time, use for initialization

class polyswarmclient.events.OnNewBlockCallback[source]

Bases: polyswarmclient.events.Callback

Called upon receiving a new block, scheduled events triggered separately

class polyswarmclient.events.OnNewBountyCallback[source]

Bases: polyswarmclient.events.Callback

Called upon receiving a new bounty

class polyswarmclient.events.OnNewAssertionCallback[source]

Bases: polyswarmclient.events.Callback

Called upon receiving a new assertion

class polyswarmclient.events.OnRevealAssertionCallback[source]

Bases: polyswarmclient.events.Callback

Called upon receiving a new assertion reveal

class polyswarmclient.events.OnNewVoteCallback[source]

Bases: polyswarmclient.events.Callback

Called upon receiving a new arbiter vote

class polyswarmclient.events.OnQuorumReachedCallback[source]

Bases: polyswarmclient.events.Callback

Called upon a bounty reaching quorum

class polyswarmclient.events.OnSettledBountyCallback[source]

Bases: polyswarmclient.events.Callback

Called upon a bounty being settled

class polyswarmclient.events.OnInitializedChannelCallback[source]

Bases: polyswarmclient.events.Callback

Called upon a channel being initialized

class polyswarmclient.events.Schedule[source]

Bases: object

Generic Schedule class. Uses a PriorityQueue data structure to store Events.

empty(self)[source]

Return True if the queue is empty.

Returns

Is the queue empty.

Return type

boolean

peek(self)[source]

Return True if the queue is empty.

Returns

Tuple at the front of the queue if the queue is full, else None.

Return type

(block, event)

get(self)[source]

Pop the lowest valued block in the queue.

Returns

The lowest valued block in the PriorityQueue.

Return type

(block, event)

put(self, block, event)[source]

Add a tuple (block, event) to the PriorityQueue. Block signifies the priority of the event.

class polyswarmclient.events.Event(guid)[source]

Bases: object

Generic Event class. Stores GUID and can compare for equality and order Events.

Parameters

guid (str) – GUID of the event.

__eq__(self, other)[source]
__lt__(self, other)[source]
class polyswarmclient.events.RevealAssertion(guid, index, nonce, verdicts, metadata)[source]

Bases: polyswarmclient.events.Event

An assertion scheduled to be publically revealed

Parameters
  • guid (str) – GUID of the bounty being asserted on

  • index (int) – Index of the assertion to reveal

  • nonce (str) – Secret nonce used to reveal assertion

  • verdicts (List[bool]) – List of verdicts for each artifact in the bounty

  • metadata (str) – Optional metadata

class polyswarmclient.events.OnRevealAssertionDueCallback[source]

Bases: polyswarmclient.events.Callback

Called when an assertion is needing to be revealed

class polyswarmclient.events.VoteOnBounty(guid, votes, valid_bloom)[source]

Bases: polyswarmclient.events.Event

A scheduled vote from an arbiter :param guid: GUID of the bounty being voted on :type guid: str :param votes: List of votes for each artifact in the bounty :type votes: List[bool] :param valid_bloom: Is the bloom filter submitted with the bounty valid :type valid_bloom: bool

class polyswarmclient.events.OnVoteOnBountyDueCallback[source]

Bases: polyswarmclient.events.Callback

Called when a bounty is needing to be voted on

class polyswarmclient.events.SettleBounty(guid)[source]

Bases: polyswarmclient.events.Event

A bounty scheduled to be settled :param guid: GUID of the bounty being asserted on :type guid: str

class polyswarmclient.events.OnSettleBountyDueCallback[source]

Bases: polyswarmclient.events.Callback

Called when a bounty is needing to be settled

polyswarmclient.log_formatter
Module Contents
class polyswarmclient.log_formatter.ExtraTextFormatter[source]

Bases: logging.Formatter

Custom formatter that adds extra fields to the message string

format(self, record)[source]

Takes a LogRecord and sets record.message = record.msg % record.args This one does some extra work. It searches the record dict for some extra keys we use in the client. (specified as extra= in the logger statement) If it finds one, it grabs the dict and adds an extra %s arg to record.msg, and the dict value to the record.args tuple.

class polyswarmclient.log_formatter.JSONFormatter[source]

Bases: pythonjsonlogger.jsonlogger.JsonFormatter

Class to add custom JSON fields to our logger. Presently just adds a timestamp if one isn’t present and the log level. INFO: https://github.com/madzak/python-json-logger#customizing-fields

add_fields(self, log_record, record, message_dict)[source]
polyswarmclient.offersclient
Module Contents
polyswarmclient.offersclient.logger[source]
class polyswarmclient.offersclient.OffersClient(client)[source]

Bases: object

OffersClient to handle offers. Presently stores a given client and parameters.

polyswarmclient.parameters
Module Contents
class polyswarmclient.parameters.Parameters(p)[source]

Bases: object

Trivial wrapper around a dict but protected via a RWLock to allow updates

polyswarmclient.producer
Module Contents
polyswarmclient.producer.logger[source]
polyswarmclient.producer.KEY_TIMEOUT = 20[source]
class polyswarmclient.producer.Producer(client, redis_uri, queue, time_to_post)[source]
polyswarmclient.relayclient
Module Contents
polyswarmclient.relayclient.logger[source]
class polyswarmclient.relayclient.RelayDepositTransaction(client, amount)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.relayclient.RelayWithdrawTransaction(client, amount)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.relayclient.RelayClient(client)[source]

Bases: object

polyswarmclient.stakingclient
Module Contents
polyswarmclient.stakingclient.logger[source]
class polyswarmclient.stakingclient.StakeDepositTransaction(client, amount)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.stakingclient.StakeWithdrawTransaction(client, amount)[source]

Bases: polyswarmclient.transaction.AbstractTransaction

get_path(self)[source]
get_body(self)[source]
has_required_event(self, transaction_events)[source]
class polyswarmclient.stakingclient.StakingClient(client)[source]

Bases: object

polyswarmclient.transaction
Module Contents
polyswarmclient.transaction.logger[source]
polyswarmclient.transaction.LOG_MSG_ENGINE_TOO_SLOW = PLEASE REVIEW YOUR SCANNING LOGIC. Bounty inactive errors indicate that the microengine received the bounty, but was unable to respond to the bounty within the time window. Such errors are considered fatal during testing so you can easily identify them. If your engine is unable to respond within the time window on the live PolySwarm network, you risk losing the bid amount of the bounty at hand. We strongly encourage you to review your artifact scan process to identify areas where engine speed can be improved.[source]
class polyswarmclient.transaction.NonceManager(client, chain)[source]

Manages the nonce for some Ethereum chain

all_finished(self)[source]

Check that all tasks have finished

mark_update_nonce(self)[source]

Call this when the nonce is out of sync. This sets the update flag to true. The next acquire after being set will trigger an update

class polyswarmclient.transaction.AbstractTransaction(client, verifiers)[source]

Used to verify and post groups of transactions that make up a specific action.

For instance, when approving some funds to move, and calling a contract function that will consumer them.

has_required_event(self, transaction_events)[source]

Checks for existence of events in transaction logs, ensuring successful completion

Returns

True if the required event was in the list, false otherwise

get_path(self)[source]

Get the path of the route to build this transaction

Returns

Polyswarmd path to get the transaction data

Return type

str

get_body(self)[source]

Build the payload to send to polyswarmd :returns: Dict payload

verify(self, transactions)[source]

Check the given transactions against known expectations

Parameters

transactions (list) –

Returns

True if transactions match expectations. False otherwise

Return type

(bool)

polyswarmclient.utils
Module Contents
polyswarmclient.utils.logger[source]
polyswarmclient.utils.TASK_TIMEOUT = 1.0[source]
polyswarmclient.utils.MAX_WAIT[source]
polyswarmclient.utils.MAX_WORKERS = 4[source]
polyswarmclient.utils.to_string(value)[source]
polyswarmclient.utils.sha3_256(x)[source]
polyswarmclient.utils.sha3(seed)[source]
polyswarmclient.utils.int_to_bytes(i)[source]
polyswarmclient.utils.int_from_bytes(b)[source]
polyswarmclient.utils.bool_list_to_int(bs)[source]
polyswarmclient.utils.int_to_bool_list(i, expected_size)[source]
polyswarmclient.utils.guid_as_string(guid)[source]
polyswarmclient.utils.calculate_commitment(account, verdicts, nonce=None)[source]
polyswarmclient.utils.configure_event_loop()[source]
polyswarmclient.utils.asyncio_join()[source]
Gather all remaining tasks, assumes loop is not running
polyswarmclient.utils.asyncio_stop()[source]
Stop the main event loop
polyswarmclient.utils.exit(exit_status)[source]
Exit the program entirely.
polyswarmclient.utils.check_response(response)[source]
Check the status of responses from polyswarmd
Parameters

response – Response dict parsed from JSON from polyswarmd

Returns

True if successful else False

Return type

(bool)

polyswarmclient.utils.is_valid_ipfs_uri(ipfs_uri)[source]
Ensure that a given ipfs_uri is valid by checking length and base58 encoding.
Parameters

ipfs_uri (str) – ipfs_uri to validate

Returns

is this valid?

Return type

bool

polyswarmclient.verifiers
Module Contents
polyswarmclient.verifiers.logger[source]
polyswarmclient.verifiers.UNKNOWN_PARAMETER = XXX[source]
class polyswarmclient.verifiers.DecodedTransaction(to, value, data, abi, signature, parameters)[source]

This is a decoded representation of the transaction object returned by polyswarmd.

classmethod from_transaction(cls, transaction, abi)[source]

Parse a transaction from data returned from polyswarmd.

Parameters
  • transaction (dict) – Transaction to be simplified

  • abi (str, list[str]) – ABI of the expected function call

Returns

If valid, returns a SimplifiedTransaction

Return type

DecodedTransaction

Raises

ValueError – If invalid transaction is provided

__repr__(self)[source]
class polyswarmclient.verifiers.AbstractTransactionVerifier(parameters)[source]

Verifier is used to verify the details of a single transaction.

ABI = ['', []][source]
verify(self, transaction)[source]

Called when a list of transactions were returned from polyswarmd. This function will verify the transactions, and determines if the transactions are expected.

Parameters

transaction – Transaction representation returned from polyswarmd

Returns

True if valid and expected

__repr__(self)[source]
class polyswarmclient.verifiers.NctApproveVerifier(amount)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['approve', ['address', 'uint256']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.NctTransferVerifier(amount)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['transfer', ['address', 'uint256']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.PostBountyVerifier(artifact_type, amount, artifact_uri, num_artifacts, duration, bloom)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['postBounty', ['uint128', 'uint256', 'uint256', 'string', 'uint256', 'uint256', 'uint256[8]']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.PostAssertionVerifier(bounty_guid, bid, mask, commitment)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['postAssertion', ['uint128', 'uint256', 'uint256', 'uint256']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.RevealAssertionVerifier(bounty_guid, index, nonce, verdicts, metadata)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['revealAssertion', ['uint128', 'uint256', 'uint256', 'uint256', 'string']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.PostVoteVerifier(bounty_guid, votes, valid_bloom)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['voteOnBounty', ['uint128', 'uint256', 'bool']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.SettleBountyVerifier(bounty_guid)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['settleBounty', ['uint128']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.StakingDepositVerifier(amount)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['deposit', ['uint256']][source]
verify(self, transaction)[source]
class polyswarmclient.verifiers.StakingWithdrawVerifier(amount)[source]

Bases: polyswarmclient.verifiers.AbstractTransactionVerifier

ABI = ['withdraw', ['uint256']][source]
verify(self, transaction)[source]

Package Contents

class polyswarmclient.BalanceClient(client)[source]

Bases: object

class polyswarmclient.BountiesClient(client)[source]

Bases: object

class polyswarmclient.StakingClient(client)[source]

Bases: object

class polyswarmclient.OffersClient(client)[source]

Bases: object

OffersClient to handle offers. Presently stores a given client and parameters.

class polyswarmclient.RelayClient(client)[source]

Bases: object

class polyswarmclient.NonceManager(client, chain)[source]

Manages the nonce for some Ethereum chain

all_finished(self)

Check that all tasks have finished

mark_update_nonce(self)

Call this when the nonce is out of sync. This sets the update flag to true. The next acquire after being set will trigger an update

polyswarmclient.asyncio_join()[source]
Gather all remaining tasks, assumes loop is not running
polyswarmclient.asyncio_stop()[source]
Stop the main event loop
polyswarmclient.configure_event_loop()[source]
polyswarmclient.exit(exit_status)[source]
Exit the program entirely.
polyswarmclient.MAX_WAIT[source]
polyswarmclient.check_response(response)[source]
Check the status of responses from polyswarmd
Parameters

response – Response dict parsed from JSON from polyswarmd

Returns

True if successful else False

Return type

(bool)

polyswarmclient.is_valid_ipfs_uri(ipfs_uri)[source]
Ensure that a given ipfs_uri is valid by checking length and base58 encoding.
Parameters

ipfs_uri (str) – ipfs_uri to validate

Returns

is this valid?

Return type

bool

polyswarmclient.logger[source]
polyswarmclient.w3[source]
polyswarmclient.REQUEST_TIMEOUT = 300.0[source]
polyswarmclient.MAX_ARTIFACTS = 256[source]
polyswarmclient.RATE_LIMIT_SLEEP = 2.0[source]
class polyswarmclient.Client(polyswarmd_addr, keyfile, password, api_key=None, tx_error_fatal=False, insecure_transport=False)[source]

Bases: object

Client to connected to a Ethereum wallet as well as a polyswarmd instance.

Parameters
  • polyswarmd_addr (str) – URI of polyswarmd you are referring to.

  • keyfile (str) – Keyfile filename.

  • password (str) – Password associated with keyfile.

  • api_key (str) – Your PolySwarm API key.

  • tx_error_fatal (bool) – Transaction errors are fatal and exit the program

  • insecure_transport (bool) – Allow insecure transport such as HTTP?

class __GetArtifacts(client, ipfs_uri, api_key=None)[source]

Bases: object

run(self, chains=None)[source]

Run the main event loop

Parameters

chains (set(str)) – Set of chains to operate on. Defaults to {‘home’, ‘side’}

sign_transactions(self, transactions)[source]

Sign a set of transactions

Parameters

transactions (List[Transaction]) – The transactions to sign

Returns

The signed transactions

Return type

List[Transaction]

static to_wei(amount, unit='ether')[source]
static from_wei(amount, unit='ether')[source]
get_artifacts(self, ipfs_uri, api_key=None)[source]

Get an iterator to return artifacts.

Parameters
  • ipfs_uri (str) – URI where artificats are located

  • api_key (str) – Override default API key

Returns

__GetArtifacts iterator

schedule(self, expiration, event, chain)[source]

Schedule an event to execute on a particular block

Parameters
  • expiration (int) – Which block to execute on

  • event (Event) – Event to trigger on expiration block

  • chain (str) – Which chain to operate on

ambassador

Submodules

ambassador.__main__
Module Contents
ambassador.__main__.logger[source]
ambassador.__main__.choose_backend(backend)[source]
Resolves amabassador name string to implementation
Parameters

backend (str) – Name of the backend to load, either one of the predefined implementations or the name of a module to load (module:ClassName syntax or default of module:Ambassador)

Returns

Ambassador class of the selected implementation

Return type

(Class)

Raises

(Exception) – If backend is not found

ambassador.__main__.main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend, testing, insecure_transport, chains, watchdog, log_format, submission_rate)[source]
Entrypoint for the ambassador driver
Parameters
  • log (str) – Logging level for all app logs

  • client_log (str) – Logging level for all polyswarmclient logs

  • polyswarmd_addr (str) – Address of polyswarmd

  • keyfile (str) – Path to private key file to use to sign transactions

  • password (str) – Password to decrypt the encrypted private key

  • backend (str) – Backend implementation to use

  • api_key (str) – API key to use with polyswarmd

  • testing (int) – Mode to process N bounties then exit (optional)

  • insecure_transport (bool) – Connect to polyswarmd without TLS

  • chains (List[str]) – Chain(s) to operate on

  • watchdog (int) – Number of blocks to look back and see if bounties are being submitted

  • log_format (str) – Format to output logs in. text or json

ambassador.eicar
Module Contents
ambassador.eicar.logger[source]
ambassador.eicar.EICAR[source]
ambassador.eicar.NOT_EICAR = this is not malicious[source]
ambassador.eicar.ARTIFACTS = [None, None][source]
ambassador.eicar.BOUNTY_TEST_DURATION_BLOCKS[source]
class ambassador.eicar.Ambassador(client, testing=0, chains=None, watchdog=0, submission_rate=30)[source]

Bases: polyswarmclient.abstractambassador.AbstractAmbassador

Ambassador which submits the EICAR test file

ambassador.filesystem
Module Contents
ambassador.filesystem.logger[source]
ambassador.filesystem.ARTIFACT_DIRECTORY[source]
ambassador.filesystem.ARTIFACT_BLACKLIST[source]
ambassador.filesystem.BOUNTY_TEST_DURATION_BLOCKS[source]
class ambassador.filesystem.Ambassador(client, testing=0, chains=None, watchdog=0, submission_rate=30)[source]

Bases: polyswarmclient.abstractambassador.AbstractAmbassador

Ambassador which submits artifacts from a directory

microengine

Submodules

microengine.__main__
Module Contents
microengine.__main__.logger[source]
microengine.__main__.choose_backend(backend)[source]
Resolves microengine name string to implementation
Parameters

backend (str) – Name of the backend to load, either one of the predefined implementations or the name of a module to load (module:ClassName syntax or default of module:Microengine)

Returns

Microengine class of the selected implementation

Return type

(Class)

Raises

(Exception) – If backend is not found

microengine.__main__.main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend, testing, insecure_transport, chains, log_format, artifact_type)[source]
Entrypoint for the microengine driver
Parameters
  • log (str) – Logging level for all app logs

  • client_log (str) – Logging level for all polyswarmclient logs

  • polyswarmd_addr (str) – Address of polyswarmd

  • keyfile (str) – Path to private key file to use to sign transactions

  • password (str) – Password to decrypt the encrypted private key

  • backend (str) – Backend implementation to use

  • api_key (str) – API key to use with polyswarmd

  • testing (int) – Mode to process N bounties then exit (optional)

  • insecure_transport (bool) – Connect to polyswarmd without TLS

  • chains (list[str]) – List of chains on which to scan artifacts

  • log_format (str) – Format to output logs in. text or json

  • artifact_type (list[str]) – List of artifact types to scan

microengine.clamav
Module Contents
microengine.clamav.logger[source]
microengine.clamav.CLAMD_HOST[source]
microengine.clamav.CLAMD_PORT[source]
microengine.clamav.CLAMD_TIMEOUT = 30.0[source]
class microengine.clamav.Scanner[source]

Bases: polyswarmclient.abstractscanner.AbstractScanner

class microengine.clamav.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

Microengine which scans samples through clamd.

Parameters
  • client (Client) – Client to use

  • testing (int) – How many test bounties to respond to

  • chains (set[str]) – Chain(s) to operate on

microengine.eicar
Module Contents
microengine.eicar.logger[source]
microengine.eicar.EICAR[source]
class microengine.eicar.Scanner[source]

Bases: polyswarmclient.abstractscanner.AbstractScanner

class microengine.eicar.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

Microengine which tests for the EICAR test file.

Parameters
  • client (Client) – Client to use

  • testing (int) – How many test bounties to respond to

  • chains (set[str]) – Chain(s) to operate on

microengine.multi
Module Contents
microengine.multi.logger[source]
microengine.multi.BACKENDS[source]
class microengine.multi.Scanner[source]

Bases: polyswarmclient.abstractscanner.AbstractScanner

class microengine.multi.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

Microengine which aggregates multiple sub-microengines

microengine.producer
Module Contents
microengine.producer.logger[source]
microengine.producer.REDIS_ADDR[source]
microengine.producer.QUEUE[source]
microengine.producer.TIME_TO_POST_ASSERTION = 4[source]
microengine.producer.KEY_TIMEOUT = 20[source]
class microengine.producer.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

microengine.scratch
Module Contents
microengine.scratch.logger[source]
class microengine.scratch.Scanner[source]

Bases: polyswarmclient.abstractscanner.AbstractScanner

class microengine.scratch.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

Scratch microengine is the same as the default behavior.

Parameters
  • client (Client) – Client to use

  • testing (int) – How many test bounties to respond to

  • chains (set[str]) – Chain(s) to operate on

microengine.yara
Module Contents
microengine.yara.logger[source]
microengine.yara.RULES_DIR[source]
class microengine.yara.Scanner[source]

Bases: polyswarmclient.abstractscanner.AbstractScanner

class microengine.yara.Microengine(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractmicroengine.AbstractMicroengine

Microengine which matches samples against yara rules

arbiter

Subpackages

arbiter.verbatimdb
Submodules
arbiter.verbatimdb.__main__
Module Contents
arbiter.verbatimdb.__main__.main(malicious, benign, output, log_format)[source]
arbiter.verbatimdb.db
Module Contents
arbiter.verbatimdb.db.generate_db(db_file, malicious_dir, benign_dir)[source]
arbiter.verbatimdb.db.insert(cursor, path, result)[source]

Submodules

arbiter.__main__
Module Contents
arbiter.__main__.logger[source]
arbiter.__main__.choose_backend(backend)[source]
Resolves arbiter name string to implementation
Parameters

backend (str) – Name of the backend to load, either one of the predefined implementations or the name of a module to load (module:ClassName syntax or default of module:Arbiter)

Returns

Arbiter class of the selected implementation

Return type

(Class)

Raises

(Exception) – If backend is not found

arbiter.__main__.main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend, testing, insecure_transport, chains, log_format, artifact_type)[source]
Entrypoint for the arbiter driver
Parameters
  • log (str) – Logging level for all app logs

  • client_log (str) – Logging level for all polyswarmclient logs

  • polyswarmd_addr (str) – Address of polyswarmd

  • keyfile (str) – Path to private key file to use to sign transactions

  • password (str) – Password to decrypt the encrypted private key

  • backend (str) – Backend implementation to use

  • api_key (str) – API key to use with polyswarmd

  • testing (int) – Mode to process N bounties then exit (optional)

  • insecure_transport (bool) – Connect to polyswarmd without TLS

  • chains (List[str]) – Chain(s) to operate on

  • log_format (str) – Format to output logs in. text or json

  • artifact_type (list[str]) – List of artifact types to scan

arbiter.clamav
Module Contents
arbiter.clamav.logger[source]
class arbiter.clamav.Arbiter(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractarbiter.AbstractArbiter

Arbiter which scans samples through clamd.

Re-uses the scanner from the clamav microengine

Parameters
  • client (Client) – Client to use

  • testing (int) – How many test bounties to respond to

  • chains (set[str]) – Chain(s) to operate on

arbiter.producer
Module Contents
arbiter.producer.logger[source]
arbiter.producer.REDIS_ADDR[source]
arbiter.producer.QUEUE[source]
arbiter.producer.TIME_TO_POST_VOTE = 4[source]
class arbiter.producer.Arbiter(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractarbiter.AbstractArbiter

arbiter.verbatim
Module Contents
arbiter.verbatim.logger[source]
arbiter.verbatim.ARTIFACT_DIRECTORY[source]
arbiter.verbatim.EICAR[source]
class arbiter.verbatim.Arbiter(client, testing=0, scanner=None, chains=None, artifact_types=None)[source]

Bases: polyswarmclient.abstractarbiter.AbstractArbiter

Arbiter which matches hashes to a database of known samples

worker

Submodules

worker.__main__
Module Contents
worker.__main__.logger[source]
worker.__main__.choose_backend(backend)[source]
Resolves scanner name string to implementation
Parameters
  • backend (str) – Name of the backend to load, either one of the predefined implementations or the name of a module

  • load (to) –

  • (module – ClassName syntax or default of module:Scanner)

Returns

Scanner class of the selected implementation

Return type

(Class)

Raises

(Exception) – If backend is not found

worker.__main__.main(log, client_log, redis_addr, queue, backend, tasks, download_limit, scan_limit, api_key, testing, log_format)[source]
Entrypoint for the worker driver
Parameters
  • log (str) – Logging level for all app logs

  • client_log (str) – Logging level for all polyswarmclient logs

  • redis_addr (str) – Address of redis

  • backend (str) – Backend implementation to use

  • queue (str) – Name of queue to listen on

  • tasks (int) – Number of simultaneous tasks this worker runs

  • download_limit (int) – Number of simultaneous downloads this worker can handle

  • scan_limit (int) – Number of simultaneous scans this worker can handle

  • api_key (str) – API key to use with polyswarmd

  • testing (int) – Mode to process N bounties then exit (optional)

  • log_format (str) – Format to output logs in. text or json

Package Contents

worker.logger[source]
worker.REQUEST_TIMEOUT = 5.0[source]
exception worker.ApiKeyException[source]

Bases: Exception

exception worker.ExpiredException[source]

Bases: Exception

class worker.Worker(redis_addr, queue, task_count=1, download_limit=1, scan_limit=1, api_key=None, testing=0, scanner=None)[source]

Bases: object

run(self)[source]
1

Created with sphinx-autoapi

polyswarm-client is a convenient library on which to build PolySwarm market participants.

Here you’ll find auto-generated documentation based on the polyswarm-client source code.

Consulting these low level details is unnecessary for developing a successful PolySwarm participant. Most users will instead want to consult the PolySwarm Documentation.

Developers interested in low level polyswarm-client details can do so by navigating to “API Reference” on the left.