diff --git a/src/main/tjava/com/r35157/cryptowallet/solana/SolanaWallet.tjava b/src/main/tjava/com/r35157/cryptowallet/solana/SolanaWallet.tjava index c0fb335..e9bd819 100644 --- a/src/main/tjava/com/r35157/cryptowallet/solana/SolanaWallet.tjava +++ b/src/main/tjava/com/r35157/cryptowallet/solana/SolanaWallet.tjava @@ -52,6 +52,42 @@ public interface SolanaWallet { @NotNull SolanaSPLTokenProgram splProgram ) throws IOException, InterruptedException; + /** + * Sends a specific amount of SOL to another wallet. + * + *

The wallet builds, signs and submits the required transaction.

+ * + * @param recipient the wallet that should receive the SOL + * @param amount the amount of SOL to send + * @return the transaction signature returned by Solana RPC + * @throws IllegalArgumentException if the recipient or amount is invalid + * @throws IOException if the transaction cannot be built, signed or sent + * @throws InterruptedException if the calling thread is interrupted + */ + @NotNull + ΩSolanaTransactionSignatureΩ sendSolana( + @NotNull ΩSolanaWalletIdΩ recipient, + @NotNull ΩSolanaAmountΩ amount + ) throws IOException, InterruptedException; + + /** + * Sends the wallet's complete native SOL balance to another wallet after + * paying the exact transaction fee. + * + *

The wallet builds, signs and submits the required transaction.

+ * + * @param recipient the wallet that should receive the SOL + * @return the transaction signature returned by Solana RPC + * @throws IllegalArgumentException if the recipient is invalid + * @throws IllegalStateException if the balance cannot cover a transfer + * @throws IOException if the transaction cannot be built, signed or sent + * @throws InterruptedException if the calling thread is interrupted + */ + @NotNull + ΩSolanaTransactionSignatureΩ sendAllSolana( + @NotNull ΩSolanaWalletIdΩ recipient + ) throws IOException, InterruptedException; + /** * Builds an unsigned transaction that transfers a specific amount of SOL. * diff --git a/src/main/tjava/com/r35157/cryptowallet/solana/impl/ref/SolanaWalletImpl.tjava b/src/main/tjava/com/r35157/cryptowallet/solana/impl/ref/SolanaWalletImpl.tjava index 9eb6037..373b7c1 100644 --- a/src/main/tjava/com/r35157/cryptowallet/solana/impl/ref/SolanaWalletImpl.tjava +++ b/src/main/tjava/com/r35157/cryptowallet/solana/impl/ref/SolanaWalletImpl.tjava @@ -52,6 +52,40 @@ public class SolanaWalletImpl implements SolanaWallet { : tokenHolding.uiAmount(); } + @Override + public @NotNull ΩSolanaTransactionSignatureΩ sendSolana( + @NotNull ΩSolanaWalletIdΩ recipient, + @NotNull ΩSolanaAmountΩ amount + ) throws IOException, InterruptedException { + SolanaUnsignedTransaction unsignedTransaction = + solanaBlockChain.buildSolanaTransferTransaction( + address, + recipient, + amount + ); + + SolanaSignedTransaction signedTransaction = + signTransaction(unsignedTransaction); + + return solanaBlockChain.sendTransaction(signedTransaction); + } + + @Override + public @NotNull ΩSolanaTransactionSignatureΩ sendAllSolana( + @NotNull ΩSolanaWalletIdΩ recipient + ) throws IOException, InterruptedException { + SolanaUnsignedTransaction unsignedTransaction = + solanaBlockChain.buildSolanaTransferAllTransaction( + address, + recipient + ); + + SolanaSignedTransaction signedTransaction = + signTransaction(unsignedTransaction); + + return solanaBlockChain.sendTransaction(signedTransaction); + } + @Override public @NotNull SolanaUnsignedTransaction buildSolanaTransferTransaction( @NotNull ΩSolanaWalletIdΩ recipient,