Search in sources :

Example 1 with PoolSupplier

use of com.samourai.whirlpool.client.wallet.data.pool.PoolSupplier in project sparrow by sparrowwallet.

the class SparrowDataSource method computeUtxoSupplier.

@Override
protected BasicUtxoSupplier computeUtxoSupplier(WhirlpoolWallet whirlpoolWallet, WalletSupplier walletSupplier, UtxoConfigSupplier utxoConfigSupplier, ChainSupplier chainSupplier, PoolSupplier poolSupplier, Tx0ParamService tx0ParamService) throws Exception {
    return new BasicUtxoSupplier(walletSupplier, utxoConfigSupplier, chainSupplier, poolSupplier, tx0ParamService) {

        @Override
        public void refresh() throws Exception {
            SparrowDataSource.this.refresh();
        }

        @Override
        protected void onUtxoChanges(UtxoData utxoData) {
            super.onUtxoChanges(utxoData);
            whirlpoolWallet.onUtxoChanges(utxoData);
        }

        @Override
        protected byte[] _getPrivKeyBytes(WhirlpoolUtxo whirlpoolUtxo) {
            UnspentOutput utxo = whirlpoolUtxo.getUtxo();
            Wallet wallet = getWallet(utxo.xpub.m);
            Map<BlockTransactionHashIndex, WalletNode> walletUtxos = wallet.getWalletUtxos();
            WalletNode node = walletUtxos.entrySet().stream().filter(entry -> entry.getKey().getHash().equals(Sha256Hash.wrap(utxo.tx_hash)) && entry.getKey().getIndex() == utxo.tx_output_n).map(Map.Entry::getValue).findFirst().orElseThrow(() -> new IllegalStateException("Cannot find UTXO " + utxo));
            if (node.getWallet().isBip47()) {
                try {
                    Keystore keystore = node.getWallet().getKeystores().get(0);
                    return keystore.getKey(node).getPrivKeyBytes();
                } catch (Exception e) {
                    log.error("Error getting private key", e);
                }
            }
            return null;
        }
    };
}
Also used : BasicUtxoSupplier(com.samourai.whirlpool.client.wallet.data.utxo.BasicUtxoSupplier) java.util(java.util) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) ExtendedKey(com.sparrowwallet.drongo.ExtendedKey) com.sparrowwallet.drongo.wallet(com.sparrowwallet.drongo.wallet) UtxoConfigSupplier(com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfigSupplier) WalletAddressesChangedEvent(com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent) LoggerFactory(org.slf4j.LoggerFactory) ChainSupplier(com.samourai.whirlpool.client.wallet.data.chain.ChainSupplier) MinerFeeSupplier(com.samourai.whirlpool.client.wallet.data.minerFee.MinerFeeSupplier) PoolSupplier(com.samourai.whirlpool.client.wallet.data.pool.PoolSupplier) WalletSupplier(com.samourai.whirlpool.client.wallet.data.wallet.WalletSupplier) WalletHistoryChangedEvent(com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) UtxoData(com.samourai.whirlpool.client.wallet.data.utxo.UtxoData) TransactionOutput(com.sparrowwallet.drongo.protocol.TransactionOutput) Utils(com.sparrowwallet.drongo.Utils) WalletResponseDataSource(com.samourai.whirlpool.client.wallet.data.dataSource.WalletResponseDataSource) BasicUtxoSupplier(com.samourai.whirlpool.client.wallet.data.utxo.BasicUtxoSupplier) WalletResponse(com.samourai.wallet.api.backend.beans.WalletResponse) DataPersister(com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersister) Subscribe(com.google.common.eventbus.Subscribe) UnspentOutput(com.samourai.wallet.api.backend.beans.UnspentOutput) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) Tx0ParamService(com.samourai.whirlpool.client.tx0.Tx0ParamService) Transaction(com.sparrowwallet.drongo.protocol.Transaction) Logger(org.slf4j.Logger) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) Platform(javafx.application.Platform) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Network(com.sparrowwallet.drongo.Network) ElectrumServer(com.sparrowwallet.sparrow.net.ElectrumServer) EventManager(com.sparrowwallet.sparrow.EventManager) Sha256Hash(com.sparrowwallet.drongo.protocol.Sha256Hash) NewBlockEvent(com.sparrowwallet.sparrow.event.NewBlockEvent) MinerFeeTarget(com.samourai.wallet.api.backend.MinerFeeTarget) TransactionInput(com.sparrowwallet.drongo.protocol.TransactionInput) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) UnspentOutput(com.samourai.wallet.api.backend.beans.UnspentOutput) UtxoData(com.samourai.whirlpool.client.wallet.data.utxo.UtxoData)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)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 HD_Wallet (com.samourai.wallet.hd.HD_Wallet)1 Tx0ParamService (com.samourai.whirlpool.client.tx0.Tx0ParamService)1 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)1 WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)1 ChainSupplier (com.samourai.whirlpool.client.wallet.data.chain.ChainSupplier)1 DataPersister (com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersister)1 WalletResponseDataSource (com.samourai.whirlpool.client.wallet.data.dataSource.WalletResponseDataSource)1 MinerFeeSupplier (com.samourai.whirlpool.client.wallet.data.minerFee.MinerFeeSupplier)1 PoolSupplier (com.samourai.whirlpool.client.wallet.data.pool.PoolSupplier)1 BasicUtxoSupplier (com.samourai.whirlpool.client.wallet.data.utxo.BasicUtxoSupplier)1 UtxoData (com.samourai.whirlpool.client.wallet.data.utxo.UtxoData)1 UtxoConfigSupplier (com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfigSupplier)1 WalletSupplier (com.samourai.whirlpool.client.wallet.data.wallet.WalletSupplier)1 ExtendedKey (com.sparrowwallet.drongo.ExtendedKey)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 Network (com.sparrowwallet.drongo.Network)1