From 485505001a673765086e91dad6663991a147ce0d Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Thu, 22 May 2014 15:28:05 +0200 Subject: [PATCH] Removing wrappers from ucoinpy api --- ucoin/wrappers/__init__.py | 33 ---------- ucoin/wrappers/coins.py | 86 -------------------------- ucoin/wrappers/transactions.py | 106 --------------------------------- 3 files changed, 225 deletions(-) delete mode 100644 ucoin/wrappers/__init__.py delete mode 100644 ucoin/wrappers/coins.py delete mode 100644 ucoin/wrappers/transactions.py diff --git a/ucoin/wrappers/__init__.py b/ucoin/wrappers/__init__.py deleted file mode 100644 index 31fc5405..00000000 --- a/ucoin/wrappers/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python3 -# -# 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 -# - -import logging -from .. import pks, hdc, network, registry, settings - -logger = logging.getLogger("wrappers") - -class Wrapper: - def __init__(self, server=None, port=None): - self.server = server - self.port = port - - def __call__(self): - pass - -from . import transactions, coins diff --git a/ucoin/wrappers/coins.py b/ucoin/wrappers/coins.py deleted file mode 100644 index c292b3cc..00000000 --- a/ucoin/wrappers/coins.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python3 -# -# 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 -# - -import logging -from . import Wrapper, pks, network, hdc, settings - -logger = logging.getLogger("coins") - -class Coins(Wrapper): - def __init__(self, pgp_fingerprint, server=None, port=None): - super().__init__(server, port) - - self.pgp_fingerprint = pgp_fingerprint - -class Get(Coins): - def __init__(self, pgp_fingerprint, values, server=None, port=None): - super().__init__(pgp_fingerprint, server, port) - - self.values = values - - def __call__(self): - __list = hdc.coins.List(self.pgp_fingerprint, self.server, self.port).get() - coins = {} - for c in __list['coins']: - for id in c['ids']: - n,b,p,t,i = id.split('-') - amount = int(b) * 10**int(p) - if amount not in coins: coins[amount] = [] - coins[amount].append({'issuer': c['issuer'], 'number': int(n), 'base': int(b), 'power': int(p), 'type': t, 'type_number': int(i), 'amount': amount}) - - issuers = {} - for v in self.values: - if v in coins and coins[v]: - c = coins[v].pop() - issuers[c['issuer']] = issuers.get(c['issuer']) or [] - issuers[c['issuer']].append(c) - else: - raise ValueError('You do not have enough coins of value (%d)' % v) - - res = '' - for i, issuer in enumerate(issuers): - if i > 0: res += ',' - res += issuer - for c in issuers[issuer]: - res += ':%(number)d' % c - - return res - -class List(Coins): - def __init__(self, pgp_fingerprint, limit=None, server=None, port=None): - super().__init__(pgp_fingerprint, server, port) - - self.limit = limit - - def __call__(self): - __list = hdc.coins.List(self.pgp_fingerprint, self.server, self.port).get() - coins = [] - __sum = 0 - - for c in __list['coins']: - for id in c['ids']: - n,b,p,t,i = id.split('-') - amount = int(b) * 10**int(p) - __dict = {'issuer': c['issuer'], 'number': int(n), 'base': int(b), 'power': int(p), 'type': t, 'type_number': int(i), 'amount': amount} - - if not self.limit or self.limit >= amount: - coins.append(__dict) - __sum += amount - - return __sum, coins diff --git a/ucoin/wrappers/transactions.py b/ucoin/wrappers/transactions.py deleted file mode 100644 index 78eec453..00000000 --- a/ucoin/wrappers/transactions.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 -# -# 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 -# - -import hashlib, logging, re -from . import Wrapper, pks, network, hdc, registry, settings - -logger = logging.getLogger("transactions") - - -class Transaction(Wrapper): - def __init__(self, pgp_fingerprint, recipient, coins, message='', keyid=None, peering=None, server=None, port=None): - super().__init__(server, port) - self.keyid = keyid - self.pgp_fingerprint = pgp_fingerprint - self.message = message - self.error = None - self.peering = peering - self.recipient = recipient - self.coins = coins - self.coins.sort() - - def __call__(self): - tx = self.get_message() - txs = settings['gpg'].sign(tx, keyid=self.keyid, detach=True) - return (tx, txs) - - def get_context_data(self): - return {} - - def get_message(self): - try: - last_tx = hdc.transactions.sender.Last(count=1, pgp_fingerprint=self.pgp_fingerprint, - server=self.server, port=self.port).get() - last_tx = last_tx['transactions'][0] - last_tx = hdc.transactions.sender.View(self.pgp_fingerprint, tx_number=last_tx['number'], - server=self.server, port=self.port).get() - except ValueError: - last_tx = None - - if last_tx: - previous_hash = hashlib.sha1(("%s%s" % (last_tx['raw'], last_tx['transaction']['signature'])).encode('ascii')).hexdigest().upper() - else: - previous_hash = None - - context_data = {} - context_data.update(settings) - context_data.update(self.peering if self.peering else network.Peering(server=self.server, port=self.port).get()) - context_data['version'] = 1 - context_data['number'] = 0 if not last_tx else last_tx['transaction']['number']+1 - context_data['previousHash'] = previous_hash - context_data['message'] = self.message - context_data['fingerprint'] = self.pgp_fingerprint - context_data['recipient'] = self.recipient - context_data.update(self.get_context_data()) - - tx = """\ -Version: %(version)d -Currency: %(currency)s -Sender: %(fingerprint)s -Number: %(number)d -""" % context_data - - if last_tx: tx += "PreviousHash: %(previousHash)s\n" % context_data - - - tx += """\ -Recipient: %(recipient)s -Coins: -""" % context_data - - for coin in self.coins: - tx += '%s' % coin - ownership = hdc.coins.view.Owner(coin, self.server, self.port).get() - if 'transaction' in ownership: - tx += ':%(transaction)s\n' % ownership - else: - tx += "\n" - - return tx - - tx += """\ -Comment: -%(message)s""" % context_data - - tx = tx.replace("\n", "\r\n") - return tx - - def get_error(self): - return self.error - -- GitLab