API

Utils

class simplecoin.utils.Benchmark(name)[source]
class simplecoin.utils.ShareTracker(algo)[source]
accepted
algo
count_slice(slc)[source]
dup_efficiency
efficiency
hashrate(typ='acc')[source]
low_efficiency
rejected
stale_efficiency
total
class simplecoin.utils.ShareTypeTracker(share_type)[source]
simplecoin.utils.anon_users(*args, **kwargs)[source]
simplecoin.utils.collect_pool_stats()[source]

Collects the necessary data to render the /pool_stats view or the API

simplecoin.utils.collect_user_stats(user_address)[source]

Accumulates all aggregate user data for serving via API or rendering into main user stats page

simplecoin.utils.get_alerts(*args, **kwargs)[source]
simplecoin.utils.get_past_chain_profit()[source]
simplecoin.utils.get_pool_hashrate(*args, **kwargs)[source]

Retrieves the pools hashrate average for the last 10 minutes.

simplecoin.utils.last_block_time(algo, merged=False)[source]

Retrieves the last time a block was solved using progressively less accurate methods. Essentially used to calculate round time. TODO XXX: Add pool selector to each of the share queries to grab only x11, etc

simplecoin.utils.orphan_percentage(*args, **kwargs)[source]
simplecoin.utils.pool_share_tracker(*args, **kwargs)[source]

Get accepted and rejected share count totals for the last month

simplecoin.utils.resort_recent_visit(recent)[source]

Accepts a new dictionary of recent visitors and calculates what percentage of your total visits have gone to that address. Used to dim low percentage addresses. Also sortes showing most visited on top.

simplecoin.utils.time_format(seconds)[source]
simplecoin.utils.validate_message_vals(address, **kwargs)[source]
simplecoin.utils.validate_str_perc(perc, round=Decimal('0.01'))[source]

Tries to convert a var representing an 0-100 scale percentage into a mathematically useful Python Decimal. Default is rounding to 0.01%

Then checks to ensure decimal is within valid bounds

simplecoin.utils.verify_message(address, curr, message, signature)[source]

Models

class simplecoin.models.Block(**kwargs)[source]

This class stores metadata on all blocks found by the pool

algo
algo_obj
average_hashrate
chain_distrib()[source]
chain_profitability()[source]

Creates a dictionary that is keyed by chainid to represent the BTC earned per number of shares for every share chain that helped solve this block

confirms_remaining
contributed

Total fees + donations associated with this block

currency
currency_obj
difficulty
duration
found_at
hash
hashes_to_solve
height
id
luck
mature
merged
orphan
shares_to_solve

Total shares that were required to solve the block

standard_join = ['status', 'merged', 'currency', 'worker', 'explorer_link', 'luck', 'total_value', 'difficulty', 'duration', 'found_at', 'time_started']
status
time_started
timestamp
total_value
transaction_fees
user
worker
class simplecoin.models.ChainPayout(**kwargs)[source]
amount
block
block_id
chain_shares
chainid
config_obj
distribute()[source]
donations
fees
hashes
make_credit_obj(user, address, currency, shares)[source]

Makes the appropriate credit object given a few details. Payout amount too be calculated.

mhashes
payout_shares
solve_slice
class simplecoin.models.Credit(**kwargs)[source]

A credit for currency directly crediting a users balance. These have no intermediary exchanges.

address
amount
block
block_id
currency
currency_obj
cut_perc
fee_perc
height
hr_fee_perc
hr_pd_perc
id
classmethod make_credit(currency, block, **kwargs)[source]
mined
payable
payable_amount
payout
payout_id
pd_perc
perc_applied
sharechain_id
sharechain_title
source
standard_join = ['status', 'created_at', 'explorer_link', 'text_perc_applied', 'mined', 'height', 'transaction_id']
status
text_perc_applied
type
user
class simplecoin.models.CreditExchange(**kwargs)[source]

A credit that needs a sale and a buy to get to the correct currency

address
amount
block
block_id
buy_amount
buy_req
buy_req_id
currency
fee_perc
final_amount
id
payable
payable_amount
payout
payout_id
pd_perc
sell_amount
sell_req
sell_req_id
sharechain_id
source
status
type
user
class simplecoin.models.DeviceSlice(**kwargs)[source]

An data sample that pertains to a single workers device. Currently used to temperature and hashrate.

classmethod combine(*lst)

Takes an iterable and combines the values. Usually either returns an average or a sum. Can assume at least one item in list

device
from_db = {0: 'hashrate', 1: 'temperature'}
get_stat(stat)[source]
key

alias of Key

keys = ['user', 'worker', 'device', 'stat_val']
set_stat(stat)[source]
span
span_config = [{'window': datetime.timedelta(0, 3600), 'slice': datetime.timedelta(0, 60)}, {'window': datetime.timedelta(1), 'slice': datetime.timedelta(0, 300)}, {'window': datetime.timedelta(30), 'slice': datetime.timedelta(0, 3600)}]
stat
stat_val
time
to_db = {'temperature': 1, 'hashrate': 0}
user
value
worker
class simplecoin.models.Payout(**kwargs)[source]
address
amount
count
created_at
currency
currency_obj
id
payout_currency
status
timestamp
transaction
transaction_id
user
class simplecoin.models.PayoutAddress(**kwargs)[source]
address
classmethod create(address, currency)[source]
currency
exchangeable
user
class simplecoin.models.ShareSlice(**kwargs)[source]
SHARE_TYPES = ['acc', 'low', 'dup', 'stale']
algo
classmethod combine(*lst)

Takes a query list and combines the values. Usually either returns an average or a sum. Can assume at least one item in ql

key

alias of Key

keys = ['user', 'worker', 'algo', 'share_type']
share_type
span
span_config = [{'window': datetime.timedelta(0, 3600), 'slice': datetime.timedelta(0, 60)}, {'window': datetime.timedelta(1), 'slice': datetime.timedelta(0, 300)}, {'window': datetime.timedelta(30), 'slice': datetime.timedelta(0, 3600)}]
time
user
value
worker
class simplecoin.models.TimeSlice[source]

An time abstracted data sample that pertains to a single worker. Currently used to represent accepted and rejected shares.

classmethod add_value(user, value, time, worker)[source]
classmethod compress(span, delete=True)[source]
classmethod create(user, worker, algo, value, time)[source]
end_time
classmethod floor_time(time, span, stamp=False)[source]
classmethod get_span(lower=None, upper=None, stamp=False, ret_query=False, slice_size=None, **kwargs)[source]

A utility to grab a group of slices and automatically compress smaller slices into larger slices

address, worker, and algo are just filters. They may be a single string or list of strings.

upper and lower are datetimes.

item_key
class simplecoin.models.TradeRequest(**kwargs)[source]

Used to provide info necessary to external applications for trading currencies

Created rows will be checked + updated externally

classmethod create(currency, quantity)[source]
created_at
credits
currency
distribute()[source]
exchanged_quantity
fees
id
quantity
status
type
class simplecoin.models.Transaction(**kwargs)[source]
confirmed
created_at
currency
currency_obj
id
network_fee
standard_join = ['txid', 'confirmed', 'created_at', 'currency', '__dont_mongo']
status
timestamp
txid
url_for
class simplecoin.models.UserSettings(**kwargs)[source]
addresses
anon
apply(shares, user_currency, block_currency, valid_currencies)[source]

Given a share amount, a currency we’re paying out, and the valid exchangeable currencies we return a new distribution of shares among some number of addresses.

classmethod create(user, pdonate_perc, spayout_perc, spayout_addr, spayout_curr, del_spayout_addr, anon, set_addrs)[source]
exchangeable_addresses
hr_pdonation_perc
hr_perc
hr_spayout_perc
pdonation_perc
spayout_addr
spayout_curr
spayout_perc
unexchangeable_addresses
classmethod update(address, set_addrs, del_addrs, pdonate_perc, spayout_perc, spayout_addr, spayout_curr, del_spayout_addr, anon)[source]
user
simplecoin.models.average_combine

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
def f(cls, arg1, arg2, ...): ... f = classmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.

simplecoin.models.make_upper_lower(trim=None, span=None, offset=None, clip=None, fmt='dt')[source]

Generates upper and lower bounded datetime objects.

simplecoin.models.sum_combine

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
def f(cls, arg1, arg2, ...): ... f = classmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.

Scheduled Tasks

simplecoin.scheduler.cache_profitability()[source]

Calculates the profitability from recent blocks

simplecoin.scheduler.cache_user_donation()[source]

Grab all user donations and loop through them then cache donation %

simplecoin.scheduler.chain_cleanup(chain, dont_simulate)[source]

Handles removing all redis share slices that we are fairly certain won’t be needed to credit a block if one were to be solved in the future.

simplecoin.scheduler.collect_minutes()[source]

Grabs all the pending minute shares out of redis and puts them in the database

simplecoin.scheduler.collect_ppagent_data()[source]

Grabs all the pending ppagent data points

simplecoin.scheduler.compress_five_minute()[source]
simplecoin.scheduler.compress_minute()[source]
simplecoin.scheduler.compress_slices()[source]
simplecoin.scheduler.create_payouts()[source]

Groups payable payouts at the end of the day by currency for easier paying out and database compaction, allowing deletion of regular payout records.

simplecoin.scheduler.create_trade_req(typ)[source]

Takes all the credits in need of exchanging (either buying or selling, not both) and attaches them to a new trade request.

simplecoin.scheduler.credit_block(redis_key, simulate=False)[source]

Calculates credits for users from share records for the latest found block.

simplecoin.scheduler.credit_cleanup(days_ago=7, batch_size=10000, sleep=1, dont_simulate=True)[source]
simplecoin.scheduler.crontab(func)[source]

Handles rolling back SQLAlchemy exceptions to prevent breaking the connection for the whole scheduler. Also records timing information into the cache

simplecoin.scheduler.distributor(*args, **kwargs)[source]
simplecoin.scheduler.generate_credits(dont_simulate=True)[source]

Loops through all the blocks that haven’t been credited out and attempts to process them

simplecoin.scheduler.leaderboard()[source]
simplecoin.scheduler.main()[source]
simplecoin.scheduler.reload_cached()[source]

Recomputes all the cached values that normally get refreshed by tasks. Good to run if celery has been down, site just setup, etc.

simplecoin.scheduler.server_status()[source]

Periodically poll the backend to get number of workers and other general status information.

simplecoin.scheduler.share_cleanup(dont_simulate=True)[source]

Runs chain_cleanup on each chain.

simplecoin.scheduler.update_block_state(block_id=None)[source]

Loops through blocks (default immature and non-orphaned blocks)

If block_id is passed, instead of the checking the default blocks, all blocks of the same currency of a >= id will be updated.

First checks to see if blocks are orphaned, then it checks to see if they are now matured.

simplecoin.scheduler.update_network()[source]

Queries the RPC servers confirmed to update network stats information.

simplecoin.scheduler.update_online_workers()[source]
Grabs data on all currently connected clients. Forms a dictionary of this form:
dict(address=dict(worker_name=dict(powerpool_id=connection_count)))

And caches each addresses connection summary as a single cache key.

Views

RPC Views

simplecoin.rpc_views.api_error_handler(exc)[source]
simplecoin.rpc_views.associate_payouts()[source]

Used to update a SC Payout with a network transaction. This will create a new CoinTransaction object and link it to the transactions to signify that the transaction has been processed.

simplecoin.rpc_views.check_signature()[source]
simplecoin.rpc_views.confirm_transactions()[source]

Used to confirm that a transaction is now complete on the network.

simplecoin.rpc_views.get_payouts()[source]

Used by remote procedure call to retrieve a list of payout amounts to be processed. Transaction information is signed for safety.

simplecoin.rpc_views.get_trade_requests()[source]

Used by remote procedure call to retrieve a list of sell requests to be processed. Transaction information is signed for safety.

simplecoin.rpc_views.sign(data, code=200)[source]
simplecoin.rpc_views.update_trade_requests()[source]

Used as a response from an rpc sell request system. This will update the amount received for a sell request and its status. Both request and response are signed.

Config Objects

class simplecoin.config.Algo(bootstrap)[source]
defaults = {'enabled': True}
class simplecoin.config.AlgoKeeper(configs)[source]
active_algos()[source]
type_map = {'default': <class 'simplecoin.config.Algo'>}
class simplecoin.config.Chain(bootstrap)[source]
algo
calc_shares(block_payout)[source]

Pass a block_payout object with only chain ID and blockhash populated and compute share amounts

currencies
defaults = {'safety_margin': 2, 'currencies': [], 'block_bonus': '0'}
max_indexes = 1000
min_index = 0
requires = ['type', 'fee_perc', '_algo', '_currencies', 'safety_margin']
class simplecoin.config.ChainKeeper(configs)[source]
type_map = {'pplns': <class 'simplecoin.config.PPLNSChain'>, 'prop': <class 'simplecoin.config.PropChain'>}
class simplecoin.config.ConfigChecker(cfg, app)[source]

This class provides various methods for validating config values and checks configuration values and makes sure they’re properly filled out.

It needs a lot of expansion :/

Currently validates the following keys: pool_payout_addr currencies

check_is_bcaddress(val)[source]

Helper method: Checks a value for truthiness

check_truthiness(val)[source]

Helper method: Checks a value for truthiness

check_type(val, obj_type)[source]

Helper method: Checks a value to make sure its the correct type

lookup_key(key, nested=None)[source]

Helper method: Checks the config for the specified key and raises an error if not found

class simplecoin.config.ConfigObject(bootstrap)[source]
defaults = {}
requires = []
class simplecoin.config.Currency(bootstrap)[source]
algo
defaults = {'tx_explore': None, 'coinserv': {}, 'sellable': False, 'block_explore': None, 'minimum_payout': '0.00000001', 'pool_payout_addr': None, 'buyable': False, 'merged': False}
pool_payout
requires = ['_algo', 'name', 'address_version', 'trans_confirmations', 'block_time', 'block_mature_confirms']
class simplecoin.config.CurrencyKeeper(configs)[source]
available_versions
buyable_currencies
lookup_payable_addr(address)[source]

Checks an address to determine if its a valid and payable(buyable) address. Typically used to validate a username address. Returns the payable currency object for that version.

When calling this function you should always expect exceptions to be raised.

!!! This function assumes that a currency will not be configured as buyable if there is a version conflict with another currency.

Although it makes this assumption - it should return a consistent Currency obj even if configuration is incorrect

sellable_currencies
type_map = {'default': <class 'simplecoin.config.Currency'>}
unbuyable_currencies
unmineable_currencies
unsellable_currencies
validate_bc_address(bc_address_str)[source]

The go-to function for all your bitcoin style address validation needs.

Expects to receive a string believed to represent a bitcoin address Raises appropriate errors if any checks are failed, otherwise returns a list of Currency objects that have the same addr version.

class simplecoin.config.Keeper(configs)[source]
class simplecoin.config.Location(bootstrap)[source]
required = ['location_acronym', 'location', 'country_flag', 'address']
stratums_by_algo()[source]
class simplecoin.config.LocationKeeper(configs)[source]
type_map = {'default': <class 'simplecoin.config.Location'>}
class simplecoin.config.PPLNSChain(bootstrap)[source]
calc_shares(block_payout)[source]
requires = ['type', 'fee_perc', '_algo', '_currencies', 'safety_margin', 'last_n']
class simplecoin.config.PowerPool(bootstrap)[source]
chain
display_text
full_info()[source]
location
request(url, method='GET', max_age=None, signed=True, **kwargs)[source]
requires = ['_chain', 'port', 'address', 'monitor_address', '_location']
stratum_address
timeout = 10
class simplecoin.config.PowerPoolKeeper(configs)[source]
type_map = {'default': <class 'simplecoin.config.PowerPool'>}
class simplecoin.config.PropChain(bootstrap)[source]
calc_shares(block_payout)[source]