Skip to content
Snippets Groups Projects
Commit 789b0263 authored by Caner Candan's avatar Caner Candan
Browse files

* compatible with python2, added Hardship service

parent 76fad95e
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ import requests, logging, json
logger = logging.getLogger("ucoin")
class ConnectionHandler:
class ConnectionHandler(object):
"""Helper class used by other API classes to ease passing server connection information."""
def __init__(self, server, port):
......@@ -43,7 +43,7 @@ class ConnectionHandler:
def __str__(self):
return 'connection info: %s:%d' % (self.server, self.port)
class API:
class API(object):
"""APIRequest is a class used as an interface. The intermediate derivated classes are the modules and the leaf classes are the API requests."""
def __init__(self, connection_handler, module):
......
......@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/blockchain")
class Blockchain(API):
def __init__(self, connection_handler, module='blockchain'):
super().__init__(connection_handler, module)
super(Blockchain, self).__init__(connection_handler, module)
class Parameters(Blockchain):
"""GET the blockchain parameters used by this node."""
......@@ -49,7 +49,7 @@ class Block(Blockchain):
- `number`: block number to select
"""
super().__init__(connection_handler)
super(Block, self).__init__(connection_handler)
self.number = number
......@@ -62,3 +62,28 @@ class Block(Blockchain):
assert 'signature' in kwargs
return self.requests_post('/block', **kwargs).json()
class Current(Blockchain):
"""GET, same as block/[number], but return last accepted block."""
def __get__(self, **kwargs):
return self.requests_get('/current', **kwargs).json()
class Hardship(Blockchain):
"""GET hardship level for given member's fingerprint for writing next block."""
def __init__(self, connection_handler, fingerprint):
"""
Use the number parameter in order to select a block number.
Arguments:
- `fingerprint`: member fingerprint
"""
super(Hardship, self).__init__(connection_handler)
self.fingerprint = fingerprint
def __get__(self, **kwargs):
assert self.fingerprint is not None
return self.requests_get('/hardship/%s' % self.fingerprint.upper(), **kwargs).json()
......@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/network")
class Network(API):
def __init__(self, connection_handler, module='network'):
super().__init__(connection_handler, module)
super(Network, self).__init__(connection_handler, module)
class Peering(Network):
"""GET peering information about a peer."""
......
......@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/network/peering")
class Base(Network):
def __init__(self, connection_handler):
super().__init__(connection_handler, 'network/peering')
super(Base, self).__init__(connection_handler, 'network/peering')
class Peers(Base):
"""GET peering entries of every node inside the currency network."""
......
......@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/tx")
class Tx(API):
def __init__(self, connection_handler, module='tx'):
super().__init__(connection_handler, module)
super(Tx, self).__init__(connection_handler, module)
class Process(Tx):
"""POST a transaction."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment