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

+ added new GET requests, I finished to add all the get request described from...

+ added new GET requests, I finished to add all the get request described from the HTTP API of ucoin
parent 0189672f
No related branches found
No related tags found
No related merge requests found
...@@ -22,4 +22,4 @@ class HDC(API): ...@@ -22,4 +22,4 @@ class HDC(API):
def __init__(self, module='hdc'): def __init__(self, module='hdc'):
super().__init__(module) super().__init__(module)
from . import amendments, transactions from . import amendments, coins, transactions
#
# 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
class Base(HDC):
def __init__(self):
super().__init__('hdc/amendments')
class Promoted(Base):
"""GET the current promoted amendment (amendment which received enough votes to be accepted)."""
def __init__(self, number=None):
"""
Uses number to fit the result.
Arguments:
- `number`: amendment number
"""
super().__init__()
self.number = number
def get(self):
if not self.number:
return self.requests_get('/promoted').json()
return self.requests_get('/promoted/%d' % self.number).json()
class Current(Promoted):
"""Alias of amendments/promoted."""
pass
class List(Base):
"""GET the list of amendments through the previousHash value."""
def get(self):
"""creates a generator with one amendment per iteration."""
current = self.requests_get('/promoted').json()
yield current
while 'previousHash' in current and current['previousHash']:
current = self.requests_get('/promoted/%d' % (current['number']-1)).json()
yield current
class CurrentVotes(Base):
"""GET the votes that legitimate the current amendment."""
def get(self):
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):
"""
Uses amendment_id to fit the result.
Arguments:
- `amendment_id`: amendment id
"""
super().__init__()
self.amendment_id = amendment_id
def get(self):
if not self.amendment_id:
return self.requests_get('/votes').json()
return self.merkle_easy_parser('/votes/%s' % self.amendment_id)
def post(self):
pass
from . import view
#
# 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
class View(HDC):
def __init__(self, amendment_id):
super().__init__('hdc/amendments/view/%s' % amendment_id)
class Members(View):
"""GET the members present in the Community for this amendment."""
def get(self):
return self.merkle_easy_parser('/members')
class Self(View):
"""Shows the raw data of the amendment [AMENDMENT_ID]."""
def get(self):
return self.requests_get('/self').json()
class Voters(View):
"""GET the voters listed in this amendment."""
def get(self):
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.
"""
def get(self):
return self.merkle_easy_parser('/signatures')
...@@ -16,22 +16,27 @@ ...@@ -16,22 +16,27 @@
# Caner Candan <caner@candan.fr>, http://caner.candan.fr # Caner Candan <caner@candan.fr>, http://caner.candan.fr
# #
from . import HDC from .. import HDC
class Base(HDC): class Coins(HDC):
def __init__(self): def __init__(self, pgp_fingerprint):
super().__init__('hdc/amendments') super().__init__('hdc/coins/%s' % pgp_fingerprint)
class List(Base): class List(Coins):
"""GET the list of amendments through the previousHash value.""" """GET a list of coins owned by the given [PGP_FINGERPRINT]."""
def get(self): def get(self):
"""creates a generator with one amendment per iteration.""" return self.requests_get('/list').json()
current = self.requests_get('/current').json() class View(Coins):
yield current """GET the ownership state of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT]."""
while 'previousHash' in current and current['previousHash']: def __init__(self, pgp_fingerprint, coin_number):
current['previousNumber'] = current['number']-1 super().__init__(pgp_fingerprint)
current = self.requests_get('/view/%(previousNumber)d-%(previousHash)s/self' % current).json()
yield current self.coin_number = coin_number
def get(self):
return self.requests_get('/view/%d' % self.coin_number).json()
from . import view
...@@ -19,13 +19,11 @@ ...@@ -19,13 +19,11 @@
from . import HDC from . import HDC
class Base(HDC): class Base(HDC):
def __init__(self): def __init__(self, pgp_fingerprint, coin_number):
super().__init__('hdc/transactions') super().__init__('hdc/coins/%s/view/%d' % (pgp_fingerprint, coin_number))
class All(Base): class History(Base):
"""GET all the transactions stored by this node.""" """GET a transaction history of the coin [COIN_NUMBER] issued by [PGP_FINGERPRINT]."""
def get(self): def get(self):
"""creates a generator with one transaction per iteration.""" return self.requests_get('/history').json()
return self.merkle_easy_parser('/all')
#
# 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
class Base(HDC):
def __init__(self):
super().__init__('hdc/transactions')
class Process(Base):
"""POST a transaction."""
def __init__(self, transaction, signature):
"""
Arguments:
- `transaction`: The raw transaction.
- `signature`: The signature of the transaction.
"""
super().__init__()
self.transaction = transaction
self.signature = signature
def post(self):
pass
class All(Base):
"""GET all the transactions stored by this node."""
def get(self):
"""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):
"""creates a generator with one key per iteration."""
return self.merkle_easy_parser('/keys')
class Last(Base):
"""GET the last received transaction."""
def __init__(self, count=None):
"""
Arguments:
- `count`: Integer indicating to retrieve the last [COUNT] transactions.
"""
super().__init__()
self.count = count
def get(self):
if not self.count:
return self.requests_get('/last').json()
return self.requests_get('/last/%d' % self.count).json()
class Sender(Base):
"""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):
"""
Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
"""
super().__init__()
self.pgp_fingerprint = pgp_fingerprint
def get(self):
return self.merkle_easy_parser('/sender/%s' % self.pgp_fingerprint)
class Recipient(Base):
"""GET all the transactions received for this recipient stored by this node."""
def __init__(self, pgp_fingerprint):
"""
Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
"""
super().__init__()
self.pgp_fingerprint = pgp_fingerprint
def get(self):
return self.merkle_easy_parser('/recipient/%s' % self.pgp_fingerprint)
class View(Base):
"""GET the transaction of given TRANSACTION_ID."""
def __init__(self, transaction_id):
"""
Arguments:
- `transaction_id`: The transaction unique identifier.
"""
super().__init__()
self.transaction_id = transaction_id
def get(self):
return self.requests_get('/view/%s' % self.transaction_id).json()
from . import sender
#
# 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
class Base(HDC):
"""Get the last received transaction of a PGP key."""
def __init__(self, pgp_fingerprint):
"""
Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
"""
super().__init__('hdc/transactions/sender/%s' % pgp_fingerprint)
class Last(Base):
"""Get the last received transaction of a PGP key."""
def __init__(self, pgp_fingerprint, count=None):
"""
Arguments:
- `count`: Integer indicating to retrieve the last [COUNT] transactions.
"""
super().__init__(pgp_fingerprint)
self.count = count
def get(self):
if not self.count:
return self.requests_get('/last').json()
return self.requests_get('/last/%d' % self.count).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)."""
def get(self):
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)."""
def get(self):
return self.merkle_easy_parser('/issuance')
from . import issuance
#
# 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
class Base(HDC):
"""Get the received issuance transaction of a PGP key."""
def __init__(self, pgp_fingerprint):
"""
Arguments:
- `pgp_fingerprint`: PGP fingerprint of the key we want to see sent transactions.
"""
super().__init__('hdc/transactions/sender/%s/issuance' % pgp_fingerprint)
class Last(Base):
"""GET the last received issuance transaction of a PGP key."""
def get(self):
return self.requests_get('/last').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):
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):
"""
Arguments:
- `am_number`: amendment number
"""
super().__init__(pgp_fingerprint)
self.am_number = am_number
def get(self):
if not self.am_number:
return self.merkle_easy_parser('/dividend')
return self.merkle_easy_parser('/dividend/%d' % self.am_number)
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