Skip to content

Commit

Permalink
Merge pull request bisq-network#4 from ManfredKarrer/mk-http-api
Browse files Browse the repository at this point in the history
Merge latest changes on master into http-api branch
  • Loading branch information
mrosseel authored Oct 24, 2018
2 parents 2018d6a + ac552f6 commit d5be6be
Show file tree
Hide file tree
Showing 53 changed files with 719 additions and 388 deletions.
9 changes: 0 additions & 9 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,3 @@ dependencies {
compile "org.openjfx:javafx-graphics:11:$platform"
compile "org.openjfx:javafx-controls:11:$platform"
}

compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
4 changes: 4 additions & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ message PersistableEnvelope {
UserPayload user_payload = 10;
PaymentAccountList payment_account_list = 11;

// deprecated
// BsqState bsq_state = 12; // not used but as other non-dao data have a higher index number we leave it to make clear that we cannot change following indexes

AccountAgeWitnessStore account_age_witness_store = 13;
Expand Down Expand Up @@ -1272,6 +1273,9 @@ message PreferencesPayload {
bool use_market_notifications = 43;
bool use_price_notifications = 44;
bool use_standby_mode = 45;
bool is_dao_full_node = 46;
string rpc_user = 47;
string rpc_pw = 48;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(DaoOptionKeys.FULL_DAO_NODE,
description("If set to true the node requests the blockchain data via RPC requests from Bitcoin Core and " +
"provide the validated BSQ txs to the network. It requires that the other RPC properties are " +
"set as well.", false))
.withRequiredArg()
.ofType(boolean.class);
"set as well.", ""))
.withRequiredArg();
parser.accepts(DaoOptionKeys.GENESIS_TX_ID,
description("Genesis transaction ID when not using the hard coded one", ""))
.withRequiredArg();
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/BsqWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,8 @@ public Address getUnusedAddress() {
.findAny()
.orElse(wallet.freshReceiveAddress());
}

public String getUnusedBsqAddressAsString() {
return "B" + getUnusedAddress().toBase58();
}
}
110 changes: 96 additions & 14 deletions core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import bisq.core.dao.state.blockchain.TxOutput;
import bisq.core.dao.state.blockchain.TxOutputKey;
import bisq.core.dao.state.blockchain.TxType;
import bisq.core.dao.state.governance.Issuance;
import bisq.core.dao.state.governance.Param;
import bisq.core.dao.state.period.DaoPhase;
import bisq.core.dao.state.period.PeriodService;
Expand All @@ -80,6 +81,8 @@
import java.util.Optional;
import java.util.Set;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;


Expand All @@ -90,6 +93,7 @@
* Provides a facade to interact with the Dao domain. Hides complexity and domain details to clients (e.g. UI or APIs)
* by providing a reduced API and/or aggregating subroutines.
*/
@Slf4j
public class DaoFacade implements DaoSetupService {
private final ProposalListPresentation proposalListPresentation;
private final BallotListService ballotListService;
Expand Down Expand Up @@ -212,13 +216,11 @@ public ObservableList<Proposal> getActiveOrMyUnconfirmedProposals() {
// Creation of Proposal and proposalTransaction
public ProposalWithTransaction getCompensationProposalWithTransaction(String name,
String link,
Coin requestedBsq,
String bsqAddress)
Coin requestedBsq)
throws ValidationException, InsufficientMoneyException, TxException {
return compensationProposalService.createProposalWithTransaction(name,
link,
requestedBsq,
bsqAddress);
requestedBsq);
}

public ProposalWithTransaction getParamProposalWithTransaction(String name,
Expand Down Expand Up @@ -358,16 +360,92 @@ public void publishBlindVote(Coin stake, ResultHandler resultHandler, ExceptionH
// Use case: Presentation of phases
///////////////////////////////////////////////////////////////////////////////////////////

public int getFirstBlockOfPhase(int height, DaoPhase.Phase phase) {
return periodService.getFirstBlockOfPhase(height, phase);
}

public int getLastBlockOfPhase(int height, DaoPhase.Phase phase) {
return periodService.getLastBlockOfPhase(height, phase);
}

public int getDurationForPhase(DaoPhase.Phase phase) {
return periodService.getDurationForPhase(phase, daoStateService.getChainHeight());
// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getFirstBlockOfPhaseForDisplay(int height, DaoPhase.Phase phase) {
int firstBlock = periodService.getFirstBlockOfPhase(height, phase);
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
break;
case BREAK1:
firstBlock++;
break;
case BLIND_VOTE:
break;
case BREAK2:
firstBlock++;
break;
case VOTE_REVEAL:
break;
case BREAK3:
firstBlock++;
break;
case RESULT:
break;
}

return firstBlock;
}

// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getLastBlockOfPhaseForDisplay(int height, DaoPhase.Phase phase) {
int lastBlock = periodService.getLastBlockOfPhase(height, phase);
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
lastBlock--;
break;
case BREAK1:
break;
case BLIND_VOTE:
lastBlock--;
break;
case BREAK2:
break;
case VOTE_REVEAL:
lastBlock--;
break;
case BREAK3:
break;
case RESULT:
break;
}
return lastBlock;
}

// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getDurationForPhaseForDisplay(DaoPhase.Phase phase) {
int duration = periodService.getDurationForPhase(phase, daoStateService.getChainHeight());
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
duration--;
break;
case BREAK1:
duration++;
break;
case BLIND_VOTE:
duration--;
break;
case BREAK2:
duration++;
break;
case VOTE_REVEAL:
duration--;
break;
case BREAK3:
duration++;
break;
case RESULT:
break;
}
return duration;
}

// listeners for phase change
Expand Down Expand Up @@ -439,6 +517,10 @@ public Coin getGenesisTotalSupply() {
return daoStateService.getGenesisTotalSupply();
}

public Set<Issuance> getIssuanceSet() {
return daoStateService.getIssuanceSet();
}

public Set<Tx> getFeeTxs() {
return daoStateService.getBurntFeeTxs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ private void persist() {
}

private boolean canRemoveProposal(Proposal proposal, DaoStateService daoStateService, PeriodService periodService) {
return daoStateService.getTx(proposal.getTxId())
.filter(tx -> isTxInProposalPhaseAndCycle(tx, periodService, daoStateService))
.isPresent();
boolean inPhase = periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL);
return isMine(proposal) && inPhase;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ public CompensationProposalService(BsqWalletService bsqWalletService,

public ProposalWithTransaction createProposalWithTransaction(String name,
String link,
Coin requestedBsq,
String bsqAddress)
Coin requestedBsq)
throws ValidationException, InsufficientMoneyException, TxException {
this.requestedBsq = requestedBsq;
this.bsqAddress = bsqAddress;
this.bsqAddress = bsqWalletService.getUnusedBsqAddressAsString();

return super.createProposalWithTransaction(name, link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ public void validateParamValue(Param param, long paramValue) throws ChangeParamV
break;
case DEFAULT_TAKER_FEE_BSQ:
break;
case MIN_MAKER_FEE_BSQ:
break;
case MIN_TAKER_FEE_BSQ:
break;
case DEFAULT_MAKER_FEE_BTC:
break;
case DEFAULT_TAKER_FEE_BTC:
break;
case MIN_MAKER_FEE_BTC:
break;
case MIN_TAKER_FEE_BTC:
break;

case PROPOSAL_FEE:
break;
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/java/bisq/core/dao/node/BsqNodeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

package bisq.core.dao.node;

import bisq.core.dao.DaoOptionKeys;
import bisq.core.dao.node.full.FullNode;
import bisq.core.dao.node.lite.LiteNode;
import bisq.core.user.Preferences;

import com.google.inject.Inject;

import javax.inject.Named;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -39,7 +37,14 @@ public class BsqNodeProvider {
@Inject
public BsqNodeProvider(LiteNode bsqLiteNode,
FullNode bsqFullNode,
@Named(DaoOptionKeys.FULL_DAO_NODE) boolean fullDaoNode) {
bsqNode = fullDaoNode ? bsqFullNode : bsqLiteNode;
Preferences preferences) {

boolean rpcDataSet = preferences.getRpcUser() != null && !preferences.getRpcUser().isEmpty()
&& preferences.getRpcPw() != null && !preferences.getRpcPw().isEmpty();
boolean daoFullNode = preferences.isDaoFullNode();
if (daoFullNode && !rpcDataSet)
log.warn("daoFullNode is set but RPC user and pw are missing");

bsqNode = rpcDataSet && daoFullNode ? bsqFullNode : bsqLiteNode;
}
}
22 changes: 16 additions & 6 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

package bisq.core.dao.node.full;

import bisq.core.app.BisqEnvironment;
import bisq.core.dao.DaoOptionKeys;
import bisq.core.dao.state.blockchain.PubKeyScript;
import bisq.core.dao.state.blockchain.RawBlock;
import bisq.core.dao.state.blockchain.RawTx;
import bisq.core.dao.state.blockchain.RawTxOutput;
import bisq.core.dao.state.blockchain.TxInput;
import bisq.core.user.Preferences;

import bisq.common.UserThread;
import bisq.common.handlers.ResultHandler;
Expand Down Expand Up @@ -90,15 +92,23 @@ public class RpcService {

@SuppressWarnings("WeakerAccess")
@Inject
public RpcService(@Named(DaoOptionKeys.RPC_USER) String rpcUser,
@Named(DaoOptionKeys.RPC_PASSWORD) String rpcPassword,
public RpcService(Preferences preferences,
@Named(DaoOptionKeys.RPC_PORT) String rpcPort,
@Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockPort,
@Named(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA) boolean dumpBlockchainData) {
this.rpcUser = rpcUser;
this.rpcPassword = rpcPassword;
this.rpcPort = rpcPort;
this.rpcBlockPort = rpcBlockPort;
this.rpcUser = preferences.getRpcUser();
this.rpcPassword = preferences.getRpcPw();

// mainnet is 8332, testnet 18332, regtest 18443
boolean isPortSet = rpcPort != null && !rpcPort.isEmpty();
boolean isMainnet = BisqEnvironment.getBaseCurrencyNetwork().isMainnet();
boolean isTestnet = BisqEnvironment.getBaseCurrencyNetwork().isTestnet();
this.rpcPort = isPortSet ? rpcPort :
isMainnet ? "8332" :
isTestnet ? "18332" :
"18443"; // regtest
this.rpcBlockPort = rpcBlockPort != null && !rpcBlockPort.isEmpty() ? rpcBlockPort : "5125";

this.dumpBlockchainData = dumpBlockchainData;
}

Expand Down
25 changes: 15 additions & 10 deletions core/src/main/java/bisq/core/dao/state/governance/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@ public enum Param {
PHASE_RESULT(2);

// See: https://github.com/bisq-network/proposals/issues/46
/*
PHASE_UNDEFINED(0),
PHASE_PROPOSAL(3600), // 24 days
PHASE_BREAK1(150), // 1 day
PHASE_BLIND_VOTE(600), // 4 days
PHASE_BREAK2(10), // 10 blocks
PHASE_VOTE_REVEAL(300), // 2 days
PHASE_BREAK3(10), // 10 blocks
PHASE_RESULT(10); // 10 block
*/
// The last block in the proposal and vote phases are not shown to the user as he cannot make a tx there as it would be
// confirmed in the next block which would be the following break phase. To hide that complexity we show only the
// blocks where the user can be active. To have still round numbers for the durations we add 1 block to those
// phases and subtract 1 block from the following breaks.
// So in the UI the user will see 3600 blocks and the last
// block of the technical 3601 blocks is displayed as part of the break1 phase.
/* PHASE_UNDEFINED(0),
PHASE_PROPOSAL(3601), // 24 days
PHASE_BREAK1(149), // 1 day
PHASE_BLIND_VOTE(601), // 4 days
PHASE_BREAK2(9), // 10 blocks
PHASE_VOTE_REVEAL(301), // 2 days
PHASE_BREAK3(9), // 10 blocks
PHASE_RESULT(10); // 10 block*/


@Getter
private long defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static void setSupportedCapabilities(BisqEnvironment bisqEnvironment) {
supportedCapabilities.add(Capabilities.Capability.BLIND_VOTE.ordinal());
supportedCapabilities.add(Capabilities.Capability.BSQ_BLOCK.ordinal());

if (bisqEnvironment.getProperty(DaoOptionKeys.FULL_DAO_NODE, Boolean.class, false))
String isFullDaoNode = bisqEnvironment.getProperty(DaoOptionKeys.FULL_DAO_NODE, String.class, "");
if (isFullDaoNode != null && !isFullDaoNode.isEmpty())
supportedCapabilities.add(Capabilities.Capability.DAO_FULL_NODE.ordinal());
}

Expand Down
Loading

0 comments on commit d5be6be

Please sign in to comment.