Search in sources :

Example 1 with AccountAgeWitnessService

use of bisq.core.payment.AccountAgeWitnessService in project bisq-core by bisq-network.

the class VerifyPeersAccountAgeWitness method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (CurrencyUtil.isFiatCurrency(trade.getOffer().getCurrencyCode())) {
            final AccountAgeWitnessService accountAgeWitnessService = processModel.getAccountAgeWitnessService();
            final TradingPeer tradingPeer = processModel.getTradingPeer();
            final PaymentAccountPayload peersPaymentAccountPayload = checkNotNull(tradingPeer.getPaymentAccountPayload(), "Peers peersPaymentAccountPayload must not be null");
            final PubKeyRing peersPubKeyRing = checkNotNull(tradingPeer.getPubKeyRing(), "peersPubKeyRing must not be null");
            byte[] nonce = tradingPeer.getAccountAgeWitnessNonce();
            byte[] signature = tradingPeer.getAccountAgeWitnessSignature();
            if (nonce != null && signature != null) {
                final String[] errorMsg = new String[1];
                long currentDateAsLong = tradingPeer.getCurrentDate();
                // In case the peer has an older version we get 0, so we use our time instead
                final Date peersCurrentDate = currentDateAsLong > 0 ? new Date(currentDateAsLong) : new Date();
                boolean result = accountAgeWitnessService.verifyAccountAgeWitness(trade, peersPaymentAccountPayload, peersCurrentDate, peersPubKeyRing, nonce, signature, errorMessage -> errorMsg[0] = errorMessage);
                if (result)
                    complete();
                else
                    failed(errorMsg[0]);
            } else {
                String msg = "Seems that offer was created with an application before v0.6 which did not support the account age witness verification.";
                msg += "\nTrade ID=" + trade.getId();
                if (new Date().after(AccountAgeWitnessService.FULL_ACTIVATION)) {
                    msg = "The account age witness verification failed.\nReason: " + msg + "\nAfter first of Feb. 2018 we don't support old offers without account age witness verification anymore.";
                    log.error(msg);
                    failed(msg);
                } else {
                    log.warn(msg + "\nWe tolerate offers without account age witness until first of Feb. 2018");
                    complete();
                }
            }
        } else {
            complete();
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : TradingPeer(bisq.core.trade.protocol.TradingPeer) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) PubKeyRing(bisq.common.crypto.PubKeyRing) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) Date(java.util.Date)

Aggregations

PubKeyRing (bisq.common.crypto.PubKeyRing)1 AccountAgeWitnessService (bisq.core.payment.AccountAgeWitnessService)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 TradingPeer (bisq.core.trade.protocol.TradingPeer)1 Date (java.util.Date)1