From d4912b61735a3f455995912f8169b6f8e0fd7597 Mon Sep 17 00:00:00 2001
From: Innokenty <innokenty@singularitynet.io>
Date: Thu, 24 Oct 2024 13:31:27 +0300
Subject: [PATCH] snet_gate updated since new verion of snet-sdk released

---
 python/hyperon/exts/snet_io/snet_gate.py      | 83 +++----------------
 .../hyperon/exts/snet_io/test_snet_call.metta |  7 +-
 .../hyperon/exts/snet_io/test_snet_meta.metta |  3 +-
 3 files changed, 14 insertions(+), 79 deletions(-)

diff --git a/python/hyperon/exts/snet_io/snet_gate.py b/python/hyperon/exts/snet_io/snet_gate.py
index e334ffad5..c550eb384 100644
--- a/python/hyperon/exts/snet_io/snet_gate.py
+++ b/python/hyperon/exts/snet_io/snet_gate.py
@@ -14,21 +14,13 @@ def init_sdk(self,
                  private_key=os.getenv("SNET_PRIVATE_KEY", '0' * 32),
                  eth_rpc_endpoint=os.getenv("ETH_RPC_ENDPOINT"),
                  email=os.getenv("SNET_EMAIL"),
-                 identity_name="hyperon",
-                 network="mainnet",
-                 identity_type="key",
                  concurrency=False,
                  force_update=False):
-        config = {
-            "private_key": private_key,
-            "eth_rpc_endpoint": eth_rpc_endpoint,
-            "email": email,
-            "concurrency": concurrency,
-            "identity_name": identity_name,
-            "network": network,
-            "identity_type": identity_type,
-            "force_update": force_update
-        }
+        self.email = email
+        config = sdk.config.Config(private_key=private_key,
+                                   eth_rpc_endpoint=eth_rpc_endpoint,
+                                   concurrency=concurrency,
+                                   force_update=force_update)
         self.snet_sdk = sdk.SnetSDK(config)
 
     def organization_list(self):
@@ -44,7 +36,7 @@ def create_service_client(self, org_id, service_id,
             free_call_token_expiry_block = int(free_call_token_expiry_block)
         service_client = self.snet_sdk.create_service_client(
             org_id=org_id, service_id=service_id,
-            # group_name="default_group",
+            email=self.email,
             free_call_auth_token_bin=free_call_auth_token_bin,
             free_call_token_expiry_block=free_call_token_expiry_block)
         return ServiceCall(service_client)
@@ -103,60 +95,6 @@ def __call__(self, command_a, *args_a):
         return [E(S('Error'), E(S('snet-sdk'), command_a, *args_a),
                   ValueAtom(f'unknown command {repr(command_a)}'))]
 
-len_threshold = 50
-current_len = 0
-def pretty_print_atoms(input_atoms):
-
-    global len_threshold
-    global current_len
-    def process_svg_atom(atom):
-        global len_threshold
-        global current_len
-        repr_atom = repr(atom)
-        current_len += len(repr_atom)
-        return repr_atom
-
-    def check_len(depth):
-        global len_threshold
-        global current_len
-        if current_len > len_threshold:
-            current_len = 0
-            return "\n" + "\t" * (depth - 1)
-        else:
-            return ""
-
-    def process_atom(atom, depth):
-        global len_threshold
-        global current_len
-        process_res = ""
-        metatype = atom.get_metatype()
-        if metatype == AtomKind.EXPR:
-            len_to_last_eol_flag = current_len > 5
-            current_len *= (depth <= 1) * (not len_to_last_eol_flag)
-            process_res += ("\n" + "\t" * depth) * (
-                    depth > 0) * len_to_last_eol_flag + f"({process_expr_atom(atom, depth + 1)})"
-        elif (metatype == AtomKind.SYMBOL) or (metatype == AtomKind.VARIABLE) or (metatype == AtomKind.GROUNDED):
-            process_res += process_svg_atom(atom) + check_len(depth)
-        else:
-            raise Exception(f"Unexpected type of the Atom: {str(metatype)}")
-        return process_res
-
-    def process_expr_atom(expr_atom, depth):
-        sub_atoms = expr_atom.get_children()
-        process_res = ""
-        for sub_atom in sub_atoms:
-            process_atom_res = process_atom(sub_atom, depth)
-            process_res += process_atom_res + check_len(depth)
-            process_res += " "
-        return process_res[:-1]
-
-    res_string = "(" * (not (input_atoms[0].get_metatype() == AtomKind.EXPR))
-    current_len = 0
-    for atom in input_atoms:
-        res_string += process_atom(atom, 0)
-        res_string += "\n\n"
-        current_len = 0
-    return res_string
 
 class ServiceCall:
 
@@ -195,13 +133,14 @@ def get_service_messages(self):
     def get_operation_atom(self):
         return OperationAtom(self.service_details[1], self)
 
-    def generate_callers_text(self):
-        return pretty_print_atoms(self.generate_callers())
-
     def open_channel_and_deposit(self, amount, expiration):
         self.service_client.deposit_and_open_channel(amount, expiration)
         return [E()]
 
+    def generate_callers_text(self):
+        # TODO: pretty print
+        return "\n".join([repr(e) for e in self.generate_callers()])
+
     def _map_type(self, t):
         type_map = {'bool': 'Bool',
                     'string': 'String',
@@ -245,4 +184,4 @@ def snet_atoms():
     # TODO: new-sdk-atom
     return {
         'snet-sdk': defaultSDKAtom,
-    }
+    }
\ No newline at end of file
diff --git a/python/hyperon/exts/snet_io/test_snet_call.metta b/python/hyperon/exts/snet_io/test_snet_call.metta
index 7ecabda78..f2912469d 100644
--- a/python/hyperon/exts/snet_io/test_snet_call.metta
+++ b/python/hyperon/exts/snet_io/test_snet_call.metta
@@ -24,7 +24,7 @@
 (&image-generation
     "Gen" "Text" (Kwargs (sentence "Hello World") (type False)))
 
-(bind! &generative-lms
+!(bind! &generative-lms
   (snet-sdk create_service_client "naint" "generative-lms"))
 ; we can add a wrapper for the service
 (add-reduct &self
@@ -45,7 +45,4 @@
 (gen_gpt_2 "What was the largest dinosaur?" "universal" 0.5 2 100)
 
 ; possible usage of open_channel_and_deposit function. 100 is the amount of AGIX and 10000 is a payment channel's TTL in blocks
-(snet-sdk open_channel_and_deposit &generative-lms 100 10000)
-
-; usage of generate_callers_text method
-((py-dot &generative-lms generate_callers_text))
\ No newline at end of file
+(snet-sdk open_channel_and_deposit &generative-lms 100 10000)
\ No newline at end of file
diff --git a/python/hyperon/exts/snet_io/test_snet_meta.metta b/python/hyperon/exts/snet_io/test_snet_meta.metta
index 0d83b1620..74c692b50 100644
--- a/python/hyperon/exts/snet_io/test_snet_meta.metta
+++ b/python/hyperon/exts/snet_io/test_snet_meta.metta
@@ -31,5 +31,4 @@
 ; (naint punctuation-restoration) returns a service caller now
 !((py-dot (naint punctuation-restoration) get_service_messages))
 ; we can also get a list of all service methods as typed metta functions
-!(naint punctuation-restoration methods)
-
+!(naint punctuation-restoration methods)
\ No newline at end of file