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

The following examples show how to use org.bitcoinj.wallet.Wallet#getParams() . 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: WalletService.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @param serializedTransaction The serialized transaction to be added to the wallet
 * @return The transaction we added to the wallet, which is different as the one we passed as argument!
 * @throws VerificationException
 */
public static Transaction maybeAddTxToWallet(byte[] serializedTransaction,
                                             Wallet wallet,
                                             TransactionConfidence.Source source) throws VerificationException {
    Transaction tx = new Transaction(wallet.getParams(), serializedTransaction);
    Transaction walletTransaction = wallet.getTransaction(tx.getHash());

    if (walletTransaction == null) {
        // We need to recreate the transaction otherwise we get a null pointer...
        tx.getConfidence(Context.get()).setSource(source);
        //wallet.maybeCommitTx(tx);
        wallet.receivePending(tx, null, true);
        return tx;
    } else {
        return walletTransaction;
    }
}
 
Example 2
Source File: StoredPaymentChannelServerStates.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 {
        this.wallet = containingWallet;
        ServerState.StoredServerPaymentChannels states = ServerState.StoredServerPaymentChannels.parseFrom(data);
        NetworkParameters params = containingWallet.getParams();
        for (ServerState.StoredServerPaymentChannel storedState : states.getChannelsList()) {
            final int majorVersion = storedState.getMajorVersion();
            TransactionOutput clientOutput = null;
            ECKey clientKey = null;
            if (majorVersion == 1) {
                clientOutput = new TransactionOutput(params, null, storedState.getClientOutput().toByteArray(), 0);
            } else {
                clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray());
            }
            StoredServerChannel channel = new StoredServerChannel(null,
                    majorVersion,
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    clientOutput,
                    storedState.getRefundTransactionUnlockTimeSecs(),
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray()),
                    clientKey,
                    Coin.valueOf(storedState.getBestValueToMe()),
                    storedState.hasBestValueSignature() ? storedState.getBestValueSignature().toByteArray() : null);
            putChannel(channel);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 3
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 4
Source File: StoredPaymentChannelServerStates.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 {
        this.wallet = containingWallet;
        ServerState.StoredServerPaymentChannels states = ServerState.StoredServerPaymentChannels.parseFrom(data);
        NetworkParameters params = containingWallet.getParams();
        for (ServerState.StoredServerPaymentChannel storedState : states.getChannelsList()) {
            final int majorVersion = storedState.getMajorVersion();
            TransactionOutput clientOutput = null;
            ECKey clientKey = null;
            if (majorVersion == 1) {
                clientOutput = new TransactionOutput(params, null, storedState.getClientOutput().toByteArray(), 0);
            } else {
                clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray());
            }
            StoredServerChannel channel = new StoredServerChannel(null,
                    majorVersion,
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    clientOutput,
                    storedState.getRefundTransactionUnlockTimeSecs(),
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray()),
                    clientKey,
                    Coin.valueOf(storedState.getBestValueToMe()),
                    storedState.hasBestValueSignature() ? storedState.getBestValueSignature().toByteArray() : null);
            putChannel(channel);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 5
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 6
Source File: StoredPaymentChannelServerStates.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 {
        this.wallet = containingWallet;
        ServerState.StoredServerPaymentChannels states = ServerState.StoredServerPaymentChannels.parseFrom(data);
        NetworkParameters params = containingWallet.getParams();
        for (ServerState.StoredServerPaymentChannel storedState : states.getChannelsList()) {
            final int majorVersion = storedState.getMajorVersion();
            TransactionOutput clientOutput = null;
            ECKey clientKey = null;
            if (majorVersion == 1) {
                clientOutput = new TransactionOutput(params, null, storedState.getClientOutput().toByteArray(), 0);
            } else {
                clientKey = ECKey.fromPublicOnly(storedState.getClientKey().toByteArray());
            }
            StoredServerChannel channel = new StoredServerChannel(null,
                    majorVersion,
                    params.getDefaultSerializer().makeTransaction(storedState.getContractTransaction().toByteArray()),
                    clientOutput,
                    storedState.getRefundTransactionUnlockTimeSecs(),
                    ECKey.fromPrivate(storedState.getMyKey().toByteArray()),
                    clientKey,
                    Coin.valueOf(storedState.getBestValueToMe()),
                    storedState.hasBestValueSignature() ? storedState.getBestValueSignature().toByteArray() : null);
            putChannel(channel);
        }
    } finally {
        lock.unlock();
    }
}
 
Example 7
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();
    }
}