Skip to content

Commit

Permalink
Internal code abstraction into blkmk_set_times
Browse files Browse the repository at this point in the history
Ported from C libblkmaker commit 0299bfc068c17204873d5f96da85563ddeebd1b5
  • Loading branch information
luke-jr committed Sep 29, 2014
1 parent f63429e commit 408d007
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions blkmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ def _extranonce(tmpl, workid):
coinbase = _append_cb(tmpl, extradata)
return coinbase

def _set_times(tmpl, usetime = None, out_expire = None):
time_passed = int(usetime - tmpl._time_rcvd)
timehdr = tmpl.curtime + time_passed
if (timehdr > tmpl.maxtime):
timehdr = tmpl.maxtime
return _pack('<I', timehdr)
if not out_expire is None:
out_expire[0] = tmpl.expires - time_passed - 1

def get_data(tmpl, usetime = None, out_expire = None):
if usetime is None: usetime = _time()
if (not (time_left(tmpl, usetime) and work_left(tmpl))):
Expand All @@ -130,15 +139,8 @@ def get_data(tmpl, usetime = None, out_expire = None):
return (None, None)
cbuf += merkleroot

time_passed = int(usetime - tmpl._time_rcvd)
timehdr = tmpl.curtime + time_passed
if (timehdr > tmpl.maxtime):
timehdr = tmpl.maxtime

cbuf += _pack('<I', timehdr)
cbuf += _set_times(tmpl, usetime, out_expire)
cbuf += tmpl.diffbits
if not out_expire is None:
out_expire[0] = tmpl.expires - time_passed - 1

return (cbuf, dataid)

Expand Down

0 comments on commit 408d007

Please sign in to comment.