From 9ca9fa595fe796da8e1809a7fa3376744fd621f6 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 7 Jul 2013 16:11:22 +0000 Subject: [PATCH] Replace "%p" with the previous block hash in CoinbaserCmd --- config.py.example | 2 ++ eloipool.py | 4 +++- merklemaker.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config.py.example b/config.py.example index cd1ea7c..f69811b 100644 --- a/config.py.example +++ b/config.py.example @@ -59,6 +59,8 @@ IdleSleepTime = 0.1 TrackerAddr = 'mrsP7M31efGkQHXb7nRiWLDjfV2M8oakf2' # testnet # Coinbaser command to control reward delegation +# %d is replaced with the total value of the block reward (in satoshis) +# %p is replaced with the previous block hash in hexadecimal # NOTE: This example donates 1% of block rewards to Luke-Jr for Eloipool development CoinbaserCmd = 'echo -e "1\\n$((%d / 100))\\n1579aXhdwvKZEMrAKoCZhzGuqMa8EonuXU"' diff --git a/eloipool.py b/eloipool.py index 6ddd358..3a90c83 100755 --- a/eloipool.py +++ b/eloipool.py @@ -90,11 +90,12 @@ except: from bitcoin.script import BitcoinScript from bitcoin.txn import Txn from base58 import b58decode +from binascii import b2a_hex from struct import pack import subprocess from time import time -def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True): +def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True, prevBlockHex = None): txn = Txn.new() if useCoinbaser and hasattr(config, 'CoinbaserCmd') and config.CoinbaserCmd: @@ -102,6 +103,7 @@ def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True): try: cmd = config.CoinbaserCmd cmd = cmd.replace('%d', str(coinbaseValue)) + cmd = cmd.replace('%p', prevBlockHex or '""') p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) nout = int(p.stdout.readline()) for i in range(nout): diff --git a/merklemaker.py b/merklemaker.py index 0b54709..5f8401d 100644 --- a/merklemaker.py +++ b/merklemaker.py @@ -375,7 +375,7 @@ class merkleMaker(threading.Thread): self._makeBlockSafe(MP, txnlist, txninfo) - cbtxn = self.makeCoinbaseTxn(MP['coinbasevalue']) + cbtxn = self.makeCoinbaseTxn(MP['coinbasevalue'], prevBlockHex = MP['previousblockhash']) cbtxn.setCoinbase(b'\0\0') cbtxn.assemble() txnlist.insert(0, cbtxn.data) @@ -788,7 +788,7 @@ def _test(): txninfo[2]['fee'] = 0 assert MBS(1) == (MP, txnlist, txninfo) # _ProcessGBT tests - def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True): + def makeCoinbaseTxn(coinbaseValue, useCoinbaser = True, prevBlockHex = None): txn = Txn.new() txn.addOutput(coinbaseValue, b'') return txn -- 2.1.4