Java Code Examples for org.bitcoinj.utils.BriefLogFormatter#init()

The following examples show how to use org.bitcoinj.utils.BriefLogFormatter#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockChain.java    From polling-station-app with GNU Lesser General Public License v3.0 7 votes vote down vote up
public void startDownload() {
    BriefLogFormatter.init();
    String filePrefix = "voting-wallet";
    File walletFile = new File(Environment.getExternalStorageDirectory() + "/" + Util.FOLDER_DIGITAL_VOTING_PASS);
    if (!walletFile.exists()) {
        walletFile.mkdirs();
    }
    kit = new WalletAppKit(params, walletFile, filePrefix);

    //set the observer
    kit.setDownloadListener(progressTracker);

    kit.setBlockingStartup(false);

    PeerAddress peer = new PeerAddress(params, peeraddr);
    kit.setPeerNodes(peer);
    kit.startAsync();
}
 
Example 2
Source File: WatchMempool.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    BriefLogFormatter.init();
    PeerGroup peerGroup = new PeerGroup(PARAMS);
    peerGroup.setMaxConnections(32);
    peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS));
    peerGroup.addOnTransactionBroadcastListener(new OnTransactionBroadcastListener() {
        @Override
        public void onTransaction(Peer peer, Transaction tx) {
            Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze();
            incrementCounter(TOTAL_KEY);
            log.info("tx {} result {}", tx.getHash(), result);
            incrementCounter(result.name());
            if (result == Result.NON_STANDARD)
                incrementCounter(Result.NON_STANDARD + "-" + DefaultRiskAnalysis.isStandard(tx));
        }
    });
    peerGroup.start();

    while (true) {
        Thread.sleep(STATISTICS_FREQUENCY_MS);
        printCounters();
    }
}
 
Example 3
Source File: WatchMempool.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    BriefLogFormatter.init();
    PeerGroup peerGroup = new PeerGroup(PARAMS);
    peerGroup.setMaxConnections(32);
    peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS));
    peerGroup.addOnTransactionBroadcastListener(new OnTransactionBroadcastListener() {
        @Override
        public void onTransaction(Peer peer, Transaction tx) {
            Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze();
            incrementCounter(TOTAL_KEY);
            log.info("tx {} result {}", tx.getHash(), result);
            incrementCounter(result.name());
            if (result == Result.NON_STANDARD)
                incrementCounter(Result.NON_STANDARD + "-" + DefaultRiskAnalysis.isStandard(tx));
        }
    });
    peerGroup.start();

    while (true) {
        Thread.sleep(STATISTICS_FREQUENCY_MS);
        printCounters();
    }
}
 
Example 4
Source File: FetchBlock.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.start();
    PeerAddress addr = new PeerAddress(params, InetAddress.getLocalHost());
    peerGroup.addAddress(addr);
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash blockHash = Sha256Hash.wrap(args[0]);
    Future<Block> future = peer.getBlock(blockHash);
    System.out.println("Waiting for node to send us the requested block: " + blockHash);
    Block block = future.get();
    System.out.println(block);
    peerGroup.stopAsync();
}
 
Example 5
Source File: ChainSplitTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Utils.setMockClock(); // Use mock clock
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
    MemoryBlockStore blockStore = new MemoryBlockStore(PARAMS);
    wallet = new Wallet(PARAMS);
    ECKey key1 = wallet.freshReceiveKey();
    ECKey key2 = wallet.freshReceiveKey();
    chain = new BlockChain(PARAMS, wallet, blockStore);
    coinsTo = key1.toAddress(PARAMS);
    coinsTo2 = key2.toAddress(PARAMS);
    someOtherGuy = new ECKey().toAddress(PARAMS);
}
 
Example 6
Source File: KeyChainGroupTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    BriefLogFormatter.init();
    Utils.setMockClock();
    group = new KeyChainGroup(PARAMS);
    group.setLookaheadSize(LOOKAHEAD_SIZE);   // Don't want slow tests.
    group.getActiveKeyChain();  // Force create a chain.

    watchingAccountKey = DeterministicKey.deserializeB58(null, XPUB, PARAMS);
}
 
Example 7
Source File: ECKeyTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
    ScryptParameters scryptParameters = scryptParametersBuilder.build();
    keyCrypter = new KeyCrypterScrypt(scryptParameters);

    BriefLogFormatter.init();
}
 
Example 8
Source File: DeterministicKeyChainTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    BriefLogFormatter.init();
    // You should use a random seed instead. The secs constant comes from the unit test file, so we can compare
    // serialized data properly.
    long secs = 1389353062L;
    chain = new DeterministicKeyChain(ENTROPY, "", secs);
    chain.setLookaheadSize(10);
    assertEquals(secs, checkNotNull(chain.getSeed()).getCreationTimeSeconds());
}
 
Example 9
Source File: KeyCrypterScryptTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder()
            .setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
    scryptParameters = scryptParametersBuilder.build();

    BriefLogFormatter.init();
}
 
Example 10
Source File: ECKeyTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
    ScryptParameters scryptParameters = scryptParametersBuilder.build();
    keyCrypter = new KeyCrypterScrypt(scryptParameters);

    BriefLogFormatter.init();
}
 
Example 11
Source File: ExamplePaymentChannelClient.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    OptionParser parser = new OptionParser();
    OptionSpec<NetworkEnum> net = parser.accepts("net", "The network to run the examples on").withRequiredArg().ofType(NetworkEnum.class).defaultsTo(NetworkEnum.TEST);
    OptionSpec<Integer> version = parser.accepts("version", "The payment channel protocol to use").withRequiredArg().ofType(Integer.class);
    parser.accepts("help", "Displays program options");
    OptionSet opts = parser.parse(args);
    if (opts.has("help") || !opts.has(net) || opts.nonOptionArguments().size() != 1) {
        System.err.println("usage: ExamplePaymentChannelClient --net=MAIN/TEST/REGTEST --version=1/2 host");
        parser.printHelpOn(System.err);
        return;
    }
    IPaymentChannelClient.ClientChannelProperties clientChannelProperties = new PaymentChannelClient.DefaultClientChannelProperties(){
        @Override
        public PaymentChannelClient.VersionSelector versionSelector() { return PaymentChannelClient.VersionSelector.VERSION_1; }
    };

    if (opts.has("version")) {
        switch (version.value(opts)) {
            case 1:
                // Keep the default
                break;
            case 2:
                clientChannelProperties = new PaymentChannelClient.DefaultClientChannelProperties(){
                    @Override
                    public PaymentChannelClient.VersionSelector versionSelector() { return PaymentChannelClient.VersionSelector.VERSION_2; }
                };
                break;
            default:
                System.err.println("Invalid version - valid versions are 1, 2");
                return;
        }
    }
    NetworkParameters params = net.value(opts).get();
    new ExamplePaymentChannelClient().run(opts.nonOptionArguments().get(0), clientChannelProperties, params);
}
 
Example 12
Source File: ExamplePaymentChannelServer.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    OptionParser parser = new OptionParser();
    OptionSpec<NetworkEnum> net = parser.accepts("net", "The network to run the examples on").withRequiredArg().ofType(NetworkEnum.class).defaultsTo(NetworkEnum.TEST);
    parser.accepts("help", "Displays program options");
    OptionSet opts = parser.parse(args);
    if (opts.has("help") || !opts.has(net)) {
        System.err.println("usage: ExamplePaymentChannelServer --net=MAIN/TEST/REGTEST");
        parser.printHelpOn(System.err);
        return;
    }
    NetworkParameters params = net.value(opts).get();
    new ExamplePaymentChannelServer().run(params);
}
 
Example 13
Source File: ExamplePaymentChannelServer.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    OptionParser parser = new OptionParser();
    OptionSpec<NetworkEnum> net = parser.accepts("net", "The network to run the examples on").withRequiredArg().ofType(NetworkEnum.class).defaultsTo(NetworkEnum.TEST);
    parser.accepts("help", "Displays program options");
    OptionSet opts = parser.parse(args);
    if (opts.has("help") || !opts.has(net)) {
        System.err.println("usage: ExamplePaymentChannelServer --net=MAIN/TEST/REGTEST");
        parser.printHelpOn(System.err);
        return;
    }
    NetworkParameters params = net.value(opts).get();
    new ExamplePaymentChannelServer().run(params);
}
 
Example 14
Source File: FetchTransactions.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    System.out.println("Connecting to node");
    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.start();
    peerGroup.addAddress(new PeerAddress(params, InetAddress.getLocalHost()));
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash txHash = Sha256Hash.wrap(args[0]);
    ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash);
    System.out.println("Waiting for node to send us the requested transaction: " + txHash);
    Transaction tx = future.get();
    System.out.println(tx);

    System.out.println("Waiting for node to send us the dependencies ...");
    List<Transaction> deps = peer.downloadDependencies(tx).get();
    for (Transaction dep : deps) {
        System.out.println("Got dependency " + dep.getHashAsString());
    }

    System.out.println("Done.");
    peerGroup.stop();
}
 
Example 15
Source File: TestWithWallet.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
    wallet = new Wallet(UNITTEST);
    myKey = wallet.currentReceiveKey();
    myAddress = LegacyAddress.fromKey(UNITTEST, myKey);
    blockStore = new MemoryBlockStore(UNITTEST);
    chain = new BlockChain(UNITTEST, wallet, blockStore);
}
 
Example 16
Source File: KeyChainGroupTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    BriefLogFormatter.init();
    Utils.setMockClock();
    group = new KeyChainGroup(MAINNET);
    group.setLookaheadSize(LOOKAHEAD_SIZE);   // Don't want slow tests.
    group.getActiveKeyChain();  // Force create a chain.

    watchingAccountKey = DeterministicKey.deserializeB58(null, XPUB, MAINNET);
}
 
Example 17
Source File: DeterministicKeyChainTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    BriefLogFormatter.init();
    // You should use a random seed instead. The secs constant comes from the unit test file, so we can compare
    // serialized data properly.
    long secs = 1389353062L;
    chain = new DeterministicKeyChain(ENTROPY, "", secs);
    chain.setLookaheadSize(10);
    assertEquals(secs, checkNotNull(chain.getSeed()).getCreationTimeSeconds());

    bip44chain = new DeterministicKeyChain(new DeterministicSeed(ENTROPY, "", secs),
            ImmutableList.of(new ChildNumber(44, true), new ChildNumber(1, true), ChildNumber.ZERO_HARDENED));
    bip44chain.setLookaheadSize(10);
    assertEquals(secs, checkNotNull(bip44chain.getSeed()).getCreationTimeSeconds());
}
 
Example 18
Source File: AbstractFullPrunedBlockChainTest.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
}
 
Example 19
Source File: Main.java    From thundernetwork with GNU Affero General Public License v3.0 4 votes vote down vote up
private void realStart (Stage mainWindow) throws IOException {
    this.mainWindow = mainWindow;
    instance = this;
    // Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
    GuiUtils.handleCrashesOnThisThread();

    // Load the GUI. The MainController class will be automagically created and wired up.
    File file = new File("main.fxml");
    URL location = getClass().getResource("main.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    mainUI = loader.load();
    controller = loader.getController();
    // Configure the window with a StackPane so we can overlay things on top of the main UI, and a
    // NotificationBarPane so we can slide messages and progress bars in from the bottom. Note that
    // ordering of the construction and connection matters here, otherwise we get (harmless) CSS error
    // spew to the logs.
    notificationBar = new NotificationBarPane(mainUI);
    mainWindow.setTitle(APP_NAME);
    uiStack = new StackPane();
    Scene scene = new Scene(uiStack);
    TextFieldValidator.configureScene(scene);   // Add CSS that we need.
    scene.getStylesheets().add(getClass().getResource("wallet.css").toString());
    uiStack.getChildren().add(notificationBar);
    mainWindow.setScene(scene);

    // Make log output concise.
    BriefLogFormatter.init();
    // Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
    // we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
    // we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
    // a future version.
    Threading.USER_THREAD = Platform::runLater;
    // Create the app kit. It won't do any heavyweight initialization until after we start it.
    setupWalletKit(null);

    if (bitcoin.isChainFileLocked()) {
        if (REQUEST != null) {
            PaymentProtocolClientSocket.sendPaymentRequest(REQUEST);
            Platform.exit();
            return;
        }
        informationalAlert("Already running", "This application is already running and cannot be started twice.");
        Platform.exit();
        return;
    }
    PaymentProtocolServerSocket.init();

    mainWindow.show();

    WalletSetPasswordController.estimateKeyDerivationTimeMsec();

    bitcoin.addListener(new Service.Listener() {
        @Override
        public void failed (Service.State from, Throwable failure) {
            GuiUtils.crashAlert(failure);
        }
    }, Platform::runLater);
    bitcoin.startAsync();

    System.out.println("init");
    node.init();
    wallet = new MockWallet(Constants.getNetwork());
    thunderContext = new ThunderContext(wallet, dbHandler, node);
    thunderContext.startUp(new NullResultCommand());

    scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+F"), () -> bitcoin.peerGroup().getDownloadPeer().close());
}
 
Example 20
Source File: AbstractFullPrunedBlockChainTest.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
}