Search in sources :

Example 1 with UTXOProviderException

use of co.rsk.bitcoinj.core.UTXOProviderException in project rskj by rsksmart.

the class BridgeSupport method createMigrationTransaction.

private Pair<BtcTransaction, List<UTXO>> createMigrationTransaction(Wallet originWallet, Address destinationAddress) {
    Coin expectedMigrationValue = originWallet.getBalance();
    logger.debug("[createMigrationTransaction] Balance to migrate: {}", expectedMigrationValue);
    for (; ; ) {
        BtcTransaction migrationBtcTx = new BtcTransaction(originWallet.getParams());
        migrationBtcTx.addOutput(expectedMigrationValue, destinationAddress);
        SendRequest sr = SendRequest.forTx(migrationBtcTx);
        sr.changeAddress = destinationAddress;
        sr.feePerKb = getFeePerKb();
        sr.missingSigsMode = Wallet.MissingSigsMode.USE_OP_ZERO;
        sr.recipientsPayFees = true;
        try {
            originWallet.completeTx(sr);
            for (TransactionInput transactionInput : migrationBtcTx.getInputs()) {
                transactionInput.disconnect();
            }
            List<UTXO> selectedUTXOs = originWallet.getUTXOProvider().getOpenTransactionOutputs(originWallet.getWatchedAddresses()).stream().filter(utxo -> migrationBtcTx.getInputs().stream().anyMatch(input -> input.getOutpoint().getHash().equals(utxo.getHash()) && input.getOutpoint().getIndex() == utxo.getIndex())).collect(Collectors.toList());
            return Pair.of(migrationBtcTx, selectedUTXOs);
        } catch (InsufficientMoneyException | Wallet.ExceededMaxTransactionSize | Wallet.CouldNotAdjustDownwards e) {
            expectedMigrationValue = expectedMigrationValue.divide(2);
        } catch (Wallet.DustySendRequested e) {
            throw new IllegalStateException("Retiring federation wallet cannot be emptied", e);
        } catch (UTXOProviderException e) {
            throw new RuntimeException("Unexpected UTXO provider error", e);
        }
    }
}
Also used : OneOffWhiteListEntry(co.rsk.peg.whitelist.OneOffWhiteListEntry) Arrays(java.util.Arrays) VMException(org.ethereum.vm.exception.VMException) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) Address(co.rsk.bitcoinj.core.Address) LoggerFactory(org.slf4j.LoggerFactory) RskAddress(co.rsk.core.RskAddress) UTXOProviderException(co.rsk.bitcoinj.core.UTXOProviderException) TxSenderAddressType(co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType) Keccak256(co.rsk.crypto.Keccak256) RSKIP219(org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP219) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) TransactionSignature(co.rsk.bitcoinj.crypto.TransactionSignature) Context(co.rsk.bitcoinj.core.Context) Pair(org.apache.commons.lang3.tuple.Pair) BtcBlockChain(co.rsk.bitcoinj.core.BtcBlockChain) Map(java.util.Map) BigInteger(java.math.BigInteger) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) RSKIP186(org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP186) MerkleBranch(co.rsk.peg.bitcoin.MerkleBranch) Wallet(co.rsk.bitcoinj.wallet.Wallet) Coin(co.rsk.bitcoinj.core.Coin) TransactionOutput(co.rsk.bitcoinj.core.TransactionOutput) FastBridgeRedeemScriptParser(co.rsk.bitcoinj.script.FastBridgeRedeemScriptParser) Set(java.util.Set) CallType(co.rsk.rpc.modules.trace.CallType) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Repository(org.ethereum.core.Repository) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) Objects(java.util.Objects) ScriptBuilder(co.rsk.bitcoinj.script.ScriptBuilder) Script(co.rsk.bitcoinj.script.Script) List(java.util.List) VerificationException(co.rsk.bitcoinj.core.VerificationException) Optional(java.util.Optional) UTXO(co.rsk.bitcoinj.core.UTXO) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) LockWhitelistEntry(co.rsk.peg.whitelist.LockWhitelistEntry) CheckpointManager(co.rsk.bitcoinj.core.CheckpointManager) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) co.rsk.peg.utils(co.rsk.peg.utils) ProgramSubtrace(co.rsk.rpc.modules.trace.ProgramSubtrace) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) ArrayList(java.util.ArrayList) Hex(org.bouncycastle.util.encoders.Hex) Block(org.ethereum.core.Block) BridgeUtils.getRegularPegoutTxSize(co.rsk.peg.BridgeUtils.getRegularPegoutTxSize) InsufficientMoneyException(co.rsk.bitcoinj.core.InsufficientMoneyException) BridgeConstants(co.rsk.config.BridgeConstants) Nullable(javax.annotation.Nullable) AddressFormatException(co.rsk.bitcoinj.core.AddressFormatException) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) PanicProcessor(co.rsk.panic.PanicProcessor) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ScriptChunk(co.rsk.bitcoinj.script.ScriptChunk) Logger(org.slf4j.Logger) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) HashUtil(org.ethereum.crypto.HashUtil) DataWord(org.ethereum.vm.DataWord) IOException(java.io.IOException) LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) SendRequest(co.rsk.bitcoinj.wallet.SendRequest) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Program(org.ethereum.vm.program.Program) UnlimitedWhiteListEntry(co.rsk.peg.whitelist.UnlimitedWhiteListEntry) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) PartialMerkleTree(co.rsk.bitcoinj.core.PartialMerkleTree) ByteUtil(org.ethereum.util.ByteUtil) InternalTransaction(org.ethereum.vm.program.InternalTransaction) PeginInstructionsException(co.rsk.peg.pegininstructions.PeginInstructionsException) RskAllowUnconfirmedCoinSelector(co.rsk.peg.bitcoin.RskAllowUnconfirmedCoinSelector) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ProgramResult(org.ethereum.vm.program.ProgramResult) StoredBlock(co.rsk.bitcoinj.core.StoredBlock) Transaction(org.ethereum.core.Transaction) Collections(java.util.Collections) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) TransferInvoke(org.ethereum.vm.program.invoke.TransferInvoke) InputStream(java.io.InputStream) ECKey(org.ethereum.crypto.ECKey) SendRequest(co.rsk.bitcoinj.wallet.SendRequest) Wallet(co.rsk.bitcoinj.wallet.Wallet) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) InsufficientMoneyException(co.rsk.bitcoinj.core.InsufficientMoneyException) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) Coin(co.rsk.bitcoinj.core.Coin) UTXO(co.rsk.bitcoinj.core.UTXO) UTXOProviderException(co.rsk.bitcoinj.core.UTXOProviderException)

Aggregations

Address (co.rsk.bitcoinj.core.Address)1 AddressFormatException (co.rsk.bitcoinj.core.AddressFormatException)1 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)1 BtcBlockChain (co.rsk.bitcoinj.core.BtcBlockChain)1 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)1 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)1 CheckpointManager (co.rsk.bitcoinj.core.CheckpointManager)1 Coin (co.rsk.bitcoinj.core.Coin)1 Context (co.rsk.bitcoinj.core.Context)1 InsufficientMoneyException (co.rsk.bitcoinj.core.InsufficientMoneyException)1 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)1 PartialMerkleTree (co.rsk.bitcoinj.core.PartialMerkleTree)1 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)1 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)1 TransactionInput (co.rsk.bitcoinj.core.TransactionInput)1 TransactionOutput (co.rsk.bitcoinj.core.TransactionOutput)1 UTXO (co.rsk.bitcoinj.core.UTXO)1 UTXOProviderException (co.rsk.bitcoinj.core.UTXOProviderException)1 VerificationException (co.rsk.bitcoinj.core.VerificationException)1 TransactionSignature (co.rsk.bitcoinj.crypto.TransactionSignature)1