mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Refactoring: Merge BsqBlockVo into BsqBlock, TxInputVo into TxInput and TxOutputVo into TxOutput
This commit is contained in:
parent
92d803d08c
commit
72a7104f94
@ -410,24 +410,10 @@ message PubKeyScript {
|
||||
string hex = 5;
|
||||
}
|
||||
|
||||
message TxInputVo {
|
||||
message TxInput {
|
||||
string tx_id = 1;
|
||||
int32 tx_output_index = 2;
|
||||
}
|
||||
|
||||
message TxInput {
|
||||
TxInputVo tx_input_vo = 1;
|
||||
TxOutput connected_tx_output = 2;
|
||||
}
|
||||
|
||||
message TxOutputVo {
|
||||
int32 index = 1;
|
||||
int64 value = 2;
|
||||
string tx_id = 3;
|
||||
PubKeyScript pub_key_script = 4;
|
||||
string address = 5;
|
||||
bytes op_return_data = 6;
|
||||
int32 block_height= 7;
|
||||
TxOutput connected_tx_output = 3;
|
||||
}
|
||||
|
||||
message SpentInfo {
|
||||
@ -449,11 +435,17 @@ enum TxOutputType {
|
||||
}
|
||||
|
||||
message TxOutput {
|
||||
TxOutputVo tx_output_vo = 1;
|
||||
bool is_unspent = 2;
|
||||
bool is_verified = 3;
|
||||
TxOutputType tx_output_type = 4;
|
||||
SpentInfo spent_info = 5;
|
||||
int32 index = 1;
|
||||
int64 value = 2;
|
||||
string tx_id = 3;
|
||||
PubKeyScript pub_key_script = 4;
|
||||
string address = 5;
|
||||
bytes op_return_data = 6;
|
||||
int32 block_height= 7;
|
||||
bool is_unspent = 8;
|
||||
bool is_verified = 9;
|
||||
TxOutputType tx_output_type = 10;
|
||||
SpentInfo spent_info = 11;
|
||||
}
|
||||
|
||||
message TxVo {
|
||||
@ -486,16 +478,12 @@ message Tx {
|
||||
int64 burnt_fee = 4;
|
||||
TxType tx_type = 5;
|
||||
}
|
||||
|
||||
message BsqBlockVo {
|
||||
|
||||
message BsqBlock {
|
||||
int32 height = 1;
|
||||
string hash = 2;
|
||||
string previous_block_hash = 3;
|
||||
}
|
||||
|
||||
message BsqBlock {
|
||||
BsqBlockVo bsq_block_vo = 1;
|
||||
repeated Tx txs = 2;
|
||||
repeated Tx txs = 4;
|
||||
}
|
||||
|
||||
message TxIdIndexTuple {
|
||||
|
@ -108,10 +108,9 @@ public class BsqParser {
|
||||
List<Tx> bsqTxsInBlock = findBsqTxsInBlock(btcdBlock,
|
||||
genesisBlockHeight,
|
||||
genesisTxId);
|
||||
final BsqBlockVo bsqBlockVo = new BsqBlockVo(btcdBlock.getHeight(),
|
||||
final BsqBlock bsqBlock = new BsqBlock(btcdBlock.getHeight(),
|
||||
btcdBlock.getHash(),
|
||||
btcdBlock.getPreviousBlockHash());
|
||||
final BsqBlock bsqBlock = new BsqBlock(bsqBlockVo,
|
||||
btcdBlock.getPreviousBlockHash(),
|
||||
ImmutableList.copyOf(bsqTxsInBlock));
|
||||
|
||||
bsqChainState.addBlock(bsqBlock);
|
||||
@ -173,10 +172,9 @@ public class BsqParser {
|
||||
List<Tx> bsqTxsInBlock = findBsqTxsInBlock(btcdBlock,
|
||||
genesisBlockHeight,
|
||||
genesisTxId);
|
||||
final BsqBlockVo bsqBlockVo = new BsqBlockVo(btcdBlock.getHeight(),
|
||||
final BsqBlock bsqBlock = new BsqBlock(btcdBlock.getHeight(),
|
||||
btcdBlock.getHash(),
|
||||
btcdBlock.getPreviousBlockHash());
|
||||
final BsqBlock bsqBlock = new BsqBlock(bsqBlockVo,
|
||||
btcdBlock.getPreviousBlockHash(),
|
||||
ImmutableList.copyOf(bsqTxsInBlock));
|
||||
bsqChainState.addBlock(bsqBlock);
|
||||
return bsqBlock;
|
||||
@ -252,7 +250,7 @@ public class BsqParser {
|
||||
|
||||
// we check if we have any valid BSQ from that tx set
|
||||
bsqTxsInBlock.addAll(txsWithoutInputsFromSameBlock.stream()
|
||||
.filter(tx -> isValidBsqTx(blockHeight, tx))
|
||||
.filter(tx -> isBsqTx(blockHeight, tx))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
log.debug("Parsing of all txsWithoutInputsFromSameBlock is done.");
|
||||
@ -277,7 +275,7 @@ public class BsqParser {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidBsqTx(int blockHeight, Tx tx) {
|
||||
private boolean isBsqTx(int blockHeight, Tx tx) {
|
||||
boolean isBsqTx = false;
|
||||
long availableValue = 0;
|
||||
for (int inputIndex = 0; inputIndex < tx.getInputs().size(); inputIndex++) {
|
||||
|
@ -33,7 +33,10 @@ import com.neemre.btcdcli4j.daemon.event.BlockListener;
|
||||
import io.bisq.core.dao.DaoOptionKeys;
|
||||
import io.bisq.core.dao.blockchain.btcd.PubKeyScript;
|
||||
import io.bisq.core.dao.blockchain.exceptions.BsqBlockchainException;
|
||||
import io.bisq.core.dao.blockchain.vo.*;
|
||||
import io.bisq.core.dao.blockchain.vo.Tx;
|
||||
import io.bisq.core.dao.blockchain.vo.TxInput;
|
||||
import io.bisq.core.dao.blockchain.vo.TxOutput;
|
||||
import io.bisq.core.dao.blockchain.vo.TxVo;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
@ -157,7 +160,7 @@ public class RpcService {
|
||||
final List<TxInput> txInputs = rawTransaction.getVIn()
|
||||
.stream()
|
||||
.filter(rawInput -> rawInput != null && rawInput.getVOut() != null && rawInput.getTxId() != null)
|
||||
.map(rawInput -> new TxInput(new TxInputVo(rawInput.getTxId(), rawInput.getVOut())))
|
||||
.map(rawInput -> new TxInput(rawInput.getTxId(), rawInput.getVOut()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<TxOutput> txOutputs = rawTransaction.getVOut()
|
||||
@ -184,14 +187,13 @@ public class RpcService {
|
||||
String address = scriptPubKey.getAddresses() != null &&
|
||||
scriptPubKey.getAddresses().size() == 1 ? scriptPubKey.getAddresses().get(0) : null;
|
||||
final PubKeyScript pubKeyScript = dumpBlockchainData ? new PubKeyScript(scriptPubKey) : null;
|
||||
final TxOutputVo txOutputVo = new TxOutputVo(rawOutput.getN(),
|
||||
return new TxOutput(rawOutput.getN(),
|
||||
rawOutput.getValue().movePointRight(8).longValue(),
|
||||
rawTransaction.getTxId(),
|
||||
pubKeyScript,
|
||||
address,
|
||||
opReturnData,
|
||||
blockHeight);
|
||||
return new TxOutput(txOutputVo);
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -27,11 +27,15 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class BsqBlock implements PersistablePayload {
|
||||
private final BsqBlockVo bsqBlockVo;
|
||||
private final int height;
|
||||
private final String hash;
|
||||
private final String previousBlockHash;
|
||||
private final List<Tx> txs;
|
||||
|
||||
public BsqBlock(BsqBlockVo bsqBlockVo, List<Tx> txs) {
|
||||
this.bsqBlockVo = bsqBlockVo;
|
||||
public BsqBlock(int height, String hash, String previousBlockHash, List<Tx> txs) {
|
||||
this.height = height;
|
||||
this.hash = hash;
|
||||
this.previousBlockHash = previousBlockHash;
|
||||
this.txs = txs;
|
||||
}
|
||||
|
||||
@ -42,7 +46,9 @@ public class BsqBlock implements PersistablePayload {
|
||||
|
||||
public PB.BsqBlock toProtoMessage() {
|
||||
return PB.BsqBlock.newBuilder()
|
||||
.setBsqBlockVo(bsqBlockVo.toProtoMessage())
|
||||
.setHeight(height)
|
||||
.setHash(hash)
|
||||
.setPreviousBlockHash(previousBlockHash)
|
||||
.addAllTxs(txs.stream()
|
||||
.map(Tx::toProtoMessage)
|
||||
.collect(Collectors.toList()))
|
||||
@ -50,7 +56,9 @@ public class BsqBlock implements PersistablePayload {
|
||||
}
|
||||
|
||||
public static BsqBlock fromProto(PB.BsqBlock proto) {
|
||||
return new BsqBlock(BsqBlockVo.fromProto(proto.getBsqBlockVo()),
|
||||
return new BsqBlock(proto.getHeight(),
|
||||
proto.getHash(),
|
||||
proto.getPreviousBlockHash(),
|
||||
proto.getTxsList().isEmpty() ?
|
||||
new ArrayList<>() :
|
||||
proto.getTxsList().stream()
|
||||
@ -67,7 +75,6 @@ public class BsqBlock implements PersistablePayload {
|
||||
txs.stream().forEach(Tx::reset);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BsqBlock{" +
|
||||
@ -77,23 +84,4 @@ public class BsqBlock implements PersistablePayload {
|
||||
",\n txs='" + txs + '\'' +
|
||||
"\n}";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Delegates
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public int getHeight() {
|
||||
return bsqBlockVo.getHeight();
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return bsqBlockVo.getHash();
|
||||
}
|
||||
|
||||
public String getPreviousBlockHash() {
|
||||
return bsqBlockVo.getPreviousBlockHash();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bisq.core.dao.blockchain.vo;
|
||||
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@Getter
|
||||
public class BsqBlockVo implements PersistablePayload {
|
||||
private final int height;
|
||||
private final String hash;
|
||||
private final String previousBlockHash;
|
||||
|
||||
public BsqBlockVo(int height, String hash, String previousBlockHash) {
|
||||
this.height = height;
|
||||
this.hash = hash;
|
||||
this.previousBlockHash = previousBlockHash;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public PB.BsqBlockVo toProtoMessage() {
|
||||
return PB.BsqBlockVo.newBuilder()
|
||||
.setHeight(height)
|
||||
.setHash(hash)
|
||||
.setPreviousBlockHash(previousBlockHash).build();
|
||||
}
|
||||
|
||||
public static BsqBlockVo fromProto(PB.BsqBlockVo proto) {
|
||||
return new BsqBlockVo(proto.getHeight(),
|
||||
proto.getHash(),
|
||||
proto.getPreviousBlockHash());
|
||||
}
|
||||
}
|
@ -26,12 +26,13 @@ import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class TxInput implements PersistablePayload {
|
||||
private final TxInputVo txInputVo;
|
||||
private final String txId;
|
||||
private final int txOutputIndex;
|
||||
@Nullable
|
||||
private TxOutput connectedTxOutput;
|
||||
|
||||
public TxInput(TxInputVo txInputVo) {
|
||||
this(txInputVo, null);
|
||||
public TxInput(String txId, int txOutputIndex) {
|
||||
this(txId, txOutputIndex, null);
|
||||
}
|
||||
|
||||
|
||||
@ -39,20 +40,25 @@ public class TxInput implements PersistablePayload {
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private TxInput(TxInputVo txInputVo, @Nullable TxOutput connectedTxOutput) {
|
||||
this.txInputVo = txInputVo;
|
||||
private TxInput(String txId, int txOutputIndex, @Nullable TxOutput connectedTxOutput) {
|
||||
this.txId = txId;
|
||||
this.txOutputIndex = txOutputIndex;
|
||||
this.connectedTxOutput = connectedTxOutput;
|
||||
}
|
||||
|
||||
public PB.TxInput toProtoMessage() {
|
||||
final PB.TxInput.Builder builder = PB.TxInput.newBuilder()
|
||||
.setTxInputVo(txInputVo.toProtoMessage());
|
||||
.setTxId(txId)
|
||||
.setTxOutputIndex(txOutputIndex);
|
||||
|
||||
Optional.ofNullable(connectedTxOutput).ifPresent(e -> builder.setConnectedTxOutput(e.toProtoMessage()));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static TxInput fromProto(PB.TxInput proto) {
|
||||
return new TxInput(TxInputVo.fromProto(proto.getTxInputVo()),
|
||||
return new TxInput(proto.getTxId(),
|
||||
proto.getTxOutputIndex(),
|
||||
proto.hasConnectedTxOutput() ? TxOutput.fromProto(proto.getConnectedTxOutput()) : null);
|
||||
}
|
||||
|
||||
@ -65,28 +71,16 @@ public class TxInput implements PersistablePayload {
|
||||
connectedTxOutput = null;
|
||||
}
|
||||
|
||||
public TxIdIndexTuple getTxIdIndexTuple() {
|
||||
return new TxIdIndexTuple(txId, txOutputIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TxInput{" +
|
||||
"\n txId=" + getTxId() +
|
||||
",\n txOutputIndex=" + getTxOutputIndex() +
|
||||
",\n txOutput='" + connectedTxOutput + '\'' +
|
||||
"\n txId=" + txId +
|
||||
",\n txOutputIndex=" + txOutputIndex +
|
||||
",\n connectedTxOutput='" + connectedTxOutput + '\'' +
|
||||
"\n}";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Delegates
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getTxId() {
|
||||
return txInputVo.getTxId();
|
||||
}
|
||||
|
||||
public int getTxOutputIndex() {
|
||||
return txInputVo.getTxOutputIndex();
|
||||
}
|
||||
|
||||
public TxIdIndexTuple getTxIdIndexTuple() {
|
||||
return txInputVo.getTxIdIndexTuple();
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bisq.core.dao.blockchain.vo;
|
||||
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class TxInputVo implements PersistablePayload {
|
||||
private final String txId;
|
||||
private final int txOutputIndex;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public PB.TxInputVo toProtoMessage() {
|
||||
return PB.TxInputVo.newBuilder()
|
||||
.setTxId(txId)
|
||||
.setTxOutputIndex(txOutputIndex)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static TxInputVo fromProto(PB.TxInputVo proto) {
|
||||
return new TxInputVo(proto.getTxId(),
|
||||
proto.getTxOutputIndex());
|
||||
}
|
||||
|
||||
public TxIdIndexTuple getTxIdIndexTuple() {
|
||||
return new TxIdIndexTuple(txId, txOutputIndex);
|
||||
}
|
||||
}
|
@ -17,10 +17,11 @@
|
||||
|
||||
package io.bisq.core.dao.blockchain.vo;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.common.util.JsonExclude;
|
||||
import io.bisq.core.dao.blockchain.btcd.PubKeyScript;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Utils;
|
||||
@ -29,18 +30,43 @@ import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class TxOutput implements PersistablePayload {
|
||||
private final TxOutputVo txOutputVo;
|
||||
private final int index;
|
||||
private final long value;
|
||||
private final String txId;
|
||||
@Nullable
|
||||
private final PubKeyScript pubKeyScript;
|
||||
@Nullable
|
||||
private final String address;
|
||||
@Nullable
|
||||
@JsonExclude
|
||||
private final byte[] opReturnData;
|
||||
private final int blockHeight;
|
||||
private boolean isUnspent;
|
||||
private boolean isVerified;
|
||||
private TxOutputType txOutputType = TxOutputType.UNDEFINED;
|
||||
@Nullable
|
||||
private SpentInfo spentInfo;
|
||||
|
||||
public TxOutput(TxOutputVo txOutputVo) {
|
||||
this.txOutputVo = txOutputVo;
|
||||
public TxOutput(int index,
|
||||
long value,
|
||||
String txId,
|
||||
@Nullable PubKeyScript pubKeyScript,
|
||||
@Nullable String address,
|
||||
@Nullable byte[] opReturnData,
|
||||
int blockHeight) {
|
||||
this(index,
|
||||
value,
|
||||
txId,
|
||||
pubKeyScript,
|
||||
address,
|
||||
opReturnData,
|
||||
blockHeight,
|
||||
false,
|
||||
false,
|
||||
TxOutputType.UNDEFINED,
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
@ -48,20 +74,56 @@ public class TxOutput implements PersistablePayload {
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private TxOutput(int index,
|
||||
long value,
|
||||
String txId,
|
||||
@Nullable PubKeyScript pubKeyScript,
|
||||
@Nullable String address,
|
||||
@Nullable byte[] opReturnData,
|
||||
int blockHeight,
|
||||
boolean isUnspent,
|
||||
boolean isVerified,
|
||||
TxOutputType txOutputType,
|
||||
@Nullable SpentInfo spentInfo) {
|
||||
this.index = index;
|
||||
this.value = value;
|
||||
this.txId = txId;
|
||||
this.pubKeyScript = pubKeyScript;
|
||||
this.address = address;
|
||||
this.opReturnData = opReturnData;
|
||||
this.blockHeight = blockHeight;
|
||||
this.isUnspent = isUnspent;
|
||||
this.isVerified = isVerified;
|
||||
this.txOutputType = txOutputType;
|
||||
this.spentInfo = spentInfo;
|
||||
}
|
||||
|
||||
public PB.TxOutput toProtoMessage() {
|
||||
final PB.TxOutput.Builder builder = PB.TxOutput.newBuilder()
|
||||
.setTxOutputVo(txOutputVo.toProtoMessage())
|
||||
.setIndex(index)
|
||||
.setValue(value)
|
||||
.setTxId(txId)
|
||||
.setBlockHeight(blockHeight)
|
||||
.setIsUnspent(isUnspent)
|
||||
.setIsVerified(isVerified)
|
||||
.setTxOutputType(txOutputType.toProtoMessage());
|
||||
|
||||
Optional.ofNullable(pubKeyScript).ifPresent(e -> builder.setPubKeyScript(pubKeyScript.toProtoMessage()));
|
||||
Optional.ofNullable(address).ifPresent(e -> builder.setAddress(address));
|
||||
Optional.ofNullable(opReturnData).ifPresent(e -> builder.setOpReturnData(ByteString.copyFrom(opReturnData)));
|
||||
Optional.ofNullable(spentInfo).ifPresent(e -> builder.setSpentInfo(e.toProtoMessage()));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static TxOutput fromProto(PB.TxOutput proto) {
|
||||
return new TxOutput(TxOutputVo.fromProto(proto.getTxOutputVo()),
|
||||
return new TxOutput(proto.getIndex(),
|
||||
proto.getValue(),
|
||||
proto.getTxId(),
|
||||
proto.hasPubKeyScript() ? PubKeyScript.fromProto(proto.getPubKeyScript()) : null,
|
||||
proto.getAddress().isEmpty() ? null : proto.getAddress(),
|
||||
proto.getOpReturnData().isEmpty() ? null : proto.getOpReturnData().toByteArray(),
|
||||
proto.getBlockHeight(),
|
||||
proto.getIsUnspent(),
|
||||
proto.getIsVerified(),
|
||||
TxOutputType.fromProto(proto.getTxOutputType()),
|
||||
@ -80,23 +142,6 @@ public class TxOutput implements PersistablePayload {
|
||||
spentInfo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TxOutput{" +
|
||||
"\n index=" + getIndex() +
|
||||
",\n value=" + getValue() +
|
||||
",\n txId='" + getId() + '\'' +
|
||||
",\n pubKeyScript=" + getPubKeyScript() +
|
||||
",\n address='" + getAddress() + '\'' +
|
||||
",\n opReturnData=" + (getOpReturnData() != null ? Utils.HEX.encode(getOpReturnData()) : "null") +
|
||||
",\n blockHeight=" + getBlockHeight() +
|
||||
",\n isUnspent=" + isUnspent +
|
||||
",\n isVerified=" + isVerified +
|
||||
",\n txOutputType=" + txOutputType +
|
||||
",\n spentInfo=" + (spentInfo != null ? spentInfo.toString() : "null") +
|
||||
"\n}";
|
||||
}
|
||||
|
||||
public boolean isCompensationRequestBtcOutput() {
|
||||
return txOutputType == TxOutputType.COMPENSATION_REQUEST_BTC_OUTPUT;
|
||||
}
|
||||
@ -105,46 +150,28 @@ public class TxOutput implements PersistablePayload {
|
||||
return txOutputType == TxOutputType.SPONSORING_BTC_OUTPUT;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Delegates
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public int getIndex() {
|
||||
return txOutputVo.getIndex();
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
return txOutputVo.getValue();
|
||||
}
|
||||
|
||||
public String getTxId() {
|
||||
return txOutputVo.getTxId();
|
||||
}
|
||||
|
||||
public PubKeyScript getPubKeyScript() {
|
||||
return txOutputVo.getPubKeyScript();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAddress() {
|
||||
return txOutputVo.getAddress();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public byte[] getOpReturnData() {
|
||||
return txOutputVo.getOpReturnData();
|
||||
}
|
||||
|
||||
public int getBlockHeight() {
|
||||
return txOutputVo.getBlockHeight();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return txOutputVo.getId();
|
||||
return txId + ":" + index;
|
||||
}
|
||||
|
||||
public TxIdIndexTuple getTxIdIndexTuple() {
|
||||
return txOutputVo.getTxIdIndexTuple();
|
||||
return new TxIdIndexTuple(txId, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TxOutput{" +
|
||||
"\n index=" + index +
|
||||
",\n value=" + value +
|
||||
",\n txId='" + getId() + '\'' +
|
||||
",\n pubKeyScript=" + pubKeyScript +
|
||||
",\n address='" + address + '\'' +
|
||||
",\n opReturnData=" + (opReturnData != null ? Utils.HEX.encode(opReturnData) : "null") +
|
||||
",\n blockHeight=" + blockHeight +
|
||||
",\n isUnspent=" + isUnspent +
|
||||
",\n isVerified=" + isVerified +
|
||||
",\n txOutputType=" + txOutputType +
|
||||
",\n spentInfo=" + (spentInfo != null ? spentInfo.toString() : "null") +
|
||||
"\n}";
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bisq.core.dao.blockchain.vo;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.bisq.common.proto.persistable.PersistablePayload;
|
||||
import io.bisq.common.util.JsonExclude;
|
||||
import io.bisq.core.dao.blockchain.btcd.PubKeyScript;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
@Value
|
||||
public class TxOutputVo implements PersistablePayload {
|
||||
private final int index;
|
||||
private final long value;
|
||||
private final String txId;
|
||||
@Nullable
|
||||
private final PubKeyScript pubKeyScript;
|
||||
@Nullable
|
||||
private final String address;
|
||||
@Nullable
|
||||
@JsonExclude
|
||||
private final byte[] opReturnData;
|
||||
private final int blockHeight;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public PB.TxOutputVo toProtoMessage() {
|
||||
final PB.TxOutputVo.Builder builder = PB.TxOutputVo.newBuilder()
|
||||
.setIndex(index)
|
||||
.setValue(value)
|
||||
.setTxId(txId)
|
||||
.setBlockHeight(blockHeight);
|
||||
|
||||
Optional.ofNullable(pubKeyScript).ifPresent(e -> builder.setPubKeyScript(pubKeyScript.toProtoMessage()));
|
||||
Optional.ofNullable(address).ifPresent(e -> builder.setAddress(address));
|
||||
Optional.ofNullable(opReturnData).ifPresent(e -> builder.setOpReturnData(ByteString.copyFrom(opReturnData)));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static TxOutputVo fromProto(PB.TxOutputVo proto) {
|
||||
return new TxOutputVo(proto.getIndex(),
|
||||
proto.getValue(),
|
||||
proto.getTxId(),
|
||||
proto.hasPubKeyScript() ? PubKeyScript.fromProto(proto.getPubKeyScript()) : null,
|
||||
proto.getAddress().isEmpty() ? null : proto.getAddress(),
|
||||
proto.getOpReturnData().isEmpty() ? null : proto.getOpReturnData().toByteArray(),
|
||||
proto.getBlockHeight());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return txId + ":" + index;
|
||||
}
|
||||
|
||||
public TxIdIndexTuple getTxIdIndexTuple() {
|
||||
return new TxIdIndexTuple(txId, index);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user