From fc8af8c072af444caafe5b91abce0fa06cd4e78f Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:01:02 -0300 Subject: [PATCH 1/4] Define new grpc bsq/btc balances protos This change adds proto serivces and messages to support new api implementations for serving bsq, btc or all wallet balances. - RPC GetBsqBalances will return complete BSQ balance info. - Message BsqBalanceInfo is proto returned by rpc GetBsqBalances. - RPC GetBtcBalances wil return complete BTC balance info. - Message BtcBalanceInfo is proto returned by rpc GetBtcBalances. - RPC GetBalances returns complete BTC and BSQ balance info. - Message BalancesInfo is proto returned by rpc GetBalances. RPC GetBalance remains unchnaged, still returns only the available BTC balance. It may be deprecated and removed in a future PR. --- proto/src/main/proto/grpc.proto | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index d9e0a3973d8..901c94afa9e 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -275,6 +275,12 @@ message TradeInfo { service Wallets { rpc GetBalance (GetBalanceRequest) returns (GetBalanceReply) { } + rpc GetBalances (GetBalancesRequest) returns (GetBalancesReply) { + } + rpc GetBsqBalances (GetBsqBalancesRequest) returns (GetBsqBalancesReply) { + } + rpc GetBtcBalances (GetBtcBalancesRequest) returns (GetBtcBalancesReply) { + } rpc GetAddressBalance (GetAddressBalanceRequest) returns (GetAddressBalanceReply) { } rpc GetFundingAddresses (GetFundingAddressesRequest) returns (GetFundingAddressesReply) { @@ -296,6 +302,27 @@ message GetBalanceReply { uint64 balance = 1; } +message GetBalancesRequest { +} + +message GetBalancesReply { + BalancesInfo balances = 1; +} + +message GetBsqBalancesRequest { +} + +message GetBsqBalancesReply { + BsqBalanceInfo bsqBalanceInfo = 1; +} + +message GetBtcBalancesRequest { +} + +message GetBtcBalancesReply { + BtcBalanceInfo btcBalanceInfo = 1; +} + message GetAddressBalanceRequest { string address = 1; } @@ -340,6 +367,27 @@ message UnlockWalletRequest { message UnlockWalletReply { } +message BalancesInfo { + BsqBalanceInfo bsqBalanceInfo = 1; + BtcBalanceInfo btcBalanceInfo = 2; +} + +message BsqBalanceInfo { + uint64 availableConfirmedBalance = 1; + uint64 unverifiedBalance = 2; + uint64 unconfirmedChangeBalance = 3; + uint64 lockedForVotingBalance = 4; + uint64 lockupBondsBalance = 5; + uint64 unlockingBondsBalance = 6; +} + +message BtcBalanceInfo { + uint64 availableBalance = 1; + uint64 reservedBalance = 2; + uint64 totalAvailableBalance = 3; + uint64 lockedBalance = 4; +} + message AddressBalanceInfo { string address = 1; int64 balance = 2; From faf45ec301974b5a45af84b1e2246a6d2c1d02f4 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:24:08 -0300 Subject: [PATCH 2/4] Add proto wrappers for serving bsq, btc or all balances This change adds proto wrappers for sending bsq, btc, or all balances to the CLI. They will be used in future api method implementations: getbsqbalance, getbtcbalance and getbalances. --- .../bisq/core/api/model/BalancesInfo.java | 42 +++++++++ .../bisq/core/api/model/BsqBalanceInfo.java | 87 +++++++++++++++++++ .../bisq/core/api/model/BtcBalanceInfo.java | 70 +++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 core/src/main/java/bisq/core/api/model/BalancesInfo.java create mode 100644 core/src/main/java/bisq/core/api/model/BsqBalanceInfo.java create mode 100644 core/src/main/java/bisq/core/api/model/BtcBalanceInfo.java diff --git a/core/src/main/java/bisq/core/api/model/BalancesInfo.java b/core/src/main/java/bisq/core/api/model/BalancesInfo.java new file mode 100644 index 00000000000..39179fde2b3 --- /dev/null +++ b/core/src/main/java/bisq/core/api/model/BalancesInfo.java @@ -0,0 +1,42 @@ +package bisq.core.api.model; + +import bisq.common.Payload; + +import lombok.Getter; + +@Getter +public class BalancesInfo implements Payload { + + private final BsqBalanceInfo bsqBalanceInfo; + private final BtcBalanceInfo btcBalanceInfo; + + public BalancesInfo(BsqBalanceInfo bsqBalanceInfo, BtcBalanceInfo btcBalanceInfo) { + this.bsqBalanceInfo = bsqBalanceInfo; + this.btcBalanceInfo = btcBalanceInfo; + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public bisq.proto.grpc.BalancesInfo toProtoMessage() { + return bisq.proto.grpc.BalancesInfo.newBuilder() + .setBsqBalanceInfo(bsqBalanceInfo.toProtoMessage()) + .setBtcBalanceInfo(btcBalanceInfo.toProtoMessage()) + .build(); + } + + public static BalancesInfo fromProto(bisq.proto.grpc.BalancesInfo proto) { + return new BalancesInfo(BsqBalanceInfo.fromProto(proto.getBsqBalanceInfo()), + BtcBalanceInfo.fromProto(proto.getBtcBalanceInfo())); + } + + @Override + public String toString() { + return "BalancesInfo{" + "\n" + + " " + bsqBalanceInfo.toString() + "\n" + + ", " + btcBalanceInfo.toString() + "\n" + + '}'; + } +} diff --git a/core/src/main/java/bisq/core/api/model/BsqBalanceInfo.java b/core/src/main/java/bisq/core/api/model/BsqBalanceInfo.java new file mode 100644 index 00000000000..ff314e087ba --- /dev/null +++ b/core/src/main/java/bisq/core/api/model/BsqBalanceInfo.java @@ -0,0 +1,87 @@ +package bisq.core.api.model; + +import bisq.common.Payload; + +import com.google.common.annotations.VisibleForTesting; + +import lombok.Getter; + +@Getter +public class BsqBalanceInfo implements Payload { + + // All balances are in BSQ satoshis. + private final long availableConfirmedBalance; + private final long unverifiedBalance; + private final long unconfirmedChangeBalance; + private final long lockedForVotingBalance; + private final long lockupBondsBalance; + private final long unlockingBondsBalance; + + public BsqBalanceInfo(long availableConfirmedBalance, + long unverifiedBalance, + long unconfirmedChangeBalance, + long lockedForVotingBalance, + long lockupBondsBalance, + long unlockingBondsBalance) { + this.availableConfirmedBalance = availableConfirmedBalance; + this.unverifiedBalance = unverifiedBalance; + this.unconfirmedChangeBalance = unconfirmedChangeBalance; + this.lockedForVotingBalance = lockedForVotingBalance; + this.lockupBondsBalance = lockupBondsBalance; + this.unlockingBondsBalance = unlockingBondsBalance; + } + + @VisibleForTesting + public static BsqBalanceInfo valueOf(long availableConfirmedBalance, + long unverifiedBalance, + long unconfirmedChangeBalance, + long lockedForVotingBalance, + long lockupBondsBalance, + long unlockingBondsBalance) { + // Convenience for creating a model instance instead of a proto. + return new BsqBalanceInfo(availableConfirmedBalance, + unverifiedBalance, + unconfirmedChangeBalance, + lockedForVotingBalance, + lockupBondsBalance, + unlockingBondsBalance); + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public bisq.proto.grpc.BsqBalanceInfo toProtoMessage() { + return bisq.proto.grpc.BsqBalanceInfo.newBuilder() + .setAvailableConfirmedBalance(availableConfirmedBalance) + .setUnverifiedBalance(unverifiedBalance) + .setUnconfirmedChangeBalance(unconfirmedChangeBalance) + .setLockedForVotingBalance(lockedForVotingBalance) + .setLockupBondsBalance(lockupBondsBalance) + .setUnlockingBondsBalance(unlockingBondsBalance) + .build(); + + } + + public static BsqBalanceInfo fromProto(bisq.proto.grpc.BsqBalanceInfo proto) { + return new BsqBalanceInfo(proto.getAvailableConfirmedBalance(), + proto.getUnverifiedBalance(), + proto.getUnconfirmedChangeBalance(), + proto.getLockedForVotingBalance(), + proto.getLockupBondsBalance(), + proto.getUnlockingBondsBalance()); + } + + @Override + public String toString() { + return "BsqBalanceInfo{" + + "availableConfirmedBalance=" + availableConfirmedBalance + + ", unverifiedBalance=" + unverifiedBalance + + ", unconfirmedChangeBalance=" + unconfirmedChangeBalance + + ", lockedForVotingBalance=" + lockedForVotingBalance + + ", lockupBondsBalance=" + lockupBondsBalance + + ", unlockingBondsBalance=" + unlockingBondsBalance + + '}'; + } +} diff --git a/core/src/main/java/bisq/core/api/model/BtcBalanceInfo.java b/core/src/main/java/bisq/core/api/model/BtcBalanceInfo.java new file mode 100644 index 00000000000..6e8708c3e37 --- /dev/null +++ b/core/src/main/java/bisq/core/api/model/BtcBalanceInfo.java @@ -0,0 +1,70 @@ +package bisq.core.api.model; + +import bisq.common.Payload; + +import com.google.common.annotations.VisibleForTesting; + +import lombok.Getter; + +@Getter +public class BtcBalanceInfo implements Payload { + + // All balances are in BTC satoshis. + private final long availableBalance; + private final long reservedBalance; + private final long totalAvailableBalance; // available + reserved + private final long lockedBalance; + + public BtcBalanceInfo(long availableBalance, + long reservedBalance, + long totalAvailableBalance, + long lockedBalance) { + this.availableBalance = availableBalance; + this.reservedBalance = reservedBalance; + this.totalAvailableBalance = totalAvailableBalance; + this.lockedBalance = lockedBalance; + } + + @VisibleForTesting + public static BtcBalanceInfo valueOf(long availableBalance, + long reservedBalance, + long totalAvailableBalance, + long lockedBalance) { + // Convenience for creating a model instance instead of a proto. + return new BtcBalanceInfo(availableBalance, + reservedBalance, + totalAvailableBalance, + lockedBalance); + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public bisq.proto.grpc.BtcBalanceInfo toProtoMessage() { + return bisq.proto.grpc.BtcBalanceInfo.newBuilder() + .setAvailableBalance(availableBalance) + .setReservedBalance(reservedBalance) + .setTotalAvailableBalance(totalAvailableBalance) + .setLockedBalance(lockedBalance) + .build(); + } + + public static BtcBalanceInfo fromProto(bisq.proto.grpc.BtcBalanceInfo proto) { + return new BtcBalanceInfo(proto.getAvailableBalance(), + proto.getReservedBalance(), + proto.getTotalAvailableBalance(), + proto.getLockedBalance()); + } + + @Override + public String toString() { + return "BtcBalanceInfo{" + + "availableBalance=" + availableBalance + + ", reservedBalance=" + reservedBalance + + ", totalAvailableBalance=" + totalAvailableBalance + + ", lockedBalance=" + lockedBalance + + '}'; + } +} From 4c03b463fefb472cf518f055ab17201bec57d352 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:35:06 -0300 Subject: [PATCH 3/4] Define proto for api method 'getunusedbsqaddress' This change adds a proto to support a future api implementation for getting an unused, bsq funding address. --- proto/src/main/proto/grpc.proto | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 901c94afa9e..8f9ca52813c 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -283,6 +283,8 @@ service Wallets { } rpc GetAddressBalance (GetAddressBalanceRequest) returns (GetAddressBalanceReply) { } + rpc GetUnusedBsqAddress (GetUnusedBsqAddressRequest) returns (GetUnusedBsqAddressReply) { + } rpc GetFundingAddresses (GetFundingAddressesRequest) returns (GetFundingAddressesReply) { } rpc SetWalletPassword (SetWalletPasswordRequest) returns (SetWalletPasswordReply) { @@ -331,6 +333,13 @@ message GetAddressBalanceReply { AddressBalanceInfo addressBalanceInfo = 1; } +message GetUnusedBsqAddressRequest { +} + +message GetUnusedBsqAddressReply { + string address = 1; +} + message GetFundingAddressesRequest { } From 3e98910cc6e620ee2a56d001de9b53d984d25498 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Fri, 13 Nov 2020 11:44:42 -0300 Subject: [PATCH 4/4] Define proto fapi method 'sendbsq' This change adds the proto to support a future api implementation for transfering bsq. --- proto/src/main/proto/grpc.proto | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 8f9ca52813c..b18dab2e7ae 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -285,6 +285,8 @@ service Wallets { } rpc GetUnusedBsqAddress (GetUnusedBsqAddressRequest) returns (GetUnusedBsqAddressReply) { } + rpc SendBsq (SendBsqRequest) returns (SendBsqReply) { + } rpc GetFundingAddresses (GetFundingAddressesRequest) returns (GetFundingAddressesReply) { } rpc SetWalletPassword (SetWalletPasswordRequest) returns (SetWalletPasswordReply) { @@ -340,6 +342,14 @@ message GetUnusedBsqAddressReply { string address = 1; } +message SendBsqRequest { + string address = 1; + double amount = 2; +} + +message SendBsqReply { +} + message GetFundingAddressesRequest { }