1 # Eloipool - Python Bitcoin pool server
2 # Copyright (C) 2011-2012 Luke Dashjr <luke-jr+eloipool@utopios.org>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as
6 # published by the Free Software Foundation, either version 3 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from hashlib import sha256
18 from util import doublesha
21 def __init__(self, data, detailed=False):
23 self.recalculate(detailed)
24 self._hash_steps = None
26 def recalculate(self, detailed=False):
38 if detailed or Ll > 1:
47 L = PreL + [doublesha(L[i] + L[i + 1]) for i in range(StartL, Ll, 2)]
53 if self._hash_steps == None:
54 self._hash_steps = doublesha(''.join(self._steps))
55 return self._hash_steps
57 def withFirst(self, f):
64 return self.withFirst(self.data[0])
71 mt = MerkleTree([None] + [binascii.unhexlify(a) for a in [
72 '999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971',
73 '3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d',
74 'a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6',
75 '28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0',
78 b'82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a' ==
79 binascii.b2a_hex(mt.withFirst(binascii.unhexlify('d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7')))
82 print '82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a'
83 txes = [binascii.unhexlify(a) for a in [
84 'd43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7',
85 '999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971',
86 '3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d',
87 'a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6',
88 '28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0',
94 y = int('d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7', 16)
96 coinbasehash = binascii.unhexlify("%x" % y)
97 x = binascii.b2a_hex(mt.withFirst(coinbasehash))
100 print time.time() - s
102 if __name__ == '__main__':