Skip to content

Commit fd84e40

Browse files
committed
Handle deposit PDA edge cases in CanWithdrawToAccount
1 parent 7dc8cf0 commit fd84e40

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/code/server/transaction/withdraw.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (s *transactionServer) CanWithdrawToAccount(ctx context.Context, req *trans
9191
//
9292

9393
var isVmDepositPda bool
94-
_, err = s.data.GetTimelockByDepositPda(ctx, accountToCheck.PublicKey().ToBase58())
94+
timelockRecord, err := s.data.GetTimelockByDepositPda(ctx, accountToCheck.PublicKey().ToBase58())
9595
switch err {
9696
case nil:
9797
isVmDepositPda = true
@@ -108,6 +108,21 @@ func (s *transactionServer) CanWithdrawToAccount(ctx context.Context, req *trans
108108
}, nil
109109
}
110110

111+
if isVmDepositPda {
112+
accountInfoRecord, err := s.data.GetAccountInfoByTokenAddress(ctx, timelockRecord.VaultAddress)
113+
if err != nil {
114+
log.WithError(err).Warn("failure checking account info db")
115+
return nil, status.Error(codes.Internal, "")
116+
}
117+
118+
if accountInfoRecord.AccountType != commonpb.AccountType_PRIMARY || accountInfoRecord.MintAccount != mintAccount.PublicKey().ToBase58() {
119+
return &transactionpb.CanWithdrawToAccountResponse{
120+
IsValidPaymentDestination: false,
121+
AccountType: transactionpb.CanWithdrawToAccountResponse_Unknown,
122+
}, nil
123+
}
124+
}
125+
111126
ata, err := accountToCheck.ToAssociatedTokenAccount(mintAccount)
112127
if err != nil {
113128
log.WithError(err).Warn("failure getting ata address")

0 commit comments

Comments
 (0)