Commit 83fe6109 authored by zeroleak's avatar zeroleak
Browse files

add UTXO.toUnspentOutputs()

parent 04feff5c
......@@ -38,6 +38,21 @@ public class UnspentOutput {
this.xpub = copy.xpub;
}
public UnspentOutput(MyTransactionOutPoint outPoint, String pubkey, String path, String xpub) {
this.tx_hash = outPoint.getTxHash().toString();
this.tx_output_n = outPoint.getTxOutputN();
this.tx_version = -1; // ignored
this.tx_locktime = -1; // ignored
this.value = outPoint.getValue().getValue();
this.script = outPoint.getScriptBytes() != null ? Hex.toHexString(outPoint.getScriptBytes()) : null;
this.addr = outPoint.getAddress();
this.pubkey = pubkey;
this.confirmations = outPoint.getConfirmations();
this.xpub = new Xpub();
this.xpub.path = path;
this.xpub.m = xpub;
}
public int computePathChainIndex() {
return Integer.parseInt(xpub.path.split(PATH_SEPARATOR)[1]);
}
......@@ -60,7 +75,7 @@ public class UnspentOutput {
public MyTransactionOutPoint computeOutpoint(NetworkParameters params) {
Sha256Hash sha256Hash = Sha256Hash.wrap(Hex.decode(tx_hash));
// use MyTransactionOutPoint to forward scriptBytes + address
return new MyTransactionOutPoint(params, sha256Hash, tx_output_n, BigInteger.valueOf(value), getScriptBytes(), addr);
return new MyTransactionOutPoint(params, sha256Hash, tx_output_n, BigInteger.valueOf(value), getScriptBytes(), addr, confirmations);
}
public TransactionInput computeSpendInput(NetworkParameters params) {
......
......@@ -24,7 +24,7 @@ public class TestCahootsWallet extends SimpleCahootsWallet {
String path = "M/0/1"; // mock path
ECKey key = ECKey.fromPrivate(BigInteger.valueOf(1234)); // mock key
byte[] scriptBytes = mockScriptBytes();
MyTransactionOutPoint outpoint = new MyTransactionOutPoint(getParams(), Sha256Hash.of(txid.getBytes()), n, BigInteger.valueOf(value), scriptBytes, address);
MyTransactionOutPoint outpoint = new MyTransactionOutPoint(getParams(), Sha256Hash.of(txid.getBytes()), n, BigInteger.valueOf(value), scriptBytes, address, 99);
CahootsUtxo utxo = new CahootsUtxo(outpoint, path, key);
addUtxo(account, utxo);
}
......
......@@ -11,12 +11,18 @@ public class MyTransactionOutPoint extends TransactionOutPoint {
private byte[] scriptBytes;
private BigInteger value;
private String address;
private int confirmations;
public MyTransactionOutPoint(NetworkParameters params, Sha256Hash txHash, int txOutputN, BigInteger value, byte[] scriptBytes, String address) throws ProtocolException {
public MyTransactionOutPoint(NetworkParameters params, Sha256Hash txHash, int txOutputN, BigInteger value, byte[] scriptBytes, String address, int confirmations) throws ProtocolException {
super(params, txOutputN, new Sha256Hash(txHash.getBytes()));
this.scriptBytes = scriptBytes;
this.value = value;
this.address = address;
this.confirmations = confirmations;
}
public int getConfirmations() {
return confirmations;
}
public byte[] getScriptBytes() {
......@@ -31,6 +37,10 @@ public class MyTransactionOutPoint extends TransactionOutPoint {
return address;
}
public void setConfirmations(int confirmations) {
this.confirmations = confirmations;
}
public Script computeScript() {
return new Script(scriptBytes);
}
......
package com.samourai.wallet.send;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import com.samourai.wallet.api.backend.beans.UnspentOutput;
import java.util.*;
//import org.apache.commons.lang3.tuple.Pair;
......@@ -22,6 +21,14 @@ public class UTXO {
this.path = path;
}
public Collection<UnspentOutput> toUnspentOutputs(String xpub) {
List<UnspentOutput> unspentOutputs = new LinkedList<>();
for (MyTransactionOutPoint outPoint : outpoints) {
unspentOutputs.add(new UnspentOutput(outPoint, null, path, xpub));
}
return unspentOutputs;
}
public List<MyTransactionOutPoint> getOutpoints() {
return outpoints;
}
......
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