All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.osslabz.bitcoin.Network Maven / Gradle / Ivy

Go to download

This package decouples my bitcoin related libraries from the underlying implementation although it seems unlikely this will ever change ;-)

The newest version!
package net.osslabz.bitcoin;

import java.util.Arrays;
import java.util.Objects;
import org.bitcoinj.core.NetworkParameters;

public enum Network {


    MAIN_NET(NetworkParams.NETWORK_PARAMETERS_MAIN_NET),


    REG_NET(NetworkParams.NETWORK_PARAMETERS_REG_NET),


    TEST_NET(NetworkParams.TESTNET_PARAMETERS_TEST_NET);


    private final NetworkParameters networkParameters;


    Network(NetworkParameters networkParameters) {
        this.networkParameters = networkParameters;
    }


    public NetworkParameters getNetworkParameters() {
        return networkParameters;
    }


    public static Network fromNetworkParameters(NetworkParameters networkParameters) {
        Objects.requireNonNull(networkParameters, "networkParameters must not be null");
        return Arrays.stream(Network.values()).filter(n -> n.networkParameters.getId().equals(networkParameters.getId())).findAny().orElseThrow();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy