Author

Topic: Example coinbaser script: proportional payout (Read 1781 times)

hero member
Activity: 742
Merit: 503
January 03, 2013, 12:25:41 PM
#4
will this work for eloipool?  Huh Huh  Kiss
It should, if you setup the SQL schemas and such correctly.

thanks for the update!
legendary
Activity: 2576
Merit: 1186
December 19, 2012, 04:19:33 PM
#3
will this work for eloipool?  Huh Huh  Kiss
It should, if you setup the SQL schemas and such correctly.
hero member
Activity: 742
Merit: 503
December 19, 2012, 03:13:56 PM
#2
will this work for eloipool?  Huh Huh  Kiss
legendary
Activity: 2576
Merit: 1186
For a while, there has been one key component of Eligius that isn't open source: the coinbaser script. The reason for this is mainly due to the absurd ugliness it has become over time, and I hope to one day rewrite it in a clean way.

In the meantime, I stumbled upon a copy of the original coinbaser, before it got so messy. This was from when Eligius was a proportional pool, so I'm not sure how useful it is, but I thought it'd be good to publish it anyway...

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import jsonrpc
import sqlite3

access = jsonrpc.ServiceProxy('http://bitcoinrpc:[email protected]:8332')
gs = access.listtransactions('*', 5)
gs = filter(lambda txn: txn['category'] in ('immature', 'generate'), gs)
gs = gs[-2:]

available = 50e8
distribution = {}

def distribute(addr, amount):
global available, distribution
if amount < 1:
return
available -= amount
if addr in distribution:
    amount += distribution[addr]
distribution[addr] = amount

# Make sure there's some leftover, so it shows up on listtransactions next time ;)
available -= 1

# Fee for running the pool: 1 base unit for every second :P
distribute('1CT1Wbu5kkQArCkWjHnzKyx6YaPCiFTJdB', gs[1]['time'] - gs[0]['time'])

sql = sqlite3.connect('/home/bitcoinpool/pool/data.sqlite')
sqlc = sql.cursor()
sqlc.execute('select count(username), username from shares where time > ?', (gs[1]['time'],))
shares = sqlc.fetchall()
sqlc.close()
del sqlc
sql.close()
del sql

total_available = available
total_shares = sum(map(lambda share: share[0], shares))
for share_count, share_addr in shares:
if not access.validateaddress(share_addr)['isvalid']:
continue
amount = total_available * share_count // total_shares
distribute(share_addr, amount)

print(len(distribution))
for addr, amount in distribution.iteritems():
print(amount)
print(addr)
Jump to: