Search in sources :

Example 1 with WalletServerHistoryResponse

use of eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse in project account-identity by cryptofiat.

the class EscrowService method clearToAddress.

public List<EscrowTransfer> clearToAddress(Escrow escrow, String address, int nonceIncrement) throws IOException, JSONException {
    WalletServerAccountResponse addrDetails = wsService.getAccount(escrow.getAddress());
    List<WalletServerHistoryResponse> history = wsService.getHistory(escrow.getAddress());
    accountService.deactivateAddress(escrow.getAddress());
    long bal = addrDetails.getBalance();
    if (bal > 0) {
        log.info("Move total of: " + String.valueOf(addrDetails.getBalance()) + " to " + address + " sign with " + encUtils.decrypt(escrow.getPrivateKey()));
        List<EscrowTransfer> escrowTransfers = new ArrayList();
        for (WalletServerHistoryResponse tx : history) {
            String txHash = ethereumService.sendBalance(address, encUtils.decrypt(escrow.getPrivateKey()), nonceIncrement, tx.getAmount());
            nonceIncrement++;
            wsService.copyReference(tx.getId(), txHash);
            escrowTransfers.add(EscrowTransfer.builder().amount(tx.getAmount()).transactionHash(txHash).timestamp(new Date().getTime()).build());
        }
        return escrowTransfers;
    } else {
        return null;
    }
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) EscrowTransfer(eu.cryptoeuro.accountmapper.response.EscrowTransfer) ArrayList(java.util.ArrayList) WalletServerHistoryResponse(eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse) Date(java.util.Date)

Example 2 with WalletServerHistoryResponse

use of eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse in project account-identity by cryptofiat.

the class WalletServerService method getHistory.

public List<WalletServerHistoryResponse> getHistory(String address) {
    ObjectMapper mapper = new ObjectMapper();
    WalletServerHistoryResponse[] obj = null;
    try {
        obj = mapper.readValue(new URL(walletServer + "/v1/accounts/" + address + "/transfers"), WalletServerHistoryResponse[].class);
        for (WalletServerHistoryResponse resp : obj) {
            log.info("History: tx " + resp.getId() + " from " + resp.getSourceAccount());
        }
    } catch (Exception e) {
        log.error("Failed loading history data from wallet-server", e);
    }
    return Arrays.asList(obj);
}
Also used : WalletServerHistoryResponse(eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONException(org.json.JSONException)

Aggregations

WalletServerHistoryResponse (eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EscrowTransfer (eu.cryptoeuro.accountmapper.response.EscrowTransfer)1 WalletServerAccountResponse (eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 JSONException (org.json.JSONException)1