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

* added server and port parameters to all API as well as wrappers classes

parent 1eb1f982
No related branches found
No related tags found
No related merge requests found
...@@ -92,7 +92,7 @@ class Response: ...@@ -92,7 +92,7 @@ class Response:
class API: class API:
"""APIRequest is a class used as an interface. The intermediate derivated classes are the modules and the leaf classes are the API requests.""" """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, module): def __init__(self, module, server=None, port=None):
""" """
Asks a module in order to create the url used then by derivated classes. Asks a module in order to create the url used then by derivated classes.
...@@ -100,7 +100,9 @@ class API: ...@@ -100,7 +100,9 @@ class API:
- `module`: module name - `module`: module name
""" """
self.url = 'http://%s:%d/%s' % (settings['server'], settings['port'], module) self.url = 'http://%s:%d/%s' % (server if server else settings['server'],
port if port else settings['port'],
module)
self.headers = {} self.headers = {}
if settings['auth']: if settings['auth']:
......
...@@ -21,7 +21,7 @@ from .. import API, logging ...@@ -21,7 +21,7 @@ from .. import API, logging
logger = logging.getLogger("ucoin/hdc") logger = logging.getLogger("ucoin/hdc")
class HDC(API): class HDC(API):
def __init__(self, module='hdc'): def __init__(self, module='hdc', server=None, port=None):
super().__init__(module) super().__init__(module, server, port)
from . import amendments, coins, transactions from . import amendments, coins, transactions
...@@ -22,13 +22,13 @@ import logging ...@@ -22,13 +22,13 @@ import logging
logger = logging.getLogger("ucoin/hdc/amendments") logger = logging.getLogger("ucoin/hdc/amendments")
class Base(HDC): class Base(HDC):
def __init__(self): def __init__(self, server=None, port=None):
super().__init__('hdc/amendments') super().__init__('hdc/amendments', server, port)
class Promoted(Base): class Promoted(Base):
"""GET the current promoted amendment (amendment which received enough votes to be accepted).""" """GET the current promoted amendment (amendment which received enough votes to be accepted)."""
def __init__(self, number=None): def __init__(self, number=None, server=None, port=None):
""" """
Uses number to fit the result. Uses number to fit the result.
...@@ -36,15 +36,15 @@ class Promoted(Base): ...@@ -36,15 +36,15 @@ class Promoted(Base):
- `number`: amendment number - `number`: amendment number
""" """
super().__init__() super().__init__(server, port)
self.number = number self.number = number
def __get__(self, **kwargs): def __get__(self, **kwargs):
if not self.number: if not self.number:
return self.requests_get('/promoted').json() return self.requests_get('/promoted', **kwargs).json()
return self.requests_get('/promoted/%d' % self.number).json() return self.requests_get('/promoted/%d' % self.number, **kwargs).json()
class Current(Promoted): class Current(Promoted):
"""Alias of amendments/promoted.""" """Alias of amendments/promoted."""
...@@ -57,11 +57,11 @@ class List(Base): ...@@ -57,11 +57,11 @@ class List(Base):
def __get__(self, **kwargs): def __get__(self, **kwargs):
"""creates a generator with one amendment per iteration.""" """creates a generator with one amendment per iteration."""
current = self.requests_get('/promoted').json() current = self.requests_get('/promoted', **kwargs).json()
yield current yield current
while 'previousHash' in current and current['previousHash']: while 'previousHash' in current and current['previousHash']:
current = self.requests_get('/promoted/%d' % (current['number']-1)).json() current = self.requests_get('/promoted/%d' % (current['number']-1), **kwargs).json()
yield current yield current
class CurrentVotes(Base): class CurrentVotes(Base):
...@@ -73,7 +73,7 @@ class CurrentVotes(Base): ...@@ -73,7 +73,7 @@ class CurrentVotes(Base):
class Votes(Base): class Votes(Base):
"""GET an index of votes received by this node.""" """GET an index of votes received by this node."""
def __init__(self, amendment_id=None): def __init__(self, amendment_id=None, server=None, port=None):
""" """
Uses amendment_id to fit the result. Uses amendment_id to fit the result.
...@@ -81,13 +81,13 @@ class Votes(Base): ...@@ -81,13 +81,13 @@ class Votes(Base):
- `amendment_id`: amendment id - `amendment_id`: amendment id
""" """
super().__init__() super().__init__(server, port)
self.amendment_id = amendment_id self.amendment_id = amendment_id
def __get__(self, **kwargs): def __get__(self, **kwargs):
if not self.amendment_id: if not self.amendment_id:
return self.requests_get('/votes').json() return self.requests_get('/votes', **kwargs).json()
return self.merkle_easy_parser('/votes/%s' % self.amendment_id) return self.merkle_easy_parser('/votes/%s' % self.amendment_id)
......
...@@ -21,8 +21,8 @@ from . import HDC, logging ...@@ -21,8 +21,8 @@ from . import HDC, logging
logger = logging.getLogger("ucoin/hdc/amendments/view") logger = logging.getLogger("ucoin/hdc/amendments/view")
class View(HDC): class View(HDC):
def __init__(self, amendment_id): def __init__(self, amendment_id, server=None, port=None):
super().__init__('hdc/amendments/view/%s' % amendment_id) super().__init__('hdc/amendments/view/%s' % amendment_id, server, port)
class Members(View): class Members(View):
"""GET the members present in the Community for this amendment.""" """GET the members present in the Community for this amendment."""
...@@ -34,7 +34,7 @@ class Self(View): ...@@ -34,7 +34,7 @@ class Self(View):
"""Shows the raw data of the amendment [AMENDMENT_ID].""" """Shows the raw data of the amendment [AMENDMENT_ID]."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/self').json() return self.requests_get('/self', **kwargs).json()
class Voters(View): class Voters(View):
"""GET the voters listed in this amendment.""" """GET the voters listed in this amendment."""
......
...@@ -21,24 +21,24 @@ from .. import HDC, logging ...@@ -21,24 +21,24 @@ from .. import HDC, logging
logger = logging.getLogger("ucoin/hdc/coins") logger = logging.getLogger("ucoin/hdc/coins")
class Coins(HDC): class Coins(HDC):
def __init__(self, pgp_fingerprint): def __init__(self, pgp_fingerprint, server=None, port=None):
super().__init__('hdc/coins/%s' % pgp_fingerprint) super().__init__('hdc/coins/%s' % pgp_fingerprint, server, port)
class List(Coins): class List(Coins):
"""GET a list of coins owned by the given [PGP_FINGERPRINT].""" """GET a list of coins owned by the given [PGP_FINGERPRINT]."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/list').json() return self.requests_get('/list', **kwargs).json()
class View(Coins): class View(Coins):
"""GET the ownership state of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT].""" """GET the ownership state of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT]."""
def __init__(self, pgp_fingerprint, coin_number): def __init__(self, pgp_fingerprint, coin_number, server=None, port=None):
super().__init__(pgp_fingerprint) super().__init__(pgp_fingerprint, server, port)
self.coin_number = coin_number self.coin_number = coin_number
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/view/%d' % self.coin_number).json() return self.requests_get('/view/%d' % self.coin_number, **kwargs).json()
from . import view from . import view
...@@ -21,11 +21,11 @@ from . import HDC, logging ...@@ -21,11 +21,11 @@ from . import HDC, logging
logger = logging.getLogger("ucoin/hdc/coins/view") logger = logging.getLogger("ucoin/hdc/coins/view")
class Base(HDC): class Base(HDC):
def __init__(self, pgp_fingerprint, coin_number): def __init__(self, pgp_fingerprint, coin_number, server=None, port=None):
super().__init__('hdc/coins/%s/view/%d' % (pgp_fingerprint, coin_number)) super().__init__('hdc/coins/%s/view/%d' % (pgp_fingerprint, coin_number), server, port)
class History(Base): class History(Base):
"""GET a transaction history of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT].""" """GET a transaction history of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT]."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/history').json() return self.requests_get('/history', **kwargs).json()
...@@ -21,8 +21,8 @@ from .. import HDC, logging ...@@ -21,8 +21,8 @@ from .. import HDC, logging
logger = logging.getLogger("ucoin/hdc/transactions") logger = logging.getLogger("ucoin/hdc/transactions")
class Base(HDC): class Base(HDC):
def __init__(self): def __init__(self, server=None, port=None):
super().__init__('hdc/transactions') super().__init__('hdc/transactions', server, port)
class Process(Base): class Process(Base):
"""POST a transaction.""" """POST a transaction."""
...@@ -52,26 +52,26 @@ class Keys(Base): ...@@ -52,26 +52,26 @@ class Keys(Base):
class Last(Base): class Last(Base):
"""GET the last received transaction.""" """GET the last received transaction."""
def __init__(self, count=None): def __init__(self, count=None, server=None, port=None):
""" """
Arguments: Arguments:
- `count`: Integer indicating to retrieve the last [COUNT] transactions. - `count`: Integer indicating to retrieve the last [COUNT] transactions.
""" """
super().__init__() super().__init__(server, port)
self.count = count self.count = count
def __get__(self, **kwargs): def __get__(self, **kwargs):
if not self.count: if not self.count:
return self.requests_get('/last').json() return self.requests_get('/last', **kwargs).json()
return self.requests_get('/last/%d' % self.count).json() return self.requests_get('/last/%d' % self.count, **kwargs).json()
class Sender(Base): class Sender(Base):
"""GET all the transactions sent by this sender and stored by this node (should contain all transactions of the sender).""" """GET all the transactions sent by this sender and stored by this node (should contain all transactions of the sender)."""
def __init__(self, pgp_fingerprint, begin=None, end=None): def __init__(self, pgp_fingerprint, begin=None, end=None, server=None, port=None):
""" """
Arguments: Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
...@@ -79,7 +79,7 @@ class Sender(Base): ...@@ -79,7 +79,7 @@ class Sender(Base):
- `end`: integer value used by the merkle parser to know when to end requesting. - `end`: integer value used by the merkle parser to know when to end requesting.
""" """
super().__init__() super().__init__(server, port)
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
self.begin = begin self.begin = begin
...@@ -91,7 +91,7 @@ class Sender(Base): ...@@ -91,7 +91,7 @@ class Sender(Base):
class Recipient(Base): class Recipient(Base):
"""GET all the transactions received for this recipient stored by this node.""" """GET all the transactions received for this recipient stored by this node."""
def __init__(self, pgp_fingerprint, begin=None, end=None): def __init__(self, pgp_fingerprint, begin=None, end=None, server=None, port=None):
""" """
Arguments: Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
...@@ -99,7 +99,7 @@ class Recipient(Base): ...@@ -99,7 +99,7 @@ class Recipient(Base):
- `end`: integer value used by the merkle parser to know when to end requesting. - `end`: integer value used by the merkle parser to know when to end requesting.
""" """
super().__init__() super().__init__(server, port)
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
self.begin = begin self.begin = begin
...@@ -111,17 +111,17 @@ class Recipient(Base): ...@@ -111,17 +111,17 @@ class Recipient(Base):
class View(Base): class View(Base):
"""GET the transaction of given TRANSACTION_ID.""" """GET the transaction of given TRANSACTION_ID."""
def __init__(self, transaction_id): def __init__(self, transaction_id, server=None, port=None):
""" """
Arguments: Arguments:
- `transaction_id`: The transaction unique identifier. - `transaction_id`: The transaction unique identifier.
""" """
super().__init__() super().__init__(server, port)
self.transaction_id = transaction_id self.transaction_id = transaction_id
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/view/%s' % self.transaction_id).json() return self.requests_get('/view/%s' % self.transaction_id, **kwargs).json()
from . import sender from . import sender
...@@ -23,32 +23,32 @@ logger = logging.getLogger("ucoin/hdc/transactions/sender") ...@@ -23,32 +23,32 @@ logger = logging.getLogger("ucoin/hdc/transactions/sender")
class Base(HDC): class Base(HDC):
"""Get the last received transaction of a PGP key.""" """Get the last received transaction of a PGP key."""
def __init__(self, pgp_fingerprint): def __init__(self, pgp_fingerprint, server=None, port=None):
""" """
Arguments: Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
""" """
super().__init__('hdc/transactions/sender/%s' % pgp_fingerprint) super().__init__('hdc/transactions/sender/%s' % pgp_fingerprint, server, port)
class Last(Base): class Last(Base):
"""Get the last received transaction of a PGP key.""" """Get the last received transaction of a PGP key."""
def __init__(self, pgp_fingerprint, count=None): def __init__(self, pgp_fingerprint, count=None, server=None, port=None):
""" """
Arguments: Arguments:
- `count`: Integer indicating to retrieve the last [COUNT] transactions. - `count`: Integer indicating to retrieve the last [COUNT] transactions.
""" """
super().__init__(pgp_fingerprint) super().__init__(pgp_fingerprint, server, port)
self.count = count self.count = count
def __get__(self, **kwargs): def __get__(self, **kwargs):
if not self.count: if not self.count:
return self.requests_get('/last').json() return self.requests_get('/last', **kwargs).json()
return self.requests_get('/last/%d' % self.count).json() return self.requests_get('/last/%d' % self.count, **kwargs).json()
class Transfer(Base): class Transfer(Base):
"""GET all transfer transactions sent by this sender and stored by this node (should contain all transfert transactions of the sender).""" """GET all transfer transactions sent by this sender and stored by this node (should contain all transfert transactions of the sender)."""
......
...@@ -23,19 +23,19 @@ logger = logging.getLogger("ucoin/hdc/transactions/sender/issuance") ...@@ -23,19 +23,19 @@ logger = logging.getLogger("ucoin/hdc/transactions/sender/issuance")
class Base(HDC): class Base(HDC):
"""Get the received issuance transaction of a PGP key.""" """Get the received issuance transaction of a PGP key."""
def __init__(self, pgp_fingerprint): def __init__(self, pgp_fingerprint, server=None, port=None):
""" """
Arguments: Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
""" """
super().__init__('hdc/transactions/sender/%s/issuance' % pgp_fingerprint) super().__init__('hdc/transactions/sender/%s/issuance' % pgp_fingerprint, server, port)
class Last(Base): class Last(Base):
"""GET the last received issuance transaction of a PGP key.""" """GET the last received issuance transaction of a PGP key."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/last').json() return self.requests_get('/last', **kwargs).json()
class Fusion(Base): class Fusion(Base):
"""GET all fusion transactions sent by this sender and stored by this node (should contain all fusion transactions of the sender).""" """GET all fusion transactions sent by this sender and stored by this node (should contain all fusion transactions of the sender)."""
...@@ -46,13 +46,13 @@ class Fusion(Base): ...@@ -46,13 +46,13 @@ class Fusion(Base):
class Dividend(Base): class Dividend(Base):
"""GET all dividend transactions (issuance of new coins) sent by this sender and stored by this node (should contain all dividend transactions of the sender).""" """GET all dividend transactions (issuance of new coins) sent by this sender and stored by this node (should contain all dividend transactions of the sender)."""
def __init__(self, pgp_fingerprint, am_number=None): def __init__(self, pgp_fingerprint, am_number=None, server=None, port=None):
""" """
Arguments: Arguments:
- `am_number`: amendment number - `am_number`: amendment number
""" """
super().__init__(pgp_fingerprint) super().__init__(pgp_fingerprint, server, port)
self.am_number = am_number self.am_number = am_number
......
...@@ -21,8 +21,8 @@ from .. import API, logging ...@@ -21,8 +21,8 @@ from .. import API, logging
logger = logging.getLogger("ucoin/pks") logger = logging.getLogger("ucoin/pks")
class PKS(API): class PKS(API):
def __init__(self, module='pks'): def __init__(self, module='pks', server=None, port=None):
super().__init__(module) super().__init__(module, server, port)
class Add(PKS): class Add(PKS):
"""POST ASCII-armored OpenPGP certificates.""" """POST ASCII-armored OpenPGP certificates."""
......
...@@ -21,25 +21,25 @@ from .. import API, logging ...@@ -21,25 +21,25 @@ from .. import API, logging
logger = logging.getLogger("ucoin/ucg") logger = logging.getLogger("ucoin/ucg")
class UCG(API): class UCG(API):
def __init__(self, module='ucg'): def __init__(self, module='ucg', server=None, port=None):
super().__init__(module) super().__init__(module, server, port)
class Pubkey(UCG): class Pubkey(UCG):
"""GET the public key of the peer.""" """GET the public key of the peer."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/pubkey').text return self.requests_get('/pubkey', **kwargs).text
class Peering(UCG): class Peering(UCG):
"""GET peering information about a peer.""" """GET peering information about a peer."""
def __get__(self, **kwargs): def __get__(self, **kwargs):
return self.requests_get('/peering').json() return self.requests_get('/peering', **kwargs).json()
class THT(UCG): class THT(UCG):
"""GET/POST THT entries.""" """GET/POST THT entries."""
def __init__(self, pgp_fingerprint=None): def __init__(self, pgp_fingerprint=None, server=None, port=None):
""" """
Use the pgp fingerprint parameter in order to fit the result. Use the pgp fingerprint parameter in order to fit the result.
...@@ -47,7 +47,7 @@ class THT(UCG): ...@@ -47,7 +47,7 @@ class THT(UCG):
- `pgp_fingerprint`: pgp fingerprint to use as a filter - `pgp_fingerprint`: pgp fingerprint to use as a filter
""" """
super().__init__() super().__init__(server, port)
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
......
...@@ -21,8 +21,8 @@ from .. import UCG, logging ...@@ -21,8 +21,8 @@ from .. import UCG, logging
logger = logging.getLogger("ucoin/ucg/peering") logger = logging.getLogger("ucoin/ucg/peering")
class Base(UCG): class Base(UCG):
def __init__(self): def __init__(self, server=None, port=None):
super().__init__('ucg/peering') super().__init__('ucg/peering', server, port)
class Keys(Base): class Keys(Base):
"""GET PGP keys' fingerprint this node manages, i.e. this node will have transactions history and follow ohter nodes for this history.""" """GET PGP keys' fingerprint this node manages, i.e. this node will have transactions history and follow ohter nodes for this history."""
...@@ -38,7 +38,7 @@ class Peer(Base): ...@@ -38,7 +38,7 @@ class Peer(Base):
def __get__(self, **kwargs): def __get__(self, **kwargs):
"""returns peering entry of the node.""" """returns peering entry of the node."""
return self.requests_get('/peer').json() return self.requests_get('/peer', **kwargs).json()
class Peers(Base): class Peers(Base):
"""GET peering entries of every node inside the currency network.""" """GET peering entries of every node inside the currency network."""
......
...@@ -21,13 +21,13 @@ from . import UCG, logging ...@@ -21,13 +21,13 @@ from . import UCG, logging
logger = logging.getLogger("ucoin/ucg/peering/peers") logger = logging.getLogger("ucoin/ucg/peering/peers")
class Base(UCG): class Base(UCG):
def __init__(self): def __init__(self, server=None, port=None):
super().__init__('ucg/peering/peers') super().__init__('ucg/peering/peers', server, port)
class Stream(Base): class Stream(Base):
"""GET a list of peers this node is listening to/by for ANY incoming transaction.""" """GET a list of peers this node is listening to/by for ANY incoming transaction."""
def __init__(self, request, pgp_fingerprint=None): def __init__(self, request, pgp_fingerprint=None, server=None, port=None):
""" """
Use the pgp fingerprint parameter in order to fit the result. Use the pgp fingerprint parameter in order to fit the result.
...@@ -36,7 +36,7 @@ class Stream(Base): ...@@ -36,7 +36,7 @@ class Stream(Base):
- `pgp_fingerprint`: pgp fingerprint to use as a filter - `pgp_fingerprint`: pgp fingerprint to use as a filter
""" """
super().__init__() super().__init__(server, port)
self.request = request self.request = request
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
...@@ -45,14 +45,14 @@ class Stream(Base): ...@@ -45,14 +45,14 @@ class Stream(Base):
"""returns the corresponding peer list.""" """returns the corresponding peer list."""
if not self.pgp_fingerprint: if not self.pgp_fingerprint:
return self.requests_get('/%s' % self.request).json() return self.requests_get('/%s' % self.request, **kwargs).json()
return self.requests_get('/%s/%s' % (self.request, self.pgp_fingerprint)).json() return self.requests_get('/%s/%s' % (self.request, self.pgp_fingerprint), **kwargs).json()
class UpStream(Stream): class UpStream(Stream):
"""GET a list of peers this node is listening to for ANY incoming transaction.""" """GET a list of peers this node is listening to for ANY incoming transaction."""
def __init__(self, pgp_fingerprint=None): def __init__(self, pgp_fingerprint=None, server=None, port=None):
""" """
Use the pgp fingerprint parameter in order to fit the result. Use the pgp fingerprint parameter in order to fit the result.
...@@ -60,12 +60,12 @@ class UpStream(Stream): ...@@ -60,12 +60,12 @@ class UpStream(Stream):
- `pgp_fingerprint`: pgp fingerprint to use as a filter - `pgp_fingerprint`: pgp fingerprint to use as a filter
""" """
super().__init__('upstream', pgp_fingerprint) super().__init__('upstream', pgp_fingerprint, server, port)
class DownStream(Stream): class DownStream(Stream):
"""GET a list of peers this node is listening by for ANY incoming transaction.""" """GET a list of peers this node is listening by for ANY incoming transaction."""
def __init__(self, pgp_fingerprint=None): def __init__(self, pgp_fingerprint=None, server=None, port=None):
""" """
Use the pgp fingerprint parameter in order to fit the result. Use the pgp fingerprint parameter in order to fit the result.
...@@ -73,4 +73,4 @@ class DownStream(Stream): ...@@ -73,4 +73,4 @@ class DownStream(Stream):
- `pgp_fingerprint`: pgp fingerprint to use as a filter - `pgp_fingerprint`: pgp fingerprint to use as a filter
""" """
super().__init__('downstream', pgp_fingerprint) super().__init__('downstream', pgp_fingerprint, server, port)
...@@ -23,6 +23,10 @@ from .. import pks, ucg, hdc, settings ...@@ -23,6 +23,10 @@ from .. import pks, ucg, hdc, settings
logger = logging.getLogger("wrappers") logger = logging.getLogger("wrappers")
class Wrapper: class Wrapper:
def __init__(self, server=None, port=None):
self.server = server
self.port = port
def __call__(self): def __call__(self):
pass pass
......
...@@ -23,16 +23,19 @@ from . import Wrapper, pks, ucg, hdc, settings ...@@ -23,16 +23,19 @@ from . import Wrapper, pks, ucg, hdc, settings
logger = logging.getLogger("coins") logger = logging.getLogger("coins")
class Coins(Wrapper): class Coins(Wrapper):
def __init__(self, pgp_fingerprint): def __init__(self, pgp_fingerprint, server=None, port=None):
super().__init__(server, port)
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
class Get(Coins): class Get(Coins):
def __init__(self, pgp_fingerprint, values): def __init__(self, pgp_fingerprint, values, server=None, port=None):
super().__init__(pgp_fingerprint) super().__init__(pgp_fingerprint, server, port)
self.values = values self.values = values
def __call__(self): def __call__(self):
__list = hdc.coins.List(self.pgp_fingerprint).get() __list = hdc.coins.List(self.pgp_fingerprint, self.server, self.port).get()
coins = {} coins = {}
for c in __list['coins']: for c in __list['coins']:
for id in c['ids']: for id in c['ids']:
...@@ -60,12 +63,13 @@ class Get(Coins): ...@@ -60,12 +63,13 @@ class Get(Coins):
return res return res
class List(Coins): class List(Coins):
def __init__(self, pgp_fingerprint, limit=None): def __init__(self, pgp_fingerprint, limit=None, server=None, port=None):
super().__init__(pgp_fingerprint) super().__init__(pgp_fingerprint, server, port)
self.limit = limit self.limit = limit
def __call__(self): def __call__(self):
__list = hdc.coins.List(self.pgp_fingerprint).get() __list = hdc.coins.List(self.pgp_fingerprint, self.server, self.port).get()
coins = [] coins = []
__sum = 0 __sum = 0
......
...@@ -23,7 +23,9 @@ from . import Wrapper, pks, ucg, hdc, settings ...@@ -23,7 +23,9 @@ from . import Wrapper, pks, ucg, hdc, settings
logger = logging.getLogger("transactions") logger = logging.getLogger("transactions")
class Transaction(Wrapper): class Transaction(Wrapper):
def __init__(self, type, pgp_fingerprint, message='', peering=None): def __init__(self, type, pgp_fingerprint, message='', peering=None, server=None, port=None):
super().__init__(server, port)
self.pgp_fingerprint = pgp_fingerprint self.pgp_fingerprint = pgp_fingerprint
self.message = message self.message = message
self.type = type self.type = type
...@@ -32,7 +34,7 @@ class Transaction(Wrapper): ...@@ -32,7 +34,7 @@ class Transaction(Wrapper):
def __call__(self): def __call__(self):
try: try:
last_tx = hdc.transactions.sender.Last(self.pgp_fingerprint).get() last_tx = hdc.transactions.sender.Last(self.pgp_fingerprint, self.server, self.port).get()
except ValueError: except ValueError:
last_tx = None last_tx = None
...@@ -83,7 +85,7 @@ Comment: ...@@ -83,7 +85,7 @@ Comment:
def process(self, tx, txs): def process(self, tx, txs):
try: try:
hdc.transactions.Process().post(transaction=tx, signature=txs) hdc.transactions.Process(self.server, self.port).post(transaction=tx, signature=txs)
except ValueError as e: except ValueError as e:
self.error = str(e) self.error = str(e)
else: else:
...@@ -97,7 +99,7 @@ Comment: ...@@ -97,7 +99,7 @@ Comment:
data = coin.split(':') data = coin.split(':')
issuer, numbers = data[0], data[1:] issuer, numbers = data[0], data[1:]
for number in numbers: for number in numbers:
view = hdc.coins.View(issuer, int(number)).get() view = hdc.coins.View(issuer, int(number), self.server, self.port).get()
if view['owner'] != self.pgp_fingerprint: if view['owner'] != self.pgp_fingerprint:
raise ValueError('Trying to divide a coin you do not own (%s)' % view['id']) raise ValueError('Trying to divide a coin you do not own (%s)' % view['id'])
coins.append(view) coins.append(view)
...@@ -115,8 +117,9 @@ Comment: ...@@ -115,8 +117,9 @@ Comment:
if not m: raise ValueError('bad sum value %d' % __sum) if not m: raise ValueError('bad sum value %d' % __sum)
class Transfer(Transaction): class Transfer(Transaction):
def __init__(self, pgp_fingerprint, recipient, coins, message=''): def __init__(self, pgp_fingerprint, recipient, coins, message='', server=None, port=None):
super().__init__('TRANSFER', pgp_fingerprint, message) super().__init__('TRANSFER', pgp_fingerprint, message, server, port)
self.recipient = recipient self.recipient = recipient
self.coins = coins self.coins = coins
...@@ -133,7 +136,7 @@ Coins: ...@@ -133,7 +136,7 @@ Coins:
data = coin.split(':') data = coin.split(':')
issuer = data[0] issuer = data[0]
for number in data[1:]: for number in data[1:]:
context_data.update(hdc.coins.View(issuer, int(number)).get()) context_data.update(hdc.coins.View(issuer, int(number), self.server, self.port).get())
tx += '%(id)s, %(transaction)s\n' % context_data tx += '%(id)s, %(transaction)s\n' % context_data
return tx return tx
...@@ -154,7 +157,7 @@ Coins: ...@@ -154,7 +157,7 @@ Coins:
""" % context_data """ % context_data
try: try:
last_issuance = hdc.transactions.sender.issuance.Last(self.pgp_fingerprint).get() last_issuance = hdc.transactions.sender.issuance.Last(self.pgp_fingerprint, self.server, self.port).get()
except ValueError: except ValueError:
last_issuance = None last_issuance = None
...@@ -168,8 +171,9 @@ Coins: ...@@ -168,8 +171,9 @@ Coins:
return tx return tx
class Issue(MonoTransaction): class Issue(MonoTransaction):
def __init__(self, pgp_fingerprint, amendment, coins, message=''): def __init__(self, pgp_fingerprint, amendment, coins, message='', server=None, port=None):
super().__init__('ISSUANCE', pgp_fingerprint, message) super().__init__('ISSUANCE', pgp_fingerprint, message, server, port)
self.amendment = amendment self.amendment = amendment
self.coins = coins self.coins = coins
...@@ -184,8 +188,9 @@ class Issue(MonoTransaction): ...@@ -184,8 +188,9 @@ class Issue(MonoTransaction):
return tx return tx
class Fusion(MonoTransaction): class Fusion(MonoTransaction):
def __init__(self, pgp_fingerprint, coins, message=''): def __init__(self, pgp_fingerprint, coins, message='', server=None, port=None):
super().__init__('FUSION', pgp_fingerprint, message) super().__init__('FUSION', pgp_fingerprint, message, server, port)
self.coins = coins self.coins = coins
def get_mono_message(self, context_data, tx=''): def get_mono_message(self, context_data, tx=''):
...@@ -200,8 +205,9 @@ class Fusion(MonoTransaction): ...@@ -200,8 +205,9 @@ class Fusion(MonoTransaction):
return tx return tx
class Divide(MonoTransaction): class Divide(MonoTransaction):
def __init__(self, pgp_fingerprint, old_coins, new_coins, message=''): def __init__(self, pgp_fingerprint, old_coins, new_coins, message='', server=None, port=None):
super().__init__('DIVISION', pgp_fingerprint, message) super().__init__('DIVISION', pgp_fingerprint, message, server, port)
self.old_coins = old_coins self.old_coins = old_coins
self.new_coins = new_coins self.new_coins = new_coins
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment