-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aa71a99
Showing
69 changed files
with
4,915 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"> | ||
<attributes> | ||
<attribute name="owner.project.facets" value="jst.web"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>bitcoin-component</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.wst.common.project.facet.core.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.wst.validation.validationbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> | ||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> | ||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src/main/webapp"/> | ||
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/> | ||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject"> | ||
<attributes> | ||
<attribute name="hide" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/> | ||
<classpathentry kind="output" path=""/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/main/resources=UTF-8 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> | ||
<wb-module deploy-name="bitcoin"> | ||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> | ||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> | ||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> | ||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> | ||
<dependent-module archiveName="bitcoinj-core-0.14.5.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/bitcoinj-core/bitcoinj-core"> | ||
<dependency-type>uses</dependency-type> | ||
</dependent-module> | ||
<property name="java-output-path" value="/bitcoin-component/target/classes"/> | ||
<property name="context-root" value="bitcoin"/> | ||
</wb-module> | ||
</project-modules> |
7 changes: 7 additions & 0 deletions
7
.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<root> | ||
<facet id="jst.jaxrs"> | ||
<node name="libprov"> | ||
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/> | ||
</node> | ||
</facet> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<faceted-project> | ||
<runtime name="Apache Tomcat v7.0"/> | ||
<fixed facet="wst.jsdt.web"/> | ||
<installed facet="java" version="1.7"/> | ||
<installed facet="jst.web" version="2.5"/> | ||
<installed facet="jst.jaxrs" version="2.0"/> | ||
<installed facet="wst.jsdt.web" version="1.0"/> | ||
</faceted-project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
disabled=06target | ||
eclipse.preferences.version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>jersey</groupId> | ||
<artifactId>bitcoin-component</artifactId> | ||
<packaging>war</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>bitcoin</name> | ||
|
||
<build> | ||
<finalName>bitcoin</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.5.1</version> | ||
<inherited>true</inherited> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey</groupId> | ||
<artifactId>jersey-bom</artifactId> | ||
<version>${jersey.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-servlet-core</artifactId> | ||
<!-- use the following artifactId if you don't need servlet 2.x compatibility --> | ||
<!-- artifactId>jersey-container-servlet</artifactId --> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.inject</groupId> | ||
<artifactId>jersey-hk2</artifactId> | ||
</dependency> | ||
<!-- uncomment this to get JSON support | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-json-binding</artifactId> | ||
</dependency> | ||
--> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-json-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.bitcoinj</groupId> | ||
<artifactId>bitcoinj-core</artifactId> | ||
<version>0.14.5</version> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<jersey.version>2.26</jersey.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/msgilligan/bitcoinj/json/conversion/AddressDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.msgilligan.bitcoinj.json.conversion; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.exc.InvalidFormatException; | ||
import org.bitcoinj.core.Address; | ||
import org.bitcoinj.core.AddressFormatException; | ||
import org.bitcoinj.core.NetworkParameters; | ||
import org.bitcoinj.core.Sha256Hash; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AddressDeserializer extends JsonDeserializer<Address> { | ||
private NetworkParameters netParams; | ||
|
||
public AddressDeserializer(NetworkParameters netParams) { | ||
this.netParams = netParams; | ||
} | ||
|
||
@Override | ||
public Address deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
JsonToken token = p.getCurrentToken(); | ||
switch (token) { | ||
case VALUE_STRING: | ||
try { | ||
return Address.fromBase58(netParams, p.getValueAsString()); | ||
} catch (AddressFormatException e) { | ||
throw new InvalidFormatException(p, "Invalid Address", p.getValueAsString(), Address.class); | ||
} | ||
default: | ||
return (Address) ctxt.handleUnexpectedToken(Address.class, p); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/msgilligan/bitcoinj/json/conversion/AddressKeyDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.msgilligan.bitcoinj.json.conversion; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.KeyDeserializer; | ||
import org.bitcoinj.core.Address; | ||
import org.bitcoinj.core.NetworkParameters; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Key Deserializer to support using Address as the key in a Map. | ||
*/ | ||
public class AddressKeyDeserializer extends KeyDeserializer { | ||
private final NetworkParameters netParams; | ||
|
||
public AddressKeyDeserializer(NetworkParameters netParams) { | ||
this.netParams = netParams; | ||
} | ||
|
||
@Override | ||
public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
return Address.fromBase58(netParams, key); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/msgilligan/bitcoinj/json/conversion/AddressSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.msgilligan.bitcoinj.json.conversion; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.bitcoinj.core.Address; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AddressSerializer extends JsonSerializer<Address> { | ||
@Override | ||
public void serialize(Address value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { | ||
gen.writeString(value.toString()); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/msgilligan/bitcoinj/json/conversion/BitcoinMath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.msgilligan.bitcoinj.json.conversion; | ||
|
||
import org.bitcoinj.core.Coin; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.MathContext; | ||
import java.math.RoundingMode; | ||
|
||
/** | ||
* Utilities for Bitcoin Math | ||
*/ | ||
public class BitcoinMath { | ||
public static final MathContext DEFAULT_CONTEXT = new MathContext(0, RoundingMode.UNNECESSARY); | ||
public static final int DEFAULT_SCALE = Coin.SMALLEST_UNIT_EXPONENT; | ||
public static final BigDecimal satoshiPerCoinDecimal = new BigDecimal(Coin.COIN.value, DEFAULT_CONTEXT); | ||
|
||
/** | ||
* Convert from BTC `BigDecimal` value to satoshi `long`. | ||
* | ||
* @param btc Bitcoin amount in BTC units | ||
* @return number of satoshi (long) | ||
*/ | ||
public static long btcToSatoshi(final BigDecimal btc) { | ||
BigDecimal satoshisDecimal = btc.multiply(satoshiPerCoinDecimal); | ||
return satoshisDecimal.longValueExact(); | ||
} | ||
|
||
/** | ||
* Convert from satoshi `long` to BTC `BigDecimal`. | ||
* | ||
* @param satoshi number of satoshi (long) | ||
* @return Bitcoin amount in BTC units | ||
*/ | ||
public static BigDecimal satoshiToBtc(final long satoshi) { | ||
BigDecimal bdSatoshi = new BigDecimal(satoshi, BitcoinMath.DEFAULT_CONTEXT); | ||
return bdSatoshi.divide(satoshiPerCoinDecimal, DEFAULT_SCALE, RoundingMode.UNNECESSARY); | ||
} | ||
|
||
/** | ||
* Convert from BTC `BigDecimal` value to `Coin` type. | ||
* | ||
* @param btc Bitcoin amount in BTC units | ||
* @return bitcoinj `Coin` type (uses satoshi unit internally) | ||
*/ | ||
public static Coin btcToCoin(final BigDecimal btc) { | ||
return Coin.valueOf(btcToSatoshi(btc)); | ||
} | ||
|
||
/** | ||
* Convert from `Coin` type to BTC `BigDecimal` value . | ||
* | ||
* @param coin Coin value to convert to BTC | ||
* @return Bitcoin amount in BTC units | ||
*/ | ||
public static BigDecimal coinToBTC(final Coin coin) { | ||
return satoshiToBtc(coin.value); | ||
} | ||
} |
Oops, something went wrong.