Java Code Examples for org.bitcoinj.wallet.Wallet#findKeyFromPubKey()

The following examples show how to use org.bitcoinj.wallet.Wallet#findKeyFromPubKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoredPaymentChannelClientStates.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {
    lock.lock();
    try {
        checkState(this.containingWallet == null || this.containingWallet == containingWallet);
        this.containingWallet = containingWallet;
        NetworkParameters params = containingWallet.getParams();
        ClientState.StoredClientPaymentChannels states = ClientState.StoredClientPaymentChannels.parseFrom(data);
        for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) {
            Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray());
            refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF);
            ECKey myKey = (storedState.getMyKey().isEmpty()) ?
                    containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray());
            ECKey serverKey = storedState.hasServerKey() ? ECKey.fromPublicOnly(storedState.getServerKey().toByteArray()) : null;
            StoredClientChannel channel = new StoredClientChannel(storedState.getMajorVersion(),
                    Sha256Hash.wrap(storedState.getId().toByteArray()),
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    refundTransaction,
                    myKey,
                    serverKey,
                    Coin.valueOf(storedState.getValueToMe()),
                    Coin.valueOf(storedState.getRefundFees()),
                    storedState.getExpiryTime(),
                    false);
            if (storedState.hasCloseTransactionHash()) {
                Sha256Hash closeTxHash = Sha256Hash.wrap(storedState.getCloseTransactionHash().toByteArray());
                channel.close = containingWallet.getTransaction(closeTxHash);
            }
            putChannel(channel, false);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 2
Source File: StoredPaymentChannelClientStates.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {
    lock.lock();
    try {
        checkState(this.containingWallet == null || this.containingWallet == containingWallet);
        this.containingWallet = containingWallet;
        NetworkParameters params = containingWallet.getParams();
        ClientState.StoredClientPaymentChannels states = ClientState.StoredClientPaymentChannels.parseFrom(data);
        for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) {
            Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray());
            refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF);
            ECKey myKey = (storedState.getMyKey().isEmpty()) ?
                    containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray());
            ECKey serverKey = storedState.hasServerKey() ? ECKey.fromPublicOnly(storedState.getServerKey().toByteArray()) : null;
            StoredClientChannel channel = new StoredClientChannel(storedState.getMajorVersion(),
                    Sha256Hash.wrap(storedState.getId().toByteArray()),
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    refundTransaction,
                    myKey,
                    serverKey,
                    Coin.valueOf(storedState.getValueToMe()),
                    Coin.valueOf(storedState.getRefundFees()),
                    storedState.getExpiryTime(),
                    false);
            if (storedState.hasCloseTransactionHash()) {
                Sha256Hash closeTxHash = Sha256Hash.wrap(storedState.getCloseTransactionHash().toByteArray());
                channel.close = containingWallet.getTransaction(closeTxHash);
            }
            putChannel(channel, false);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 3
Source File: StoredPaymentChannelClientStates.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {
    lock.lock();
    try {
        checkState(this.containingWallet == null || this.containingWallet == containingWallet);
        this.containingWallet = containingWallet;
        NetworkParameters params = containingWallet.getParams();
        ClientState.StoredClientPaymentChannels states = ClientState.StoredClientPaymentChannels.parseFrom(data);
        for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) {
            Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray());
            refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF);
            ECKey myKey = (storedState.getMyKey().isEmpty()) ?
                    containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray());
            ECKey serverKey = storedState.hasServerKey() ? ECKey.fromPublicOnly(storedState.getServerKey().toByteArray()) : null;
            StoredClientChannel channel = new StoredClientChannel(storedState.getMajorVersion(),
                    Sha256Hash.wrap(storedState.getId().toByteArray()),
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    refundTransaction,
                    myKey,
                    serverKey,
                    Coin.valueOf(storedState.getValueToMe()),
                    Coin.valueOf(storedState.getRefundFees()),
                    storedState.getExpiryTime(),
                    false);
            if (storedState.hasCloseTransactionHash()) {
                Sha256Hash closeTxHash = Sha256Hash.wrap(storedState.getCloseTransactionHash().toByteArray());
                channel.close = containingWallet.getTransaction(closeTxHash);
            }
            putChannel(channel, false);
        }
    } finally {
        lock.unlock();
    }
}