Skip to content

Commit db00818

Browse files
committed
Move VA network RPC variable to config
1 parent 1b478dc commit db00818

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ If you just want to start a single instance of the app and run it directly::
297297
password_providers:
298298
- module: "synapse.handlers.vaccount_auth.VaccountAuthProvider"
299299
config:
300+
NETWORK_PRC_URI: "https://api.velas.com"
300301
REDIS_HOSTNAME: "redis"
301302
REDIS_PASS: "development"
302303
REDIS_REPLICATION_MODE: "master"

synapse/handlers/vaccount_auth/auth_provider.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
from hashlib import sha256
2424

2525
from twisted.internet import defer
26+
from solana.rpc.api import Client
2627
from solana.publickey import PublicKey
2728
from nacl.signing import VerifyKey
2829
from nacl.exceptions import BadSignatureError
2930
from redis import Redis
3031

3132
import logging
3233

33-
from synapse.handlers.vaccount_auth.constants import SIGN_TIMESTAMP_TOLERANCE, OPERATIONAL_STATE
34+
from synapse.handlers.vaccount_auth.constants import SIGN_TIMESTAMP_TOLERANCE, OPERATIONAL_STATE, TESTNET_PRC_URI
3435
from synapse.handlers.vaccount_auth.utils import VaccountInfo, get_vaccount_evm_address
3536
from synapse.api.errors import HttpResponseException
3637
from synapse.handlers.vaccount_auth.utils import is_valid_vaccount_address
@@ -48,6 +49,9 @@ class VaccountAuthProvider:
4849
def __init__(self, config, account_handler: ModuleApi):
4950
self.account_handler = account_handler
5051
self.store: DataStore = account_handler._hs.get_datastore()
52+
self.velas_client = Client(
53+
endpoint=config.get('NETWORK_PRC_URI', TESTNET_PRC_URI),
54+
)
5155
self.redis = Redis(
5256
host=config.get('REDIS_HOSTNAME'),
5357
port=config.get('REDIS_PORT'),
@@ -215,7 +219,7 @@ async def register_user(self, localpart, displayname):
215219
async def _is_active_vaccount(self, vaccount_address: PublicKey, signer: PublicKey, signer_type: str) -> bool:
216220
"""
217221
"""
218-
vaccount_info = VaccountInfo(vaccount_address)
222+
vaccount_info = VaccountInfo(vaccount_address, self.velas_client)
219223

220224
if vaccount_info.is_ephemeral():
221225
return is_valid_vaccount_address(signer, vaccount_address)

synapse/handlers/vaccount_auth/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
VACCOUNT_PROGRAM_ID = PublicKey("VAcccHVjpknkW5N5R9sfRppQxYJrJYVV7QJGKchkQj5")
1414
VACCOUNT_SEED = b'vaccount'
15-
VELAS_RPC_URI = 'https://api.testnet.velas.com'
15+
TESTNET_PRC_URI = 'https://api.testnet.velas.com'
1616
BASE_OPERATIONAL_LEN = 134
1717

1818
SIGN_TIMESTAMP_TOLERANCE = 120

synapse/handlers/vaccount_auth/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
VACCOUNT_PROGRAM_ID,
1212
VACCOUNT_SEED,
1313
VACCOUNT_INFO,
14-
VELAS_RPC_URI,
1514
OPERATIONAL_INFO,
1615
)
1716

@@ -48,7 +47,7 @@ def is_valid_vaccount_address(genesis_key_seed: PublicKey, vaccount_id: PublicKe
4847
return False
4948

5049

51-
def find_vaccount_address(genesis_key_seed: PublicKey) -> [Tuple[PublicKey, int], None]:
50+
def find_vaccount_address(genesis_key_seed: PublicKey) -> Union[Tuple[PublicKey, int], None]:
5251
"""Find valid `Vaccount` address.
5352
5453
Valid `Vaccount` addresses must fall off the ed25519 curve. This function
@@ -113,7 +112,7 @@ def get_vaccount_evm_address(vaccount_address: PublicKey) -> str:
113112
class VaccountInfo:
114113
"""Parsed representing Vaccount information"""
115114

116-
def __init__(self, vaccount_pubkey: Union[PublicKey, bytearray, bytes, int, str, List[int]], client=Client(VELAS_RPC_URI)):
115+
def __init__(self, vaccount_pubkey: Union[PublicKey, bytearray, bytes, int, str, List[int]], client: Client):
117116
self.client = client
118117
self.pubkey = vaccount_pubkey if isinstance(vaccount_pubkey, PublicKey) else PublicKey(vaccount_pubkey)
119118
self.version = None

0 commit comments

Comments
 (0)