diff --git a/hdc/transactions/sender/issuance.py b/hdc/transactions/sender/issuance.py deleted file mode 100644 index d5cd20cfc8edfa8ca3681956e8e5707b68fd6dba..0000000000000000000000000000000000000000 --- a/hdc/transactions/sender/issuance.py +++ /dev/null @@ -1,63 +0,0 @@ -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Authors: -# Caner Candan <caner@candan.fr>, http://caner.candan.fr -# - -from . import HDC, logging - -logger = logging.getLogger("ucoin/hdc/transactions/sender/issuance") - -class Base(HDC): - """Get the received issuance transaction of a PGP key.""" - - def __init__(self, pgp_fingerprint, server=None, port=None): - """ - Arguments: - - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - """ - - super().__init__('hdc/transactions/sender/%s/issuance' % pgp_fingerprint, server, port) - -class Last(Base): - """GET the last received issuance transaction of a PGP key.""" - - def __get__(self, **kwargs): - return self.requests_get('/last', **kwargs).json() - -class Fusion(Base): - """GET all fusion transactions sent by this sender and stored by this node (should contain all fusion transactions of the sender).""" - - def __get__(self, **kwargs): - return self.merkle_easy_parser('/fusion') - -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).""" - - def __init__(self, pgp_fingerprint, am_number=None, server=None, port=None): - """ - Arguments: - - `am_number`: amendment number - """ - - super().__init__(pgp_fingerprint, server, port) - - self.am_number = am_number - - def __get__(self, **kwargs): - if not self.am_number: - return self.merkle_easy_parser('/dividend') - - return self.merkle_easy_parser('/dividend/%d' % self.am_number) diff --git a/__init__.py b/ucoinpy/__init__.py similarity index 76% rename from __init__.py rename to ucoinpy/__init__.py index 21ffd2736645c46353eb7756a5aacdbfe4449fa4..6f72c61da64512c194e3d338a9e4bc463d1c4e46 100644 --- a/__init__.py +++ b/ucoinpy/__init__.py @@ -18,11 +18,14 @@ __all__ = ['api'] -__author__ = 'Caner Candan' -__version__ = '0.0.1' -__nonsense__ = 'uCoin' +__author__ = 'uCoin team' +__version__ = '0.2' +__nonsense__ = 'uCoin' -import requests, logging, gnupg, json +import requests +import logging +import gnupg +import json settings = { 'server': 'localhost', @@ -32,6 +35,7 @@ settings = { logger = logging.getLogger("ucoin") + class Response: """Wrapper of requests.Response class in order to verify signed message.""" @@ -66,11 +70,13 @@ class Response: def split_n_verify(self, response): """ - Split the signed message thanks to the boundary value got in content-type header. + Split the signed message thanks to the boundary + value got in content-type header. returns a tuple with the status, the clear message and the signature. - `response`: the response returns by requests.get() needed to access to headers and response content. + `response`: the response returns by requests.get() needed + to access to headers and response content. """ begin = '-----BEGIN PGP SIGNATURE-----' @@ -89,12 +95,16 @@ class Response: return (bool(settings['gpg'].verify(clearsigned)), clear, signed) + 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, 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. Arguments: - `module`: module name @@ -117,8 +127,10 @@ class API: - `path`: the request path """ - url = 'http://%s:%d/%s' % (self.server if self.server else settings['server'], - self.port if self.port else settings['port'], + url = 'http://%s:%d/%s' % (self.server if self.server + else settings['server'], + self.port if self.port + else settings['port'], self.module) return url + path @@ -159,12 +171,15 @@ class API: response = None if not settings.get('auth'): - response = requests.get(self.reverse_url(path), params=kwargs, headers=self.headers) + response = requests.get(self.reverse_url(path), params=kwargs, + headers=self.headers) else: - response = Response(requests.get(self.reverse_url(path), params=kwargs, headers=self.headers)) + response = Response(requests.get(self.reverse_url(path), + params=kwargs, headers=self.headers)) if response.status_code != 200: - raise ValueError('status code != 200 => %d (%s)' % (response.status_code, response.text)) + raise ValueError('status code != 200 => %d (%s)' + % (response.status_code, response.text)) return response @@ -176,10 +191,12 @@ class API: - `path`: the request path """ - response = requests.post(self.reverse_url(path), data=kwargs, headers=self.headers) + response = requests.post(self.reverse_url(path), + data=kwargs, headers=self.headers) if response.status_code != 200: - raise ValueError('status code != 200 => %d (%s)' % (response.status_code, response.text)) + raise ValueError('status code != 200 => %d (%s)' + % (response.status_code, response.text)) return response @@ -188,4 +205,7 @@ class API: for leaf in root['leaves'][begin:end]: yield self.requests_get(path, leaf=leaf).json()['leaf'] -from . import pks, ucg, hdc, wrappers +from . import pks +from . import hdc +from . import wrappers +from . import network diff --git a/hdc/__init__.py b/ucoinpy/hdc/__init__.py similarity index 95% rename from hdc/__init__.py rename to ucoinpy/hdc/__init__.py index 9e242612dd3ac3ae98ef654d55333e8650208ebf..fbfe1cd3df612ff8ef2dc2915c6cf2d8a7265681 100644 --- a/hdc/__init__.py +++ b/ucoinpy/hdc/__init__.py @@ -16,10 +16,12 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import API, logging +from .. import API +from .. import logging logger = logging.getLogger("ucoin/hdc") + class HDC(API): def __init__(self, module='hdc', server=None, port=None): super().__init__(module, server, port) diff --git a/hdc/amendments/__init__.py b/ucoinpy/hdc/amendments/__init__.py similarity index 56% rename from hdc/amendments/__init__.py rename to ucoinpy/hdc/amendments/__init__.py index 812066a5186a3512bc2c9423e559048599af19d3..eada4013355063d5c43b3a1eb76e2bfc49a45f56 100644 --- a/hdc/amendments/__init__.py +++ b/ucoinpy/hdc/amendments/__init__.py @@ -17,16 +17,19 @@ # from .. import HDC -import logging +from .. import logging logger = logging.getLogger("ucoin/hdc/amendments") + class Base(HDC): def __init__(self, server=None, port=None): super().__init__('hdc/amendments', server, port) + 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, server=None, port=None): """ @@ -46,54 +49,17 @@ class Promoted(Base): return self.requests_get('/promoted/%d' % self.number, **kwargs).json() -class Current(Promoted): - """Alias of amendments/promoted.""" - - pass - -class List(Base): - """GET the list of amendments through the previousHash value.""" - - def __get__(self, **kwargs): - """creates a generator with one amendment per iteration.""" - - current = self.requests_get('/promoted', **kwargs).json() - yield current - - while 'previousHash' in current and current['previousHash']: - current = self.requests_get('/promoted/%d' % (current['number']-1), **kwargs).json() - yield current - -class CurrentVotes(Base): - """GET the votes that legitimate the current amendment.""" - - def __get__(self, **kwargs): - return self.merkle_easy_parser('/current/votes') class Votes(Base): """GET an index of votes received by this node.""" - def __init__(self, amendment_id=None, server=None, port=None): - """ - Uses amendment_id to fit the result. - - Arguments: - - `amendment_id`: amendment id - """ - - super().__init__(server, port) - - self.amendment_id = amendment_id - def __get__(self, **kwargs): - if not self.amendment_id: - return self.requests_get('/votes', **kwargs).json() - - return self.merkle_easy_parser('/votes/%s' % self.amendment_id) + return self.requests_get('/votes', **kwargs).json() def __post__(self, **kwargs): assert 'amendment' in kwargs assert 'signature' in kwargs + assert 'peer' in kwargs return self.requests_post('/votes', **kwargs).json() diff --git a/hdc/amendments/view.py b/ucoinpy/hdc/amendments/view.py similarity index 69% rename from hdc/amendments/view.py rename to ucoinpy/hdc/amendments/view.py index 418606dcc877bb3c46b54e5fb594e46faf03eb4c..02a74f1eea3a335703cbbdd3f8876a8365b85e50 100644 --- a/hdc/amendments/view.py +++ b/ucoinpy/hdc/amendments/view.py @@ -16,19 +16,16 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from . import HDC, logging +from .. import HDC +from .. import logging logger = logging.getLogger("ucoin/hdc/amendments/view") + class View(HDC): def __init__(self, amendment_id, server=None, port=None): super().__init__('hdc/amendments/view/%s' % amendment_id, server, port) -class Members(View): - """GET the members present in the Community for this amendment.""" - - def __get__(self, **kwargs): - return self.merkle_easy_parser('/members') class Self(View): """Shows the raw data of the amendment [AMENDMENT_ID].""" @@ -36,17 +33,9 @@ class Self(View): def __get__(self, **kwargs): return self.requests_get('/self', **kwargs).json() -class Voters(View): - """GET the voters listed in this amendment.""" - - def __get__(self, **kwargs): - return self.merkle_easy_parser('/voters') class Signatures(View): - """GET the signatures of the Community listed in this amendment. - - This URL should give the same result as hdc/amendments/votes/[PREVIOUS_AMENDEMENT_ID] if all votes present in this URL were taken in count as signatures for this AMENDMENT_ID. - """ + """GET the signatures of the Community listed in this amendment.""" def __get__(self, **kwargs): return self.merkle_easy_parser('/signatures') diff --git a/hdc/coins/__init__.py b/ucoinpy/hdc/coins/__init__.py similarity index 68% rename from hdc/coins/__init__.py rename to ucoinpy/hdc/coins/__init__.py index 83c174128f533002af05c7e7cb9d1dc38f97aca4..a4915137e5e78e0dd88b0d1b40816e3cdf8253c2 100644 --- a/hdc/coins/__init__.py +++ b/ucoinpy/hdc/coins/__init__.py @@ -16,29 +16,21 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import HDC, logging +from .. import HDC +from .. import logging logger = logging.getLogger("ucoin/hdc/coins") + class Coins(HDC): def __init__(self, pgp_fingerprint, server=None, port=None): super().__init__('hdc/coins/%s' % pgp_fingerprint, server, port) + class List(Coins): - """GET a list of coins owned by the given [PGP_FINGERPRINT].""" + """GET a list of coins owned by [PGP_FINGERPRINT].""" def __get__(self, **kwargs): return self.requests_get('/list', **kwargs).json() -class View(Coins): - """GET the ownership state of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT].""" - - def __init__(self, pgp_fingerprint, coin_number, server=None, port=None): - super().__init__(pgp_fingerprint, server, port) - - self.coin_number = coin_number - - def __get__(self, **kwargs): - return self.requests_get('/view/%d' % self.coin_number, **kwargs).json() - from . import view diff --git a/hdc/coins/view.py b/ucoinpy/hdc/coins/view.py similarity index 66% rename from hdc/coins/view.py rename to ucoinpy/hdc/coins/view.py index 846aefef31aa047e8d43159146441d1750f0c467..8489bc015fd284290ad9c580b70dd458de814170 100644 --- a/hdc/coins/view.py +++ b/ucoinpy/hdc/coins/view.py @@ -16,16 +16,27 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from . import HDC, logging +from .. import HDC +from .. import logging logger = logging.getLogger("ucoin/hdc/coins/view") + class Base(HDC): - def __init__(self, pgp_fingerprint, coin_number, server=None, port=None): - super().__init__('hdc/coins/%s/view/%d' % (pgp_fingerprint, coin_number), server, port) + def __init__(self, coin_id, server=None, port=None): + super().__init__('hdc/coins/view/%s' % coin_id, server, port) + + +class Owner(Base): + """GET a coin owner + justifying transaction if it exists.""" + + def __get__(self, **kwargs): + return self.requests_get('/owner', **kwargs).json() + class History(Base): - """GET a transaction history of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT].""" + """GET a coin owner + justifying transaction + for each state a coin has gone trough.""" def __get__(self, **kwargs): return self.requests_get('/history', **kwargs).json() diff --git a/hdc/transactions/__init__.py b/ucoinpy/hdc/transactions/__init__.py similarity index 57% rename from hdc/transactions/__init__.py rename to ucoinpy/hdc/transactions/__init__.py index 0aaa09d3062921628f103de1656fd83d80eb1309..60ac2d0645e9de5d609eed80e4851b6c42dc4114 100644 --- a/hdc/transactions/__init__.py +++ b/ucoinpy/hdc/transactions/__init__.py @@ -16,14 +16,17 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import HDC, logging +from .. import HDC +from .. import logging logger = logging.getLogger("ucoin/hdc/transactions") + class Base(HDC): def __init__(self, server=None, port=None): super().__init__('hdc/transactions', server, port) + class Process(Base): """POST a transaction.""" @@ -33,21 +36,6 @@ class Process(Base): return self.requests_post('/process', **kwargs).json() -class All(Base): - """GET all the transactions stored by this node.""" - - def __get__(self, **kwargs): - """creates a generator with one transaction per iteration.""" - - return self.merkle_easy_parser('/all') - -class Keys(Base): - """GET PGP keys for which some transactions have been recoreded by this node (sent and received).""" - - def __get__(self, **kwargs): - """creates a generator with one key per iteration.""" - - return self.merkle_easy_parser('/keys') class Last(Base): """GET the last received transaction.""" @@ -55,7 +43,8 @@ class Last(Base): def __init__(self, count=None, server=None, port=None): """ Arguments: - - `count`: Integer indicating to retrieve the last [COUNT] transactions. + - `count`: Integer indicating to + retrieve the last [COUNT] transactions. """ super().__init__(server, port) @@ -68,15 +57,20 @@ class Last(Base): return self.requests_get('/last/%d' % self.count, **kwargs).json() + 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, server=None, port=None): """ Arguments: - - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - - `begin`: integer value used by the merkle parser to know when to begin requesting. - - `end`: integer value used by the merkle parser to know when to end requesting. + - `pgp_fingerprint`: PGP fingerprint of the + key we want to see sent transactions. + - `begin`: integer value used by the + merkle parser to know when to begin requesting. + - `end`: integer value used by the + merkle parser to know when to end requesting. """ super().__init__(server, port) @@ -86,17 +80,24 @@ class Sender(Base): self.end = end def __get__(self, **kwargs): - return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint, begin=self.begin, end=self.end) + return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint, + begin=self.begin, end=self.end) + 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, server=None, port=None): + def __init__(self, pgp_fingerprint, begin=None, end=None, + server=None, port=None): """ Arguments: - - `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions. - - `begin`: integer value used by the merkle parser to know when to begin requesting. - - `end`: integer value used by the merkle parser to know when to end requesting. + - `pgp_fingerprint`: PGP fingerprint of the + key we want to see sent transactions. + - `begin`: integer value used by the + merkle parser to know when to begin requesting. + - `end`: integer value used by the + merkle parser to know when to end requesting. """ super().__init__(server, port) @@ -106,12 +107,16 @@ class Recipient(Base): self.end = end def __get__(self, **kwargs): - return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint, begin=self.begin, end=self.end) + return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint, + begin=self.begin, end=self.end) + -class View(Base): - """GET the transaction of given TRANSACTION_ID.""" +#TODO: Manager /refering/pgp_fingerprint/tx_number/ +class Refering(Base): + """GET all the transactions refering to source + transaction #[TX_NUMBER] issued by [PGP_FINGERPRINT].""" - def __init__(self, transaction_id, server=None, port=None): + def __init__(self, pgp_fingerprint, tx_number, server=None, port=None): """ Arguments: - `transaction_id`: The transaction unique identifier. @@ -119,9 +124,12 @@ class View(Base): super().__init__(server, port) - self.transaction_id = transaction_id + self.pgp_fingerprint = pgp_fingerprint + self.tx_number = tx_number def __get__(self, **kwargs): - return self.requests_get('/view/%s' % self.transaction_id, **kwargs).json() + return self.requests_get('/refering/%s/%d' + % (self.pgp_fingerprint, self.tx_number), + **kwargs).json() from . import sender diff --git a/hdc/transactions/sender/__init__.py b/ucoinpy/hdc/transactions/sender/__init__.py similarity index 58% rename from hdc/transactions/sender/__init__.py rename to ucoinpy/hdc/transactions/sender/__init__.py index 3dc85196eb5f7c00b0e378b28afe01ecc85ebede..f7913c6e6b45754e479a8b0d0b925d0e35d0b2bc 100644 --- a/hdc/transactions/sender/__init__.py +++ b/ucoinpy/hdc/transactions/sender/__init__.py @@ -16,50 +16,65 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import HDC, logging +from ... import HDC +from ... import logging logger = logging.getLogger("ucoin/hdc/transactions/sender") + class Base(HDC): """Get the last received transaction of a PGP key.""" def __init__(self, pgp_fingerprint, server=None, port=None): """ 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, server, port) + super().__init__('hdc/transactions/sender/%s' % pgp_fingerprint, + server, port) + class Last(Base): """Get the last received transaction of a PGP key.""" - def __init__(self, pgp_fingerprint, count=None, server=None, port=None): + def __init__(self, pgp_fingerprint, count=None, from_=None, + server=None, port=None): """ Arguments: - - `count`: Integer indicating to retrieve the last [COUNT] transactions. + - `count`: Integer indicating to retrieve the last [COUNT] transactions """ super().__init__(pgp_fingerprint, server, port) self.count = count + self.from_ = from_ def __get__(self, **kwargs): if not self.count: return self.requests_get('/last', **kwargs).json() - return self.requests_get('/last/%d' % self.count, **kwargs).json() + if not self.from_: + return self.request_get('/last/%d' % self.count, **kwargs).json() -class Transfer(Base): - """GET all transfer transactions sent by this sender and stored by this node (should contain all transfert transactions of the sender).""" + return self.requests_get('/last/%d/%d' % (self.count, self.from_), + **kwargs).json() - def __get__(self, **kwargs): - return self.merkle_easy_parser('/transfert') -class Issuance(Base): - """GET all issuance transactions (forged coins) sent by this sender and stored by this node (should contain all issuance transactions of the sender).""" +class View(Base): + """GET the transaction of given TRANSACTION_ID.""" - def __get__(self, **kwargs): - return self.merkle_easy_parser('/issuance') + def __init__(self, pgp_fingerprint, tx_number, + server=None, port=None): + """ + Arguments: + - `count`: Integer indicating to retrieve the last [COUNT] transactions + """ + + super().__init__(pgp_fingerprint, server, port) -from . import issuance + self.tx_number = tx_number + + def __get__(self, **kwargs): + return self.requests_get('/view/%d' % self.tx_number, **kwargs).json() diff --git a/ucg/__init__.py b/ucoinpy/network/__init__.py similarity index 80% rename from ucg/__init__.py rename to ucoinpy/network/__init__.py index cf1d7ff0a04bc9769a1bdaeb41ba58074264ee52..b791fd978f5939573143003f28829a222b88f856 100644 --- a/ucg/__init__.py +++ b/ucoinpy/network/__init__.py @@ -16,28 +16,33 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import API, logging +from .. import API +from .. import logging logger = logging.getLogger("ucoin/ucg") -class UCG(API): + +class Network(API): def __init__(self, module='ucg', server=None, port=None): super().__init__(module, server, port) -class Pubkey(UCG): + +class Pubkey(Network): """GET the public key of the peer.""" def __get__(self, **kwargs): return self.requests_get('/pubkey', **kwargs).text -class Peering(UCG): + +class Peering(Network): """GET peering information about a peer.""" def __get__(self, **kwargs): return self.requests_get('/peering', **kwargs).json() -class THT(UCG): - """GET/POST THT entries.""" + +class Wallet(Network): + """GET/POST Wallet entries.""" def __init__(self, pgp_fingerprint=None, server=None, port=None): """ @@ -53,14 +58,15 @@ class THT(UCG): def __get__(self, **kwargs): if not self.pgp_fingerprint: - return self.merkle_easy_parser('/tht') + return self.merkle_easy_parser('/wallet') - return self.merkle_easy_parser('/tht/%s' % self.pgp_fingerprint).json() + return self.merkle_easy_parser('/wallet/%s' + % self.pgp_fingerprint).json() def __post__(self, **kwargs): assert 'entry' in kwargs assert 'signature' in kwargs - return self.requests_post('/tht', **kwargs) + return self.requests_post('/wallet', **kwargs) from . import peering diff --git a/ucg/peering/__init__.py b/ucoinpy/network/peering/__init__.py similarity index 72% rename from ucg/peering/__init__.py rename to ucoinpy/network/peering/__init__.py index f08b9a57949bccdca6b22f0fb1de6c8dc3d8704b..f0ddc3780268534557fc45f9b29d5abeca164cf6 100644 --- a/ucg/peering/__init__.py +++ b/ucoinpy/network/peering/__init__.py @@ -14,31 +14,18 @@ # # Authors: # Caner Candan <caner@candan.fr>, http://caner.candan.fr -# - -from .. import UCG, logging +#networkfrom .. import UCG, logging -logger = logging.getLogger("ucoin/ucg/peering") +from .. import Network +from .. import logging -class Base(UCG): - def __init__(self, server=None, port=None): - super().__init__('ucg/peering', server, port) +logger = logging.getLogger("ucoin/network/peering") -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.""" - - def __get__(self, **kwargs): - """creates a generator with one transaction per iteration.""" - return self.merkle_easy_parser('/keys') - -class Peer(Base): - """GET the peering informations of this node.""" - - def __get__(self, **kwargs): - """returns peering entry of the node.""" +class Base(Network): + def __init__(self, server=None, port=None): + super().__init__('network/peering', server, port) - return self.requests_get('/peer', **kwargs).json() class Peers(Base): """GET peering entries of every node inside the currency network.""" diff --git a/ucg/peering/peers.py b/ucoinpy/network/peering/peers.py similarity index 82% rename from ucg/peering/peers.py rename to ucoinpy/network/peering/peers.py index 29fd76c5333f22c76c03708a19ee8584c5850663..f69d314aac00a532c5305ebbcc307e1005e4b8f3 100644 --- a/ucg/peering/peers.py +++ b/ucoinpy/network/peering/peers.py @@ -15,14 +15,14 @@ # Authors: # Caner Candan <caner@candan.fr>, http://caner.candan.fr # +from .. import Network +from .. import logging -from . import UCG, logging +logger = logging.getLogger("ucoin/network/peering/peers") -logger = logging.getLogger("ucoin/ucg/peering/peers") - -class Base(UCG): +class Base(Network): def __init__(self, server=None, port=None): - super().__init__('ucg/peering/peers', server, port) + super().__init__('network/peering/peers', server, port) class Stream(Base): """GET a list of peers this node is listening to/by for ANY incoming transaction.""" @@ -41,13 +41,6 @@ class Stream(Base): self.request = request self.pgp_fingerprint = pgp_fingerprint - def __get__(self, **kwargs): - """returns the corresponding peer list.""" - - if not self.pgp_fingerprint: - return self.requests_get('/%s' % self.request, **kwargs).json() - - return self.requests_get('/%s/%s' % (self.request, self.pgp_fingerprint), **kwargs).json() class UpStream(Stream): """GET a list of peers this node is listening to for ANY incoming transaction.""" @@ -62,6 +55,11 @@ class UpStream(Stream): super().__init__('upstream', pgp_fingerprint, server, port) + def __get__(self, **kwargs): + """returns the corresponding peer list.""" + + return self.requests_get('/upstream/%s' % (self.request, self.pgp_fingerprint), **kwargs).json() + class DownStream(Stream): """GET a list of peers this node is listening by for ANY incoming transaction.""" @@ -74,3 +72,8 @@ class DownStream(Stream): """ super().__init__('downstream', pgp_fingerprint, server, port) + + def __get__(self, **kwargs): + """returns the corresponding peer list.""" + + return self.requests_get('/downstream/%s' % (self.request, self.pgp_fingerprint), **kwargs).json() diff --git a/pks/__init__.py b/ucoinpy/pks/__init__.py similarity index 97% rename from pks/__init__.py rename to ucoinpy/pks/__init__.py index 2c52bb407f034549971e4ab1ca10a48f39306e02..809acbb7f82f2ee4508feee3f5c02627a829bf13 100644 --- a/pks/__init__.py +++ b/ucoinpy/pks/__init__.py @@ -16,14 +16,17 @@ # Caner Candan <caner@candan.fr>, http://caner.candan.fr # -from .. import API, logging +from .. import API +from .. import logging logger = logging.getLogger("ucoin/pks") + class PKS(API): def __init__(self, module='pks', server=None, port=None): super().__init__(module, server, port) + class Add(PKS): """POST ASCII-armored OpenPGP certificates.""" @@ -33,6 +36,7 @@ class Add(PKS): return self.requests_post('/add', **kwargs) + class Lookup(PKS): """Allows to search for OpenPGP certificates, according to HKP draft.""" @@ -46,6 +50,7 @@ class Lookup(PKS): return r.json() + class All(PKS): """GET all the received public keys.""" diff --git a/ucoinpy/registry/__init__.py b/ucoinpy/registry/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c3793a484c8e17ca6346c79e31664293d66c5187 --- /dev/null +++ b/ucoinpy/registry/__init__.py @@ -0,0 +1,38 @@ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +from .. import API +from .. import logging + +logger = logging.getLogger("ucoin/registry") + + +class Registry(API): + def __init__(self, module='registry', server=None, port=None): + super().__init__(module, server, port) + + +class Parameters(Registry): + """GET parameters used by this community.""" + + def __get__(self, **kwargs): + return self.requests_get('/parameters', **kwargs).json() + + +class Amendment(Registry): + """GET parameters used by this community.""" + + def __get__(self, **kwargs): + return self.requests_get('/amendment', **kwargs).json() diff --git a/ucoinpy/registry/amendment/__init__.py b/ucoinpy/registry/amendment/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7ef12380be969bba04806537db538e79e71eaa2c --- /dev/null +++ b/ucoinpy/registry/amendment/__init__.py @@ -0,0 +1,37 @@ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +from .. import Registry +from .. import logging + +logger = logging.getLogger("ucoin/registry") + + +class Base(Registry): + def __init__(self, server=None, port=None): + super().__init__('registry/amendment', server, port) + + +class Vote(Base): + + """GET the vote of current node for given amendment number + (both amendment + signature). + Such vote may be used by any node to broadcast the whole network.""" + + def __init__(self, am_number=None, server=None, port=None): + super().__init__(server, port) + + def __get__(self, **kwargs): + return self.merkle_easy_parser('/%s/vote' % self.am_number) diff --git a/ucoinpy/registry/community/__init__.py b/ucoinpy/registry/community/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..6c21d5e5a59fdd5323f0421d574efca5d93fb556 --- /dev/null +++ b/ucoinpy/registry/community/__init__.py @@ -0,0 +1,38 @@ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +from .. import Registry +from .. import logging + +logger = logging.getLogger("ucoin/registry") + + +class Base(Registry): + def __init__(self, server=None, port=None): + super().__init__('registry/community', server, port) + + +class Members(Base): + """GET the members present in the Community for this amendment.""" + + def __get__(self, **kwargs): + return self.merkle_easy_parser('/members') + + +class Voters(Base): + """GET the voters listed in this amendment.""" + + def __get__(self, **kwargs): + return self.merkle_easy_parser('/voters') diff --git a/ucoinpy/registry/community/members.py b/ucoinpy/registry/community/members.py new file mode 100644 index 0000000000000000000000000000000000000000..55de75cd892c72e4a5d3e7e6397cfa42a53d3501 --- /dev/null +++ b/ucoinpy/registry/community/members.py @@ -0,0 +1,65 @@ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# + +from .. import Registry +from .. import logging + +logger = logging.getLogger("ucoin/registry/community") + + +class Base(Registry): + def __init__(self, server=None, port=None): + super().__init__('hdc/registry/community', server, port) + + +class Current(Base): + """GET the last valid membership document for member pgp_fingerprint""" + + def __init__(self, pgp_fingerprint=None, server=None, port=None): + """ + Uses number to fit the result. + + Arguments: + - `number`: amendment number + """ + + super().__init__(server, port) + + self.pgp_fingerprint = pgp_fingerprint + + def __get__(self, **kwargs): + return self.requests_get('/members/%s/current' % self.pgp_fingerprint, + **kwargs).json() + + +class History(Base): + """GET the all received and stored membership documents""" + + def __init__(self, pgp_fingerprint=None, server=None, port=None): + """ + Uses number to fit the result. + + Arguments: + - `number`: amendment number + """ + + super().__init__(server, port) + + self.pgp_fingerprint = pgp_fingerprint + + def __get__(self, **kwargs): + return self.requests_get('/members/%s/history' % self.pgp_fingerprint, + **kwargs).json() diff --git a/ucoinpy/registry/community/voters.py b/ucoinpy/registry/community/voters.py new file mode 100644 index 0000000000000000000000000000000000000000..9f403502f137772bba3cf67b4b4039542efdc3bc --- /dev/null +++ b/ucoinpy/registry/community/voters.py @@ -0,0 +1,65 @@ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# + +from .. import Registry +from .. import logging + +logger = logging.getLogger("ucoin/registry/community") + + +class Base(Registry): + def __init__(self, server=None, port=None): + super().__init__('hdc/registry/community', server, port) + + +class Current(Base): + """GET the last valid membership document for member pgp_fingerprint""" + + def __init__(self, pgp_fingerprint=None, server=None, port=None): + """ + Uses number to fit the result. + + Arguments: + - `number`: amendment number + """ + + super().__init__(server, port) + + self.pgp_fingerprint = pgp_fingerprint + + def __get__(self, **kwargs): + return self.requests_get('/voters/%s/current' % self.pgp_fingerprint, + **kwargs).json() + + +class History(Base): + """GET the all received and stored membership documents""" + + def __init__(self, pgp_fingerprint=None, server=None, port=None): + """ + Uses number to fit the result. + + Arguments: + - `number`: amendment number + """ + + super().__init__(server, port) + + self.pgp_fingerprint = pgp_fingerprint + + def __get__(self, **kwargs): + return self.requests_get('/voters/%s/history' % self.pgp_fingerprint, + **kwargs).json() diff --git a/wrappers/__init__.py b/ucoinpy/wrappers/__init__.py similarity index 95% rename from wrappers/__init__.py rename to ucoinpy/wrappers/__init__.py index ee7cd804aa46748bd0faee2a6c465093f7277b0a..55b11c19314f98130db7c060adc5969362954c84 100644 --- a/wrappers/__init__.py +++ b/ucoinpy/wrappers/__init__.py @@ -18,7 +18,8 @@ # import logging -from .. import pks, ucg, hdc, settings +from .. import pks, hdc, settings +import network logger = logging.getLogger("wrappers") diff --git a/wrappers/coins.py b/ucoinpy/wrappers/coins.py similarity index 100% rename from wrappers/coins.py rename to ucoinpy/wrappers/coins.py diff --git a/wrappers/transactions.py b/ucoinpy/wrappers/transactions.py similarity index 100% rename from wrappers/transactions.py rename to ucoinpy/wrappers/transactions.py