Skip to content

Commit

Permalink
Merge pull request #85 from juzi-code/sendRawTransaction
Browse files Browse the repository at this point in the history
Add support for directly sending signed raw transactions in the RpcApi class
  • Loading branch information
skynetcap authored Dec 28, 2024
2 parents dd4d91a + 7dbf1e0 commit d152a71
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/main/java/org/p2p/solanaj/rpc/RpcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,41 @@ public String sendTransaction(Transaction transaction, List<Account> signers, St
return sendTransaction(transaction, signers, recentBlockHash, new RpcSendTransactionConfig());
}

/**
* Sends a raw transaction to the network for processing.
*
* @param encodeSerializedTransaction The serialized transaction encoded in Base64 or Base58.
* @param rpcSendTransactionConfig The configuration object for sending transactions via RPC.
* @return The transaction ID as a string.
* @throws RpcException If an error occurs during the RPC call.
*/
public String sendRawTransaction(String encodeSerializedTransaction, RpcSendTransactionConfig rpcSendTransactionConfig)
throws RpcException {

List<Object> params = new ArrayList<>();

params.add(encodeSerializedTransaction);
params.add(rpcSendTransactionConfig);

return client.call("sendTransaction", params, String.class);
}

public void sendAndConfirmTransaction(Transaction transaction, List<Account> signers,
NotificationEventListener listener) throws RpcException {
NotificationEventListener listener) throws RpcException {
String signature = sendTransaction(transaction, signers, null);

SubscriptionWebSocketClient subClient = SubscriptionWebSocketClient.getInstance(client.getEndpoint());
subClient.signatureSubscribe(signature, listener);
}

public void sendAndConfirmRawTransaction(String encodeSerializedTransaction, RpcSendTransactionConfig rpcSendTransactionConfig,
NotificationEventListener listener) throws RpcException {
String signature = sendRawTransaction(encodeSerializedTransaction, rpcSendTransactionConfig);

SubscriptionWebSocketClient subClient = SubscriptionWebSocketClient.getInstance(client.getEndpoint());
subClient.signatureSubscribe(signature, listener);
}

public long getBalance(PublicKey account) throws RpcException {
return getBalance(account, null);
}
Expand Down Expand Up @@ -496,12 +523,12 @@ public List<RecentPrioritizationFees> getRecentPrioritizationFees(List<PublicKey
}

List<Map<String, Object>> rawResult = client.call("getRecentPrioritizationFees", params, List.class);

List<RecentPrioritizationFees> result = new ArrayList<>();
for (Map<String, Object> item : rawResult) {
result.add(new RecentPrioritizationFees(item));
}

return result;
}

Expand All @@ -524,7 +551,7 @@ public Long getStakeMinimumDelegation() throws RpcException {
*/
public Long getStakeMinimumDelegation(Commitment commitment) throws RpcException {
List<Object> params = new ArrayList<>();

if (commitment != null) {
Map<String, Object> configMap = new HashMap<>();
configMap.put("commitment", commitment.getValue());
Expand Down Expand Up @@ -924,17 +951,17 @@ public List<TokenAccount> getTokenLargestAccounts(PublicKey tokenMint, Commitmen
}

public TokenAccountInfo getTokenAccountsByOwner(PublicKey accountOwner, Map<String, Object> requiredParams,
Map<String, Object> optionalParams) throws RpcException {
Map<String, Object> optionalParams) throws RpcException {
return getTokenAccount(accountOwner, requiredParams, optionalParams, "getTokenAccountsByOwner");
}

public TokenAccountInfo getTokenAccountsByDelegate(PublicKey accountDelegate, Map<String, Object> requiredParams,
Map<String, Object> optionalParams) throws RpcException {
Map<String, Object> optionalParams) throws RpcException {
return getTokenAccount(accountDelegate, requiredParams, optionalParams, "getTokenAccountsByDelegate");
}

private TokenAccountInfo getTokenAccount(PublicKey account, Map<String, Object> requiredParams,
Map<String, Object> optionalParams, String method) throws RpcException {
Map<String, Object> optionalParams, String method) throws RpcException {
List<Object> params = new ArrayList<>();
params.add(account.toString());

Expand Down

0 comments on commit d152a71

Please sign in to comment.