support actual buyer & seller security deposit in TradeInfo

This commit is contained in:
woodser 2023-01-18 07:12:28 -05:00
parent b745eaccd4
commit 422819efb4
4 changed files with 64 additions and 28 deletions

View File

@ -71,6 +71,8 @@ public class TradeInfo implements Payload {
private final String takerDepositTxId; private final String takerDepositTxId;
private final String payoutTxId; private final String payoutTxId;
private final long amountAsLong; private final long amountAsLong;
private final long buyerSecurityDeposit;
private final long sellerSecurityDeposit;
private final String price; private final String price;
private final String volume; private final String volume;
private final String arbitratorNodeAddress; private final String arbitratorNodeAddress;
@ -104,6 +106,8 @@ public class TradeInfo implements Payload {
this.takerDepositTxId = builder.getTakerDepositTxId(); this.takerDepositTxId = builder.getTakerDepositTxId();
this.payoutTxId = builder.getPayoutTxId(); this.payoutTxId = builder.getPayoutTxId();
this.amountAsLong = builder.getAmountAsLong(); this.amountAsLong = builder.getAmountAsLong();
this.buyerSecurityDeposit = builder.getBuyerSecurityDeposit();
this.sellerSecurityDeposit = builder.getSellerSecurityDeposit();
this.price = builder.getPrice(); this.price = builder.getPrice();
this.volume = builder.getVolume(); this.volume = builder.getVolume();
this.arbitratorNodeAddress = builder.getArbitratorNodeAddress(); this.arbitratorNodeAddress = builder.getArbitratorNodeAddress();
@ -160,6 +164,8 @@ public class TradeInfo implements Payload {
.withTakerDepositTxId(trade.getTaker().getDepositTxHash()) .withTakerDepositTxId(trade.getTaker().getDepositTxHash())
.withPayoutTxId(trade.getPayoutTxId()) .withPayoutTxId(trade.getPayoutTxId())
.withAmountAsLong(trade.getAmountAsLong()) .withAmountAsLong(trade.getAmountAsLong())
.withBuyerSecurityDeposit(trade.getBuyerSecurityDeposit() == null ? -1 : trade.getBuyerSecurityDeposit().value)
.withSellerSecurityDeposit(trade.getSellerSecurityDeposit() == null ? -1 : trade.getSellerSecurityDeposit().value)
.withPrice(toPreciseTradePrice.apply(trade)) .withPrice(toPreciseTradePrice.apply(trade))
.withVolume(toRoundedVolume.apply(trade)) .withVolume(toRoundedVolume.apply(trade))
.withArbitratorNodeAddress(toArbitratorNodeAddress.apply(trade)) .withArbitratorNodeAddress(toArbitratorNodeAddress.apply(trade))
@ -202,6 +208,8 @@ public class TradeInfo implements Payload {
.setTakerDepositTxId(takerDepositTxId == null ? "" : takerDepositTxId) .setTakerDepositTxId(takerDepositTxId == null ? "" : takerDepositTxId)
.setPayoutTxId(payoutTxId == null ? "" : payoutTxId) .setPayoutTxId(payoutTxId == null ? "" : payoutTxId)
.setAmountAsLong(amountAsLong) .setAmountAsLong(amountAsLong)
.setBuyerSecurityDeposit(buyerSecurityDeposit)
.setSellerSecurityDeposit(sellerSecurityDeposit)
.setPrice(price) .setPrice(price)
.setTradeVolume(volume) .setTradeVolume(volume)
.setArbitratorNodeAddress(arbitratorNodeAddress) .setArbitratorNodeAddress(arbitratorNodeAddress)
@ -238,6 +246,8 @@ public class TradeInfo implements Payload {
.withTakerDepositTxId(proto.getTakerDepositTxId()) .withTakerDepositTxId(proto.getTakerDepositTxId())
.withPayoutTxId(proto.getPayoutTxId()) .withPayoutTxId(proto.getPayoutTxId())
.withAmountAsLong(proto.getAmountAsLong()) .withAmountAsLong(proto.getAmountAsLong())
.withBuyerSecurityDeposit(proto.getBuyerSecurityDeposit())
.withSellerSecurityDeposit(proto.getSellerSecurityDeposit())
.withPrice(proto.getPrice()) .withPrice(proto.getPrice())
.withVolume(proto.getTradeVolume()) .withVolume(proto.getTradeVolume())
.withPeriodState(proto.getPeriodState()) .withPeriodState(proto.getPeriodState())
@ -274,6 +284,8 @@ public class TradeInfo implements Payload {
", takerDepositTxId='" + takerDepositTxId + '\'' + "\n" + ", takerDepositTxId='" + takerDepositTxId + '\'' + "\n" +
", payoutTxId='" + payoutTxId + '\'' + "\n" + ", payoutTxId='" + payoutTxId + '\'' + "\n" +
", amountAsLong='" + amountAsLong + '\'' + "\n" + ", amountAsLong='" + amountAsLong + '\'' + "\n" +
", buyerSecurityDeposit='" + buyerSecurityDeposit + '\'' + "\n" +
", sellerSecurityDeposit='" + sellerSecurityDeposit + '\'' + "\n" +
", price='" + price + '\'' + "\n" + ", price='" + price + '\'' + "\n" +
", arbitratorNodeAddress='" + arbitratorNodeAddress + '\'' + "\n" + ", arbitratorNodeAddress='" + arbitratorNodeAddress + '\'' + "\n" +
", tradingPeerNodeAddress='" + tradingPeerNodeAddress + '\'' + "\n" + ", tradingPeerNodeAddress='" + tradingPeerNodeAddress + '\'' + "\n" +

View File

@ -40,6 +40,8 @@ public final class TradeInfoV1Builder {
private boolean isCurrencyForTakerFeeBtc; private boolean isCurrencyForTakerFeeBtc;
private long txFeeAsLong; private long txFeeAsLong;
private long takerFeeAsLong; private long takerFeeAsLong;
private long buyerSecurityDeposit;
private long sellerSecurityDeposit;
private String makerDepositTxId; private String makerDepositTxId;
private String takerDepositTxId; private String takerDepositTxId;
private String payoutTxId; private String payoutTxId;
@ -106,6 +108,16 @@ public final class TradeInfoV1Builder {
return this; return this;
} }
public TradeInfoV1Builder withBuyerSecurityDeposit(long buyerSecurityDeposit) {
this.buyerSecurityDeposit = buyerSecurityDeposit;
return this;
}
public TradeInfoV1Builder withSellerSecurityDeposit(long sellerSecurityDeposit) {
this.sellerSecurityDeposit = sellerSecurityDeposit;
return this;
}
public TradeInfoV1Builder withMakerDepositTxId(String makerDepositTxId) { public TradeInfoV1Builder withMakerDepositTxId(String makerDepositTxId) {
this.makerDepositTxId = makerDepositTxId; this.makerDepositTxId = makerDepositTxId;
return this; return this;

View File

@ -1414,11 +1414,23 @@ public abstract class Trade implements Tradable, Model {
} }
public Coin getBuyerSecurityDeposit() { public Coin getBuyerSecurityDeposit() {
return HavenoUtils.atomicUnitsToCoin(getWallet().getTx(this.getBuyer().getDepositTxHash()).getIncomingAmount()); if (this.getBuyer().getDepositTxHash() == null) return null;
try {
MoneroTxWallet depositTx = getWallet().getTx(this.getBuyer().getDepositTxHash()); // TODO (monero-java): return null if tx id not found instead of throw exception
return HavenoUtils.atomicUnitsToCoin(depositTx.getIncomingAmount());
} catch (Exception e) {
return null;
}
} }
public Coin getSellerSecurityDeposit() { public Coin getSellerSecurityDeposit() {
return HavenoUtils.atomicUnitsToCoin(getWallet().getTx(this.getSeller().getDepositTxHash()).getIncomingAmount()).subtract(getAmount()); if (this.getSeller().getDepositTxHash() == null) return null;
try {
MoneroTxWallet depositTx = getWallet().getTx(this.getSeller().getDepositTxHash()); // TODO (monero-java): return null if tx id not found instead of throw exception
return HavenoUtils.atomicUnitsToCoin(depositTx.getIncomingAmount()).subtract(getAmount());
} catch (Exception e) {
return null;
}
} }
@Nullable @Nullable

View File

@ -829,32 +829,32 @@ message TradeInfo {
uint64 tx_fee_as_long = 7; uint64 tx_fee_as_long = 7;
uint64 taker_fee_as_long = 8; uint64 taker_fee_as_long = 8;
string taker_fee_tx_id = 9; string taker_fee_tx_id = 9;
reserved 10; // was depositTxId string payout_tx_id = 10;
string payout_tx_id = 11; uint64 amount_as_long = 11;
uint64 amount_as_long = 12; uint64 buyer_security_deposit = 12;
string price = 13; uint64 seller_security_deposit = 13;
string arbitrator_node_address = 14; string price = 14;
string trading_peer_node_address = 15; string arbitrator_node_address = 15;
string state = 16; string trading_peer_node_address = 16;
string phase = 17; string state = 17;
string period_state = 18; string phase = 18;
string payout_state = 19; string period_state = 19;
string dispute_state = 20; string payout_state = 20;
bool is_deposit_published = 21; string dispute_state = 21;
bool is_deposit_confirmed = 22; bool is_deposit_published = 22;
bool is_deposit_unlocked = 23; bool is_deposit_confirmed = 23;
bool is_payment_sent = 24; bool is_deposit_unlocked = 24;
bool is_payment_received = 25; bool is_payment_sent = 25;
bool is_payout_published = 26; bool is_payment_received = 26;
bool is_payout_confirmed = 27; bool is_payout_published = 27;
bool is_payout_unlocked = 28; bool is_payout_confirmed = 28;
bool is_completed = 29; bool is_payout_unlocked = 29;
string contract_as_json = 30; bool is_completed = 30;
ContractInfo contract = 31; string contract_as_json = 31;
string trade_volume = 32; ContractInfo contract = 32;
string trade_volume = 33;
string maker_deposit_tx_id = 100; string maker_deposit_tx_id = 34;
string taker_deposit_tx_id = 101; string taker_deposit_tx_id = 35;
} }
message ContractInfo { message ContractInfo {