From 95640d4c52c19a25fb2775d2319baf41c2905391 Mon Sep 17 00:00:00 2001
From: crokkon <33018033+crokkon@users.noreply.github.com>
Date: Wed, 20 Jun 2018 16:50:18 +0200
Subject: [PATCH] move get_similar_account_names to Blockchain

---
 beem/account.py    | 29 ++++++++++-------------------
 beem/blockchain.py | 26 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/beem/account.py b/beem/account.py
index 15f2d2a8..9d3c1da6 100644
--- a/beem/account.py
+++ b/beem/account.py
@@ -215,29 +215,20 @@ class Account(BlockchainObject):
         return self.get_similar_account_names(limit=limit)
 
     def get_similar_account_names(self, limit=5):
-        """ Returns limit similar accounts with name as list
+        """ Returns ``limit`` account names similar to the current account
+            name as a list
 
-        :param int limit: limits the number of accounts, which will be returned
-        :returns: Similar account names as list
-        :rtype: list
+            :param int limit: limits the number of accounts, which will be
+                returned
+            :returns: Similar account names as list
+            :rtype: list
 
-        .. code-block:: python
-
-            >>> from beem.account import Account
-            >>> account = Account("test")
-            >>> len(account.get_similar_account_names(limit=5))
-            5
+            This is a wrapper around ``Blockchain.get_similar_account_names()``
+            using the current account name as reference.
 
         """
-        if not self.steem.is_connected():
-            return None
-        self.steem.rpc.set_next_node_on_empty_reply(False)
-        if self.steem.rpc.get_use_appbase():
-            account = self.steem.rpc.list_accounts({'start': self.name, 'limit': limit}, api="database")
-            if bool(account):
-                return account["accounts"]
-        else:
-            return self.steem.rpc.lookup_accounts(self.name, limit)
+        b = Blockchain(steem_instance=self.steem)
+        return b.get_similar_account_names(self.name, limit=limit)
 
     @property
     def name(self):
diff --git a/beem/blockchain.py b/beem/blockchain.py
index cdb89250..bbda7ced 100644
--- a/beem/blockchain.py
+++ b/beem/blockchain.py
@@ -847,3 +847,29 @@ class Blockchain(object):
             lastname = account_name
             if len(ret) < steps:
                 raise StopIteration
+
+    def get_similar_account_names(self, name, limit=5):
+        """ Returns limit similar accounts with name as list
+
+        :param str name: account name to search similars for
+        :param int limit: limits the number of accounts, which will be returned
+        :returns: Similar account names as list
+        :rtype: list
+
+        .. code-block:: python
+
+            >>> from beem.blockchain import Blockchain
+            >>> blockchain = Blockchain()
+            >>> blockchain.get_similar_account_names("test", limit=5)
+            ['test', 'test-1', 'test-2', 'test-ico', 'test-ilionx-123']
+
+        """
+        if not self.steem.is_connected():
+            return None
+        self.steem.rpc.set_next_node_on_empty_reply(False)
+        if self.steem.rpc.get_use_appbase():
+            account = self.steem.rpc.list_accounts({'start': name, 'limit': limit}, api="database")
+            if bool(account):
+                return account["accounts"]
+        else:
+            return self.steem.rpc.lookup_accounts(name, limit)
-- 
GitLab