Skip to content

Commit

Permalink
Split FundingInfo id into external (blockchain) and internal (exchang…
Browse files Browse the repository at this point in the history
…e) id.
  • Loading branch information
mmazi committed Apr 7, 2017
1 parent f75b0d3 commit dfb2ce0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,13 @@ public static List<FundingRecord> adaptFundingHistory(BitfinexDepositWithdrawalH
for (BitfinexDepositWithdrawalHistoryResponse responseEntry : bitfinexDepositWithdrawalHistoryResponses) {
String address = responseEntry.getAddress();
String description = responseEntry.getDescription();
String txnId = "";
String txnId = null;
final Currency currency = Currency.getInstance(responseEntry.getCurrency());
if (currency == Currency.BTC && responseEntry.getType() == FundingRecord.Type.WITHDRAWAL &&
description.contains(",")){
if (description.contains("txid: ")){
txnId = description.substring(description.indexOf("txid: ")+ "txid: ".length());
}
FundingRecord fundingRecordEntry = new FundingRecord(address, responseEntry.getTimestamp(),
currency, responseEntry.getAmount(), txnId, responseEntry.getType(),
currency, responseEntry.getAmount(), String.valueOf(responseEntry.getId()), txnId, responseEntry.getType(),
responseEntry.getStatus(), null, null, description);

fundingRecords.add(fundingRecordEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ public void testAdaptFundingHistory() throws IOException {
if (record.getType().name().equalsIgnoreCase(FundingRecord.Type.DEPOSIT.name())){
assertEquals(new BigDecimal("0.01"), record.getAmount());
assertEquals("jlsd98087sdfkjldsflj432kjlsdf8", record.getAddress());
assertEquals("", record.getId());
assertEquals("", record.getExternalId());
assertEquals(Currency.BTC, record.getCurrency());
} else {
assertEquals(new BigDecimal("0.07"), record.getAmount());
assertEquals("3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ", record.getAddress());
assertEquals("3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ, txid: offchain transfer", record.getDescription());
assertEquals("offchain transfer", record.getId());
assertEquals("offchain transfer", record.getExternalId());
assertEquals(Currency.BTC, record.getCurrency());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static List<FundingRecord> adaptFundingHistory(final BTCChinaGetDepositsR
final BTCChinaDeposit[] deposits = depositsResponse.getResult().getDeposits();
for (final BTCChinaDeposit deposit : deposits) {
FundingRecord fundingRecordEntry = new FundingRecord(deposit.getAddress(), adaptDate(deposit.getDate()), Currency.getInstance(deposit.getCurrency()),
deposit.getAmount(), String.valueOf(deposit.getId()), FundingRecord.Type.DEPOSIT, deposit.getStatus(), null, null, null);
deposit.getAmount(), String.valueOf(deposit.getId()), null, FundingRecord.Type.DEPOSIT, deposit.getStatus(), null, null, null);
fundingRecords.add(fundingRecordEntry);
}
}
Expand All @@ -408,7 +408,7 @@ public static List<FundingRecord> adaptFundingHistory(final BTCChinaGetDepositsR
final BTCChinaWithdrawal[] withdrawals = withdrawalsResponse.getResult().getWithdrawals();
for (final BTCChinaWithdrawal withdrawal : withdrawals) {
FundingRecord fundingRecordEntry = new FundingRecord(withdrawal.getAddress(), adaptDate(withdrawal.getDate()), Currency.getInstance(withdrawal.getCurrency()),
withdrawal.getAmount(), String.valueOf(withdrawal.getId()), FundingRecord.Type.WITHDRAWAL, withdrawal.getStatus(), null, null, null);
withdrawal.getAmount(), String.valueOf(withdrawal.getId()), withdrawal.getTransaction(), FundingRecord.Type.WITHDRAWAL, withdrawal.getStatus(), null, null, null);
fundingRecords.add(fundingRecordEntry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ public final class FundingRecord {
*/
private final BigDecimal amount;


/**
* Transaction id or reference whenever available
* Internal transaction identifier, specific to the Exchange.
*/
private final String id;
private final String internalId;

/**
* External Transaction id that identifies the transaction within the public ledger, eg. blockchain transaction hash.
*/
private final String externalId;

/**
* Description of the transaction
Expand Down Expand Up @@ -78,21 +81,24 @@ public final class FundingRecord {
* @param date Date/Time of transaction
* @param currency The transaction currency
* @param amount Amount deposited/withdrawn
* @param id Transaction id or reference whenever available
* @param internalId Internal transaction identifier, specific to the Exchange
* @param externalId External Transaction id that identifies the transaction within the public ledger, eg. blockchain transaction hash
* @param type Transaction Type {@link Type}
* @param status Status of the transaction whenever available (e.g. Open, Completed or any descriptive status of transaction)
* @param balance Balance of the associated account after the transaction is performed
* @param fee Transaction Fee Amount
* @param description Description of the transaction
*/
public FundingRecord(final String address, final Date date, final Currency currency, final BigDecimal amount, final String id,
public FundingRecord(final String address, final Date date, final Currency currency, final BigDecimal amount,
final String internalId, final String externalId,
final Type type, final String status, final BigDecimal balance, final BigDecimal fee,
final String description){
this.address = address;
this.date = date;
this.currency = currency;
this.amount = amount;
this.id = id;
this.internalId = internalId;
this.externalId = externalId;
this.type = type;
this.status = status;
this.balance = balance;
Expand Down Expand Up @@ -129,10 +135,17 @@ public BigDecimal getAmount() {
}

/**
* @return Transaction id or reference whenever available
* @return Internal transaction identifier, specific to the Exchange.
*/
public String getInternalId() {
return internalId;
}

/**
* @return External Transaction id that identifies the transaction within the public ledger, eg. blockchain transaction hash.
*/
public String getId() {
return id;
public String getExternalId() {
return externalId;
}

/**
Expand Down Expand Up @@ -177,7 +190,8 @@ public String toString() {
", date=" + date +
", currency='" + currency + '\'' +
", amount=" + amount +
", id='" + id + '\'' +
", internalId='" + internalId + '\'' +
", externalId='" + externalId + '\'' +
", description='" + description + '\'' +
", type='" + type + '\'' +
", status='" + status + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static List<FundingRecord> adaptFundingHistory(Map<String, KrakenLedger>
final FundingRecord.Type type = FundingRecord.Type.fromString(krakenLedger.getLedgerType().name());
if (type != null){
FundingRecord fundingRecordEntry = new FundingRecord(null, timestamp,
currency, krakenLedger.getTransactionAmount(), krakenLedger.getRefId(),
currency, krakenLedger.getTransactionAmount(), krakenLedger.getRefId(), null,
FundingRecord.Type.fromString(krakenLedger.getLedgerType().name()),
null, krakenLedger.getBalance(), krakenLedger.getFee(), null);
fundingRecords.add(fundingRecordEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static List<FundingRecord> adaptFundingHistory(final OkCoinAccountRecords
final Currency depositCurrency = Currency.getInstance(depositRecord.getSymbol());
for (OkCoinRecords okCoinRecordEntry : depositRecord.getRecords()) {
fundingRecords.add(new FundingRecord(okCoinRecordEntry.getAddress(),adaptDate(okCoinRecordEntry.getDate()),
depositCurrency, okCoinRecordEntry.getAmount(), okCoinRecordEntry.getAddress(),
depositCurrency, okCoinRecordEntry.getAmount(), null, null,
FundingRecord.Type.DEPOSIT, okCoinRecordEntry.getStatus(), null, okCoinRecordEntry.getFee(), null)
);
}
Expand All @@ -350,7 +350,7 @@ public static List<FundingRecord> adaptFundingHistory(final OkCoinAccountRecords
final Currency withdrawalCurrency = Currency.getInstance(withdrawalRecord.getSymbol());
for (OkCoinRecords okCoinRecordEntry : withdrawalRecord.getRecords()) {
fundingRecords.add(new FundingRecord(okCoinRecordEntry.getAddress(),adaptDate(okCoinRecordEntry.getDate()),
withdrawalCurrency, okCoinRecordEntry.getAmount(), okCoinRecordEntry.getAddress(),
withdrawalCurrency, okCoinRecordEntry.getAmount(), null, null,
FundingRecord.Type.WITHDRAWAL, okCoinRecordEntry.getStatus(), null, okCoinRecordEntry.getFee(), null)
);
}
Expand Down

0 comments on commit dfb2ce0

Please sign in to comment.