Skip to content

Commit

Permalink
Wallet module implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedran committed Sep 19, 2014
1 parent 653e020 commit 65b180a
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 8 deletions.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- Package everything into a single .jar along with the dependencies -->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>

</project>
6 changes: 6 additions & 0 deletions src/main/java/info/blockchain/api/APIException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package info.blockchain.api;

/**
* The class `APIException` represents a failed call to the Blockchain API. Whenever
* the server is unable to process a request (usually due to parameter validation errors),
* an instance of this class is thrown.
*
*/
public class APIException extends Exception
{
private static final long serialVersionUID = -7731961787745059713L;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/info/blockchain/api/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import info.blockchain.api.receive.Receive;
import info.blockchain.api.receive.ReceiveResponse;
import info.blockchain.api.wallet.Address;
import info.blockchain.api.wallet.PaymentResponse;
import info.blockchain.api.wallet.Wallet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -15,6 +19,6 @@ public class App
{
public static void main( String[] args ) throws Exception
{

}
}
3 changes: 1 addition & 2 deletions src/main/java/info/blockchain/api/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*/
public class HttpClient
{
private static final String BASE_URL = "https://blockchain.info/api/";
//private static final String BASE_URL = "http://requestb.in/";
private static final String BASE_URL = "https://blockchain.info/";

/**
* Perform a GET request on a Blockchain.info API resource.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/info/blockchain/api/receive/Receive.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static ReceiveResponse receive(String receiving_address, String callback_
if (apiCode != null)
params.put("api_code", apiCode);

String response = HttpClient.post("receive", params);
String response = HttpClient.post("api/receive", params);
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(response).getAsJsonObject();

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/info/blockchain/api/receive/ReceiveResponse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package info.blockchain.api.receive;

/**
* This class is used as a response object to the Receive.receive call.
* This class is used as a response object to the `Receive.receive` method.
*
*/
public class ReceiveResponse
Expand All @@ -20,18 +20,33 @@ public ReceiveResponse(int feePercent, String destinationAddress,
this.callbackUrl = callbackUrl;
}

/**
* @return Forwarding fee
*/
public int getFeePercent()
{
return feePercent;
}

/**
* @return Destination address where the funds will be forwarded
*/
public String getDestinationAddress()
{
return destinationAddress;
}

/**
* @return Input address where the funds should be sent
*/
public String getInputAddress()
{
return inputAddress;
}

/**
* @return Callback URI that will be called upon payment
*/
public String getCallbackUrl()
{
return callbackUrl;
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/info/blockchain/api/wallet/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package info.blockchain.api.wallet;

/**
* Used in combination with the `Wallet` class
*
*/
public class Address
{
private long balance;
private String address;
private String label;
private long totalReceived;

public Address(long balance, String address, String label, long totalReceived)
{
this.balance = balance;
this.address = address;
this.label = label;
this.totalReceived = totalReceived;
}

/**
* @return Balance in satoshi
*/
public long getBalance()
{
return balance;
}

/**
* @return String representation of the address
*/
public String getAddress()
{
return address;
}

/**
* @return Label attached to the address
*/
public String getLabel()
{
return label;
}

/**
* @return Total received amount in satoshi
*/
public long getTotalReceived()
{
return totalReceived;
}
}
44 changes: 44 additions & 0 deletions src/main/java/info/blockchain/api/wallet/PaymentResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package info.blockchain.api.wallet;

/**
* Used in response to the `send` and `sendMany` methods in the `Wallet` class.
*
*/
public class PaymentResponse
{
private String message;
private String txHash;
private String notice;

public PaymentResponse(String message, String txHash, String notice)
{
this.message = message;
this.txHash = txHash;
this.notice = notice;
}

/**
* @return Response message from the server
*/
public String getMessage()
{
return message;
}

/**
* @return Transaction hash
*/
public String getTxHash()
{
return txHash;
}

/**
* @return Additional response message from the server
*/
public String getNotice()
{
return notice;
}

}
Loading

0 comments on commit 65b180a

Please sign in to comment.