dogecoin / libdohj

Java library for adding altcoin support to bitcoinj
Apache License 2.0
110 stars 87 forks source link

Send not working #34

Open kunalransing opened 6 years ago

kunalransing commented 6 years ago

Hi, I added libdohj-core-0.14-SNAPSHOT.jar & below dependencies

<dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.lambdaworks</groupId>
            <artifactId>scrypt</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.bitcoinj</groupId>
            <artifactId>**bitcoinj-core**</artifactId>
            <version>**0.14.2**</version>
        </dependency>
    </dependencies>

Now receive coins working but send not working i.e tx hash show tx not found on blockchain. Please check below log.

2018-08-01 13:23:58,172 ERROR [org.bitcoinj.core.Context] (EJB default - 3) Performing thread fixup: you are accessing bitcoinj via a thread that has not had any context set on it.
2018-08-01 13:23:58,172 ERROR [org.bitcoinj.core.Context] (EJB default - 3) This error has been corrected for, but doing this makes your app less robust.
2018-08-01 13:23:58,172 ERROR [org.bitcoinj.core.Context] (EJB default - 3) You should use Context.propagate() or a ContextPropagatingThreadFactory.
2018-08-01 13:23:58,172 ERROR [org.bitcoinj.core.Context] (EJB default - 3) Please refer to the user guide for more information about this.
2018-08-01 13:23:58,172 ERROR [org.bitcoinj.core.Context] (EJB default - 3) Thread name is EJB default - 3.
2018-08-01 13:23:58,173 INFO  [com.eno.doge.DOGEConfig] (EJB default - 3) DOGEConfig_sendCoin:Balance=1005.00 BTC
2018-08-01 13:23:58,386 INFO  [org.bitcoinj.crypto.KeyCrypterScrypt] (EJB default - 3) Deriving key took 206.7 ms for 16384 scrypt iterations.
2018-08-01 13:23:58,387 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3) Completing send tx with 1 outputs totalling 3.00 BTC and a fee of 2.00 BTC/kB
2018-08-01 13:23:58,398 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3)   with 996.55 BTC change
2018-08-01 13:23:58,421 INFO  [org.bitcoin.Secp256k1Context] (EJB default - 3) java.lang.UnsatisfiedLinkError: no secp256k1 in java.library.path
2018-08-01 13:23:58,436 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3)   completed:   a2838d507fcf1df990cf0017e00d73a4ebb2cd57b2f69df75bfd5660144b8717
     in   PUSHDATA(71)[3044022047c0b6134e0a93cdea2a490ace87773da901a1f89e5300b76d59da7ae3c2a6d7022003f568d96638d4d7a8a3f7cc3019e0663c8526e872e5ebd912e904d184804ea301] PUSHDATA(33)[02072314acce50e737791e490bff7ff44a66a325680d00f60898674a191e355f96] 1000.00 BTC
          outpoint:459bf5db26759e08f515b36caf284258776219c676f796f8a760aa3fc86fd140:0 hash160:d0108b2243988bb583e731ed0d03e25c85038f48
     out  DUP HASH160 PUSHDATA(20)[143754b58fcbf5504ad7f4833c2b62d5b2867c80] EQUALVERIFY CHECKSIG 996.55 BTC
     out  HASH160 PUSHDATA(20)[f1fcaab99bddd4171a1756850d95510c4bc05355] EQUAL 3.00 BTC
     fee  2.01793721 BTC/kB, 0.45 BTC for 223 bytes
     prps USER_PAYMENT

2018-08-01 13:23:58,437 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3) commitTx of a2838d507fcf1df990cf0017e00d73a4ebb2cd57b2f69df75bfd5660144b8717
2018-08-01 13:23:58,438 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3)   marked 459bf5db26759e08f515b36caf284258776219c676f796f8a760aa3fc86fd140:0 as spent by a2838d507fcf1df990cf0017e00d73a4ebb2cd57b2f69df75bfd5660144b8717
2018-08-01 13:23:58,438 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3)   459bf5db26759e08f515b36caf284258776219c676f796f8a760aa3fc86fd140 prevtx <-unspent ->spent
2018-08-01 13:23:58,439 INFO  [org.bitcoinj.wallet.Wallet] (EJB default - 3) ->pending: a2838d507fcf1df990cf0017e00d73a4ebb2cd57b2f69df75bfd5660144b8717

Can anyone help to find issue ?

rnicoll commented 6 years ago

I would start with fixing Performing thread fixup: you are accessing bitcoinj via a thread that has not had any context set on it. at the top. bitcoinj needs the Context set up so it knows what network parameters (i.e. Dogecoin rather than Bitcoin to use).

CATE for example handles this by creating a context at the start ( https://github.com/rnicoll/cate/blob/master/src/main/java/org/libdohj/cate/controller/MainController.java#L186 ) and using a custom thread factory to propagate the context onto every thread it creates: https://github.com/rnicoll/cate/blob/master/src/main/java/org/libdohj/cate/util/NetworkThreadFactory.java#L54

kunalransing commented 6 years ago

Hi, I have mentioned network param via wallet init code is as below, WalletAppKit kit = new WalletAppKit(DogecoinTestNet3Params.get(), new File("/home/ep"),"doge-testnet");

Below can be reason ??

2018-08-02 11:40:52,622 INFO [org.bitcoinj.core.TransactionBroadcast] (EJB default - 36) Waiting for 10 peers required for broadcast, we have 8 ...

For testnet only one dns seed mentioned i.e "testseed.jrn.me.uk". Do we have more ?

kunalransing commented 6 years ago

I guess issue solved. In code for testnet dns seeds contains only one entry. For broadcast 10 peers connection required & I had only 8 connected. Now I added few more dns seeds then peers connection crossed 10 & it broadcasts txs. Thanks.