mirror of
https://github.com/status-im/airbyte-custom-connector.git
synced 2025-02-17 03:16:36 +00:00
using multiple wallet
Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
parent
8444b3e731
commit
00e07b62c3
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
12
sample_files/wallet-2.json
Normal file
12
sample_files/wallet-2.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"wallets": [
|
||||
{
|
||||
"address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8",
|
||||
"name": "first random wallet"
|
||||
},
|
||||
{
|
||||
"address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
||||
"name": "second random wallet"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
{
|
||||
"wallet_address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8"
|
||||
"wallets": [
|
||||
{
|
||||
"address": "0x23f4569002a5A07f0Ecf688142eEB6bcD883eeF8",
|
||||
"name": "test"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -2,6 +2,12 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"wallet_name": {
|
||||
"type": [
|
||||
"null",
|
||||
"string"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": [
|
||||
"null",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user