Bitcoin Forum

Bitcoin => Mining => Topic started by: Luke-Jr on April 06, 2012, 04:00:23 PM



Title: Example coinbaser script: proportional payout
Post by: Luke-Jr on April 06, 2012, 04:00:23 PM
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:password@127.0.0.1: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)


Title: Re: Example coinbaser script: proportional payout
Post by: martychubbs on December 19, 2012, 07:13:56 PM
will this work for eloipool?  ??? ???  :-*


Title: Re: Example coinbaser script: proportional payout
Post by: Luke-Jr on December 19, 2012, 08:19:33 PM
will this work for eloipool?  ??? ???  :-*
It should, if you setup the SQL schemas and such correctly.


Title: Re: Example coinbaser script: proportional payout
Post by: martychubbs on January 03, 2013, 04:25:41 PM
will this work for eloipool?  ??? ???  :-*
It should, if you setup the SQL schemas and such correctly.

thanks for the update!