Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
135 lines (122 loc) · 5.1 KB
/
Copy pathMain.java
File metadata and controls
135 lines (122 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import View.MainView;
import javafx.application.Application;
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;
import org.iota.jota.IotaAPI;
import org.iota.jota.builder.AddressRequest;
import org.iota.jota.dto.response.GetBalancesAndFormatResponse;
import org.iota.jota.dto.response.GetNodeInfoResponse;
import org.iota.jota.model.Input;
import org.iota.jota.model.Transfer;
import org.iota.jota.pow.pearldiver.PearlDiverLocalPoW;
import org.iota.jota.utils.TrytesConverter;
import java.util.*;
public class Main extends Application {
private IotaAPI iotaAPI;
private MainView theView;
private static final String protocol = "https"; //YOUR NODE INFO GOES HERE
private static final String host = "nodes.thetangle.org"; //YOUR NODE INFO GOES HERE
private static final int port = 443; //YOUR NODE INFO GOES HERE
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage primaryStage) {
theView = new MainView(primaryStage);
theView.setup();
theView.button0.setOnAction(e -> {
try {
apiSetup();
} catch (Exception ex) {
theView.errorWindow("ERROR CONNECTING TO NODE, PLEASE CHECK THE NODE ADDRESS AND RESTART THE APP", "ERROR");
System.out.println("ERROR CONNECTING TO NODE, PLEASE CHECK THE NODE ADDRESS AND RESTART THE APP");
}
});
theView.button1.setOnAction(e -> {
theView.resetFields(1235);
if(checkSeed(theView.field1.getText()) & checkAddress(theView.field2.getText()) & checkTag(theView.field3.getText()) & checkAmount(theView.field5.getText())) sendTransaction();
});
theView.button2.setOnAction(e -> {
theView.resetFields(125);
if(checkSeed(theView.field1.getText())) getAddress();
});
theView.button3.setOnAction(e -> {
theView.resetFields(125);
if(checkSeed(theView.field1.getText())) showBalance();
});
}
public void apiSetup() {
iotaAPI = new IotaAPI.Builder()
.protocol(protocol)
.localPoW(new PearlDiverLocalPoW())
.host(host)
.port(port)
.build();
GetNodeInfoResponse response = iotaAPI.getNodeInfo();
if(iotaAPI != null) {
theView.connectionUpdate(protocol + "://" + host + ":" + port);
}
System.out.println(response);
}
public void sendTransaction() {
String tag = "IOTA9TRANSFER9TOOL";
if(!theView.field3.getText().isEmpty()) tag = theView.field3.getText();
List<Transfer> transfers = new ArrayList<>();
List<Input> inputlist = new ArrayList<>();
transfers.add(new Transfer(theView.field2.getText(), Integer.parseInt(theView.field5.getText()), TrytesConverter.asciiToTrytes(theView.field4.getText()), tag));
if(theView.field5.getText().equals("0")) iotaAPI.sendTransfer(theView.field1.getText(), 2, 2, 14, transfers, null, null, false, true, null);
else {
inputlist.addAll(iotaAPI.getInputs(theView.field1.getText(), 2, 0, 30, 0).getInputs());
iotaAPI.sendTransfer(theView.field1.getText(), 2, 2, 14, transfers, inputlist, null, false, true, null);
}
System.out.println("Transaction sent.");
}
public void getAddress() {
AddressRequest addressRequest = new AddressRequest.Builder(theView.field1.getText(), 2).checksum(true).addSpendAddresses(false).build();
System.out.println(iotaAPI.generateNewAddresses(addressRequest).getAddresses().get(0));
}
public void showBalance() {
GetBalancesAndFormatResponse res = iotaAPI.getInputs(theView.field1.getText(), 2, 0, 30, 0);
System.out.println(res);
}
public boolean checkSeed(String seed) {
if(seed.length() != 81) {
theView.incorrectField(1);
return false;
}
else for(int i = 0; i < 81; i++) if(!((seed.charAt(i) > 64 && seed.charAt(i) < 91) || seed.charAt(i) == 57)) {
theView.incorrectField(1);
return false;
}
return true;
}
public boolean checkTag(String tag) {
if(tag.length() > 27) {
theView.incorrectField(3);
return false;
}
else for(int i = 0; i < tag.length(); i++) if(!((tag.charAt(i) > 64 && tag.charAt(i) < 91) || tag.charAt(i) == 57)) {
theView.incorrectField(3);
return false;
}
return true;
}
public boolean checkAmount(String amount) {
if(StringUtils.isNumeric(amount) && !amount.isEmpty()) return true;
else {
theView.incorrectField(5);
return false;
}
}
public boolean checkAddress(String address) {
if(address.length() != 90) {
theView.incorrectField(2);
return false;
}
else for(int i = 0; i < 90; i++) if(!((address.charAt(i) > 64 && address.charAt(i) < 91) || address.charAt(i) == 57)) {
theView.incorrectField(2);
return false;
}
return true;
}
}