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

View file

@ -40,6 +40,8 @@ public final class TradeInfoV1Builder {
private boolean isCurrencyForTakerFeeBtc;
private long txFeeAsLong;
private long takerFeeAsLong;
private long buyerSecurityDeposit;
private long sellerSecurityDeposit;
private String makerDepositTxId;
private String takerDepositTxId;
private String payoutTxId;
@ -106,6 +108,16 @@ public final class TradeInfoV1Builder {
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) {
this.makerDepositTxId = makerDepositTxId;
return this;

View file

@ -1414,11 +1414,23 @@ public abstract class Trade implements Tradable, Model {
}
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() {
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

View file

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