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

Add auto-confirm feature for Monero #4458

Merged
merged 91 commits into from Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
43e4809
Add basic support for validation for XMR transfer with tx key
chimp1984 Jul 26, 2020
78da1df
Add trade date
chimp1984 Jul 27, 2020
ca8f53c
Implement XMR tx proof autoconfirm feature
Aug 2, 2020
c6f1e52
Merge remote-tracking branch 'origin/master' into add-xmr-tx-key-serv…
Aug 27, 2020
ac10d71
Add XMR proof result status code TRADE_LIMIT_EXCEEDED
Aug 27, 2020
967e053
Rename XmrProofResult to AutoConfirmResult
Aug 28, 2020
e3bf073
Persist the auto confirm state of Trade object
Aug 28, 2020
cccc6de
Default to clearnet XMR proof providers when in dev mode
Aug 29, 2020
5501822
Merge branch 'master_upstream' into xmr
chimp1984 Aug 30, 2020
d9d0814
Re-word the XMR account creation message per @m52go
Aug 30, 2020
36e2f71
Update core/src/main/resources/i18n/displayStrings.properties
Aug 30, 2020
ca9f61e
Update core/src/main/resources/i18n/displayStrings.properties
Aug 30, 2020
3e728c6
- Remove AutoConfirmResult enum from protobuf and add a AutoConfirmRe…
chimp1984 Aug 30, 2020
008ae93
Add null check for name
chimp1984 Aug 30, 2020
2dbc464
- Change tolerance from 1 day to 2 hours.
chimp1984 Aug 30, 2020
07a7612
- Make REPEAT_REQUEST_PERIOD and MAX_REQUEST_PERIOD static
chimp1984 Aug 30, 2020
2f7b24d
- Add @Nullable
chimp1984 Aug 30, 2020
2f1566b
Add NO_MATCH_FOUND in comment
chimp1984 Aug 30, 2020
ed5078c
Add abstract AutoConfirmResult class to get better support if we want
chimp1984 Aug 30, 2020
e5aee1c
No functionality has been changed by that refactoring, just moved
chimp1984 Aug 30, 2020
bfab6ff
Replace success/failure with booleans
chimp1984 Aug 30, 2020
5143b1e
Apply suggested changes from code analysis
chimp1984 Aug 30, 2020
77c203e
No functional change, pure refactoring
chimp1984 Aug 30, 2020
219094e
Merge branch 'add-xmr-tx-key-service-2' into add-xmr-tx-key-service-3
chimp1984 Aug 30, 2020
67723fa
Do not pass over xmrAutoConfirmationManager to ProcessModel but use a
chimp1984 Aug 30, 2020
595c968
Various small cleanups...
chimp1984 Aug 30, 2020
2fb6256
Refactoring: Rename getTextStatus to getStatusAsDisplayString
chimp1984 Aug 30, 2020
94c84b6
Add @Override, cleanup
chimp1984 Aug 30, 2020
2a887e1
Improve SetXmrTxKeyWindow
chimp1984 Aug 30, 2020
867e023
Merge branch 'master_upstream' into add-xmr-tx-key-service-3
chimp1984 Aug 30, 2020
38ac145
Add devMode check for NO_MATCH case.
chimp1984 Aug 30, 2020
c6c8a3e
Refactoring:
chimp1984 Aug 31, 2020
213dffb
Refactoring:
chimp1984 Aug 31, 2020
b76357e
Refactoring:
chimp1984 Aug 31, 2020
ef9ac12
Refactoring:
chimp1984 Aug 31, 2020
0740f8d
Remove @nullable from socks5ProxyProvider param
chimp1984 Aug 31, 2020
6f56f90
Refactor:
chimp1984 Aug 31, 2020
40a7320
Refactor:
chimp1984 Aug 31, 2020
f8b5c30
Refactor:
chimp1984 Aug 31, 2020
4478222
Refactor:
chimp1984 Aug 31, 2020
8707053
Refactor:
chimp1984 Aug 31, 2020
a758880
Refactor:
chimp1984 Aug 31, 2020
0e2268d
Refactor:
chimp1984 Aug 31, 2020
f3ad669
Refactor:
chimp1984 Aug 31, 2020
aab478a
Refactor:
chimp1984 Aug 31, 2020
2967530
Max amount was set to 0.1 BTC, should be 1 BTC
chimp1984 Aug 31, 2020
4f0e574
Use static field for dev test values
chimp1984 Aug 31, 2020
e9e7b48
Various refactorings, bug fixes and improvements.
chimp1984 Aug 31, 2020
12ef5aa
Update comment
chimp1984 Aug 31, 2020
7b3dc54
dont use restart routing for seed nodes if in devmode
chimp1984 Sep 1, 2020
4323b41
Adjust to codacy complaints
chimp1984 Sep 1, 2020
d36306a
More refactoring....
chimp1984 Sep 1, 2020
123183e
Remove CryptoNoteException again as it caused failed tests
chimp1984 Sep 1, 2020
6cc074a
Add default clause (codacy complaint)
chimp1984 Sep 1, 2020
3ec216d
Replace Exception with CryptoNoteException (codacy complaint)
chimp1984 Sep 1, 2020
77841e2
Change log level
chimp1984 Sep 1, 2020
3b4e183
Use tradeId for prefix for id of request.
chimp1984 Sep 1, 2020
580b059
Increase timeouts from 10 sec to 30 sec.
chimp1984 Sep 1, 2020
512f1a5
Refactor AutoConfirmSettings handling in preferences
chimp1984 Sep 1, 2020
10dcc70
Change log level if banned seed or price relay is seen from filter.
chimp1984 Sep 1, 2020
28c8150
Refactoring
chimp1984 Sep 2, 2020
4639402
Dont restart seed if localhost is used
chimp1984 Sep 2, 2020
80d85e6
Make constructor private
chimp1984 Sep 2, 2020
0398609
Merge master
chimp1984 Sep 2, 2020
7c0d24c
Refactoring: Rename package
chimp1984 Sep 2, 2020
91cc147
Add annotation
chimp1984 Sep 2, 2020
67aa46a
- Fix incorrect isTerminal default value.
chimp1984 Sep 2, 2020
7240bd6
Read numRequiredConfirmations from autoConfirmSettings just in time.
chimp1984 Sep 2, 2020
aa802a3
Fix incorrect init of AutoConfirmSettings
chimp1984 Sep 2, 2020
70a0771
Code style: Improve order of fields
chimp1984 Sep 2, 2020
320179f
Improve handling of invalid/empty tx hash/tx key
chimp1984 Sep 2, 2020
a8968da
Add listener on autoConfirmSettings changes and terminate all services
chimp1984 Sep 2, 2020
a9e61e4
Replace ObjectProperty<AssetTxProofResult> with IntegerProperty
chimp1984 Sep 2, 2020
adbb262
Add unnecessary break; at default clause to satisfy stupid codacy bot.
chimp1984 Sep 2, 2020
37241f9
Add interfaces and generic support
chimp1984 Sep 2, 2020
d725590
Remove delay form UserThread.execute
chimp1984 Sep 2, 2020
6c33385
Config XmrTxProofParser in guice module
chimp1984 Sep 2, 2020
7e6a7a5
Add AssetTxProofHttpClient interface
chimp1984 Sep 2, 2020
a0c75e9
Rename class HttpClient to HttpClientImpl and interface IHttpClient
chimp1984 Sep 2, 2020
d1379d1
Fix tests
chimp1984 Sep 2, 2020
391852b
Add DevTestXmrTxProofHttpClient
chimp1984 Sep 2, 2020
7b2823d
Add more tests for date check
chimp1984 Sep 2, 2020
8e46ba6
Simplify assertions
chimp1984 Sep 2, 2020
109f298
Add more test cases to DevTestXmrTxProofHttpClient
chimp1984 Sep 2, 2020
d3f1255
Update text
chimp1984 Sep 2, 2020
3492ae4
Cleanup
chimp1984 Sep 2, 2020
117b5bf
Add default clauses
chimp1984 Sep 2, 2020
bf73ffc
Improve looging
chimp1984 Sep 2, 2020
8682127
Add support for addresses with integrated payment ID
chimp1984 Sep 3, 2020
b17ee93
Add listeners for filter change for shutdown all requests and
chimp1984 Sep 3, 2020
77c7629
Merge branch 'master' of github.com:bisq-network/bisq into add-xmr-tx…
ripcurlx Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/filter/Filter.java
Expand Up @@ -240,13 +240,13 @@ public Filter(List<String> bannedOfferIds,
this.refundAgents = refundAgents;
this.bannedAccountWitnessSignerPubKeys = bannedAccountWitnessSignerPubKeys;
this.btcFeeReceiverAddresses = btcFeeReceiverAddresses;
this.disableAutoConf = disableAutoConf;
this.ownerPubKeyBytes = ownerPubKeyBytes;
this.creationDate = creationDate;
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);
this.signatureAsBase64 = signatureAsBase64;
this.signerPubKeyAsHex = signerPubKeyAsHex;
this.bannedPrivilegedDevPubKeys = bannedPrivilegedDevPubKeys;
this.disableAutoConf = disableAutoConf;

// ownerPubKeyBytes can be null when called from tests
if (ownerPubKeyBytes != null) {
Expand Down Expand Up @@ -358,9 +358,9 @@ public String toString() {
",\n bannedAccountWitnessSignerPubKeys=" + bannedAccountWitnessSignerPubKeys +
",\n bannedPrivilegedDevPubKeys=" + bannedPrivilegedDevPubKeys +
",\n btcFeeReceiverAddresses=" + btcFeeReceiverAddresses +
",\n disableAutoConf=" + disableAutoConf +
",\n creationDate=" + creationDate +
",\n extraDataMap=" + extraDataMap +
",\n disableAutoConf=" + disableAutoConf +
"\n}";
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/trade/TradeManager.java
Expand Up @@ -330,8 +330,8 @@ private void initPendingTrades() {
}
}

if (trade.getState() == Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG &&
trade.getCounterCurrencyExtraData() != null) {
if (trade.getState() == Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG) {
// This state can be only appear at a SellerTrade
checkArgument(trade instanceof SellerTrade, "Trade must be instance of SellerTrade");
// We delay a bit as at startup lots of stuff is happening
UserThread.runAfter(() -> maybeStartXmrTxProofServices((SellerTrade) trade), 1);
Expand Down
Expand Up @@ -58,12 +58,14 @@ protected void run() {
}

String counterCurrencyExtraData = message.getCounterCurrencyExtraData();
if (counterCurrencyExtraData != null &&
counterCurrencyExtraData.length() < 100) {
if (counterCurrencyExtraData != null && counterCurrencyExtraData.length() < 100) {
trade.setCounterCurrencyExtraData(counterCurrencyExtraData);
checkArgument(trade instanceof SellerTrade, "Trade must be instance of SellerTrade");
processModel.getTradeManager().maybeStartXmrTxProofServices((SellerTrade) trade);
}

checkArgument(trade instanceof SellerTrade, "Trade must be instance of SellerTrade");
// We return early in the service if its not XMR. We prefer to not have additional checks outside...
processModel.getTradeManager().maybeStartXmrTxProofServices((SellerTrade) trade);

processModel.removeMailboxMessageAfterProcessing(trade);

trade.setState(Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG);
Expand Down
Expand Up @@ -73,13 +73,6 @@ void requestFromAllServices(Consumer<AssetTxProofResult> resultHandler, FaultHan
callResultHandlerAndMaybeTerminate(resultHandler, AssetTxProofResult.PAYOUT_TX_ALREADY_PUBLISHED);
}
};
String txId = trade.getCounterCurrencyTxId();
String txHash = trade.getCounterCurrencyExtraData();
if (is32BitHexStringInValid(txId) || is32BitHexStringInValid(txHash)) {

callResultHandlerAndMaybeTerminate(resultHandler, AssetTxProofResult.INVALID_DATA);
return;
}

if (isTradeAmountAboveLimit(trade)) {
callResultHandlerAndMaybeTerminate(resultHandler, AssetTxProofResult.TRADE_LIMIT_EXCEEDED);
Expand Down Expand Up @@ -195,15 +188,6 @@ void terminate() {
// Validation
///////////////////////////////////////////////////////////////////////////////////////////

private boolean is32BitHexStringInValid(String hexString) {
if (hexString == null || hexString.isEmpty() || !hexString.matches("[a-fA-F0-9]{64}")) {
log.warn("Invalid hexString: {}", hexString);
return true;
}

return false;
}

private boolean isTradeAmountAboveLimit(Trade trade) {
Coin tradeAmount = trade.getTradeAmount();
Coin tradeLimit = Coin.valueOf(autoConfirmSettings.getTradeLimit());
Expand Down
Expand Up @@ -98,22 +98,30 @@ public void maybeStartRequests(Trade trade,
List<Trade> activeTrades,
Consumer<AssetTxProofResult> resultHandler,
FaultHandler faultHandler) {
Optional<AutoConfirmSettings> optionalAutoConfirmSettings = preferences.findAutoConfirmSettings("XMR");
if (!optionalAutoConfirmSettings.isPresent()) {
log.error("autoConfirmSettings is not present");
if (!isXmrBuyer(trade)) {
return;
}
AutoConfirmSettings autoConfirmSettings = optionalAutoConfirmSettings.get();

if (!isXmrBuyer(trade)) {
String txId = trade.getCounterCurrencyTxId();
String txHash = trade.getCounterCurrencyExtraData();
if (is32BitHexStringInValid(txId) || is32BitHexStringInValid(txHash)) {
trade.setAssetTxProofResult(AssetTxProofResult.INVALID_DATA.details(Res.get("portfolio.pending.autoConf.state.txKeyOrTxIdInvalid")));
return;
}

if (!isFeatureEnabled(trade, autoConfirmSettings)) {
if (!networkAndWalletReady()) {
return;
}

if (!networkAndWalletReady()) {
Optional<AutoConfirmSettings> optionalAutoConfirmSettings = preferences.findAutoConfirmSettings("XMR");
if (!optionalAutoConfirmSettings.isPresent()) {
// Not expected
log.error("autoConfirmSettings is not present");
return;
}
AutoConfirmSettings autoConfirmSettings = optionalAutoConfirmSettings.get();

if (!isFeatureEnabled(trade, autoConfirmSettings)) {
return;
}

Expand Down Expand Up @@ -164,6 +172,15 @@ private boolean isXmrBuyer(Trade trade) {
return checkNotNull(trade.getContract()).getSellerPaymentAccountPayload() instanceof AssetsAccountPayload;
}

private boolean is32BitHexStringInValid(String hexString) {
if (hexString == null || hexString.isEmpty() || !hexString.matches("[a-fA-F0-9]{64}")) {
log.warn("Invalid hexString: {}", hexString);
return true;
}

return false;
}

private boolean networkAndWalletReady() {
return p2PService.isBootstrapped() &&
walletsSetup.isDownloadComplete() &&
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Expand Up @@ -573,9 +573,10 @@ portfolio.pending.step5.completed=Completed
portfolio.pending.step3_seller.autoConf.status.label=Auto-confirm status
portfolio.pending.autoConf=Auto-confirmed

portfolio.pending.autoConf.state.xmr.txKeyReused=The peer re-used a transaction key. Please open a dispute.
portfolio.pending.autoConf.state.xmr.txKeyReused=Transaction key re-used. Please open a dispute.
portfolio.pending.autoConf.state.confirmations=Confirmations: {0}/{1}
portfolio.pending.autoConf.state.txNotFound=Transaction not confirmed yet
portfolio.pending.autoConf.state.txKeyOrTxIdInvalid=No valid transaction ID / transaction key

# suppress inspection "UnusedProperty"
portfolio.pending.autoConf.state.FEATURE_DISABLED=Auto-confirm feature is disabled
Expand Down
Expand Up @@ -37,6 +37,7 @@

import static bisq.common.app.DevEnv.isDevMode;
import static bisq.desktop.util.FormBuilder.addInputTextField;
import static javafx.beans.binding.Bindings.createBooleanBinding;

public class SetXmrTxKeyWindow extends Overlay<SetXmrTxKeyWindow> {

Expand Down Expand Up @@ -69,6 +70,21 @@ public void show() {
txKeyInputTextField.setText(XmrTxProofModel.DEV_TX_KEY);
}

actionButton.disableProperty().bind(createBooleanBinding(() -> {
String txHash = txHashInputTextField.getText();
String txKey = txKeyInputTextField.getText();

// If a field is empty we allow to continue. We do not enforce that users send the data.
if (txHash.isEmpty() || txKey.isEmpty()) {
return false;
}

// Otherwise we require that input is valid
return !txHashInputTextField.getValidator().validate(txHash).isValid ||
!txKeyInputTextField.getValidator().validate(txKey).isValid;
},
txHashInputTextField.textProperty(), txKeyInputTextField.textProperty()));

applyStyles();
display();
}
Expand Down
Expand Up @@ -74,7 +74,6 @@
import bisq.core.trade.DelayedPayoutTxValidation;
import bisq.core.trade.Trade;
import bisq.core.user.DontShowAgainLookup;
import bisq.core.util.validation.InputValidator;

import bisq.common.Timer;
import bisq.common.UserThread;
Expand Down Expand Up @@ -470,20 +469,6 @@ private void onPaymentStarted() {
return;
}

InputValidator.ValidationResult validateTxKey = setXmrTxKeyWindow.getRegexValidator().validate(txKey);
if (!validateTxKey.isValid) {
UserThread.runAfter(() -> new Popup().warning(validateTxKey.errorMessage).show(),
Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
return;
}

InputValidator.ValidationResult validateTxHash = setXmrTxKeyWindow.getRegexValidator().validate(txHash);
if (!validateTxHash.isValid) {
UserThread.runAfter(() -> new Popup().warning(validateTxHash.errorMessage).show(),
Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
return;
}

trade.setCounterCurrencyExtraData(txKey);
trade.setCounterCurrencyTxId(txHash);
showConfirmPaymentStartedPopup();
Expand Down