maker waits for ack on sign offer request

This commit is contained in:
woodser 2022-01-05 14:04:08 -05:00
parent 253ef8fabe
commit 1b78be689a
2 changed files with 29 additions and 9 deletions

View File

@ -27,6 +27,10 @@ import bisq.core.offer.Offer;
import bisq.core.offer.messages.SignOfferRequest;
import bisq.core.offer.placeoffer.PlaceOfferModel;
import bisq.core.support.dispute.mediation.mediator.Mediator;
import bisq.network.p2p.AckMessage;
import bisq.network.p2p.DecryptedDirectMessageListener;
import bisq.network.p2p.DecryptedMessageWithPubKey;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.SendDirectMessageListener;
import java.util.Date;
@ -37,6 +41,8 @@ import org.slf4j.LoggerFactory;
public class MakerSendsSignOfferRequest extends Task<PlaceOfferModel> {
private static final Logger log = LoggerFactory.getLogger(MakerSendsSignOfferRequest.class);
private boolean failed = false;
@SuppressWarnings({"unused"})
public MakerSendsSignOfferRequest(TaskRunner taskHandler, PlaceOfferModel model) {
super(taskHandler, model);
@ -70,13 +76,33 @@ public class MakerSendsSignOfferRequest extends Task<PlaceOfferModel> {
// get signing arbitrator
Mediator arbitrator = checkNotNull(model.getUser().getAcceptedMediatorByAddress(offer.getOfferPayload().getArbitratorSigner()), "user.getAcceptedMediatorByAddress(mediatorNodeAddress) must not be null");
// complete on successful ack message
DecryptedDirectMessageListener ackListener = new DecryptedDirectMessageListener() {
@Override
public void onDirectMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress sender) {
if (!(decryptedMessageWithPubKey.getNetworkEnvelope() instanceof AckMessage)) return;
if (!sender.equals(arbitrator.getNodeAddress())) return;
AckMessage ackMessage = (AckMessage) decryptedMessageWithPubKey.getNetworkEnvelope();
if (!ackMessage.getSourceMsgClassName().equals(SignOfferRequest.class.getSimpleName())) return;
if (ackMessage.isSuccess()) {
offer.setState(Offer.State.OFFER_FEE_RESERVED);
model.getP2PService().removeDecryptedDirectMessageListener(this);
complete();
} else {
if (!failed) {
failed = true;
failed(ackMessage.getErrorMessage()); // TODO: (woodser): only fail once? build into task?
}
}
}
};
model.getP2PService().addDecryptedDirectMessageListener(ackListener);
// send request
model.getP2PService().sendEncryptedDirectMessage(arbitrator.getNodeAddress(), arbitrator.getPubKeyRing(), request, new SendDirectMessageListener() {
@Override
public void onArrived() {
offer.setState(Offer.State.OFFER_FEE_RESERVED);
log.info("{} arrived: arbitrator={}; offerId={}; uid={}", request.getClass().getSimpleName(), arbitrator.getNodeAddress(), offer.getId());
complete();
}
@Override
public void onFault(String errorMessage) {

View File

@ -71,16 +71,10 @@ public class UpdateMultisigWithTradingPeer extends TradeTask {
@Override
public void onVerifiedTradeMessage(TradeMessage message, NodeAddress sender) {
if (!(message instanceof UpdateMultisigResponse)) return;
System.out.println("Received UpdateMultisigResponse!!!");
System.out.println(message);
System.out.println(sender);
UpdateMultisigResponse response = (UpdateMultisigResponse) message;
int numOutputsSigned = multisigWallet.importMultisigHex(Arrays.asList(response.getUpdatedMultisigHex()));
multisigWallet.importMultisigHex(Arrays.asList(response.getUpdatedMultisigHex()));
multisigWallet.sync();
multisigWallet.save();
System.out.println("Num outputs signed with imported multisig hex: " + numOutputsSigned);
trade.removeListener(updateMultisigResponseListener);
complete();
}