Bitcoin Forum
December 05, 2016, 12:43:15 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Example coinbaser script: proportional payout  (Read 1531 times)
Luke-Jr
Legendary
*
Offline Offline

Activity: 2086



View Profile
April 06, 2012, 04:00:23 PM
 #1

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)

1480898595
Hero Member
*
Offline Offline

Posts: 1480898595

View Profile Personal Message (Offline)

Ignore
1480898595
Reply with quote  #2

1480898595
Report to moderator
1480898595
Hero Member
*
Offline Offline

Posts: 1480898595

View Profile Personal Message (Offline)

Ignore
1480898595
Reply with quote  #2

1480898595
Report to moderator
1480898595
Hero Member
*
Offline Offline

Posts: 1480898595

View Profile Personal Message (Offline)

Ignore
1480898595
Reply with quote  #2

1480898595
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
martychubbs
Hero Member
*****
Offline Offline

Activity: 476



View Profile
December 19, 2012, 07:13:56 PM
 #2

will this work for eloipool?  Huh Huh  Kiss
Luke-Jr
Legendary
*
Offline Offline

Activity: 2086



View Profile
December 19, 2012, 08:19:33 PM
 #3

will this work for eloipool?  Huh Huh  Kiss
It should, if you setup the SQL schemas and such correctly.

martychubbs
Hero Member
*****
Offline Offline

Activity: 476



View Profile
January 03, 2013, 04: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!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!