Skip to content

Commit

Permalink
Merge pull request #6644 from HenrikJannsen/make_processing_burningma…
Browse files Browse the repository at this point in the history
…n_accounting_data_optional

Make processing burningman accounting data optional
  • Loading branch information
sqrrm authored Apr 10, 2023
2 parents 907090b + 795964f commit 8b9619f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -82,6 +85,8 @@ public class BurningManAccountingService implements DaoSetupService {
private final Map<Date, Price> averageBsqPriceByMonth = new HashMap<>(getHistoricalAverageBsqPriceByMonth());
@Getter
private final Map<String, BalanceModel> balanceModelByBurningManName = new HashMap<>();
@Getter
private BooleanProperty isProcessing = new SimpleBooleanProperty();

@Inject
public BurningManAccountingService(BurningManAccountingStoreService burningManAccountingStoreService,
Expand All @@ -105,6 +110,7 @@ public void addListeners() {

@Override
public void start() {
UserThread.execute(() -> isProcessing.set(true));
// Create the map from now back to the last entry of the historical data (April 2019-Nov. 2022).
averageBsqPriceByMonth.putAll(getAverageBsqPriceByMonth(new Date(), 2022, 10));

Expand All @@ -125,6 +131,7 @@ public void start() {
public void onInitialBlockRequestsComplete() {
updateBalanceModelByAddress();
burningManAccountingStoreService.forEachBlock(this::addAccountingBlockToBalanceModel);
UserThread.execute(() -> isProcessing.set(false));
}

public void onNewBlockReceived(AccountingBlock accountingBlock) {
Expand All @@ -133,7 +140,7 @@ public void onNewBlockReceived(AccountingBlock accountingBlock) {
}

public void addBlock(AccountingBlock block) throws BlockHashNotConnectingException, BlockHeightNotConnectingException {
burningManAccountingStoreService.addIfNewBlock(block);
burningManAccountingStoreService.addIfNewBlock(block);
}

public int getBlockHeightOfLastBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.core.dao.burningman.accounting.node.full.AccountingBlockParser;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
import bisq.core.user.Preferences;

import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.P2PService;
Expand Down Expand Up @@ -119,6 +120,7 @@ private static Set<String> getPermittedPubKeys(boolean useDevPrivilegeKeys) {
private final DaoStateService daoStateService;
protected final BurningManAccountingService burningManAccountingService;
protected final AccountingBlockParser accountingBlockParser;
private final Preferences preferences;

@Nullable
protected Consumer<String> errorMessageHandler;
Expand All @@ -132,11 +134,13 @@ private static Set<String> getPermittedPubKeys(boolean useDevPrivilegeKeys) {
public AccountingNode(P2PService p2PService,
DaoStateService daoStateService,
BurningManAccountingService burningManAccountingService,
AccountingBlockParser accountingBlockParser) {
AccountingBlockParser accountingBlockParser,
Preferences preferences) {
this.p2PService = p2PService;
this.daoStateService = daoStateService;
this.burningManAccountingService = burningManAccountingService;
this.accountingBlockParser = accountingBlockParser;
this.preferences = preferences;
}


Expand All @@ -160,6 +164,10 @@ public void onParseBlockChainComplete() {

@Override
public void addListeners() {
if (!preferences.isProcessBurningManAccountingData()) {
return;
}

if (daoStateService.isParseBlockChainComplete()) {
log.info("daoStateService.isParseBlockChainComplete is already true, " +
"we call onInitialDaoBlockParsingComplete directly");
Expand All @@ -182,7 +190,10 @@ public void onUpdatedDataReceived() {
}

@Override
public abstract void start();
public void start() {
// We do not start yet but wait until DAO block parsing is complete to not interfere with
// that higher priority activity.
}


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.core.dao.burningman.accounting.BurningManAccountingService;
import bisq.core.dao.burningman.accounting.node.full.AccountingBlockParser;
import bisq.core.dao.state.DaoStateService;
import bisq.core.user.Preferences;

import bisq.network.p2p.P2PService;

Expand All @@ -34,8 +35,10 @@ class InActiveAccountingNode extends AccountingNode {
public InActiveAccountingNode(P2PService p2PService,
DaoStateService daoStateService,
BurningManAccountingService burningManAccountingService,
AccountingBlockParser accountingBlockParser) {
super(p2PService, daoStateService, burningManAccountingService, accountingBlockParser);
AccountingBlockParser accountingBlockParser,
Preferences preferences) {
super(p2PService, daoStateService, burningManAccountingService,
accountingBlockParser, preferences);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import bisq.core.dao.node.full.rpc.NotificationHandlerException;
import bisq.core.dao.node.full.rpc.dto.RawDtoBlock;
import bisq.core.dao.state.DaoStateService;
import bisq.core.user.Preferences;

import bisq.network.p2p.P2PService;

Expand Down Expand Up @@ -65,8 +66,10 @@ public AccountingFullNode(P2PService p2PService,
BurningManAccountingService burningManAccountingService,
AccountingBlockParser accountingBlockParser,
AccountingFullNodeNetworkService accountingFullNodeNetworkService,
RpcService rpcService) {
super(p2PService, daoStateService, burningManAccountingService, accountingBlockParser);
RpcService rpcService,
Preferences preferences) {
super(p2PService, daoStateService, burningManAccountingService,
accountingBlockParser, preferences);

this.rpcService = rpcService;
this.accountingFullNodeNetworkService = accountingFullNodeNetworkService;
Expand All @@ -77,12 +80,6 @@ public AccountingFullNode(P2PService p2PService,
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public void start() {
// We do not start yes but wait until DAO block parsing is complete to not interfere with
// that higher priority activity.
}

@Override
public void shutDown() {
accountingFullNodeNetworkService.shutDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import bisq.core.dao.burningman.accounting.node.messages.GetAccountingBlocksResponse;
import bisq.core.dao.burningman.accounting.node.messages.NewAccountingBlockBroadcastMessage;
import bisq.core.dao.state.DaoStateService;
import bisq.core.user.Preferences;

import bisq.network.p2p.P2PService;
import bisq.network.p2p.network.ConnectionState;
Expand Down Expand Up @@ -76,8 +77,10 @@ public AccountingLiteNode(P2PService p2PService,
WalletsSetup walletsSetup,
BsqWalletService bsqWalletService,
AccountingLiteNodeNetworkService accountingLiteNodeNetworkService,
Preferences preferences,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
super(p2PService, daoStateService, burningManAccountingService, accountingBlockParser);
super(p2PService, daoStateService, burningManAccountingService,
accountingBlockParser, preferences);

this.walletsSetup = walletsSetup;
this.bsqWalletService = bsqWalletService;
Expand All @@ -96,12 +99,6 @@ public AccountingLiteNode(P2PService p2PService,
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public void start() {
// We do not start yes but wait until DAO block parsing is complete to not interfere with
// that higher priority activity.
}

@Override
public void shutDown() {
accountingLiteNodeNetworkService.shutDown();
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ public void setUserDefinedTradeLimit(long value) {
requestPersistence();
}

public void setProcessBurningManAccountingData(boolean processBurningManAccountingData) {
prefPayload.setProcessBurningManAccountingData(processBurningManAccountingData);
requestPersistence();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Getter
Expand Down Expand Up @@ -1012,6 +1017,10 @@ public List<String> getDefaultTxBroadcastServices() {
}
}

public boolean isProcessBurningManAccountingData() {
return prefPayload.isProcessBurningManAccountingData();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Private
Expand Down Expand Up @@ -1132,6 +1141,8 @@ private interface ExcludesDelegateMethods {

double getBuyerSecurityDepositAsPercent();

boolean isProcessBurningManAccountingData();

void setDaoFullNode(boolean value);

void setRpcUser(String value);
Expand Down Expand Up @@ -1175,5 +1186,7 @@ private interface ExcludesDelegateMethods {
void setUserDefinedTradeLimit(long userDefinedTradeLimit);

void setUserHasRaisedTradeLimit(boolean userHasRaisedTradeLimit);

void setProcessBurningManAccountingData(boolean processBurningManAccountingData);
}
}
9 changes: 7 additions & 2 deletions core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
private long userDefinedTradeLimit = Preferences.INITIAL_TRADE_LIMIT;
private boolean userHasRaisedTradeLimit = false;

// Added at 1.9.11
private boolean processBurningManAccountingData = false;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -216,7 +219,8 @@ public Message toProtoMessage() {
.setUseFullModeDaoMonitor(useFullModeDaoMonitor)
.setUseBitcoinUrisInQrCodes(useBitcoinUrisInQrCodes)
.setUserDefinedTradeLimit(userDefinedTradeLimit)
.setUserHasRaisedTradeLimit(userHasRaisedTradeLimit);
.setUserHasRaisedTradeLimit(userHasRaisedTradeLimit)
.setProcessBurningManAccountingData(processBurningManAccountingData);

Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((protobuf.TradeCurrency) e.toProtoMessage()));
Expand Down Expand Up @@ -323,7 +327,8 @@ public static PreferencesPayload fromProto(protobuf.PreferencesPayload proto, Co
proto.getUseFullModeDaoMonitor(),
proto.getUseBitcoinUrisInQrCodes(),
proto.getUserHasRaisedTradeLimit() ? proto.getUserDefinedTradeLimit() : Preferences.INITIAL_TRADE_LIMIT,
proto.getUserHasRaisedTradeLimit()
proto.getUserHasRaisedTradeLimit(),
proto.getProcessBurningManAccountingData()
);
}
}
8 changes: 8 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ setting.preferences.dao.resyncFromGenesis.popup=A resync from genesis transactio
the seed nodes and the BSQ consensus state will be rebuilt from the genesis transaction.
setting.preferences.dao.resyncFromGenesis.resync=Resync from genesis and shutdown
setting.preferences.dao.isDaoFullNode=Run Bisq as DAO full node
setting.preferences.dao.processBurningManAccountingData=Process Burningman accounting data

setting.preferences.dao.fullModeDaoMonitor=Full-mode DAO state monitoring
setting.preferences.dao.fullModeDaoMonitor.popup=If full-mode DAO state monitoring is activated the DAO state \
Expand Down Expand Up @@ -2323,6 +2324,8 @@ dao.burningman.daoBalance=Balance for DAO
dao.burningman.daoBalanceTotalBurned=Total amount of burned BSQ
dao.burningman.daoBalanceTotalDistributed=Total amount of distributed BTC / BSQ
dao.burningman.selectedContributor=Selected contributor
dao.burningman.selectedContributor.disabledAccounting=(accounting data not updated)
dao.burningman.selectedContributor.processing=(still processing data...)
dao.burningman.selectedContributorName=Contributor name
dao.burningman.selectedContributorTotalReceived=Total received
dao.burningman.selectedContributorTotalRevenue=Total revenue
Expand Down Expand Up @@ -2355,6 +2358,11 @@ dao.burningman.table.balanceEntry.revenue=Revenue
dao.burningman.table.balanceEntry.price=BSQ/BTC price
dao.burningman.table.balanceEntry.type=Type

dao.burningman.accounting.popup=To display accounting data of a burningman you need to enable the 'process burningman accounting data' option in settings.\n\
Do you want to do that now?\n\
It will require to restart Bisq to apply that change.\n\n\
If you cancel, the displayed accounting data are not up-to-date.

# From BalanceEntry.Type enum names
dao.burningman.balanceEntry.type.UNDEFINED=Undefined
dao.burningman.balanceEntry.type.BTC_TRADE_FEE_TX=Trade fee
Expand Down
Loading

0 comments on commit 8b9619f

Please sign in to comment.