org.bitcoinj.core.Address Java Examples

The following examples show how to use org.bitcoinj.core.Address. 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: WalletTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void watchingScriptsSentFrom() throws Exception {
    int baseElements = wallet.getBloomFilterElementCount();

    Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
    wallet.addWatchedAddress(watchedAddress);
    assertEquals(baseElements + 1, wallet.getBloomFilterElementCount());

    Transaction t1 = createFakeTx(UNITTEST, CENT, watchedAddress);
    Transaction t2 = createFakeTx(UNITTEST, COIN, OTHER_ADDRESS);
    sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
    assertEquals(baseElements + 2, wallet.getBloomFilterElementCount());
    Transaction st2 = new Transaction(UNITTEST);
    st2.addOutput(CENT, OTHER_ADDRESS);
    st2.addOutput(COIN, OTHER_ADDRESS);
    st2.addInput(t1.getOutput(0));
    st2.addInput(t2.getOutput(0));
    sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, st2);
    assertEquals(baseElements + 2, wallet.getBloomFilterElementCount());
    assertEquals(CENT, st2.getValueSentFromMe(wallet));
}
 
Example #2
Source File: BsqWalletService.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
public Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount)
        throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException {
    Transaction tx = new Transaction(params);
    checkArgument(Restrictions.isAboveDust(receiverAmount),
            "The amount is too low (dust limit).");
    tx.addOutput(receiverAmount, Address.fromBase58(params, receiverAddress));

    SendRequest sendRequest = SendRequest.forTx(tx);
    sendRequest.fee = Coin.ZERO;
    sendRequest.feePerKb = Coin.ZERO;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.aesKey = aesKey;
    sendRequest.shuffleOutputs = false;
    sendRequest.signInputs = false;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.changeAddress = getUnusedAddress();
    try {
        wallet.completeTx(sendRequest);
    } catch (InsufficientMoneyException e) {
        throw new InsufficientBsqException(e.missing);
    }
    checkWalletConsistency(wallet);
    verifyTransaction(tx);
    // printTx("prepareSendTx", tx);
    return tx;
}
 
Example #3
Source File: KeyChainGroup.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain, List<DeterministicKeyChain> chains,
                      @Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, @Nullable KeyCrypter crypter) {
    this.params = params;
    this.basic = basicKeyChain == null ? new BasicKeyChain() : basicKeyChain;
    this.chains = new LinkedList<>(checkNotNull(chains));
    this.keyCrypter = crypter;
    this.currentKeys = currentKeys == null
            ? new EnumMap<KeyChain.KeyPurpose, DeterministicKey>(KeyChain.KeyPurpose.class)
            : currentKeys;
    this.currentAddresses = new EnumMap<>(KeyChain.KeyPurpose.class);
    maybeLookaheadScripts();

    if (isMarried()) {
        for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) {
            Address address = makeP2SHOutputScript(entry.getValue(), getActiveKeyChain()).getToAddress(params);
            currentAddresses.put(entry.getKey(), address);
        }
    }
}
 
Example #4
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
private Transaction cleanupCommon(Address destination) throws Exception {
    receiveATransaction(wallet, myAddress);

    Coin v2 = valueOf(0, 50);
    SendRequest req = SendRequest.to(destination, v2);
    wallet.completeTx(req);

    Transaction t2 = req.tx;

    // Broadcast the transaction and commit.
    broadcastAndCommit(wallet, t2);

    // At this point we have one pending and one spent

    Coin v1 = valueOf(0, 10);
    Transaction t = sendMoneyToWallet(null, v1, myAddress);
    Threading.waitForUserCode();
    sendMoneyToWallet(null, t);
    assertEquals("Wrong number of PENDING", 2, wallet.getPoolSize(Pool.PENDING));
    assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(Pool.UNSPENT));
    assertEquals("Wrong number of ALL", 3, wallet.getTransactions(true).size());
    assertEquals(valueOf(0, 60), wallet.getBalance(Wallet.BalanceType.ESTIMATED));

    // Now we have another incoming pending
    return t;
}
 
Example #5
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void watchingScriptsSentFrom() throws Exception {
    int baseElements = wallet.getBloomFilterElementCount();

    Address watchedAddress = new ECKey().toAddress(PARAMS);
    wallet.addWatchedAddress(watchedAddress);
    assertEquals(baseElements + 1, wallet.getBloomFilterElementCount());

    Transaction t1 = createFakeTx(PARAMS, CENT, watchedAddress);
    Transaction t2 = createFakeTx(PARAMS, COIN, OTHER_ADDRESS);
    sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
    assertEquals(baseElements + 2, wallet.getBloomFilterElementCount());
    Transaction st2 = new Transaction(PARAMS);
    st2.addOutput(CENT, OTHER_ADDRESS);
    st2.addOutput(COIN, OTHER_ADDRESS);
    st2.addInput(t1.getOutput(0));
    st2.addInput(t2.getOutput(0));
    sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, st2);
    assertEquals(baseElements + 2, wallet.getBloomFilterElementCount());
    assertEquals(CENT, st2.getValueSentFromMe(wallet));
}
 
Example #6
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void removeScriptsBloomFilter() throws Exception {
    List<Address> addressesForRemoval = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Address watchedAddress = new ECKey().toAddress(PARAMS);
        addressesForRemoval.add(watchedAddress);
        wallet.addWatchedAddress(watchedAddress);
    }

    wallet.removeWatchedAddresses(addressesForRemoval);

    for (Address addr : addressesForRemoval) {
        Transaction t1 = createFakeTx(PARAMS, CENT, addr);
        TransactionOutPoint outPoint = new TransactionOutPoint(PARAMS, 0, t1);

        // Note that this has a 1e-12 chance of failing this unit test due to a false positive
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));

        sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, t1);
        assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
    }
}
 
Example #7
Source File: FakeTxBuilder.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
 * else to simulate change. There is one random input.
 */
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, Coin value, Address to, Address changeOutput) {
    Transaction t = new Transaction(params);
    TransactionOutput outputToMe = new TransactionOutput(params, t, value, to);
    t.addOutput(outputToMe);
    TransactionOutput change = new TransactionOutput(params, t, valueOf(1, 11), changeOutput);
    t.addOutput(change);
    // Make a previous tx simply to send us sufficient coins. This prev tx is not really valid but it doesn't
    // matter for our purposes.
    Transaction prevTx = new Transaction(params);
    TransactionOutput prevOut = new TransactionOutput(params, prevTx, value, to);
    prevTx.addOutput(prevOut);
    // Connect it.
    t.addInput(prevOut).setScriptSig(ScriptBuilder.createInputScript(TransactionSignature.dummy()));
    // Fake signature.
    // Serialize/deserialize to ensure internal state is stripped, as if it had been read from the wire.
    return roundTripTransaction(params, t);
}
 
Example #8
Source File: QueryUnspentOutputsRequest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public String toJson() {
    try {
        JSONObject json = new JSONObject();
        json.put("version", version);
        JSONArray array = new JSONArray();
        for (Address address : addresses) {
            array.put(address.toString());
        }
        json.put("addresses", array);
        return json.toString();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return "";
}
 
Example #9
Source File: SPVBlockStoreTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void twoStores_sequentially_grow() throws Exception {
    Address to = LegacyAddress.fromKey(UNITTEST, new ECKey());
    SPVBlockStore store = new SPVBlockStore(UNITTEST, blockStoreFile, 10, true);
    final StoredBlock block0 = store.getChainHead();
    final StoredBlock block1 = block0.build(block0.getHeader().createNextBlock(to).cloneAsHeader());
    store.put(block1);
    final StoredBlock block2 = block1.build(block1.getHeader().createNextBlock(to).cloneAsHeader());
    store.put(block2);
    store.setChainHead(block2);
    store.close();

    store = new SPVBlockStore(UNITTEST, blockStoreFile, 20, true);
    final StoredBlock read2 = store.getChainHead();
    assertEquals(block2, read2);
    final StoredBlock read1 = read2.getPrev(store);
    assertEquals(block1, read1);
    final StoredBlock read0 = read1.getPrev(store);
    assertEquals(block0, read0);
    store.close();
    assertEquals(SPVBlockStore.getFileSize(20), blockStoreFile.length());
}
 
Example #10
Source File: ConfidentialAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public Address getBitcoinAddress(final NetworkParameters params) {
    if (bytes[0] == params.getP2SHHeader())
        return Address.fromP2SHHash(params, Arrays.copyOfRange(bytes, 34, 54));
    if (bytes[0] == params.getP2WPKHHeader())
        return Address.fromP2WPKHHash(params, Arrays.copyOfRange(bytes, 34, 54));
    throw new RuntimeException();  // Cannot happen.
}
 
Example #11
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public String cashAddressToLegacy(String cashAddress) {
    try {
        CashAddressFactory cashAddressFactory = CashAddressFactory.create();
        Address leg = cashAddressFactory.getFromFormattedAddress(params, cashAddress);
        Log.d("psd", "cash to addr: leg addr = " + leg.toBase58());
        return leg.toBase58();
    } catch (AddressFormatException afe) {
        afe.printStackTrace();
        return "";
    }
}
 
Example #12
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setUTXO(List<UTXOItem> utxoList) {
    Address a;
    if (restFromWif) {
        a = wallet.getImportedKeys().get(0).toAddress(params);
    } else {
        a = wallet.currentReceiveAddress();
    }

    final List<UTXO> utxos = new ArrayList<>();

    for (UTXOItem utxo : utxoList) {
        Sha256Hash hash = Sha256Hash.wrap(utxo.getTxHash());
        utxos.add(new UTXO(hash, utxo.getTxOutputN(), Coin.valueOf(utxo.getSatoshiValue()),
                0, false, ScriptBuilder.createOutputScript(a)));
    }

    UTXOProvider utxoProvider = new UTXOProvider() {
        @Override
        public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
            return utxos;
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }

        @Override
        public NetworkParameters getParams() {
            return wallet.getParams();
        }
    };
    wallet.setUTXOProvider(utxoProvider);
}
 
Example #13
Source File: LevelDBBlockStoreTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void basics() throws Exception {
    File f = File.createTempFile("leveldbblockstore", null);
    f.delete();

    Context context = new Context(UNITTEST);
    LevelDBBlockStore store = new LevelDBBlockStore(context, f);
    store.reset();

    // Check the first block in a new store is the genesis block.
    StoredBlock genesis = store.getChainHead();
    assertEquals(UNITTEST.getGenesisBlock(), genesis.getHeader());
    assertEquals(0, genesis.getHeight());

    // Build a new block.
    Address to = LegacyAddress.fromBase58(UNITTEST, "mrj2K6txjo2QBcSmuAzHj4nD1oXSEJE1Qo");
    StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
    store.put(b1);
    store.setChainHead(b1);
    store.close();

    // Check we can get it back out again if we rebuild the store object.
    store = new LevelDBBlockStore(context, f);
    try {
        StoredBlock b2 = store.get(b1.getHeader().getHash());
        assertEquals(b1, b2);
        // Check the chain head was stored correctly also.
        StoredBlock chainHead = store.getChainHead();
        assertEquals(b1, chainHead);
    } finally {
        store.close();
        store.destroy();
    }
}
 
Example #14
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setUTXO(List<UTXOItem> utxoList) {
    if (wallet == null) {
        return;
    }

    Address a = wallet.getImportedKeys().get(0).toAddress(params);
    final List<UTXO> utxos = new ArrayList<>();

    for (UTXOItem utxo : utxoList) {
        Sha256Hash hash = Sha256Hash.wrap(utxo.getTxHash());
        utxos.add(new UTXO(hash, utxo.getTxOutputN(), Coin.valueOf(utxo.getSatoshiValue()),
                0, false, ScriptBuilder.createOutputScript(a)));
    }

    UTXOProvider utxoProvider = new UTXOProvider() {
        @Override
        public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
            return utxos;
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }

        @Override
        public NetworkParameters getParams() {
            return wallet.getParams();
        }
    };
    wallet.setUTXOProvider(utxoProvider);
}
 
Example #15
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void removeWatchedAddresses() {
    List<Address> addressesForRemoval = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Address watchedAddress = new ECKey().toAddress(PARAMS);
        addressesForRemoval.add(watchedAddress);
        wallet.addWatchedAddress(watchedAddress);
    }

    wallet.removeWatchedAddresses(addressesForRemoval);
    for (Address addr : addressesForRemoval)
        assertFalse(wallet.isAddressWatched(addr));

    assertFalse(wallet.isRequiringUpdateAllBloomFilter());
}
 
Example #16
Source File: BsqFormatter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the base-58 encoded String representation of this
 * object, including version and checksum bytes.
 */
public String getBsqAddressStringFromAddress(Address address) {
    final String addressString = address.toString();
    if (useBsqAddressFormat)
        return prefix + addressString;
    else
        return addressString;

}
 
Example #17
Source File: SendRequest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>Creates a new SendRequest to the given address for the given value.</p>
 *
 * <p>Be very careful when value is smaller than {@link Transaction#MIN_NONDUST_OUTPUT} as the transaction will
 * likely be rejected by the network in this case.</p>
 */
public static SendRequest to(Address destination, Coin value) {
    SendRequest req = new SendRequest();
    final NetworkParameters parameters = destination.getParameters();
    checkNotNull(parameters, "Address is for an unknown network");
    req.tx = new Transaction(parameters);
    req.tx.addOutput(value, destination);
    return req;
}
 
Example #18
Source File: BsqWalletService.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
public Transaction getPreparedSendBtcTx(String receiverAddress, Coin receiverAmount)
        throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException {
    Transaction tx = new Transaction(params);
    checkArgument(Restrictions.isAboveDust(receiverAmount),
            "The amount is too low (dust limit).");
    tx.addOutput(receiverAmount, Address.fromBase58(params, receiverAddress));

    SendRequest sendRequest = SendRequest.forTx(tx);
    sendRequest.fee = Coin.ZERO;
    sendRequest.feePerKb = Coin.ZERO;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.aesKey = aesKey;
    sendRequest.shuffleOutputs = false;
    sendRequest.signInputs = false;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.changeAddress = getUnusedAddress();
    sendRequest.coinSelector = nonBsqCoinSelector;
    try {
        wallet.completeTx(sendRequest);
    } catch (InsufficientMoneyException e) {
        throw new InsufficientBsqException(e.missing);
    }
    checkWalletConsistency(wallet);
    verifyTransaction(tx);
    // printTx("prepareSendTx", tx);
    return tx;
}
 
Example #19
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public void fragmentedReKeying() throws Exception {
    // Send lots of small coins and check the fee is correct.
    ECKey key = wallet.freshReceiveKey();
    Address address = key.toAddress(PARAMS);
    Utils.setMockClock();
    Utils.rollMockClock(86400);
    for (int i = 0; i < 800; i++) {
        sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, address);
    }

    MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);

    Date compromise = Utils.now();
    Utils.rollMockClock(86400);
    wallet.freshReceiveKey();
    wallet.setKeyRotationTime(compromise);
    wallet.doMaintenance(null, true);

    Transaction tx = broadcaster.waitForTransactionAndSucceed();
    final Coin valueSentToMe = tx.getValueSentToMe(wallet);
    Coin fee = tx.getValueSentFromMe(wallet).subtract(valueSentToMe);
    assertEquals(Coin.valueOf(900000), fee);
    assertEquals(KeyTimeCoinSelector.MAX_SIMULTANEOUS_INPUTS, tx.getInputs().size());
    assertEquals(Coin.valueOf(599100000), valueSentToMe);

    tx = broadcaster.waitForTransaction();
    assertNotNull(tx);
    assertEquals(200, tx.getInputs().size());
}
 
Example #20
Source File: ReceivedByAddressInfo.java    From consensusj with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public ReceivedByAddressInfo(@JsonProperty("address") Address address,
                             @JsonProperty("account") String account,
                             @JsonProperty("amount") Coin amount,
                             @JsonProperty("confirmations") int confirmations,
                             @JsonProperty("txids") List<Sha256Hash> txids,
                             @JsonProperty("label") String label) {
    this.address = address;
    this.account = account;
    this.amount = amount;
    this.confirmations = confirmations;
    this.txids = txids;
    this.label = label;
}
 
Example #21
Source File: NmcLookup.java    From consensusj with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws URISyntaxException, IOException, JsonRpcStatusException, AddressFormatException {
    NamecoinClient client = new NamecoinClient(NamecoinClient.readConfig());
    NameData result = client.nameShow("d/beelin");
    System.out.println(result.getValue());
    Address owningAddress = result.getAddress();
    System.out.println("Owning Address: " + owningAddress);
}
 
Example #22
Source File: WalletService.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public int getNumTxOutputsForAddress(Address address) {
    List<TransactionOutput> transactionOutputs = new ArrayList<>();
    wallet.getTransactions(false).forEach(t -> transactionOutputs.addAll(t.getOutputs()));
    int outputs = 0;
    for (TransactionOutput output : transactionOutputs) {
        if (isOutputScriptConvertibleToAddress(output) &&
                address != null &&
                address.equals(getAddressFromOutput(output)))
            outputs++;
    }
    return outputs;
}
 
Example #23
Source File: TradeWalletService.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
public Transaction estimateBtcTradingFeeTxSize(Address fundingAddress,
                                               Address reservedForTradeAddress,
                                               Address changeAddress,
                                               Coin reservedFundsForOffer,
                                               boolean useSavingsWallet,
                                               Coin tradingFee,
                                               Coin txFee,
                                               String feeReceiverAddresses)
        throws InsufficientMoneyException, AddressFormatException {
    Transaction tradingFeeTx = new Transaction(params);
    tradingFeeTx.addOutput(tradingFee, Address.fromBase58(params, feeReceiverAddresses));
    tradingFeeTx.addOutput(reservedFundsForOffer, reservedForTradeAddress);

    SendRequest sendRequest = SendRequest.forTx(tradingFeeTx);
    sendRequest.shuffleOutputs = false;
    sendRequest.aesKey = aesKey;
    if (useSavingsWallet)
        sendRequest.coinSelector = new BtcCoinSelector(walletsSetup.getAddressesByContext(AddressEntry.Context.AVAILABLE));
    else
        sendRequest.coinSelector = new BtcCoinSelector(fundingAddress);

    sendRequest.fee = txFee;
    sendRequest.feePerKb = Coin.ZERO;
    sendRequest.ensureMinRequiredFee = false;
    sendRequest.changeAddress = changeAddress;
    checkNotNull(wallet, "Wallet must not be null");
    log.info("estimateBtcTradingFeeTxSize");
    wallet.completeTx(sendRequest);
    return tradingFeeTx;
}
 
Example #24
Source File: NameData.java    From consensusj with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public NameData(@JsonProperty("name")       String name,
                @JsonProperty("value")      String value,
                @JsonProperty("txid")       Sha256Hash txid,
                @JsonProperty("address")    Address address,
                @JsonProperty("expires_in") int expires_in) throws IOException {
    this.name = name;
    this.value = mapper.readValue(value, mapType);
    this.txid = txid;
    this.address = address;
    this.expires_in = expires_in;
}
 
Example #25
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setUTXO(List<UTXOItem> utxoList) {
    if (wallet == null) return;

    Address a;
    if (restFromWif) {
        a = wallet.getImportedKeys().get(0).toAddress(params);
    } else {
        a = wallet.currentReceiveAddress();
    }

    final List<UTXO> utxos = new ArrayList<>();

    for (UTXOItem utxo : utxoList) {
        Sha256Hash hash = Sha256Hash.wrap(utxo.getTxHash());
        utxos.add(new UTXO(hash, utxo.getTxOutputN(), Coin.valueOf(utxo.getSatoshiValue()),
                0, false, ScriptBuilder.createOutputScript(a)));
    }

    UTXOProvider utxoProvider = new UTXOProvider() {
        @Override
        public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
            return utxos;
        }

        @Override
        public int getChainHeadHeight() throws UTXOProviderException {
            return Integer.MAX_VALUE;
        }

        @Override
        public NetworkParameters getParams() {
            return wallet.getParams();
        }
    };
    wallet.setUTXOProvider(utxoProvider);
}
 
Example #26
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public boolean isAddressValid(String address) {
    try {
        return !address.isEmpty()
                && params.equals(Address.getParametersFromAddress(address));
    } catch (Exception e) {
        return false;
    }
}
 
Example #27
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void removeWatchedAddress() {
    Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
    wallet.addWatchedAddress(watchedAddress);
    wallet.removeWatchedAddress(watchedAddress);
    assertFalse(wallet.isAddressWatched(watchedAddress));
    assertFalse(wallet.isRequiringUpdateAllBloomFilter());
}
 
Example #28
Source File: SendRequest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static SendRequest emptyWallet(Address destination) {
    SendRequest req = new SendRequest();
    final NetworkParameters parameters = destination.getParameters();
    checkNotNull(parameters, "Address is for an unknown network");
    req.tx = new Transaction(parameters);
    req.tx.addOutput(Coin.ZERO, destination);
    req.emptyWallet = true;
    return req;
}
 
Example #29
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void watchingScripts() throws Exception {
    // Verify that pending transactions to watched addresses are relevant
    Address watchedAddress = new ECKey().toAddress(PARAMS);
    wallet.addWatchedAddress(watchedAddress);
    Coin value = valueOf(5, 0);
    Transaction t1 = createFakeTx(PARAMS, value, watchedAddress);
    assertTrue(t1.getWalletOutputs(wallet).size() >= 1);
    assertTrue(wallet.isPendingTransactionRelevant(t1));
}
 
Example #30
Source File: FakeTxBuilder.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static Block makeSolvedTestBlock(Block prev, Address to, Transaction... transactions) throws BlockStoreException {
    Block b = prev.createNextBlock(to);
    // Coinbase tx already exists.
    for (Transaction tx : transactions) {
        b.addTransaction(tx);
    }
    b.solve();
    return b;
}