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

inject publickeyring #3086

Merged
merged 7 commits into from
Aug 16, 2019
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
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ configure(project(':p2p')) {
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompile("org.mockito:mockito-core:$mockitoVersion")

}
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/bisq/common/crypto/KeyRing.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@EqualsAndHashCode
@Slf4j
@Singleton
public class KeyRing {
public final class KeyRing {
private final KeyPair signatureKeyPair;
private final KeyPair encryptionKeyPair;
private final PubKeyRing pubKeyRing;
Expand Down
19 changes: 19 additions & 0 deletions common/src/main/java/bisq/common/crypto/PubKeyRingProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bisq.common.crypto;

import com.google.inject.Inject;
import com.google.inject.Provider;

public class PubKeyRingProvider implements Provider<PubKeyRing> {

private PubKeyRing pubKeyRing;

@Inject
public PubKeyRingProvider(KeyRing keyRing) {
pubKeyRing = keyRing.getPubKeyRing();
}

@Override
public PubKeyRing get() {
return pubKeyRing;
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import bisq.common.CommonOptionKeys;
import bisq.common.app.AppModule;
import bisq.common.crypto.KeyStorage;
import bisq.common.crypto.PubKeyRing;
import bisq.common.crypto.PubKeyRingProvider;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;
Expand Down Expand Up @@ -96,6 +98,7 @@ protected void configure() {
install(alertModule());
install(filterModule());
install(corePresentationModule());
bind(PubKeyRing.class).toProvider(PubKeyRingProvider.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed to be in singleton context?
Can you move it to the other bindings above, so th einstall calls are not mixed with bind calls?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah from the test below its seems its singleton.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i made sure that it is.

}

private TradeModule tradeModule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import bisq.common.app.AppModule;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.KeyStorage;
import bisq.common.crypto.PubKeyRing;
import bisq.common.crypto.PubKeyRingProvider;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.Storage;
Expand Down Expand Up @@ -103,6 +105,8 @@ protected void configure() {
install(daoModule());
install(alertModule());
install(filterModule());
bind(PubKeyRing.class).toProvider(PubKeyRingProvider.class);

}

protected void configEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import javax.annotation.Nullable;

@Slf4j
public final class PeriodService {
public class PeriodService {
private final DaoStateService daoStateService;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.PubKeyRing;
import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.persistable.PersistedDataHost;
Expand Down Expand Up @@ -85,14 +85,14 @@ public MyProposalListService(P2PService p2PService,
PeriodService periodService,
WalletsManager walletsManager,
Storage<MyProposalList> storage,
KeyRing keyRing) {
PubKeyRing pubKeyRing) {
this.p2PService = p2PService;
this.daoStateService = daoStateService;
this.periodService = periodService;
this.walletsManager = walletsManager;
this.storage = storage;

signaturePubKey = keyRing.getPubKeyRing().getSignaturePubKey();
signaturePubKey = pubKeyRing.getSignaturePubKey();

numConnectedPeersListener = (observable, oldValue, newValue) -> rePublishMyProposalsOnceWellConnected();
daoStateService.addDaoStateListener(this);
Expand Down Expand Up @@ -239,8 +239,8 @@ private void persist() {
}

private boolean canRemoveProposal(Proposal proposal, DaoStateService daoStateService, PeriodService periodService) {
boolean inPhase = periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL);
return isMine(proposal) && inPhase;
boolean inProposalPhase = periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL);
return isMine(proposal) && inProposalPhase;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bisq.core.dao.governance.proposal;

import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.state.DaoStateService;

import bisq.network.p2p.P2PService;

import bisq.common.crypto.PubKeyRing;
import bisq.common.storage.Storage;

import javafx.beans.property.SimpleIntegerProperty;

import org.junit.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class MyProposalListServiceTest {
@Test
public void canInstantiate() {
P2PService p2PService = mock(P2PService.class);
when(p2PService.getNumConnectedPeers()).thenReturn(new SimpleIntegerProperty(0));
Storage storage = mock(Storage.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is storage mocked separately? It's just passed as an argument like the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that test is just a stub that got me thinking about the pubkey.

MyProposalListService service = new MyProposalListService(p2PService,
mock(DaoStateService.class),
mock(PeriodService.class), mock(WalletsManager.class), storage, mock(PubKeyRing.class)
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import org.bitcoinj.core.Coin;

public class MakerFeeMaker {
public class MakerFeeProvider {
public Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount) {
return OfferUtil.getMakerFee(bsqWalletService, preferences, amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
private final TxFeeEstimationService txFeeEstimationService;
private final ReferralIdService referralIdService;
private final BSFormatter btcFormatter;
private MakerFeeMaker makerFeeMaker;
private MakerFeeProvider makerFeeProvider;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be final

private final String offerId;
private final BalanceListener btcBalanceListener;
private final SetChangeListener<PaymentAccount> paymentAccountsChangeListener;
Expand Down Expand Up @@ -159,7 +159,7 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager,
TxFeeEstimationService txFeeEstimationService,
ReferralIdService referralIdService,
BSFormatter btcFormatter,
MakerFeeMaker makerFeeMaker) {
MakerFeeProvider makerFeeProvider) {
super(btcWalletService);

this.openOfferManager = openOfferManager;
Expand All @@ -175,7 +175,7 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager,
this.txFeeEstimationService = txFeeEstimationService;
this.referralIdService = referralIdService;
this.btcFormatter = btcFormatter;
this.makerFeeMaker = makerFeeMaker;
this.makerFeeProvider = makerFeeProvider;

offerId = Utilities.getRandomPrefix(5, 8) + "-" +
UUID.randomUUID().toString() + "-" +
Expand Down Expand Up @@ -805,7 +805,7 @@ public Coin getMakerFee(boolean isCurrencyForMakerFeeBtc) {
}

public Coin getMakerFee() {
return makerFeeMaker.getMakerFee(bsqWalletService, preferences, amount.get());
return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount.get());
}

public Coin getMakerFeeInBtc() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package bisq.desktop.main.offer.createoffer;

import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MakerFeeProvider;
import bisq.desktop.main.offer.MutableOfferDataModel;

import bisq.core.account.witness.AccountAgeWitnessService;
Expand Down Expand Up @@ -65,7 +65,7 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager,
TxFeeEstimationService txFeeEstimationService,
ReferralIdService referralIdService,
BSFormatter btcFormatter,
MakerFeeMaker makerFeeMaker) {
MakerFeeProvider makerFeeProvider) {
super(openOfferManager,
btcWalletService,
bsqWalletService,
Expand All @@ -80,6 +80,6 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager,
txFeeEstimationService,
referralIdService,
btcFormatter,
makerFeeMaker);
makerFeeProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package bisq.desktop.main.portfolio.editoffer;


import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MakerFeeProvider;
import bisq.desktop.main.offer.MutableOfferDataModel;

import bisq.core.account.witness.AccountAgeWitnessService;
Expand Down Expand Up @@ -75,7 +75,7 @@ class EditOfferDataModel extends MutableOfferDataModel {
ReferralIdService referralIdService,
BSFormatter btcFormatter,
CorePersistenceProtoResolver corePersistenceProtoResolver,
MakerFeeMaker makerFeeMaker) {
MakerFeeProvider makerFeeProvider) {
super(openOfferManager,
btcWalletService,
bsqWalletService,
Expand All @@ -90,7 +90,7 @@ class EditOfferDataModel extends MutableOfferDataModel {
txFeeEstimationService,
referralIdService,
btcFormatter,
makerFeeMaker);
makerFeeProvider);
this.corePersistenceProtoResolver = corePersistenceProtoResolver;
}

Expand Down
2 changes: 2 additions & 0 deletions desktop/src/test/java/bisq/desktop/GuiceSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import bisq.common.ClockWatcher;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.KeyStorage;
import bisq.common.crypto.PubKeyRing;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
Expand Down Expand Up @@ -104,6 +105,7 @@ public void testGuiceSetup() {
assertSingleton(TradeLimits.class);
assertSingleton(KeyStorage.class);
assertSingleton(KeyRing.class);
assertSingleton(PubKeyRing.class);
assertSingleton(User.class);
assertSingleton(ClockWatcher.class);
assertSingleton(Preferences.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bisq.desktop.main.offer.createoffer;

import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MakerFeeProvider;

import bisq.core.btc.TxFeeEstimationService;
import bisq.core.btc.model.AddressEntry;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class CreateOfferDataModelTest {
private CreateOfferDataModel model;
private User user;
private Preferences preferences;
private MakerFeeMaker makerFeeMaker;
private MakerFeeProvider makerFeeProvider;

@Before
public void setUp() {
Expand All @@ -56,12 +56,12 @@ public void setUp() {
when(preferences.isUsePercentageBasedPrice()).thenReturn(true);
when(preferences.getBuyerSecurityDepositAsPercent(null)).thenReturn(0.01);

makerFeeMaker = mock(MakerFeeMaker.class);
makerFeeProvider = mock(MakerFeeProvider.class);
model = new CreateOfferDataModel(null, btcWalletService,
null, preferences, user, null,
null, priceFeedService, null,
null, feeService, feeEstimationService,
null, null, makerFeeMaker);
null, null, makerFeeProvider);
}

@Test
Expand All @@ -78,7 +78,7 @@ public void testUseTradeCurrencySetInOfferViewWhenInPaymentAccountAvailable() {

when(user.getPaymentAccounts()).thenReturn(paymentAccounts);
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
when(makerFeeMaker.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);
when(makerFeeProvider.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);

model.initWithData(OfferPayload.Direction.BUY, new FiatCurrency("USD"));
assertEquals("USD", model.getTradeCurrencyCode().get());
Expand All @@ -98,7 +98,7 @@ public void testUseTradeAccountThatMatchesTradeCurrencySetInOffer() {
when(user.getPaymentAccounts()).thenReturn(paymentAccounts);
when(user.findFirstPaymentAccountWithCurrency(new FiatCurrency("USD"))).thenReturn(zelleAccount);
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
when(makerFeeMaker.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);
when(makerFeeProvider.getMakerFee(any(), any(), any())).thenReturn(Coin.ZERO);

model.initWithData(OfferPayload.Direction.BUY, new FiatCurrency("USD"));
assertEquals("USD", model.getTradeCurrencyCode().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package bisq.desktop.main.offer.createoffer;

import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MakerFeeProvider;
import bisq.desktop.util.validation.AltcoinValidator;
import bisq.desktop.util.validation.BtcValidator;
import bisq.desktop.util.validation.FiatPriceValidator;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void setUp() {
when(bsqFormatter.formatCoin(any())).thenReturn("0");
when(bsqWalletService.getAvailableConfirmedBalance()).thenReturn(Coin.ZERO);

CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, feeService, txFeeEstimationService, null, bsFormatter, mock(MakerFeeMaker.class));
CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, feeService, txFeeEstimationService, null, bsFormatter, mock(MakerFeeProvider.class));
dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
dataModel.activate();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bisq.desktop.main.portfolio.editoffer;

import bisq.desktop.main.offer.MakerFeeMaker;
import bisq.desktop.main.offer.MakerFeeProvider;
import bisq.desktop.util.validation.SecurityDepositValidator;

import bisq.core.account.witness.AccountAgeWitnessService;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void setUp() {
btcWalletService, bsqWalletService, empty, user,
null, null, priceFeedService, null,
accountAgeWitnessService, feeService, null, null,
null, null, mock(MakerFeeMaker.class));
null, null, mock(MakerFeeProvider.class));
}

@Test
Expand Down
Loading