Bitcoin Forum

Bitcoin => Project Development => Topic started by: vuce on April 10, 2012, 08:43:21 AM



Title: BitcoinJ Maven
Post by: vuce on April 10, 2012, 08:43:21 AM
Does anyone know how to set this up so it'll work? Followed the instructions in the wiki but it won't collect dependencies...

Code:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany</groupId>
  <artifactId>connectcoinm</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>connectcoinm</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

 <repositories>
   <repository>
     <id>bitcoinj-release</id>
     <releases/>
     <url>http://nexus.bitcoinj.org/content/repositories/releases</url>
   </repository>
   <repository>
     <id>bitcoinj-snapshot</id>
     <snapshots/>
     <url>http://nexus.bitcoinj.org/content/repositories/snapshots</url>
   </repository>
 </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  <!-- Depend on BitCoinJ -->
  <dependency>
    <groupId>com.google</groupId>
    <artifactId>bitcoinj</artifactId>
    <version>0.3</version>
    <scope>compile</scope>
  </dependency>
  </dependencies>
</project>

This is what I get:
Code:
Failed to execute goal on project connectcoinm: Could not resolve dependencies for project com.mycompany:connectcoinm:jar:1.0-SNAPSHOT: Failed to collect dependencies for [junit:junit:jar:3.8.1 (test), com.google:bitcoinj:jar:0.3 (compile)]: Failed to read artifact descriptor for com.google:bitcoinj:jar:0.3: Could not transfer artifact com.google:bitcoinj:pom:0.3 from/to bitcoinj-release (http://nexus.bitcoinj.org/content/repositories/releases): Failed to transfer file: http://nexus.bitcoinj.org/content/repositories/releases/com/google/bitcoinj/0.3/bitcoinj-0.3.pom. Return code is: 502, ReasonPhrase:Bad Gateway. -> [Help 1]


Title: Re: BitcoinJ Maven
Post by: vuce on April 10, 2012, 08:53:11 AM
Tried putting the libraries together manually:

Code:
Exception in thread "main" java.lang.ExceptionInInitializerError
at myproject.Myproject.main(Myproject.java:33)
Caused by: java.lang.NullPointerException
at com.google.bitcoin.core.ECKey.<clinit>(ECKey.java:53)
... 1 more
Java Result: 1

Myproject.java:33
Code:
ECKey key = new ECKey();

Any help would be much appreciated.


Title: Re: BitcoinJ Maven
Post by: apetersson on April 10, 2012, 09:29:51 AM
your error message means that
Code:
SECNamedCurves.getByName("secp256k1")
returned null.

Propably you have the wrong BouncyCastle lib installed. the version used in BitcoinJ is 1.46 (see pom.xml)


Title: Re: BitcoinJ Maven
Post by: jim618 on April 10, 2012, 09:51:16 AM
MultiBit uses bitcoinj via Maven so you should be able to use the POM for the dependencies:

https://github.com/jim618/multibit/tree/v0.3 (https://github.com/jim618/multibit/tree/v0.3)

Note also that bitcoinj runs it's own repo so you need to have a couple of entries in for that.

There is quite a lot of 'packaging cruft' in that POM so let me know if you have any problems.

I have multibit pointing at the last stable release (0.4) but you might want to sit on the bleeding edge and go to 0.5-SNAPSHOT.


Title: Re: BitcoinJ Maven
Post by: vuce on April 10, 2012, 09:53:41 AM
your error message means that
Code:
SECNamedCurves.getByName("secp256k1")
returned null.

Propably you have the wrong BouncyCastle lib installed. the version used in BitcoinJ is 1.46 (see pom.xml)

you Sir are correct. Thanks a bunch!

MultiBit uses bitcoinj via Maven so you should be able to use the POM for the dependencies:

https://github.com/jim618/multibit/tree/v0.3 (https://github.com/jim618/multibit/tree/v0.3)

Note also that bitcoinj runs it's own repo so you need to have a couple of entries in for that.

There is quite a lot of 'packaging cruft' in that POM so let me know if you have any problems.

I have multibit pointing at the last stable release (0.4) but you might want to sit on the bleeding edge and go to 0.5-SNAPSHOT.

Will check it out, thank you so much!


Title: Re: BitcoinJ Maven
Post by: jim618 on April 10, 2012, 10:10:44 AM
Hi vuce,

I see from your previous posts that you are working on a prototype for commitcoin.

Feel free to reuse any of the multibit code for the bitcoinj side of things if it saves you time. It is all MIT licence.
You might be interested in the MultiBitService for a bit of network abstraction or the various actions (it should be fairly clear from the name what they do. The ones with the Submit in are the ones that actually perform the task).

Jim


Title: Re: BitcoinJ Maven
Post by: vuce on April 10, 2012, 06:35:49 PM
Hi vuce,

I see from your previous posts that you are working on a prototype for commitcoin.

Feel free to reuse any of the multibit code for the bitcoinj side of things if it saves you time. It is all MIT licence.
You might be interested in the MultiBitService for a bit of network abstraction or the various actions (it should be fairly clear from the name what they do. The ones with the Submit in are the ones that actually perform the task).

Jim

Went through the code, it will certainly come in handy. Cheers!


Title: Re: BitcoinJ Maven
Post by: vuce on April 12, 2012, 08:58:35 AM
Jim, just one more question, does the testnet work at all (I'm using bitcoinj 0.4, that's what's in the multibit pom also)? I get stuck with 7539 blocks to go... I'm guessing the change in the testnet difficulty rules might have something to do with that?


Title: Re: BitcoinJ Maven
Post by: jim618 on April 12, 2012, 09:30:11 AM
Hi vuce,

I do not know the status of testnet actually.  I do all my dev against the production network moving millis around.   You probably end up waiting longer for blocks to confirm but get your code exposed earlier to the vagaries of the network.

There is a pretty responsive google group for bitcoinj that might know.
https://groups.google.com/forum/?fromgroups#!forum/bitcoinj (https://groups.google.com/forum/?fromgroups#!forum/bitcoinj)

Jim



Title: Re: BitcoinJ Maven
Post by: apetersson on April 12, 2012, 10:01:59 AM
testnet rules from bitcoin-QT (satoshi client) have changed and those rules are only in 0.5-SNAPSHOT or in one of the upcoming 0.5 releases


Title: Re: BitcoinJ Maven
Post by: vuce on April 12, 2012, 02:35:33 PM
testnet rules from bitcoin-QT (satoshi client) have changed and those rules are only in 0.5-SNAPSHOT or in one of the upcoming 0.5 releases

Thanks for the help, tried that, but it still won't work (at least not consistently). Looks like it depends on the peer it connects to, sometimes it downloads 50k+ blocks and sometimes only 47k. Meh, I think I'll go with the way Jim uses.