Search in sources :

Example 6 with TransactionOutput

use of com.sparrowwallet.drongo.protocol.TransactionOutput in project sparrow by sparrowwallet.

the class SorobanController method calculateFee.

private long calculateFee(WalletTransaction walletTransaction, List<Map<BlockTransactionHashIndex, WalletNode>> selectedUtxoSets, Transaction transaction) {
    Map<BlockTransactionHashIndex, WalletNode> selectedUtxos = new LinkedHashMap<>();
    selectedUtxoSets.forEach(selectedUtxos::putAll);
    long feeAmt = 0L;
    for (BlockTransactionHashIndex utxo : selectedUtxos.keySet()) {
        if (utxo.getValue() == 0) {
            return walletTransaction == null ? -1 : walletTransaction.getFee();
        }
        feeAmt += utxo.getValue();
    }
    for (TransactionOutput txOutput : transaction.getOutputs()) {
        feeAmt -= txOutput.getValue();
    }
    return feeAmt;
}
Also used : TransactionOutput(com.sparrowwallet.drongo.protocol.TransactionOutput)

Example 7 with TransactionOutput

use of com.sparrowwallet.drongo.protocol.TransactionOutput in project sparrow by sparrowwallet.

the class OutputController method initializeView.

public void initializeView() {
    TransactionOutput txOutput = outputForm.getTransactionOutput();
    outputForm.signingWalletProperty().addListener((observable, oldValue, signingWallet) -> {
        updateOutputLegendFromWallet(txOutput, signingWallet);
    });
    updateOutputLegendFromWallet(txOutput, outputForm.getSigningWallet());
    value.setValue(txOutput.getValue());
    to.setVisible(false);
    try {
        Address[] addresses = txOutput.getScript().getToAddresses();
        to.setVisible(true);
        if (addresses.length == 1) {
            address.setAddress(addresses[0]);
        } else {
            address.setText("multiple addresses");
        }
    } catch (NonStandardScriptException e) {
    // ignore
    }
    spentField.managedProperty().bind(spentField.visibleProperty());
    spentByField.managedProperty().bind(spentByField.visibleProperty());
    spentByField.setVisible(false);
    if (outputForm.getPsbt() != null) {
        spent.setText("Unspent");
    } else if (outputForm.getOutputTransactions() != null) {
        updateSpent(outputForm.getOutputTransactions());
    } else {
        spent.setText("Unknown");
    }
    initializeScriptField(scriptPubKeyArea);
    scriptPubKeyArea.clear();
    scriptPubKeyArea.appendScript(txOutput.getScript(), null, null);
}
Also used : NonStandardScriptException(com.sparrowwallet.drongo.protocol.NonStandardScriptException) TransactionOutput(com.sparrowwallet.drongo.protocol.TransactionOutput) Address(com.sparrowwallet.drongo.address.Address)

Aggregations

TransactionOutput (com.sparrowwallet.drongo.protocol.TransactionOutput)7 Address (com.sparrowwallet.drongo.address.Address)3 Transaction (com.sparrowwallet.drongo.protocol.Transaction)3 TransactionInput (com.sparrowwallet.drongo.protocol.TransactionInput)3 NonStandardScriptException (com.sparrowwallet.drongo.protocol.NonStandardScriptException)2 Sha256Hash (com.sparrowwallet.drongo.protocol.Sha256Hash)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MinerFeeTarget (com.samourai.wallet.api.backend.MinerFeeTarget)1 UnspentOutput (com.samourai.wallet.api.backend.beans.UnspentOutput)1 WalletResponse (com.samourai.wallet.api.backend.beans.WalletResponse)1 Cahoots (com.samourai.wallet.cahoots.Cahoots)1 HD_Wallet (com.samourai.wallet.hd.HD_Wallet)1 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)1 ExtendedKey (com.sparrowwallet.drongo.ExtendedKey)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 PSBT (com.sparrowwallet.drongo.psbt.PSBT)1 PSBTInput (com.sparrowwallet.drongo.psbt.PSBTInput)1 PSBTOutput (com.sparrowwallet.drongo.psbt.PSBTOutput)1 PSBTParseException (com.sparrowwallet.drongo.psbt.PSBTParseException)1 com.sparrowwallet.drongo.wallet (com.sparrowwallet.drongo.wallet)1