API¶
Utils¶
-
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_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
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.
Models¶
-
class
simplecoin.models.
Block
(**kwargs)[source]¶ This class stores metadata on all blocks found by the pool
-
algo
¶
-
algo_obj
¶
-
average_hashrate
¶
-
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
¶
-
explorer_link
¶
-
found_at
¶
-
hash
¶
-
hashes_to_solve
¶
-
height
¶
-
id
¶
-
luck
¶
-
mature
¶
-
merged
¶
-
orphan
¶
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
¶
-
chainid
¶
-
config_obj
¶
-
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
¶
-
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
¶
-
mined
¶
-
payable
¶
-
payable_amount
¶
-
payout
¶
-
payout_id
¶
-
pd_perc
¶
-
perc_applied
¶
-
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
¶
-
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'}¶
-
key
¶ alias of
Key
-
keys
= ['user', 'worker', 'device', 'stat_val']¶
-
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
¶
-
classmethod
-
class
simplecoin.models.
Payout
(**kwargs)[source]¶ -
address
¶
-
amount
¶
-
count
¶
-
created_at
¶
-
currency
¶
-
currency_obj
¶
-
id
¶
-
payout_currency
¶
-
status
¶
-
timestamp
¶
-
transaction
¶
-
transaction_id
¶
-
user
¶
-
Takes a query list and combines the values. Usually either returns an average or a sum. Can assume at least one item in ql
alias of
Key
-
class
simplecoin.models.
TimeSlice
[source]¶ An time abstracted data sample that pertains to a single worker. Currently used to represent accepted and rejected shares.
-
end_time
¶
-
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
-
created_at
¶
-
credits
¶
-
currency
¶
-
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_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.
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.
generate_credits
(dont_simulate=True)[source]¶ Loops through all the blocks that haven’t been credited out and attempts to process them
-
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.
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.
Views¶
RPC Views¶
-
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.
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.
Config Objects¶
-
class
simplecoin.config.
AlgoKeeper
(configs)[source]¶ -
-
type_map
= {'default': <class 'simplecoin.config.Algo'>}¶
-
-
class
simplecoin.config.
Chain
(bootstrap)[source]¶ -
algo
¶
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
-
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.
Location
(bootstrap)[source]¶ -
required
= ['location_acronym', 'location', 'country_flag', 'address']¶
-
-
class
simplecoin.config.
LocationKeeper
(configs)[source]¶ -
type_map
= {'default': <class 'simplecoin.config.Location'>}¶
-
-
class
simplecoin.config.
PPLNSChain
(bootstrap)[source]¶ -
requires
= ['type', 'fee_perc', '_algo', '_currencies', 'safety_margin', 'last_n']¶
-
-
class
simplecoin.config.
PowerPool
(bootstrap)[source]¶ -
chain
¶
-
display_text
¶
-
location
¶
-
requires
= ['_chain', 'port', 'address', 'monitor_address', '_location']¶
-
stratum_address
¶
-
timeout
= 10¶
-