Search in sources :

Example 6 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class RedeemFunctions method redeem.

public static boolean redeem(String address_entry, String secretPhrase, String[] bitcoin_privkeys, boolean graceblock) {
    String secp_signatures = "";
    NetworkParameters params = MainNetParams.get();
    long target_id = Account.getId(Crypto.getPublicKey(secretPhrase));
    String message = Redeem.getSignMessage(Redeem.getClaimableAmount(address_entry), address_entry, target_id);
    // Sign inputs
    for (int i = 0; i < bitcoin_privkeys.length; ++i) {
        ECKey key;
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, bitcoin_privkeys[i]);
        key = dumpedPrivateKey.getKey();
        String signed = key.signMessage(message);
        bitcoin_privkeys[i] = signed;
    }
    secp_signatures = String.join("-", bitcoin_privkeys);
    final Attachment attachment = new Attachment.RedeemAttachment(address_entry, secp_signatures);
    boolean success = false;
    try {
        make(attachment, secretPhrase, Account.getId(Crypto.getPublicKey(secretPhrase)), Redeem.getClaimableAmount(address_entry), true, graceblock);
        success = true;
    } catch (Exception e) {
        Logger.logErrorMessage(e.getMessage());
    }
    return success;
}
Also used : NetworkParameters(org.bitcoinj.core.NetworkParameters) ECKey(org.bitcoinj.core.ECKey) Attachment(org.xel.Attachment) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey)

Example 7 with Attachment

use of org.xel.Attachment in project elastic-core-maven by OrdinaryDude.

the class LeaseBalance method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    int period = ParameterParser.getInt(req, "period", Constants.LEASING_DELAY, 65535, true);
    Account account = ParameterParser.getSenderAccount(req);
    long recipient = ParameterParser.getAccountId(req, "recipient", true);
    Account recipientAccount = Account.getAccount(recipient);
    if (recipientAccount == null || Account.getPublicKey(recipientAccount.getId()) == null) {
        JSONObject response = new JSONObject();
        response.put("errorCode", 8);
        response.put("errorDescription", "recipient account does not have public key");
        return response;
    }
    Attachment attachment = new Attachment.AccountControlEffectiveBalanceLeasing(period);
    return createTransaction(req, account, recipient, 0, attachment);
}
Also used : Account(org.xel.Account) JSONObject(org.json.simple.JSONObject) Attachment(org.xel.Attachment)

Aggregations

Attachment (org.xel.Attachment)7 Account (org.xel.Account)5 ArrayList (java.util.ArrayList)2 JSONObject (org.json.simple.JSONObject)2 DumpedPrivateKey (org.bitcoinj.core.DumpedPrivateKey)1 ECKey (org.bitcoinj.core.ECKey)1 NetworkParameters (org.bitcoinj.core.NetworkParameters)1 PollBuilder (org.xel.Attachment.MessagingPollCreation.PollBuilder)1 PhasingPoll (org.xel.PhasingPoll)1 Poll (org.xel.Poll)1 Transaction (org.xel.Transaction)1