dogecoin / libdohj

Java library for adding altcoin support to bitcoinj
Apache License 2.0
107 stars 89 forks source link

Upgrade to compatibility with bitcoinj 0.15 #35

Closed msgilligan closed 3 years ago

msgilligan commented 5 years ago

bitcoinj 0.15 made changes to classes like NetworkParameters that seem incompatible with libdohj. For example I'm getting the following error message when trying to use Namecoin parameters (over in ConsensusJ):

Failed to instantiate [org.bitcoinj.core.NetworkParameters]: Factory method 'networkParameters' threw exception; nested exception is java.lang.NoSuchFieldError: bip32HeaderPub
msgilligan commented 5 years ago

Attn: @JeremyRand

jjos2372 commented 4 years ago

I just made this fork compatible with bitcoinj 0.15 https://github.com/jjos2372/altcoinj

Tockra commented 3 years ago

@jjos2372 is your fork still up to date?

When I want to use a wallet for the dogecoin blockchain, what parts of bitcoinj I need to use and want are the parts of libdohj? Is it enought to use

NetworkParameters params = DogecoinMainNetParams.get();

and use this params for the wallet and the webkitapi of bitcoinj ?

jjos2372 commented 3 years ago

@jjos2372 is your fork still up to date?

When I want to use a wallet for the dogecoin blockchain, what parts of bitcoinj I need to use and want are the parts of libdohj? Is it enought to use

NetworkParameters params = DogecoinMainNetParams.get();

and use this params for the wallet and the webkitapi of bitcoinj ?

@Tockra I've been using https://github.com/jjos2372/altcoinj since I published it with no problem, as you said:

NetworkParameters params = DogecoinMainNetParams.get();

Is enough as long as you have the dependencies:

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.jjos2372:altcoinj:f26e20bb13'
    compile 'org.bitcoinj:bitcoinj-core:0.15.6'
}

In addition I also have support for LTC on it.

Tockra commented 3 years ago

Okay, I hope I did it right. So I can fully ignore everything else from altcoinj instead of DogecoinMainNetParams.get();. That sounds easy.

Maybe you can help me further. I read in a bitcoinj tutorial, that I need to save the wallet multiple times in a file. I don't understand why.

I just want to have a wallet, where I can get the balance and I want to create fresh addresses to which multiple transactions can be sent. Sometimes I want to send balance from that wallet to a other. When and why I need to write a new version of the wallet to a file?

And what happens if I make wallet transactions (getBalance, sendCoin, ...) before the blockchain is fully synced?

jjos2372 commented 3 years ago

You would be actually using all bitcoinj infrastructure, so check their docs. I particularly create a kit:

kit = new WalletAppKit(params, ...)

And them sync the chain before using it:

        kit.startAsync();
        kit.awaitRunning();

You probably should start with DogecoinTestNet3Params.get() first.

Tockra commented 3 years ago

Okay thank you. I will look ^^. I hope my questions will be answered here : https://github.com/bitcoinj/bitcoinj/issues/2020

Tockra commented 3 years ago

Following code causes into this exception:

[00:25:51 WARN]: [org.bitcoinj.net.ConnectionHandler] Error handling SelectionKey: java.nio.channels.CancelledKeyException
app    | java.nio.channels.CancelledKeyException: null
app    |    at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:74) ~[?:?]
app    |    at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:133) ~[?:?]
app    |    at java.nio.channels.SelectionKey.isWritable(SelectionKey.java:378) ~[?:?]
app    |    at org.bitcoinj.net.ConnectionHandler.handleKey(ConnectionHandler.java:244) ~[?:?]
app    |    at org.bitcoinj.net.NioClientManager.handleKey(NioClientManager.java:86) ~[?:?]
app    |    at org.bitcoinj.net.NioClientManager.run(NioClientManager.java:122) ~[?:?]
app    |    at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:66) ~[patched_1.16.1.jar:git-Paper-"0b33230f2"]
app    |    at com.google.common.util.concurrent.Callables$4.run(Callables.java:122) ~[patched_1.16.1.jar:git-Paper-"0b33230f2"]
app    |    at org.bitcoinj.utils.ContextPropagatingThreadFactory$1.run(ContextPropagatingThreadFactory.java:51) ~[?:?]
app    |    at java.lang.Thread.run(Thread.java:832) [?:?]
NetworkParameters params = DogecoinMainNetParams.get();
        this.walletKit = new WalletAppKit(params,new File(config.getWalletPath()),"wallet.dat");
        this.walletKit.setBlockingStartup(true);
        this.walletKit.startAsync();
        this.walletKit.awaitRunning();
jjos2372 commented 3 years ago

I use something like this for an existing wallet folder (previously created with bitcoinj randomly, using a seed, etc.):

        kit = new WalletAppKit(params, folderFile, filePrefix) {
            @Override
            protected void onSetupCompleted() {
                log.info("kit setup complete");
            }
        };
        // Download the block chain and wait until it's done.
        kit.startAsync();
        kit.awaitRunning();

Recall that filePrefix is the wallet file name without the .wallet, not sure where are you getting this .dat file.

Tockra commented 3 years ago

I copied it somewhere. But I still get the java.nio.channels.CancelledKeyException at application start. That isn't cool. Because they spam my console...

Tockra commented 3 years ago

So I did a unsafe workaround. I just filter all Exceptions out of my log, which happens without valid reason: log4j2.xml:

...
    <Loggers>
        <Root level="info">
            <filters>
                <MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
                <RegexFilter regex=".*java.nio.channels.CancelledKeyException.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*Error\swriting\smessage\sto\sconnection,\sclosing\sconnection.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*java.net.SocketException.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*java.net.ConnectException.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*SelectionKey.*java.lang.IllegalStateException.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*Received\sRejectMessage\sbefore\sversion\shandshake\sis\scomplete.*" onMatch="DENY" onMismatch="NEUTRAL"/>
                <RegexFilter regex=".*java.net.NoRouteToHostException.*Host\sis\sunreachable.*" onMatch="DENY" onMismatch="NEUTRAL"/>
            </filters>
        </Root>
    </Loggers>
rnicoll commented 3 years ago

I've finally had some free time, reviews of https://github.com/dogecoin/libdohj/pull/44 would be appreciated

rnicoll commented 3 years ago

Oops this was merged a while ago, closing now.