Include output addresses, if present, in BitcoinyTransaction

This commit is contained in:
catbref 2020-12-10 14:01:40 +00:00
parent b07ad094c1
commit 456bb3ca63
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package org.qortal.crosschain;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.bind.annotation.XmlAccessType;
@ -46,16 +47,25 @@ public class BitcoinyTransaction {
public static class Output {
public final String scriptPubKey;
public final long value;
public final Set<String> addresses;
// For JAXB
protected Output() {
this.scriptPubKey = null;
this.value = 0;
this.addresses = null;
}
public Output(String scriptPubKey, long value) {
this.scriptPubKey = scriptPubKey;
this.value = value;
this.addresses = null;
}
public Output(String scriptPubKey, long value, Set<String> addresses) {
this.scriptPubKey = scriptPubKey;
this.value = value;
this.addresses = addresses;
}
public String toString() {

View File

@ -329,7 +329,16 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
String scriptPubKey = (String) ((JSONObject) outputJson.get("scriptPubKey")).get("hex");
long value = (long) (((Double) outputJson.get("value")) * 1e8);
outputs.add(new BitcoinyTransaction.Output(scriptPubKey, value));
// address too, if present
Set<String> addresses = null;
Object addressesObj = ((JSONObject) outputJson.get("scriptPubKey")).get("addresses");
if (addressesObj instanceof JSONArray) {
addresses = new HashSet<>();
for (Object addressObj : (JSONArray) addressesObj)
addresses.add((String) addressObj);
}
outputs.add(new BitcoinyTransaction.Output(scriptPubKey, value, addresses));
}
return new BitcoinyTransaction(txHash, size, locktime, timestamp, inputs, outputs);