Search in sources :

Example 1 with EscrowTransfer

use of eu.cryptoeuro.accountmapper.response.EscrowTransfer 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 EscrowTransfer

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

the class EscrowService method clearAllToAddress.

public List<EscrowTransfer> clearAllToAddress(long idCode, String address) throws IOException, JSONException {
    Escrow escrow;
    List<EscrowTransfer> etxs = new ArrayList<EscrowTransfer>();
    // Need to wait until the new account approval has been mined
    // doesn't work for multiple, because of eth nonce - need to create queue
    // assuming that this is always called  after Account Approval tx
    int nonceIncrement = 1;
    while ((escrow = getExistingEscrow(idCode)) != null) {
        List<EscrowTransfer> transfers = clearToAddress(escrow, address, nonceIncrement);
        if (transfers != null) {
            etxs.addAll(transfers);
            // should change for multiple escrow tx per addr
            escrow.setClearingHash(transfers.get(0).getTransactionHash());
        }
        escrow.setCleared(true);
        escrowRepository.save(escrow);
    }
    return etxs;
}
Also used : Escrow(eu.cryptoeuro.accountmapper.domain.Escrow) EscrowTransfer(eu.cryptoeuro.accountmapper.response.EscrowTransfer) ArrayList(java.util.ArrayList)

Aggregations

EscrowTransfer (eu.cryptoeuro.accountmapper.response.EscrowTransfer)2 ArrayList (java.util.ArrayList)2 Escrow (eu.cryptoeuro.accountmapper.domain.Escrow)1 WalletServerAccountResponse (eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse)1 WalletServerHistoryResponse (eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse)1 Date (java.util.Date)1