import struct
from . import base58
-from p2pool.util import bases, math, expiring_dict, memoize, slush
+from p2pool.util import bases, math
import p2pool
class EarlyEnd(Exception):
return obj
- def pack2(self, obj):
+ def pack(self, obj):
data = self._pack(obj)
if p2pool.DEBUG:
return data
- _backing = None
-
- @classmethod
- def enable_caching(cls):
- assert cls._backing is None
- cls._backing = expiring_dict.ExpiringDict(100)
- cls._pre_pack2 = cls.pack2
- cls.pack2 = memoize.memoize_with_backing(cls._backing, [cls.unpack])(cls.pack2)
- cls._pre_unpack = cls.unpack
- cls.unpack = memoize.memoize_with_backing(cls._backing)(cls.unpack) # doesn't have an inverse
-
- @classmethod
- def disable_caching(cls):
- assert cls._backing is not None
- cls._backing.stop()
- cls._backing = None
- cls.pack2 = cls._pre_pack2
- del cls._pre_pack2
- cls.unpack = cls._pre_unpack
- del cls._pre_unpack
-
- def pack(self, obj):
- return self.pack2(slush.immutify(obj))
-
def pack_base58(self, obj):
return base58.encode(self.pack(obj))
class EnumType(Type):
def __init__(self, inner, values):
self.inner = inner
- self.values = slush.frozendict(values)
+ self.values = values
keys = {}
for k, v in values.iteritems():
if v in keys:
raise ValueError('duplicate value in values')
keys[v] = k
- self.keys = slush.frozendict(keys)
+ self.keys = keys
def read(self, file):
data, file = self.inner.read(file)
tx_type = ComposedType([
('version', StructType('<I')),
('tx_ins', ListType(ComposedType([
- ('previous_output', PossiblyNoneType(slush.frozendict(hash=0, index=2**32 - 1), ComposedType([
+ ('previous_output', PossiblyNoneType(dict(hash=0, index=2**32 - 1), ComposedType([
('hash', HashType()),
('index', StructType('<I')),
]))),
import p2pool
from p2pool import skiplists
from p2pool.bitcoin import data as bitcoin_data, script
-from p2pool.util import memoize, expiring_dict, math, forest
+from p2pool.util import math, forest
share_data_type = bitcoin_data.ComposedType([
return best, desired
- @memoize.memoize_with_backing(expiring_dict.ExpiringDict(5, get_touches=False))
def score(self, share_hash, ht):
head_height, last = self.verified.get_height_and_last(share_hash)
score2 = 0
print "Install Pygame and PIL to enable visualizations! Visualizations disabled."
print
- bitcoin_data.Type.enable_caching()
-
# connect to bitcoind over JSON-RPC and do initial getmemorypool
url = 'http://%s:%i/' % (args.bitcoind_address, args.bitcoind_rpc_port)
print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
+++ /dev/null
-_nothing = object()
-
-def memoize_with_backing(backing, has_inverses=set()):
- def a(f):
- def b(*args):
- res = backing.get((f, args), _nothing)
- if res is not _nothing:
- return res
-
- res = f(*args)
-
- backing[(f, args)] = res
- for inverse in has_inverses:
- backing[(inverse, args[:-1] + (res,))] = args[-1]
-
- return res
- return b
- return a
-
-def memoize(f):
- return memoize_with_backing({})(f)
+++ /dev/null
-class frozendict(dict):
- __slots__ = ['_hash']
-
- def __hash__(self):
- rval = getattr(self, '_hash', None)
- if rval is None:
- rval = self._hash = hash(frozenset(self.iteritems()))
- return rval
-
-class frozenlist(list):
- __slots__ = ['_hash']
-
- def __hash__(self):
- rval = getattr(self, '_hash', None)
- if rval is None:
- rval = self._hash = hash(tuple(self))
- return rval
-
-def immutify(x):
- if isinstance(x, list):
- return frozenlist(immutify(y) for y in x)
- elif isinstance(x, dict):
- return frozendict((immutify(k), immutify(v)) for k, v in x.iteritems())
- else:
- hash(x) # will throw error if not immutable
- return x