From 00e07b62c372494ef21ca345cb27ee261245b000 Mon Sep 17 00:00:00 2001 From: Alexis Pentori Date: Thu, 30 Nov 2023 18:39:06 +0100 Subject: [PATCH] using multiple wallet Signed-off-by: Alexis Pentori --- sample_files/configured_catalog.json | 19 +++++++++++++-- sample_files/wallet-2.json | 12 +++++++++ sample_files/wallet.json | 7 +++++- source_wallet_fetcher/schemas/token.json | 6 +++++ source_wallet_fetcher/source.py | 16 +++++++++--- source_wallet_fetcher/spec.yaml | 31 +++++++++++++++++------- source_wallet_fetcher/utils.py | 3 ++- 7 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 sample_files/wallet-2.json diff --git a/sample_files/configured_catalog.json b/sample_files/configured_catalog.json index 4d1a020..5cde3c5 100644 --- a/sample_files/configured_catalog.json +++ b/sample_files/configured_catalog.json @@ -7,8 +7,23 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "wallet_address": { - "type": "string" + "wallets": { + "type": "array", + "items": { + "type": "object", + "required": [ + "name", + "address" + ], + "properties": { + "name": { + "type": "string" + }, + "address": { + "type": "string" + } + } + } } } }, diff --git a/sample_files/wallet-2.json b/sample_files/wallet-2.json new file mode 100644 index 0000000..79755f1 --- /dev/null +++ b/sample_files/wallet-2.json @@ -0,0 +1,12 @@ +{ + "wallets": [ + { + "address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8", + "name": "first random wallet" + }, + { + "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7", + "name": "second random wallet" + } + ] +} diff --git a/sample_files/wallet.json b/sample_files/wallet.json index db01285..0f7678c 100644 --- a/sample_files/wallet.json +++ b/sample_files/wallet.json @@ -1,3 +1,8 @@ { - "wallet_address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8" + "wallets": [ + { + "address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8", + "name": "test" + } + ] } diff --git a/source_wallet_fetcher/schemas/token.json b/source_wallet_fetcher/schemas/token.json index 91e86c1..6013be6 100644 --- a/source_wallet_fetcher/schemas/token.json +++ b/source_wallet_fetcher/schemas/token.json @@ -2,6 +2,12 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { + "wallet_name": { + "type": [ + "null", + "string" + ] + }, "name": { "type": [ "null", diff --git a/source_wallet_fetcher/source.py b/source_wallet_fetcher/source.py index 32b6937..c0eb5a2 100644 --- a/source_wallet_fetcher/source.py +++ b/source_wallet_fetcher/source.py @@ -24,9 +24,10 @@ class Token(HttpStream): # Set this as a noop. primary_key = None - def __init__(self, wallet_address: str, **kwargs): + def __init__(self, wallet_address: str, wallet_name: str, **kwargs): super().__init__(**kwargs) self.wallet_address = wallet_address + self.wallet_name = wallet_name def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: return None @@ -56,7 +57,7 @@ class Token(HttpStream): tokens_data=response.json()['tokens'] for t in tokens_data: try: - yield extract_token(t) + yield extract_token(self.wallet_name, t) except Exception as e: logger.error('Dropping token not valid %s' % t ) # Source @@ -72,4 +73,13 @@ class SourceWalletFetcher(AbstractSource): :param config: A Mapping of the user input configuration as defined in the connector spec. """ # TODO remove the authenticator if not required. - return [Token(wallet_address=config["wallet_address"])] + tokens: List[Token] = [] + + for wallet in config["wallets"]: + tokens.append( + Token( + wallet_address=wallet['address'], + wallet_name=wallet['name'] + ) + ) + return tokens diff --git a/source_wallet_fetcher/spec.yaml b/source_wallet_fetcher/spec.yaml index e0cbe3e..4894011 100644 --- a/source_wallet_fetcher/spec.yaml +++ b/source_wallet_fetcher/spec.yaml @@ -4,13 +4,26 @@ connectionSpecification: title: Wallet Fetcher Spec type: object required: - - wallet_address - # - chains + - wallets properties: - wallet_address: - # TODO: change to List to handle multiple wallets - type: string - description: Adress of the wallet - pattern: ^[a-zA-W0-9]+$ - examples: - - '0x766c77F7f7edC99acdC9475012756B98037a8F69' + wallets: + type: array + description: list of wallet + items: + name: + type: string + description: Name of the wallet + examples: + - 'Main Wallet' + address: + type: string + description: Adress of the wallet + pattern: ^[a-zA-W0-9]+$ + examples: + - '0x766c77F7f7edC99acdC9475012756B98037a8F69' + chain: + type: string + description: 'Blockchain to scan. Not working yet' + default: ETH + + diff --git a/source_wallet_fetcher/utils.py b/source_wallet_fetcher/utils.py index 061db15..ff16663 100644 --- a/source_wallet_fetcher/utils.py +++ b/source_wallet_fetcher/utils.py @@ -2,7 +2,7 @@ import logging import json -def extract_token(token_data): +def extract_token(wallet_name, token_data): description= 'No description available' if 'description' not in token_data['tokenInfo'] else token_data['tokenInfo']['description'] symbol= 'No Symbol' if 'symbol' not in token_data['tokenInfo'] else token_data['tokenInfo']['symbol'] try: @@ -10,6 +10,7 @@ def extract_token(token_data): # The data is not valid, droping it. raise Exception('Not a valid token') token = { + "wallet_name": wallet_name, "name": token_data['tokenInfo']['name'], "symbol": symbol, "description": description,