Skip to content

Commit e660763

Browse files
authored
Reafctor: 사용자 정보 보여주기 수정 (#30)
## 작업 내역 (관련 이슈) - 사용자 정보 보여주기 기능을 수정했습니다. ## 특이 사항 -
2 parents 4c469a0 + 5406686 commit e660763

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/main/users/dto/UserInfoDto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ class UserInfoResponse(BaseModel):
66
level_title: str
77
point: float
88
total_revenue: float
9+
xrp_balance: float
10+
rlusd_balance: float

src/main/users/service/UserService.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from xrpl.clients import JsonRpcClient
22
from xrpl.asyncio.wallet import generate_faucet_wallet
3-
from xrpl.models.requests import AccountInfo, AccountTx
3+
from xrpl.models.requests import AccountInfo, AccountTx, AccountLines
44
from xrpl.utils import xrp_to_drops
55
from src.main.users.repository.UserRepository import UserRepository
66
import boto3
@@ -12,6 +12,9 @@
1212

1313
TESTNET_URL = "https://s.altnet.rippletest.net:51234"
1414
client = JsonRpcClient(TESTNET_URL)
15+
RLUSD_ISSUER = "rU3PzMJYPWXbkWZ2ze9dXzE9SG33uXqpWA"
16+
RLUSD_CURRENCY = "RLUSD"
17+
1518
class 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

Comments
 (0)