Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>com.github.mmazi</groupId>
<artifactId>rescu</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
Expand All @@ -64,6 +64,13 @@

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!--
This can be used to generate Java beans from json schema files (assumes these are located in
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/com/github/mmazi/ripplerest/AccountSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ public class AccountSettings implements Serializable, HasAdditionalProperties {
@JsonProperty("require_destination_tag")
private Boolean requireDestinationTag = null;

private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("global_freeze")
private Boolean globalFreeze = null;

@JsonProperty("no_freeze")
private Boolean noFreeze = null;

@JsonProperty("default_ripple")
private Boolean defaultRipple;

private Map<String, Object> additionalProperties = new HashMap<>();

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// other fields
Expand Down Expand Up @@ -207,6 +216,29 @@ public String toString() {
disableMaster, disallowXrp, passwordSpent, requireAuthorization, requireDestinationTag, additionalProperties, transactionSequence, emailHash, walletLocator, messageKey, domain, transferRate, signers);
}

public Boolean getGlobalFreeze() {
return globalFreeze;
}

public void setGlobalFreeze(Boolean globalFreeze) {
this.globalFreeze = globalFreeze;
}

public Boolean getNoFreeze() {
return noFreeze;
}

public void setNoFreeze(Boolean noFreeze) {
this.noFreeze = noFreeze;
}

public Boolean getDefaultRipple() {
return defaultRipple;
}

public void setDefaultRipple(Boolean defaultRipple) {
this.defaultRipple = defaultRipple;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class AddTrustlineResponse extends RippleResponse<Trustline> {

private Long ledger;

private String state;

private Trustline trustline;

public Trustline getTrustline() {
Expand All @@ -24,4 +26,12 @@ public Long getLedger() {
public Trustline getValue() {
return getTrustline();
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/github/mmazi/ripplerest/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ public class Payment implements Serializable, HasAdditionalProperties {
@Valid
private List<Amount> destinationBalanceChanges = new ArrayList<Amount>();

@JsonProperty("order_changes")
private List<Amount> orderChanges;

@JsonProperty("balance_changes")
private List<Amount> balanceChanges;

private Map<String, Object> additionalProperties = new HashMap<String, Object>();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -272,6 +278,22 @@ public List<Amount> getDestinationBalanceChanges() {
return destinationBalanceChanges;
}

public List<Amount> getBalanceChanges() {
return balanceChanges;
}

public void setBalanceChanges(List<Amount> balanceChanges) {
this.balanceChanges = balanceChanges;
}

public List<Amount> getOrderChanges() {
return orderChanges;
}

public void setOrderChanges(List<Amount> orderChanges) {
this.orderChanges = orderChanges;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
Expand Down
143 changes: 143 additions & 0 deletions src/main/java/com/github/mmazi/ripplerest/PaymentClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.github.mmazi.ripplerest;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

public class PaymentClient {
private static final String USER_ADDRESS = "rNsa4RDNCwEPUcST8zMTQhqBrfABdWkzQF";
private static final String USER_ADDRESS_SECRET = "snJTPWZCkoW753VuFZT6SqhWhch9w";
public static final String IPE_ADDRESS = "rUurnm8KNwggqTWHoS4nkhBuXqQR2PggXW";

public static void main(String[] args) throws IOException {
System.out.println(System.getProperty("java.version"));
sendPayment(105);
// processIncome();
// receivePayments();
}

private static void processIncome() throws IOException {
// String ibLastTransferIn = "1471934111000";
String ibLastTransferIn = "1471952171000";
String lastTransactionId = ibLastTransferIn;
Ripple ripple = RippleClientFactory.createClient("https://api.altnet.rippletest.net:5990");
PaymentsResponse paymentResponse = ripple.getPayments(
IPE_ADDRESS,
null,
null,
true,
0,
null,
false,
10000,
1
);
Collections.reverse(paymentResponse.getPayments());
for (PaymentWithId item: paymentResponse.getPayments()) {
System.out.println(item.getHash() + " " + item.getPayment().getTimestamp() + " " + item.getPayment().getTimestamp().getTime());
}

System.out.println("0----------------------" + ibLastTransferIn);
ibLastTransferIn = processing(ibLastTransferIn, paymentResponse);

System.out.println("1---------------------- " + ibLastTransferIn);
ibLastTransferIn = processing(ibLastTransferIn, paymentResponse);

System.out.println("2---------------------- " + ibLastTransferIn);
ibLastTransferIn = processing(ibLastTransferIn, paymentResponse);
}

private static String processing(String ibLastTransferIn, PaymentsResponse paymentResponse) {
String lastTransactionId = ibLastTransferIn;
for (PaymentWithId item: paymentResponse.getPayments()) {
if(paymentExists(ibLastTransferIn, item)) {
System.out.println("skipped: " + item.getHash());
continue;
}
lastTransactionId = getTimestampAsString(item);
System.out.println("processing: " + item.getHash());
}
return lastTransactionId;
}

private static String getTimestampAsString(PaymentWithId item) {
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(item.getPayment().getTimestamp());
return String.valueOf(cal.getTimeInMillis());
}

private static boolean paymentExists(String ibLastTransferIn, PaymentWithId item) {
if(ibLastTransferIn == null) {
return false;
}
Long current = prepareUTCLong(item.getPayment().getTimestamp());
boolean b = !(current.compareTo(new Long(ibLastTransferIn)) > 0);
return b;
}

public static long prepareUTCLong(Date completed) {
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.setTime(completed);
return calendar.getTimeInMillis();
}



private static void receivePayments() throws IOException {
Ripple ripple = RippleClientFactory.createClient("https://api.altnet.rippletest.net:5990");
final PaymentsResponse paymentsResponse = ripple.getPayments(IPE_ADDRESS, null, null, true, null, null, true, 10, 1);
final List<PaymentWithId> payments = paymentsResponse.getPayments();
System.out.println("Got " + payments.size() + " payments.");

System.out.println("----------------------------");
for (PaymentWithId payment : payments) {
System.out.println("hash: " + payment.getHash());
System.out.println("result: " + payment.getPayment().getResult());
System.out.println("value: " + payment.getPayment().getDirection());
System.out.println("timestamp: " + payment.getPayment().getTimestamp());
}
}

private static void sendPayment(int amount1) throws IOException {
Ripple ripple = RippleClientFactory.createClient("https://api.altnet.rippletest.net:5990");
final String uuid = createUUID();
final BigDecimal value = BigDecimal.valueOf(amount1);
final Amount amount = new Amount(value, "XRP");
final CreatePaymentResponse createPaymentResponse = ripple.createPayment(
USER_ADDRESS,
new PaymentRequest(USER_ADDRESS_SECRET, uuid,
new Payment(
USER_ADDRESS,
IPE_ADDRESS,
amount,
null,
BigDecimal.valueOf(0.02),
2L,
3L,
null,
false,
false,
null
)));
System.out.println("Payment status url: " + createPaymentResponse.getStatusUrl());
PaymentResponse paymentResponse = ripple.getPayment(USER_ADDRESS, uuid);
Payment payment = paymentResponse.getPayment();
final String pmtHash = paymentResponse.getHash();
paymentResponse = ripple.getPayment(USER_ADDRESS, pmtHash);
payment = paymentResponse.getPayment();

System.out.println("amount: " + payment.getSourceAmount());
System.out.println("sourceAccount: " + payment.getSourceAccount());
System.out.println("sourceAmount: " + payment.getSourceAccount());
System.out.println("destinationAccount: " + payment.getDestinationAccount());
System.out.println("paymentFee: " + payment.getFee().doubleValue());
System.out.println("paymentHash: " + payment.getHash());
System.out.println("responseHash: " + createPaymentResponse.getValue());

}

private static String createUUID() {
return UUID.randomUUID().toString();
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/github/mmazi/ripplerest/PaymentRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public PaymentRequest(String secret, String clientResourceId, Payment payment) {
super(secret, clientResourceId);
this.payment = payment;
}

@Override
public String toString() {
return "PaymentRequest{" +
"payment=" + payment +
'}';
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/github/mmazi/ripplerest/PaymentResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,35 @@

public class PaymentResponse extends RippleResponse<Payment> {

private String hash;
private String ledger;
private String state;
private Payment payment;

public String getHash() {
return hash;
}

public void setHash(String hash) {
this.hash = hash;
}

public String getLedger() {
return ledger;
}

public void setLedger(String ledger) {
this.ledger = ledger;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public Payment getPayment() {
return payment;
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/github/mmazi/ripplerest/PaymentWithId.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class PaymentWithId implements Serializable {
@JsonProperty("client_resource_id")
private String clientResourceId;

@JsonProperty("hash")
private String hash;

private Payment payment;

public String getClientResourceId() {
Expand All @@ -18,4 +21,17 @@ public String getClientResourceId() {
public Payment getPayment() {
return payment;
}

public String getHash() {
return hash;
}

@Override
public String toString() {
return "PaymentWithId{" +
"clientResourceId='" + clientResourceId + '\'' +
", hash='" + hash + '\'' +
", payment=" + payment +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ public List<PaymentWithId> getPayments() {
public List<PaymentWithId> getValue() {
return getPayments();
}

@Override
public String toString() {
return "PaymentsResponse{" +
"payments=" + payments +
'}';
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/github/mmazi/ripplerest/Ripple.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Path("v1")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
interface Ripple {
public interface Ripple {

@GET
@Path("accounts/{address}/balances")
Expand All @@ -23,8 +23,8 @@ interface Ripple {
SettingsResponse setSettings(@PathParam("address") String address, SetSettingsRequest settings) throws RippleException, IOException;

@POST
@Path("payments")
CreatePaymentResponse createPayment(PaymentRequest paymentRequest) throws RippleException, IOException;
@Path("accounts/{address}/payments")
CreatePaymentResponse createPayment(@PathParam("address") String address, PaymentRequest paymentRequest) throws RippleException, IOException;

@GET
@Path("accounts/{address}/payments/paths/{destinationAccount}/{destinationAmount}?{sourceCurrencies}")
Expand Down
Loading