Search in sources :

Example 1 with WalletServerAccountResponse

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

the class EthereumService method sendBalance.

public String sendBalance(String toAddress, String privKey, int nonceIncrement) throws IOException {
    ECKey signer = ECKey.fromPrivate(Hex.decode(without0x(privKey)));
    WalletServerAccountResponse addrDetails = wsService.getAccount(hex(signer.getAddress()));
    return sendBalance(toAddress, privKey, nonceIncrement, addrDetails.getBalance());
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ECKey(org.ethereum.crypto.ECKey)

Example 2 with WalletServerAccountResponse

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

the class EthereumService method sendBalance.

public String sendBalance(String toAddress, String privKey, int nonceIncrement, long amount) throws IOException {
    ECKey signer = ECKey.fromPrivate(Hex.decode(without0x(privKey)));
    ECKey sponsorKey = getAccountApproverKey();
    WalletServerAccountResponse addrDetails = wsService.getAccount(hex(signer.getAddress()));
    byte[] signatureArg = signDelegate(0, amount, addrDetails.getNonce() + 1 + nonceIncrement, without0x(toAddress), signer);
    byte[] callData = transferFunction.encode(addrDetails.getNonce() + 1 + nonceIncrement, toAddress, amount, 0, signatureArg, hex(sponsorKey.getAddress()));
    String txHash = sendTransaction(sponsorKey, callData, contractAddressForTransfers, nonceIncrement);
    log.info("Submitted transfer and got Tx= " + txHash);
    return txHash;
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ECKey(org.ethereum.crypto.ECKey)

Example 3 with WalletServerAccountResponse

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

the class WalletServerService method getAccount.

public WalletServerAccountResponse getAccount(String address) {
    ObjectMapper mapper = new ObjectMapper();
    WalletServerAccountResponse obj = null;
    try {
        obj = mapper.readValue(new URL(walletServer + "/v1/accounts/" + address), WalletServerAccountResponse.class);
    } catch (Exception e) {
        log.error("Failed loading account data from wallet-server", e);
    }
    return obj;
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONException(org.json.JSONException)

Example 4 with WalletServerAccountResponse

use of eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse 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 5 with WalletServerAccountResponse

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

the class EthereumService method testSigning.

public void testSigning() throws IOException {
    String addr = "65fa6548764c08c0dd77495b33ed302d0c212691";
    ECKey signer = ECKey.fromPrivate(Hex.decode(without0x("0xc33d80b3fddd6bc5d62498905b90c94cf1252ffd846def3b530acd803bbb3783")));
    signDelegate(0, 3, 1, "65fa6548764c08c0dd77495b33ed302d0c212691", signer);
    WalletServerAccountResponse addrDetails = wsService.getAccount(hex(signer.getAddress()));
    log.info("some info about address" + addrDetails.toString());
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ECKey(org.ethereum.crypto.ECKey)

Aggregations

WalletServerAccountResponse (eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse)5 ECKey (org.ethereum.crypto.ECKey)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EscrowTransfer (eu.cryptoeuro.accountmapper.response.EscrowTransfer)1 WalletServerHistoryResponse (eu.cryptoeuro.accountmapper.response.WalletServerHistoryResponse)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