From 70531a3ba4e31d3d58fd99a693690e19c7080f02 Mon Sep 17 00:00:00 2001
From: inso <insomniak.fr@gmaiL.com>
Date: Tue, 17 Jan 2017 12:41:03 +0100
Subject: [PATCH] Fix owner of sources sent ( #553 )

---
 src/sakia/data/processors/sources.py | 5 +++--
 src/sakia/services/documents.py      | 7 ++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/sakia/data/processors/sources.py b/src/sakia/data/processors/sources.py
index 70e47005..006352b5 100644
--- a/src/sakia/data/processors/sources.py
+++ b/src/sakia/data/processors/sources.py
@@ -62,12 +62,13 @@ class SourcesProcessor:
         sources = self._repo.get_all(currency=currency, pubkey=pubkey)
         return sum([s.amount * (10**s.base) for s in sources])
 
-    def available(self, currency):
+    def available(self, currency, pubkey):
         """"
         :param str currency: the currency of the sources
+        :param str pubkey: the owner of the sources
         :rtype: list[sakia.data.entities.Source]
         """
-        return self._repo.get_all(currency=currency)
+        return self._repo.get_all(currency=currency, pubkey=pubkey)
 
     def consume(self, sources):
         """
diff --git a/src/sakia/services/documents.py b/src/sakia/services/documents.py
index 2fc43b34..3be55c31 100644
--- a/src/sakia/services/documents.py
+++ b/src/sakia/services/documents.py
@@ -212,12 +212,13 @@ class DocumentsService:
         document.sign(self_cert, [key])
         return document.signed_raw(self_cert)
 
-    def tx_sources(self, amount, amount_base, currency):
+    def tx_sources(self, amount, amount_base, currency, pubkey):
         """
         Get inputs to generate a transaction with a given amount of money
         :param int amount: The amount target value
         :param int amount_base: The amount base target value
         :param str currency: The community target of the transaction
+        :param str pubkey: The pubkey owning the sources
         :return: The list of inputs to use in the transaction document
         """
 
@@ -234,7 +235,7 @@ class DocumentsService:
             return i
 
         amount, amount_base = reduce_base(amount, amount_base)
-        available_sources = self._sources_processor.available(currency)
+        available_sources = self._sources_processor.available(currency, pubkey)
         if available_sources:
             current_base = max([src.base for src in available_sources])
             value = 0
@@ -335,7 +336,7 @@ class DocumentsService:
         :return: the transaction document
         :rtype: duniterpy.documents.Transaction
         """
-        result = self.tx_sources(int(amount), amount_base, currency)
+        result = self.tx_sources(int(amount), amount_base, currency, issuer)
         sources = result[0]
         computed_outputs = result[1]
         overheads = result[2]
-- 
GitLab