forked from Qortal/qortal
Added inputs, outputs and feeAmount to /crosschain//walletbalance endpoints
The inputs and outputs contain a simpler version than the ones in the raw transaction, consisting of `address`, `amount`, and `addressInWallet`. The latter of the three is to know whether the address is one that is derived from the supplied xpub master public key.
This commit is contained in:
parent
f669e3f6c4
commit
f09677d376
@ -406,14 +406,24 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
|||||||
protected SimpleTransaction convertToSimpleTransaction(BitcoinyTransaction t, Set<String> keySet) {
|
protected SimpleTransaction convertToSimpleTransaction(BitcoinyTransaction t, Set<String> keySet) {
|
||||||
long amount = 0;
|
long amount = 0;
|
||||||
long total = 0L;
|
long total = 0L;
|
||||||
|
long totalInputAmount = 0L;
|
||||||
|
long totalOutputAmount = 0L;
|
||||||
|
List<SimpleTransaction.Input> inputs = new ArrayList<>();
|
||||||
|
List<SimpleTransaction.Output> outputs = new ArrayList<>();
|
||||||
|
|
||||||
for (BitcoinyTransaction.Input input : t.inputs) {
|
for (BitcoinyTransaction.Input input : t.inputs) {
|
||||||
try {
|
try {
|
||||||
BitcoinyTransaction t2 = getTransaction(input.outputTxHash);
|
BitcoinyTransaction t2 = getTransaction(input.outputTxHash);
|
||||||
List<String> senders = t2.outputs.get(input.outputVout).addresses;
|
List<String> senders = t2.outputs.get(input.outputVout).addresses;
|
||||||
|
long inputAmount = t2.outputs.get(input.outputVout).value;
|
||||||
|
totalInputAmount += inputAmount;
|
||||||
for (String sender : senders) {
|
for (String sender : senders) {
|
||||||
|
boolean addressInWallet = false;
|
||||||
if (keySet.contains(sender)) {
|
if (keySet.contains(sender)) {
|
||||||
total += t2.outputs.get(input.outputVout).value;
|
total += inputAmount;
|
||||||
|
addressInWallet = true;
|
||||||
}
|
}
|
||||||
|
inputs.add(new SimpleTransaction.Input(sender, inputAmount, addressInWallet));
|
||||||
}
|
}
|
||||||
} catch (ForeignBlockchainException e) {
|
} catch (ForeignBlockchainException e) {
|
||||||
LOGGER.trace("Failed to retrieve transaction information {}", input.outputTxHash);
|
LOGGER.trace("Failed to retrieve transaction information {}", input.outputTxHash);
|
||||||
@ -422,17 +432,22 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
|||||||
if (t.outputs != null && !t.outputs.isEmpty()) {
|
if (t.outputs != null && !t.outputs.isEmpty()) {
|
||||||
for (BitcoinyTransaction.Output output : t.outputs) {
|
for (BitcoinyTransaction.Output output : t.outputs) {
|
||||||
for (String address : output.addresses) {
|
for (String address : output.addresses) {
|
||||||
|
boolean addressInWallet = false;
|
||||||
if (keySet.contains(address)) {
|
if (keySet.contains(address)) {
|
||||||
if (total > 0L) {
|
if (total > 0L) {
|
||||||
amount -= (total - output.value);
|
amount -= (total - output.value);
|
||||||
} else {
|
} else {
|
||||||
amount += output.value;
|
amount += output.value;
|
||||||
}
|
}
|
||||||
|
addressInWallet = true;
|
||||||
}
|
}
|
||||||
|
outputs.add(new SimpleTransaction.Output(address, output.value, addressInWallet));
|
||||||
}
|
}
|
||||||
|
totalOutputAmount += output.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new SimpleTransaction(t.txHash, t.timestamp, amount);
|
long fee = totalInputAmount - totalOutputAmount;
|
||||||
|
return new SimpleTransaction(t.txHash, t.timestamp, amount, fee, inputs, outputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,20 +2,85 @@ package org.qortal.crosschain;
|
|||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class SimpleTransaction {
|
public class SimpleTransaction {
|
||||||
private String txHash;
|
private String txHash;
|
||||||
private Integer timestamp;
|
private Integer timestamp;
|
||||||
private long totalAmount;
|
private long totalAmount;
|
||||||
|
private long feeAmount;
|
||||||
|
private List<Input> inputs;
|
||||||
|
private List<Output> outputs;
|
||||||
|
|
||||||
|
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public static class Input {
|
||||||
|
private String address;
|
||||||
|
private long amount;
|
||||||
|
private boolean addressInWallet;
|
||||||
|
|
||||||
|
public Input() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Input(String address, long amount, boolean addressInWallet) {
|
||||||
|
this.address = address;
|
||||||
|
this.amount = amount;
|
||||||
|
this.addressInWallet = addressInWallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAddressInWallet() {
|
||||||
|
return addressInWallet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public static class Output {
|
||||||
|
private String address;
|
||||||
|
private long amount;
|
||||||
|
private boolean addressInWallet;
|
||||||
|
|
||||||
|
public Output() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Output(String address, long amount, boolean addressInWallet) {
|
||||||
|
this.address = address;
|
||||||
|
this.amount = amount;
|
||||||
|
this.addressInWallet = addressInWallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAddressInWallet() {
|
||||||
|
return addressInWallet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public SimpleTransaction() {
|
public SimpleTransaction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleTransaction(String txHash, Integer timestamp, long totalAmount) {
|
public SimpleTransaction(String txHash, Integer timestamp, long totalAmount, long feeAmount, List<Input> inputs, List<Output> outputs) {
|
||||||
this.txHash = txHash;
|
this.txHash = txHash;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.totalAmount = totalAmount;
|
this.totalAmount = totalAmount;
|
||||||
|
this.feeAmount = feeAmount;
|
||||||
|
this.inputs = inputs;
|
||||||
|
this.outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTxHash() {
|
public String getTxHash() {
|
||||||
@ -29,4 +94,16 @@ public class SimpleTransaction {
|
|||||||
public long getTotalAmount() {
|
public long getTotalAmount() {
|
||||||
return totalAmount;
|
return totalAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getFeeAmount() {
|
||||||
|
return feeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Input> getInputs() {
|
||||||
|
return this.inputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Output> getOutputs() {
|
||||||
|
return this.outputs;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user