@@ -803,47 +803,60 @@ func (s *transactionServer) CanWithdrawToAccount(ctx context.Context, req *trans
803803 }
804804 log = log .WithField ("account" , accountToCheck .PublicKey ().ToBase58 ())
805805
806+ isOnCurve := accountToCheck .IsOnCurve ()
807+
806808 //
807- // Part 1: Is this a timelock vault? If so, only allow primary accounts.
809+ // Part 1: Is this a Timelock vault? If so, only allow primary accounts.
808810 //
809811
810- accountInfoRecord , err := s .data .GetAccountInfoByTokenAddress (ctx , accountToCheck .PublicKey ().ToBase58 ())
811- switch err {
812- case nil :
813- return & transactionpb.CanWithdrawToAccountResponse {
814- IsValidPaymentDestination : accountInfoRecord .AccountType == commonpb .AccountType_PRIMARY ,
815- AccountType : transactionpb .CanWithdrawToAccountResponse_TokenAccount ,
816- }, nil
817- case account .ErrAccountInfoNotFound :
818- // Nothing to do
819- default :
820- log .WithError (err ).Warn ("failure checking account info db" )
821- return nil , status .Error (codes .Internal , "" )
812+ if ! isOnCurve {
813+ accountInfoRecord , err := s .data .GetAccountInfoByTokenAddress (ctx , accountToCheck .PublicKey ().ToBase58 ())
814+ switch err {
815+ case nil :
816+ return & transactionpb.CanWithdrawToAccountResponse {
817+ IsValidPaymentDestination : accountInfoRecord .AccountType == commonpb .AccountType_PRIMARY ,
818+ AccountType : transactionpb .CanWithdrawToAccountResponse_TokenAccount ,
819+ }, nil
820+ case account .ErrAccountInfoNotFound :
821+ // Nothing to do
822+ default :
823+ log .WithError (err ).Warn ("failure checking account info db" )
824+ return nil , status .Error (codes .Internal , "" )
825+ }
822826 }
823827
824828 //
825829 // Part 2: Is this an opened core mint token account? If so, allow it.
826830 //
827831
828- _ , err = s .data .GetBlockchainTokenAccountInfo (ctx , accountToCheck .PublicKey ().ToBase58 (), solana .CommitmentFinalized )
829- switch err {
830- case nil :
831- return & transactionpb.CanWithdrawToAccountResponse {
832- IsValidPaymentDestination : true ,
833- AccountType : transactionpb .CanWithdrawToAccountResponse_TokenAccount ,
834- }, nil
835- case token .ErrAccountNotFound , solana .ErrNoAccountInfo , token .ErrInvalidTokenAccount :
836- // Nothing to do
837- default :
838- log .WithError (err ).Warn ("failure checking against blockchain as a token account" )
839- return nil , status .Error (codes .Internal , "" )
832+ if ! isOnCurve {
833+ _ , err = s .data .GetBlockchainTokenAccountInfo (ctx , accountToCheck .PublicKey ().ToBase58 (), solana .CommitmentFinalized )
834+ switch err {
835+ case nil :
836+ return & transactionpb.CanWithdrawToAccountResponse {
837+ IsValidPaymentDestination : true ,
838+ AccountType : transactionpb .CanWithdrawToAccountResponse_TokenAccount ,
839+ }, nil
840+ case token .ErrAccountNotFound , solana .ErrNoAccountInfo , token .ErrInvalidTokenAccount :
841+ // Nothing to do
842+ default :
843+ log .WithError (err ).Warn ("failure checking against blockchain as a token account" )
844+ return nil , status .Error (codes .Internal , "" )
845+ }
840846 }
841847
842848 //
843849 // Part 3: Is this an owner account with an opened Core Mint ATA? If so, allow it.
844850 // If not, indicate to the client to pay a fee for a create-on-send withdrawal.
845851 //
846852
853+ if ! isOnCurve {
854+ return & transactionpb.CanWithdrawToAccountResponse {
855+ IsValidPaymentDestination : false ,
856+ AccountType : transactionpb .CanWithdrawToAccountResponse_Unknown ,
857+ }, nil
858+ }
859+
847860 ata , err := accountToCheck .ToAssociatedTokenAccount (common .CoreMintAccount )
848861 if err != nil {
849862 log .WithError (err ).Warn ("failure getting ata address" )
0 commit comments