-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathForwardingServlet.java
More file actions
112 lines (83 loc) · 4.14 KB
/
ForwardingServlet.java
File metadata and controls
112 lines (83 loc) · 4.14 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
package piuk.website;
import org.json.JSONObject;
import piuk.beans.BitcoinAddress;
import piuk.common.Pair;
import piuk.db.BitcoinDatabaseManager;
import piuk.website.admin.operations.ProcessForwardsOperation;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
@WebServlet({ HomeServlet.ROOT + "forwarder" })
public class ForwardingServlet extends BaseServlet {
public static final double MixingFeePercent = 1.5;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
try {
super.doGet(req, res);
} catch (ServletException e) {
return;
}
String action = req.getParameter("action");
if (action == null)
return;
try {
if (action.equals("create-mix")) {
String destinationAddress = req.getParameter("address");
if (destinationAddress == null)
throw new Exception("You Must Provide a Destination Address");
BitcoinAddress address = new BitcoinAddress(destinationAddress);
if (address == null || !address.toString().equals(destinationAddress))
throw new Exception("Error parsing Destination address");
Connection conn = BitcoinDatabaseManager.conn();
try {
conn.setAutoCommit(false);
Pair<BitcoinAddress, String> input_generated = ProcessForwardsOperation.generateNewEncryptedPK();
Pair<BitcoinAddress, String> output_generated = ProcessForwardsOperation.generateNewEncryptedPK();
//Create one forwarding which the user needs to fund
ProcessForwardsOperation.Forwarding first = new ProcessForwardsOperation.Forwarding();
first.input_address = input_generated.getFirst().toString();
first.input_priv = input_generated.getSecond();
first.output_address = output_generated.getFirst().toString();
first.taint = 0;
first.fee_percent = MixingFeePercent;
first.confirmations = 0;
if (!first.insert(conn)) {
throw new SQLException(("Error inserting input_generated forwarding pair"));
}
//Insert the second forwarding
ProcessForwardsOperation.Forwarding second = new ProcessForwardsOperation.Forwarding();
second.input_address = output_generated.getFirst().toString();
second.input_priv = output_generated.getSecond();
second.output_address = destinationAddress;
second.taint = 100; //No taint Requirement for second stage
second.fee_percent = 0; //No Fee For Second Stage
second.confirmations = 0; //Confirmations not needed
if (!second.insert(conn)) {
throw new SQLException(("Error inserting output_generated forwarding pair"));
}
conn.commit();
JSONObject obj = new JSONObject();
obj.put("input_address", input_generated.getFirst().toString());
obj.put("destination", destinationAddress);
res.setContentType("text/json");
System.out.println(obj.toString());
res.getOutputStream().print(obj.toString());
} catch (Exception e) {
conn.rollback();
throw e;
} finally {
BitcoinDatabaseManager.close(conn);
}
}
} catch (Exception e) {
e.printStackTrace();
res.setContentType("text/plain");
res.setStatus(500);
res.getOutputStream().print(e.getLocalizedMessage());
}
}
}