/
Stratum.java
79 lines (63 loc) · 2.37 KB
/
Stratum.java
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
package org.bitcoin.stratum;
import com.bitcoinpotato.util.Maps3;
import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters;
import com.google.common.base.Function;
import play.libs.WS;
import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Map;
import static com.google.common.base.Preconditions.checkArgument;
public class Stratum {
public Stratum(NetworkParameters networkParameters, String startumServerUrl) {
this.networkParameters = networkParameters;
this.startumServerUrl = startumServerUrl;
}
private final NetworkParameters networkParameters;
private final String startumServerUrl;
public static BigDecimal satoshisToBitcoin(BigInteger satoshis) {
return new BigDecimal("0.00000001").multiply(new BigDecimal(satoshis));
}
public KeyPair newKeyPair() {
ECKey key = new ECKey();
return new KeyPair(key.toAddress(networkParameters).toString(), key.getPrivKeyBytes());
}
public void sendTransaction(OutgoingRemoteTransaction outgoingTx) {
}
public AddressInfo getAddressInfo(String publicAddress) {
WS.HttpResponse response = null;
try {
response = WS.url(startumServerUrl)
.setHeader("content-type", "application/stratum")
.setParameter("id", 1)
.setParameter("method", "blockchain.address.get_history")
.setParameter("params", publicAddress)
.timeout("60s")
.post();
} catch (Exception e) {
throw new RuntimeException("Failure doing Startum.getAddress with address " + publicAddress);
}
checkArgument(response.getStatus() == 200);
// TODO
return new AddressInfo(new BigDecimal("0.01"));
}
/**
* A bulk API version
*/
public Map<String, AddressInfo> getAddressInfo(Collection<String> allPublicAddress) {
// Naive implementation for now
return Maps3.build(allPublicAddress, new Function<String, AddressInfo>() {
public AddressInfo apply(@Nullable String s) {
return null;
}
});
}
/**
* For now, this is a constant
*/
public BigDecimal getTransactionFee() {
return new BigDecimal("0.005");
}
}