using multiple wallet

Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
Alexis Pentori 2023-11-30 18:39:06 +01:00
parent 8444b3e731
commit 00e07b62c3
No known key found for this signature in database
GPG Key ID: 65250D2801E47A10
7 changed files with 78 additions and 16 deletions

View File

@ -7,8 +7,23 @@
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"type": "object", "type": "object",
"properties": { "properties": {
"wallet_address": { "wallets": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"address"
],
"properties": {
"name": {
"type": "string" "type": "string"
},
"address": {
"type": "string"
}
}
}
} }
} }
}, },

View File

@ -0,0 +1,12 @@
{
"wallets": [
{
"address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8",
"name": "first random wallet"
},
{
"address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"name": "second random wallet"
}
]
}

View File

@ -1,3 +1,8 @@
{ {
"wallet_address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8" "wallets": [
{
"address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8",
"name": "test"
}
]
} }

View File

@ -2,6 +2,12 @@
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "type": "object",
"properties": { "properties": {
"wallet_name": {
"type": [
"null",
"string"
]
},
"name": { "name": {
"type": [ "type": [
"null", "null",

View File

@ -24,9 +24,10 @@ class Token(HttpStream):
# Set this as a noop. # Set this as a noop.
primary_key = None primary_key = None
def __init__(self, wallet_address: str, **kwargs): def __init__(self, wallet_address: str, wallet_name: str, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.wallet_address = wallet_address self.wallet_address = wallet_address
self.wallet_name = wallet_name
def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]: def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
return None return None
@ -56,7 +57,7 @@ class Token(HttpStream):
tokens_data=response.json()['tokens'] tokens_data=response.json()['tokens']
for t in tokens_data: for t in tokens_data:
try: try:
yield extract_token(t) yield extract_token(self.wallet_name, t)
except Exception as e: except Exception as e:
logger.error('Dropping token not valid %s' % t ) logger.error('Dropping token not valid %s' % t )
# Source # Source
@ -72,4 +73,13 @@ class SourceWalletFetcher(AbstractSource):
:param config: A Mapping of the user input configuration as defined in the connector spec. :param config: A Mapping of the user input configuration as defined in the connector spec.
""" """
# TODO remove the authenticator if not required. # 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

View File

@ -4,13 +4,26 @@ connectionSpecification:
title: Wallet Fetcher Spec title: Wallet Fetcher Spec
type: object type: object
required: required:
- wallet_address - wallets
# - chains
properties: properties:
wallet_address: wallets:
# TODO: change to List to handle multiple wallets type: array
description: list of wallet
items:
name:
type: string
description: Name of the wallet
examples:
- 'Main Wallet'
address:
type: string type: string
description: Adress of the wallet description: Adress of the wallet
pattern: ^[a-zA-W0-9]+$ pattern: ^[a-zA-W0-9]+$
examples: examples:
- '0x766c77F7f7edC99acdC9475012756B98037a8F69' - '0x766c77F7f7edC99acdC9475012756B98037a8F69'
chain:
type: string
description: 'Blockchain to scan. Not working yet'
default: ETH

View File

@ -2,7 +2,7 @@ import logging
import json 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'] 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'] symbol= 'No Symbol' if 'symbol' not in token_data['tokenInfo'] else token_data['tokenInfo']['symbol']
try: try:
@ -10,6 +10,7 @@ def extract_token(token_data):
# The data is not valid, droping it. # The data is not valid, droping it.
raise Exception('Not a valid token') raise Exception('Not a valid token')
token = { token = {
"wallet_name": wallet_name,
"name": token_data['tokenInfo']['name'], "name": token_data['tokenInfo']['name'],
"symbol": symbol, "symbol": symbol,
"description": description, "description": description,