11from xrpl .clients import JsonRpcClient
22from xrpl .asyncio .wallet import generate_faucet_wallet
3- from xrpl .models .requests import AccountInfo , AccountTx
3+ from xrpl .models .requests import AccountInfo , AccountTx , AccountLines
44from xrpl .utils import xrp_to_drops
55from src .main .users .repository .UserRepository import UserRepository
66import boto3
1212
1313TESTNET_URL = "https://s.altnet.rippletest.net:51234"
1414client = JsonRpcClient (TESTNET_URL )
15+ RLUSD_ISSUER = "rU3PzMJYPWXbkWZ2ze9dXzE9SG33uXqpWA"
16+ RLUSD_CURRENCY = "RLUSD"
17+
1518class UserService :
1619 def __init__ (self ):
1720 self .user_repository = UserRepository ()
@@ -29,6 +32,28 @@ def __init__(self):
2932 'cognito-idp' ,
3033 region_name = os .environ .get ('AWS_REGION' , 'ap-northeast-2' )
3134 )
35+
36+ def get_user_assets (self , wallet_address : str ) -> tuple [float , float ]:
37+ try :
38+ account_info = self .get_account_info (client , wallet_address )
39+ xrp_drops = account_info .result .get ("account_data" , {}).get ("Balance" , "0" )
40+ xrp_balance = float (xrp_drops ) / 1_000_000 # XRP 변환
41+
42+ from xrpl .models .requests import AccountLines
43+ account_lines = client .request (AccountLines (account = wallet_address ))
44+ trust_lines = account_lines .result .get ("lines" , [])
45+
46+ rlusd_balance = 0.0
47+ for line in trust_lines :
48+ if line .get ("currency" ) == "RLUSD" :
49+ rlusd_balance = float (line .get ("balance" , "0" ))
50+ break
51+
52+ return xrp_balance , rlusd_balance
53+
54+ except Exception as e :
55+ print (f"[ERROR] Failed to get user assets: { e } " )
56+ return 0.0 , 0.0
3257
3358 def get_wallets (self , user_id : str ):
3459 wallets = self .user_repository .find_wallets_by_user_id (user_id )
@@ -142,9 +167,15 @@ def get_user_info(self, user_id: str) -> UserInfoResponse:
142167 total_revenue = 0.0
143168 point = 0.0
144169 nft_grade = "브론즈"
170+ xrp_balance = 0.0
171+ rlusd_balance = 0.0
145172
146173 wallets = self .user_repository .find_wallets_by_user_id (user_id )
147174 if wallets :
175+ first_wallet = wallets [0 ]
176+ wallet_address = first_wallet .get ("address" )
177+ xrp_balance , rlusd_balance = self .get_user_assets (wallet_address )
178+
148179 for wallet in wallets :
149180 total_revenue += wallet .get ('total_revenue' , 0.0 )
150181 point += wallet .get ('point' , 0.0 )
@@ -156,7 +187,9 @@ def get_user_info(self, user_id: str) -> UserInfoResponse:
156187 nickname = nickname ,
157188 level_title = nft_grade ,
158189 point = point , # XRPL 계정 잔액으로 설정
159- total_revenue = total_revenue # 계산된 총 수익
190+ total_revenue = total_revenue , # 계산된 총 수익
191+ xrp_balance = xrp_balance ,
192+ rlusd_balance = rlusd_balance
160193 )
161194
162195 return user_info
0 commit comments