Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: gettransactions method #6680

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import bisq.cli.opts.GetTradeOptionParser;
import bisq.cli.opts.GetTradesOptionParser;
import bisq.cli.opts.GetTransactionOptionParser;
import bisq.cli.opts.GetTransactionsOptionParser;
import bisq.cli.opts.OfferIdOptionParser;
import bisq.cli.opts.RegisterDisputeAgentOptionParser;
import bisq.cli.opts.RemoveWalletPasswordOptionParser;
Expand Down Expand Up @@ -346,6 +347,16 @@ public static void run(String[] args) {
out.println(formatTxFeeRateInfo(txFeeRate));
return;
}
case gettransactions: {
var opts = new GetTransactionsOptionParser(args).parse();
if (opts.isForHelp()) {
out.println(client.getMethodHelp(method));
return;
}
var txs = client.getTransactions();
new TableBuilder(TRANSACTION_TBL, txs).build().print(out);
return;
}
case gettransaction: {
var opts = new GetTransactionOptionParser(args).parse();
if (opts.isForHelp()) {
Expand Down Expand Up @@ -883,6 +894,8 @@ private static void printHelp(OptionParser parser, @SuppressWarnings("SameParame
stream.println();
stream.format(rowFormat, unsettxfeerate.name(), "", "Unset custom tx fee rate");
stream.println();
stream.format(rowFormat, gettransactions.name(), "", "Get transactions");
stream.println();
stream.format(rowFormat, gettransaction.name(), "--transaction-id=<transaction-id>", "Get transaction with id");
stream.println();
stream.format(rowFormat, createoffer.name(), "--payment-account=<payment-account-id> \\", "Create and place an offer");
Expand Down
4 changes: 4 additions & 0 deletions cli/src/main/java/bisq/cli/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public TxFeeRateInfo unsetTxFeeRate() {
return walletsServiceRequest.unsetTxFeeRate();
}

public List<TxInfo> getTransactions() {
return walletsServiceRequest.getTransactions();
}

public TxInfo getTransaction(String txId) {
return walletsServiceRequest.getTransaction(txId);
}
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/java/bisq/cli/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public enum Method {
gettrades,
failtrade,
unfailtrade,
gettransactions,
gettransaction,
gettxfeerate,
getunusedbsqaddress,
Expand Down
34 changes: 34 additions & 0 deletions cli/src/main/java/bisq/cli/opts/GetTransactionsOptionParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 bisq.cli.opts;

public class GetTransactionsOptionParser extends AbstractMethodOptionParser implements MethodOpts {

public GetTransactionsOptionParser(String[] args) {
super(args);
}

public GetTransactionsOptionParser parse() {
super.parse();

// Short circuit opt validation if user just wants help.
if (options.has(helpOpt))
return this;
return this;
}
}
7 changes: 7 additions & 0 deletions cli/src/main/java/bisq/cli/request/WalletsServiceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetNetworkRequest;
import bisq.proto.grpc.GetTransactionRequest;
import bisq.proto.grpc.GetTransactionsRequest;
import bisq.proto.grpc.GetTxFeeRateRequest;
import bisq.proto.grpc.GetUnusedBsqAddressRequest;
import bisq.proto.grpc.LockWalletRequest;
Expand Down Expand Up @@ -158,6 +159,12 @@ public TxFeeRateInfo unsetTxFeeRate() {
return grpcStubs.walletsService.unsetTxFeeRatePreference(request).getTxFeeRateInfo();
}

public List<TxInfo> getTransactions() {
var request = GetTransactionsRequest.newBuilder()
.build();
return grpcStubs.walletsService.getTransactions(request).getTxInfoList();
}

public TxInfo getTransaction(String txId) {
var request = GetTransactionRequest.newBuilder()
.setTxId(txId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import bisq.proto.grpc.TxInfo;

import java.util.List;

import javax.annotation.Nullable;
import java.util.stream.Collectors;

import static bisq.cli.table.builder.TableBuilderConstants.*;
import static bisq.cli.table.builder.TableType.TRANSACTION_TBL;
Expand All @@ -47,6 +46,7 @@ class TransactionTableBuilder extends AbstractTableBuilder {
private final Column<Long> colOutputSum;
private final Column<Long> colTxFee;
private final Column<Long> colTxSize;
private final Column<String> colMemo;

TransactionTableBuilder(List<?> protos) {
super(TRANSACTION_TBL, protos);
Expand All @@ -56,32 +56,20 @@ class TransactionTableBuilder extends AbstractTableBuilder {
this.colOutputSum = new SatoshiColumn(COL_HEADER_TX_OUTPUT_SUM);
this.colTxFee = new SatoshiColumn(COL_HEADER_TX_FEE);
this.colTxSize = new LongColumn(COL_HEADER_TX_SIZE);
this.colMemo = new StringColumn(COL_HEADER_TX_MEMO);
}

public Table build() {
// TODO Add 'gettransactions' api method & show multiple tx in the console.
// For now, a tx tbl is only one row.
TxInfo tx = (TxInfo) protos.get(0);

// Declare the columns derived from tx info.

@Nullable
Column<String> colMemo = tx.getMemo().isEmpty()
? null
: new StringColumn(COL_HEADER_TX_MEMO);

// Populate columns with tx info.

colTxId.addRow(tx.getTxId());
colIsConfirmed.addRow(!tx.getIsPending());
colInputSum.addRow(tx.getInputSum());
colOutputSum.addRow(tx.getOutputSum());
colTxFee.addRow(tx.getFee());
colTxSize.addRow((long) tx.getSize());
if (colMemo != null)
protos.stream().forEach(p -> {
TxInfo tx = (TxInfo) p;
colTxId.addRow(tx.getTxId());
colIsConfirmed.addRow(!tx.getIsPending());
colInputSum.addRow(tx.getInputSum());
colOutputSum.addRow(tx.getOutputSum());
colTxFee.addRow(tx.getFee());
colTxSize.addRow((long) tx.getSize());
colMemo.addRow(tx.getMemo());

// Define and return the table instance with populated columns.
});

if (colMemo != null) {
return new Table(colTxId,
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ public TxFeeRateInfo getMostRecentTxFeeRateInfo() {
return walletsService.getMostRecentTxFeeRateInfo();
}

public Set<Transaction> getTransactions() {
return walletsService.getTransactions();
}

public Transaction getTransaction(String txId) {
return walletsService.getTransaction(txId);
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -413,6 +414,10 @@ TxFeeRateInfo getMostRecentTxFeeRateInfo() {
feeService.getLastRequest());
}

Set<Transaction> getTransactions() {
return btcWalletService.getTransactions(false);
}

Transaction getTransaction(String txId) {
return getTransactionWithId(txId);
}
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/resources/help/gettransactions-help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
gettransactions

NAME
----
gettransactions - get transactions

SYNOPSIS
--------
gettransactions

DESCRIPTION
-----------
Returns list of a BTC transaction created by the Bisq server.

To see full transaction details, use a bitcoin-core client or an online block explorer.


EXAMPLES
--------
To see all of the transactions:
$ ./bisq-cli --password=xyz --port=9998 gettransactions
21 changes: 21 additions & 0 deletions daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import bisq.proto.grpc.GetNetworkRequest;
import bisq.proto.grpc.GetTransactionReply;
import bisq.proto.grpc.GetTransactionRequest;
import bisq.proto.grpc.GetTransactionsReply;
import bisq.proto.grpc.GetTransactionsRequest;
import bisq.proto.grpc.GetTxFeeRateReply;
import bisq.proto.grpc.GetTxFeeRateRequest;
import bisq.proto.grpc.GetUnusedBsqAddressReply;
Expand Down Expand Up @@ -68,6 +70,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -308,6 +311,24 @@ public void unsetTxFeeRatePreference(UnsetTxFeeRatePreferenceRequest req,
}
}

@Override
public void getTransactions(GetTransactionsRequest req,
StreamObserver<GetTransactionsReply> responseObserver) {
try {
Set<Transaction> transactions = coreApi.getTransactions();
log.info("Transactions count: " + transactions.size());
var reply = GetTransactionsReply.newBuilder()
.addAllTxInfo(transactions.stream()
.map(tx -> toTxInfo(tx).toProtoMessage())
.collect(Collectors.toList()))
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}
}

@Override
public void getTransaction(GetTransactionRequest req,
StreamObserver<GetTransactionReply> responseObserver) {
Expand Down
11 changes: 11 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ service Wallets {
// Remove the custom bitcoin miner transaction fee rate; revert to the Bisq network's bitcoin miner transaction fee rate.
rpc UnsetTxFeeRatePreference (UnsetTxFeeRatePreferenceRequest) returns (UnsetTxFeeRatePreferenceReply) {
}
// Get a bitcoin transactions.
rpc GetTransactions (GetTransactionsRequest) returns (GetTransactionsReply) {
}

// Get a bitcoin transaction summary.
rpc GetTransaction (GetTransactionRequest) returns (GetTransactionReply) {
}
Expand Down Expand Up @@ -880,6 +884,13 @@ message UnsetTxFeeRatePreferenceReply {
TxFeeRateInfo tx_fee_rate_info = 1; // The summary of the most recently available bitcoin transaction fee rates.
}

message GetTransactionsRequest {
}

message GetTransactionsReply {
repeated TxInfo tx_info = 1; // List of Bitcoin transactions.
}

message GetTransactionRequest {
string tx_id = 1;
}
Expand Down