This package was developed for sending and receiving RPC requests. It is using jackson library to convert between java and json objects.
It has three sub-packages
The most of the method classes have their own request classes where are kept the parameters and response class which is a method’s return type.
You can download maven project here.
Click the Code button and then download zip.
Unzip it to workspace directory and import as maven project.
The only SendRequest class’ send() method sends request to Electrum so you need to configure it in accordance your Electrum RPC configuration.
package electrum.methods;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.Base64;
public class SendRequest {
public synchronized InputStream send(String json) {
HttpClient client = HttpClient.newHttpClient();
// replace to your rpcuser and rpcpassowrd
String credentials = "user" + ":" + "t";
String auth = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes());
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://127.0.0.1:7777"))
.POST(BodyPublishers.ofString(json))
.setHeader("Content-Type", "application/x-www-form-urlencoded")
.setHeader("Authorization", auth)
.build();
HttpResponse<InputStream> response = null;
try {
response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response.body();
}
}
There are some examples in main().
package electrum.demo;
import java.util.Arrays;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import electrum.methods.Deserialize;
import electrum.methods.GetFeeRate;
import electrum.methods.GetOnChainHistory;
import electrum.methods.ListAddresses;
import electrum.methods.PayTo;
import electrum.methods.PayToMany;
import electrum.response.Output;
import electrum.response.Result;
import electrum.response.Transaction;
public class Main {
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
//getting feerate
int feerate = new GetFeeRate().getFeeRate();
System.out.println("feerate = "+ feerate);
//getting history
Result result = new GetOnChainHistory().getResult();
System.out.println("wallet balance = "+result.getSummary().getBegin().getBTC_balance()+" date = "+result.getSummary().getBegin().getDate());
System.out.println("wallet balance = "+result.getSummary().getEnd().getBTC_balance()+" date = "+result.getSummary().getEnd().getDate());
System.out.println("btc_incoming = "+result.getSummary().getFlow().getbTC_incoming());
Transaction[] transactions = result.getTransactions();
for(Transaction transaction : transactions) {
System.out.println("bc_value = "+transaction.getBc_value());
System.out.println("incoming = "+transaction.getIncoming());
System.out.println("conformations = "+transaction.getConfirmations());
System.out.println("txid = "+transaction.getTxid());
for(Output output : transaction.getOutputs()) {
System.out.println("address = " + output.getAddress());
}
System.out.println("Bc_value = "+transaction.getBc_value());
}
//deserialisig the code which you get when use payTo() or payToMany()
Output[] outputs = new Deserialize().deserialize("0200000000010126a65160de2bcc1e46308209670ed320ff23550fdb31b96a661608ede6a49d000000000000fdffffff02ac260000000000001600140ab8ce8b4c63186710c90ed4cbb14f64fecac7e310270000000000001600144fda16bb1c1d870875f54b27d705c03f89f92d4702473044022067ff1cccfaec698aeb81b74c9ff5872a4769e2e705865ad1dcbee78ce37e8cea02202c194a4d5b4e54f396c5482523fe001e31acbd75e966c4b4d29cd931df6c155a0121025ad75aac47e461cfebc26e2d3d1a53d90cc4f48556e1a89ceda06206f61a6d44493e2500");
for(Output output : outputs) {
System.out.println("address = " + output.getAddress());
//System.out.println("value_sats = " + output.getValue_sats());
}
// paying
String txid;
String[][] outputs1 = {{"tb1qq43jsy5q46sf3wljg8l7luqrjwjczeqhywjjfj", "0.0008"}, {"tb1qzs6fq7j9wn4x4w9daruvke5793fkw4yty03u5f", "0.0009"}, {"tb1q3pctvpvyzm799zmtw894achdxdw0l86zpcceu2", "0.0006"}};
txid = new PayToMany().payToMany(outputs1);
txid = new PayToMany().payToMany(outputs1);
System.out.println(txid);
txid = new PayTo().payTo("tb1qy8y23vgyzkgq438l4xpy0kp6dscp0yvkxt224l", 0.0001);
System.out.println(txid);
// getting electrum addresses
String[] strings = new ListAddresses().listAddresses();
System.out.println(Arrays.toString(strings));
try {
System.out.println(objectMapper.writeValueAsString(transactions[0].getOutputs()));
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Keno’s probability is fascinating – understanding patterns can subtly improve your game! I’ve been exploring platforms like lodibet club, and their app seems to make tracking numbers easier – a nice touch for serious players!
Smart bankroll management is key, even with accessible platforms. Seeing the emphasis on KYC & secure logins at ph978 casino login is reassuring – compliance matters! Just remember responsible gaming always.
Just scratched into the world of online gaming and PH987 is a real gem! The slots and live dealers are top-notch. Check out ph978 for an epic gaming rush!
Really insightful article! Seeing more strategic approaches to esports is awesome. Managing risk & maximizing returns-sounds like the philosophy behind a solid platform like fil777 app download. Definitely checking that out too! 🔥
Roulette’s allure is fascinating – the probabilities are deceptively simple, yet endlessly complex! Seeing platforms like ph978 casino games prioritize compliance & secure access (KYC is key!) is reassuring for players in the Philippines. It’s good to see responsible gaming gaining traction.
If you’re into slots and live games, PH987 offers a thrilling mix of excitement and top-notch security. The PH987 login process is smooth, making it easy to jump into the action. Definitely worth checking out!
Responsible gaming is key, folks! It’s easy to get carried away. Seeing platforms like legend link games focusing on secure logins & localized options (like Maya!) is a good sign. Remember to set limits!
That’s a great point about longshot value – often overlooked! Seeing platforms like wjpeso slot prioritize secure, modern tech and fast verification (KYC seems quick!) is encouraging for Philippine players. Definitely boosts trust!
Interesting read! Security in online gaming is crucial, especially with mobile access. Seeing platforms like Phlaro prioritize KYC & fast deposits is good. Check out phlaro download apk for a modern experience, but always gamble responsibly!
Interesting read! Transparency in gaming is key, and platforms like PH978 seem to be prioritizing that-especially with quick deposits via GCash. Check out the ph978 link for a data-driven experience – security & speed are a great combo!
That’s a great point about dealer interaction – it really makes or breaks a live game! Seeing how PH987 focuses on that social aspect, creating a true casino feel, is impressive. It’s not just about the tech, it’s the vibe!