Search in sources :

Example 1 with BsqBlockChain

use of bisq.core.dao.blockchain.BsqBlockChain in project bisq-core by bisq-network.

the class JsonBlockChainExporter method maybeExport.

public void maybeExport() {
    if (dumpBlockchainData) {
        ListenableFuture<Void> future = executor.submit(() -> {
            final BsqBlockChain bsqBlockChainClone = readableBsqBlockChain.getClone();
            for (Tx tx : bsqBlockChainClone.getTxMap().values()) {
                String txId = tx.getId();
                JsonTxType txType = tx.getTxType() != TxType.UNDEFINED_TX_TYPE ? JsonTxType.valueOf(tx.getTxType().name()) : null;
                List<JsonTxOutput> outputs = new ArrayList<>();
                tx.getOutputs().stream().forEach(txOutput -> {
                    final JsonTxOutput outputForJson = new JsonTxOutput(txId, txOutput.getIndex(), txOutput.isVerified() ? txOutput.getValue() : 0, !txOutput.isVerified() ? txOutput.getValue() : 0, txOutput.getBlockHeight(), txOutput.isVerified(), tx.getBurntFee(), txOutput.getAddress(), new JsonScriptPubKey(txOutput.getPubKeyScript()), txOutput.getSpentInfo() != null ? new JsonSpentInfo(txOutput.getSpentInfo()) : null, tx.getTime(), txType, txType != null ? txType.getDisplayString() : "", txOutput.getOpReturnData() != null ? Utils.HEX.encode(txOutput.getOpReturnData()) : null);
                    outputs.add(outputForJson);
                    txOutputFileManager.writeToDisc(Utilities.objectToJson(outputForJson), outputForJson.getId());
                });
                List<JsonTxInput> inputs = tx.getInputs().stream().map(txInput -> {
                    final TxOutput connectedTxOutput = txInput.getConnectedTxOutput();
                    return new JsonTxInput(txInput.getConnectedTxOutputIndex(), txInput.getConnectedTxOutputTxId(), connectedTxOutput != null ? connectedTxOutput.getValue() : 0, connectedTxOutput != null && connectedTxOutput.isVerified(), connectedTxOutput != null ? connectedTxOutput.getAddress() : null, tx.getTime());
                }).collect(Collectors.toList());
                final JsonTx jsonTx = new JsonTx(txId, tx.getBlockHeight(), tx.getBlockHash(), tx.getTime(), inputs, outputs, txType, txType != null ? txType.getDisplayString() : "", tx.getBurntFee());
                txFileManager.writeToDisc(Utilities.objectToJson(jsonTx), txId);
            }
            bsqBlockChainFileManager.writeToDisc(Utilities.objectToJson(bsqBlockChainClone), "BsqBlockChain");
            return null;
        });
        Futures.addCallback(future, new FutureCallback<Void>() {

            public void onSuccess(Void ignore) {
                log.trace("onSuccess");
            }

            public void onFailure(@NotNull Throwable throwable) {
                log.error(throwable.toString());
                throwable.printStackTrace();
            }
        });
    }
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Utilities(bisq.common.util.Utilities) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Inject(com.google.inject.Inject) DaoOptionKeys(bisq.core.dao.DaoOptionKeys) ArrayList(java.util.ArrayList) JsonFileManager(bisq.common.storage.JsonFileManager) Named(javax.inject.Named) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain) Tx(bisq.core.dao.blockchain.vo.Tx) Utils(org.bitcoinj.core.Utils) IOException(java.io.IOException) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) TxType(bisq.core.dao.blockchain.vo.TxType) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) FileUtil(bisq.common.storage.FileUtil) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Paths(java.nio.file.Paths) Storage(bisq.common.storage.Storage) NotNull(org.jetbrains.annotations.NotNull) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) Tx(bisq.core.dao.blockchain.vo.Tx) ArrayList(java.util.ArrayList) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain)

Aggregations

FileUtil (bisq.common.storage.FileUtil)1 JsonFileManager (bisq.common.storage.JsonFileManager)1 Storage (bisq.common.storage.Storage)1 Utilities (bisq.common.util.Utilities)1 DaoOptionKeys (bisq.core.dao.DaoOptionKeys)1 BsqBlockChain (bisq.core.dao.blockchain.BsqBlockChain)1 ReadableBsqBlockChain (bisq.core.dao.blockchain.ReadableBsqBlockChain)1 Tx (bisq.core.dao.blockchain.vo.Tx)1 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)1 TxType (bisq.core.dao.blockchain.vo.TxType)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Inject (com.google.inject.Inject)1 File (java.io.File)1 IOException (java.io.IOException)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1