Search in sources :

Example 1 with CompensationProposal

use of bisq.core.dao.governance.proposal.compensation.CompensationProposal in project bisq-core by bisq-network.

the class MyBlindVoteListService method getMerits.

// blindVoteTxId is null if we use the method from the getCurrentlyAvailableMerit call.
public MeritList getMerits(@Nullable String blindVoteTxId) {
    // Create a lookup set for txIds of own comp. requests
    Set<String> myCompensationProposalTxIs = myProposalListService.getList().stream().filter(proposal -> proposal instanceof CompensationProposal).map(Proposal::getTxId).collect(Collectors.toSet());
    return new MeritList(bsqStateService.getIssuanceSet().stream().map(issuance -> {
        // We check if it is our proposal
        if (!myCompensationProposalTxIs.contains(issuance.getTxId()))
            return null;
        byte[] signatureAsBytes;
        if (blindVoteTxId != null) {
            String pubKey = issuance.getPubKey();
            if (pubKey == null) {
                // Maybe add exception
                log.error("We did not have a pubKey in our issuance object. " + "txId={}, issuance={}", issuance.getTxId(), issuance);
                return null;
            }
            DeterministicKey key = bsqWalletService.findKeyFromPubKey(Utilities.decodeFromHex(pubKey));
            if (key == null) {
                // Maybe add exception
                log.error("We did not find the key for our compensation request. txId={}", issuance.getTxId());
                return null;
            }
            // We sign the txId so we be sure that the signature could not be used by anyone else
            // In the verification the txId will be checked as well.
            // As we use BitcoinJ EC keys we extend our consensus dependency to BitcoinJ.
            // Alternative would be to use our own Sig Key but then we need to share the key separately.
            // The EC key is in the blockchain already. We prefer here to stick with EC key. If any change
            // in BitcoinJ would break our consensus we would need to fall back to the old BitcoinJ EC
            // implementation.
            ECKey.ECDSASignature signature = key.sign(Sha256Hash.wrap(blindVoteTxId));
            signatureAsBytes = signature.toCanonicalised().encodeToDER();
        } else {
            // In case we use it for requesting the currently available merit we don't apply a signature
            signatureAsBytes = new byte[0];
        }
        return new Merit(issuance, signatureAsBytes);
    }).filter(Objects::nonNull).sorted(Comparator.comparing(Merit::getIssuanceTxId)).collect(Collectors.toList()));
}
Also used : CompensationProposal(bisq.core.dao.governance.proposal.compensation.CompensationProposal) MeritList(bisq.core.dao.governance.merit.MeritList) Merit(bisq.core.dao.governance.merit.Merit) ECKey(org.bitcoinj.core.ECKey) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 2 with CompensationProposal

use of bisq.core.dao.governance.proposal.compensation.CompensationProposal in project bisq-core by bisq-network.

the class IssuanceService method issueBsq.

public void issueBsq(CompensationProposal compensationProposal, int chainHeight) {
    bsqStateService.getIssuanceCandidateTxOutputs().stream().filter(txOutput -> isValid(txOutput, compensationProposal, periodService, chainHeight)).forEach(txOutput -> {
        // We don't check atm if the output is unspent. We cannot use the bsqWallet as that would not
        // reflect our current block state (could have been spent at later block which is valid and
        // bsqWallet would show that spent state). We would need to support a spent status for the outputs
        // which are interpreted as BTC (as a not yet accepted comp. request).
        Optional<Tx> optionalTx = bsqStateService.getTx(compensationProposal.getTxId());
        if (optionalTx.isPresent()) {
            long amount = compensationProposal.getRequestedBsq().value;
            Tx tx = optionalTx.get();
            // We use key from first input
            TxInput txInput = tx.getTxInputs().get(0);
            String pubKey = txInput.getPubKey();
            Issuance issuance = new Issuance(tx.getId(), chainHeight, amount, pubKey);
            bsqStateService.addIssuance(issuance);
            bsqStateService.addUnspentTxOutput(txOutput);
            StringBuilder sb = new StringBuilder();
            sb.append("\n################################################################################\n");
            sb.append("We issued new BSQ to tx with ID ").append(txOutput.getTxId()).append("\nfor compensationProposal with UID ").append(compensationProposal.getTxId()).append("\n################################################################################\n");
            log.info(sb.toString());
        } else {
            // TODO throw exception
            log.error("Tx for compensation request not found. txId={}", compensationProposal.getTxId());
        }
    });
}
Also used : Inject(javax.inject.Inject) Issuance(bisq.core.dao.state.governance.Issuance) Slf4j(lombok.extern.slf4j.Slf4j) PeriodService(bisq.core.dao.state.period.PeriodService) TxOutput(bisq.core.dao.state.blockchain.TxOutput) Tx(bisq.core.dao.state.blockchain.Tx) BsqStateService(bisq.core.dao.state.BsqStateService) Optional(java.util.Optional) CompensationProposal(bisq.core.dao.governance.proposal.compensation.CompensationProposal) DaoPhase(bisq.core.dao.state.period.DaoPhase) TxInput(bisq.core.dao.state.blockchain.TxInput) Tx(bisq.core.dao.state.blockchain.Tx) Issuance(bisq.core.dao.state.governance.Issuance) TxInput(bisq.core.dao.state.blockchain.TxInput)

Aggregations

CompensationProposal (bisq.core.dao.governance.proposal.compensation.CompensationProposal)2 Merit (bisq.core.dao.governance.merit.Merit)1 MeritList (bisq.core.dao.governance.merit.MeritList)1 BsqStateService (bisq.core.dao.state.BsqStateService)1 Tx (bisq.core.dao.state.blockchain.Tx)1 TxInput (bisq.core.dao.state.blockchain.TxInput)1 TxOutput (bisq.core.dao.state.blockchain.TxOutput)1 Issuance (bisq.core.dao.state.governance.Issuance)1 DaoPhase (bisq.core.dao.state.period.DaoPhase)1 PeriodService (bisq.core.dao.state.period.PeriodService)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Slf4j (lombok.extern.slf4j.Slf4j)1 ECKey (org.bitcoinj.core.ECKey)1 DeterministicKey (org.bitcoinj.crypto.DeterministicKey)1