Commit 9f6e218c authored by zeroleak's avatar zeroleak
Browse files

Merge branch 'fetchWallet' into dsk

parents 8c9d98d1 eb8d0e44
......@@ -176,6 +176,10 @@ public class BackendApi {
}
public void pushTx(String txHex) throws Exception {
pushTx(txHex, null);
}
public void pushTx(String txHex, List<Integer> strictModeVouts) throws Exception {
if (log.isDebugEnabled()) {
log.debug("pushTx... " + txHex);
} else {
......@@ -185,8 +189,21 @@ public class BackendApi {
Map<String,String> headers = computeHeaders();
Map<String, String> postBody = new HashMap<String, String>();
postBody.put("tx", txHex);
if(strictModeVouts != null && !strictModeVouts.isEmpty()) {
String strStrictVouts = "";
for(int i = 0; i < strictModeVouts.size(); i++) {
strStrictVouts += strictModeVouts.get(i);
if(i < (strictModeVouts.size() - 1)) {
strStrictVouts += "|";
}
}
postBody.put("strict_mode_vouts", strStrictVouts);
}
try {
httpClient.postUrlEncoded(url, Void.class, headers, postBody);
PushTxResponse pushTxResponse = httpClient.postUrlEncoded(url, PushTxResponse.class, headers, postBody);
checkPushTxResponse(pushTxResponse);
} catch (HttpException e) {
if (log.isDebugEnabled()) {
log.error("pushTx failed", e);
......@@ -198,11 +215,29 @@ public class BackendApi {
+ e.getMessage()
+ " for txHex="
+ txHex);
throw new Exception(
"PushTx failed (" + e.getResponseBody() + ") for txHex=" + txHex);
throw new Exception("PushTx failed (" + e.getResponseBody() + ") for txHex=" + txHex);
}
}
protected void checkPushTxResponse(PushTxResponse pushTxResponse) throws Exception {
if (pushTxResponse.status == PushTxResponse.PushTxStatus.ok) {
// success
return;
}
if (log.isDebugEnabled()) {
log.error("pushTx failed: "+pushTxResponse.toString());
}
// address reuse
if (pushTxResponse.error != null && PushTxResponse.PushTxError.CODE_VIOLATION_STRICT_MODE_VOUTS.equals(pushTxResponse.error.code)) {
throw new PushTxAddressReuseException();
}
// other error
throw new Exception("PushTx failed: "+pushTxResponse.toString());
}
public boolean testConnectivity() {
try {
fetchMinerFee();
......
......@@ -8,11 +8,6 @@ public class HttpException extends Exception {
this.responseBody = responseBody;
}
@Override
public String getMessage() {
return super.getMessage();
}
public String getResponseBody() {
return responseBody;
}
......
package com.samourai.wallet.api.backend.beans;
public class PushTxAddressReuseException extends Exception {
public PushTxAddressReuseException() {
super();
}
}
package com.samourai.wallet.api.backend.beans;
public class PushTxResponse {
public PushTxStatus status;
public String data;
public PushTxError error;
public PushTxResponse() {}
public enum PushTxStatus {
ok, error
}
public static class PushTxError {
public static final String CODE_VIOLATION_STRICT_MODE_VOUTS = "VIOLATION_STRICT_MODE_VOUTS";
public Object message;
public String code;
}
@Override
public String toString() {
return "PushTxResponse{" +
"status=" + status +
", data='" + data + '\'' +
", error=" + error +
'}';
}
}
......@@ -84,6 +84,10 @@ public class HD_Wallet {
return rootKey;
}
public byte[] getSeed() {
return mSeed;
}
public String getSeedHex() {
return org.bouncycastle.util.encoders.Hex.toHexString(mSeed);
}
......
......@@ -20,7 +20,7 @@ public class Bech32UtilGeneric {
private static Bech32UtilGeneric instance = null;
private Bech32UtilGeneric() { ; }
protected Bech32UtilGeneric() { ; }
public static Bech32UtilGeneric getInstance() {
......@@ -44,35 +44,22 @@ public class Bech32UtilGeneric {
}
public String getAddressFromScript(String script, NetworkParameters params) throws Exception {
String hrp = null;
if(params instanceof TestNet3Params) {
hrp = "tb";
}
else {
hrp = "bc";
}
String hrp = getHrp(params);
return Bech32Segwit.encode(hrp, (byte)0x00, Hex.decode(script.substring(4).getBytes()));
}
public String getAddressFromScript(Script script, NetworkParameters params) throws Exception {
String hrp = null;
if(params instanceof TestNet3Params) {
hrp = "tb";
}
else {
hrp = "bc";
}
String hrp = getHrp(params);
byte[] buf = script.getProgram();
byte[] scriptBytes = new byte[buf.length - 2];
System.arraycopy(buf, 2, scriptBytes, 0, scriptBytes.length);
return Bech32Segwit.encode(hrp, (byte)0x00, scriptBytes);
}
protected String getHrp(NetworkParameters params) {
return params instanceof TestNet3Params ? "tb" : "bc";
}
public String getAddressFromScript(TransactionOutput output) throws Exception {
String script = new String(Hex.encode(output.getScriptBytes()));
String outputAddressBech32 = getAddressFromScript(script, output.getParams());
......@@ -86,8 +73,8 @@ public class Bech32UtilGeneric {
public byte[] computeScriptPubKey(String address, NetworkParameters params) throws Exception {
// decode bech32
boolean isTestNet = !(params instanceof MainNetParams);
Pair<Byte, byte[]> pair = Bech32Segwit.decode(isTestNet ? "tb" : "bc", address);
String hrp = getHrp(params);
Pair<Byte, byte[]> pair = Bech32Segwit.decode(hrp, address);
// get scriptPubkey
return Bech32Segwit.getScriptPubkey(pair.getLeft(), pair.getRight());
......
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.samourai.code.wallet</groupId>
<artifactId>extlibj</artifactId>
<version>0.0.19-dsk1</version>
<version>0.0.19-dsk</version>
<name>extlibj</name>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment