org.bitcoinj.core.NetworkParameters Java Examples
The following examples show how to use
org.bitcoinj.core.NetworkParameters.
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: BIP32Test.java From green_android with GNU General Public License v3.0 | 6 votes |
private void testVector(int testCase) { log.info("======= Test vector {}", testCase); HDWTestVector tv = tvs[testCase]; NetworkParameters params = MainNetParams.get(); DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(HEX.decode(tv.seed)); assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58(params))); assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58(params))); DeterministicHierarchy dh = new DeterministicHierarchy(masterPrivateKey); for (int i = 0; i < tv.derived.size(); i++) { HDWTestVector.DerivedTestCase tc = tv.derived.get(i); log.info("{}", tc.name); assertEquals(tc.name, String.format(Locale.US, "Test%d %s", testCase + 1, tc.getPathDescription())); int depth = tc.path.length - 1; DeterministicKey ehkey = dh.deriveChild(Arrays.asList(tc.path).subList(0, depth), false, true, tc.path[depth]); assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58(params))); assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58(params))); } }
Example #2
Source File: LevelDBFullPrunedBlockStore.java From green_android with GNU General Public License v3.0 | 6 votes |
private void createNewStore(NetworkParameters params) throws BlockStoreException { try { // Set up the genesis block. When we start out fresh, it is by // definition the top of the chain. StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(), params.getGenesisBlock().getWork(), 0); // The coinbase in the genesis block is not spendable. This is // because of how the reference client inits // its database - the genesis transaction isn't actually in the db // so its spent flags can never be updated. List<Transaction> genesisTransactions = Lists.newLinkedList(); StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(), genesisTransactions); beginDatabaseBatchWrite(); put(storedGenesisHeader, storedGenesis); setChainHead(storedGenesisHeader); setVerifiedChainHead(storedGenesisHeader); batchPut(getKey(KeyType.CREATED), bytes("done")); commitDatabaseBatchWrite(); } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
Example #3
Source File: LevelDBFullPrunedBlockStore.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public LevelDBFullPrunedBlockStore(NetworkParameters params, String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock) { this.params = params; fullStoreDepth = blockCount; this.instrument = instrument; this.exitBlock = exitBlock; methodStartTime = new HashMap<>(); methodCalls = new HashMap<>(); methodTotalTime = new HashMap<>(); this.filename = filename; this.leveldbReadCache = leveldbReadCache; this.leveldbWriteCache = leveldbWriteCache; this.openOutCache = openOutCache; bloom = new BloomFilter(); totalStopwatch = Stopwatch.createStarted(); openDB(); bloom.reloadCache(db); // Reset after bloom filter loaded totalStopwatch = Stopwatch.createStarted(); }
Example #4
Source File: BisqRiskAnalysis.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
private Result analyzeIsStandard() { // The IsStandard rules don't apply on testnet, because they're just a safety mechanism and we don't want to // crush innovation with valueless test coins. if (wallet != null && !wallet.getNetworkParameters().getId().equals(NetworkParameters.ID_MAINNET)) return Result.OK; RuleViolation ruleViolation = isStandard(tx); if (ruleViolation != RuleViolation.NONE) { nonStandard = tx; return Result.NON_STANDARD; } for (Transaction dep : dependencies) { ruleViolation = isStandard(dep); if (ruleViolation != RuleViolation.NONE) { nonStandard = dep; return Result.NON_STANDARD; } } return Result.OK; }
Example #5
Source File: V3Keystore.java From token-core-android with Apache License 2.0 | 6 votes |
public V3Keystore(Metadata metadata, String password, String prvKeyHex, String id) { byte[] prvKeyBytes; if (metadata.getChainType().equals(ChainType.BITCOIN)) { NetworkParameters network = metadata.isMainNet() ? MainNetParams.get() : TestNet3Params.get(); prvKeyBytes = prvKeyHex.getBytes(); new WIFValidator(prvKeyHex, network).validate(); if (Metadata.P2WPKH.equals(metadata.getSegWit())) { this.address = new SegWitBitcoinAddressCreator(network).fromPrivateKey(prvKeyHex); } else { this.address = new BitcoinAddressCreator(network).fromPrivateKey(prvKeyHex); } } else if (metadata.getChainType().equals(ChainType.ETHEREUM)) { prvKeyBytes = NumericUtil.hexToBytes(prvKeyHex); new PrivateKeyValidator(prvKeyHex).validate(); this.address = new EthereumAddressCreator().fromPrivateKey(prvKeyBytes); } else { throw new TokenException("Can't init eos keystore in this constructor"); } this.crypto = Crypto.createPBKDF2Crypto(password, prvKeyBytes); metadata.setWalletType(Metadata.V3); this.metadata = metadata; this.version = VERSION; this.id = Strings.isNullOrEmpty(id) ? UUID.randomUUID().toString() : id; }
Example #6
Source File: DeterministicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void spendingChainAccountTwo() throws UnreadableWalletException { Utils.setMockClock(); long secs = 1389353062L; chain = new AccountTwoChain(ENTROPY, "", secs); DeterministicKey firstReceiveKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey secondReceiveKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey firstChangeKey = chain.getKey(KeyChain.KeyPurpose.CHANGE); DeterministicKey secondChangeKey = chain.getKey(KeyChain.KeyPurpose.CHANGE); NetworkParameters params = MainNetParams.get(); DeterministicKey watchingKey = chain.getWatchingKey(); final String prv58 = watchingKey.serializePrivB58(params); assertEquals("xprv9vL4k9HYXonmzR7UC1ngJ3hTjxkmjLLUo3RexSfUGSWcACHzghWBLJAwW6xzs59XeFizQxFQWtscoTfrF9PSXrUgAtBgr13Nuojax8xTBRz", prv58); watchingKey = DeterministicKey.deserializeB58(null, prv58, params); watchingKey.setCreationTimeSeconds(secs); chain = DeterministicKeyChain.spend(watchingKey); assertEquals(secs, chain.getEarliestKeyCreationTime()); chain.setLookaheadSize(10); chain.maybeLookAhead(); verifySpendableKeyChain(firstReceiveKey, secondReceiveKey, firstChangeKey, secondChangeKey, chain, "spending-wallet-account-two-serialization.txt"); }
Example #7
Source File: NetworkResolverTest.java From cate with MIT License | 5 votes |
/** * Tests the resolver maps for internal consistency. */ @Test public void shouldMapSymmetrically() { for (NetworkParameters params: NetworkResolver.getParameters()) { final String name = NetworkResolver.getName(params); final NetworkResolver.NetworkCode code = NetworkResolver.getCode(params); assertEquals(params, NetworkResolver.getParameter(name)); assertEquals(params, NetworkResolver.getParameter(code)); } }
Example #8
Source File: MarriedKeyChain.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Override protected void formatAddresses(boolean includePrivateKeys, NetworkParameters params, StringBuilder builder2) { for (DeterministicKeyChain followingChain : followingKeyChains) builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params)) .append('\n'); builder2.append('\n'); for (RedeemData redeemData : marriedKeysRedeemData.values()) formatScript(ScriptBuilder.createP2SHOutputScript(redeemData.redeemScript), builder2, params); }
Example #9
Source File: AddressGroupingItem.java From consensusj with Apache License 2.0 | 5 votes |
public AddressGroupingItem(List<Object> addressItem, NetworkParameters netParams) { String addressStr = (String) addressItem.get(0); //TODO: Try to avoid using Double Double balanceDouble = (Double) addressItem.get(1); account = (addressItem.size() > 2) ? (String) addressItem.get(2) : null; address = Address.fromString(netParams, addressStr); balance = Coin.valueOf(((Double)(balanceDouble * 100000000.0)).longValue()); }
Example #10
Source File: TransactionConfirmationAlert.java From cate with MIT License | 5 votes |
public TransactionConfirmationAlert(final NetworkParameters params, final ResourceBundle resources) { super(Alert.AlertType.CONFIRMATION); setTitle(resources.getString("sendCoins.confirm.title")); addressLabel.setText(resources.getString("sendCoins.confirm.address")); addressLabel.getStyleClass().add("label-heading"); amountLabel.setText(resources.getString("sendCoins.confirm.amount")); amountLabel.getStyleClass().add("label-heading"); memoLabel.setText(resources.getString("sendCoins.confirm.memo")); memoLabel.getStyleClass().add("label-heading"); format = params.getMonetaryFormat(); grid = new GridPane(); contentTextProperty().addListener((observable, oldVal, newVal) -> { content.setText(newVal); }); amountProperty().addListener((observable, oldVal, newVal) -> { amount.setText(format.format(newVal).toString()); }); addressProperty().addListener((observable, oldVal, newVal) -> { address.setText(newVal.toBase58()); }); grid.setHgap(MainController.DIALOG_HGAP); grid.setVgap(MainController.DIALOG_VGAP); int row = 0; grid.addRow(row++, content); grid.addRow(row++, addressLabel, address); grid.addRow(row++, memoLabel, memo); grid.addRow(row++, amountLabel, amount); getDialogPane().getStylesheets().add(CATE.DEFAULT_STYLESHEET); getDialogPane().setContent(grid); }
Example #11
Source File: ExamplePaymentChannelServer.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public void run(NetworkParameters params) throws Exception { // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so // the plugin that knows how to parse all the additional data is present during the load. appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") { @Override protected List<WalletExtension> provideWalletExtensions() { // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting // the refund transaction if its lock time has expired. It also persists channels so we can resume them // after a restart. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelServerStates(null)); } }; // Broadcasting can take a bit of time so we up the timeout for "real" networks final int timeoutSeconds = params.getId().equals(NetworkParameters.ID_REGTEST) ? 15 : 150; if (params == RegTestParams.get()) { appKit.connectToLocalHost(); } appKit.startAsync(); appKit.awaitRunning(); System.out.println(appKit.wallet()); // We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and // an implementation of HandlerFactory, which we just implement ourselves. new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), timeoutSeconds, Coin.valueOf(100000), this).bindAndStart(4242); }
Example #12
Source File: Networks.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public static void unregister(NetworkParameters network) { if (networks.contains(network)) { ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder(); for (NetworkParameters parameters : networks) { if (parameters.equals(network)) continue; builder.add(parameters); } networks = builder.build(); } }
Example #13
Source File: SPV.java From GreenBits with GNU General Public License v3.0 | 5 votes |
private void addPeer(final String address, final NetworkParameters params) throws URISyntaxException { try { mPeerGroup.addAddress(getPeerAddress(address)); } catch (final UnknownHostException e) { // FIXME: Should report this error: one the host here couldn't be resolved e.printStackTrace(); } }
Example #14
Source File: MarriedKeyChain.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override protected void formatAddresses(boolean includePrivateKeys, NetworkParameters params, StringBuilder builder2) { for (DeterministicKeyChain followingChain : followingKeyChains) builder2.append("Following chain: ").append(followingChain.getWatchingKey().serializePubB58(params)) .append('\n'); builder2.append('\n'); for (RedeemData redeemData : marriedKeysRedeemData.values()) formatScript(ScriptBuilder.createP2SHOutputScript(redeemData.redeemScript), builder2, params); }
Example #15
Source File: RpcClientModule.java From consensusj with Apache License 2.0 | 5 votes |
public RpcClientModule(NetworkParameters netParams) { super("BitcoinJMappingClient", new Version(1, 0, 0, null, null, null)); this.addDeserializer(Address.class, new AddressDeserializer(netParams)) .addDeserializer(Block.class, new BlockHexDeserializer(netParams)) .addDeserializer(Coin.class, new CoinDeserializer()) .addDeserializer(ECKey.class, new ECKeyDeserializer()) .addDeserializer(Sha256Hash.class, new Sha256HashDeserializer()) .addSerializer(Address.class, new AddressSerializer()) .addSerializer(Coin.class, new CoinSerializer()) .addSerializer(ECKey.class, new ECKeySerializer()) .addSerializer(Sha256Hash.class, new Sha256HashSerializer()) .addSerializer(Transaction.class, new TransactionHexSerializer()); }
Example #16
Source File: WalletProtobufSerializer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
/** * Cheap test to see if input stream is a wallet. This checks for a magic value at the beginning of the stream. * * @param is input stream to test * @return true if input stream is a wallet */ public static boolean isWallet(InputStream is) { try { final CodedInputStream cis = CodedInputStream.newInstance(is); final int tag = cis.readTag(); final int field = WireFormat.getTagFieldNumber(tag); if (field != 1) // network_identifier return false; final String network = cis.readString(); return NetworkParameters.fromID(network) != null; } catch (IOException x) { return false; } }
Example #17
Source File: Socks5DnsDiscovery.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private static List<PeerDiscovery> buildDiscoveries(Socks5Proxy proxy, NetworkParameters params, String[] seeds) { List<PeerDiscovery> discoveries = new ArrayList<>(seeds.length); for (String seed : seeds) discoveries.add(new Socks5DnsSeedDiscovery(proxy, params, seed)); return discoveries; }
Example #18
Source File: BackupToMnemonicSeed.java From green_android with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { NetworkParameters params = TestNet3Params.get(); Wallet wallet = new Wallet(params); DeterministicSeed seed = wallet.getKeyChainSeed(); System.out.println("seed: " + seed.toString()); System.out.println("creation time: " + seed.getCreationTimeSeconds()); System.out.println("mnemonicCode: " + Utils.join(seed.getMnemonicCode())); }
Example #19
Source File: SPV.java From green_android with GNU General Public License v3.0 | 5 votes |
private void addPeer(final String address, final NetworkParameters params) throws URISyntaxException { try { mPeerGroup.addAddress(getPeerAddress(address)); } catch (final UnknownHostException e) { // FIXME: Should report this error: one the host here couldn't be resolved e.printStackTrace(); } }
Example #20
Source File: WorldMobileCoin.java From bisq-assets with GNU Affero General Public License v3.0 | 5 votes |
private WitnessAddress(NetworkParameters params, byte[] data) throws AddressFormatException { super(params.getAddressHeader(), data); if (data.length < 1) throw new AddressFormatException("Zero data found"); final int version = getWitnessVersion(); if (version < 0 || version > 16) throw new AddressFormatException("Invalid script version: " + version); byte[] program = getWitnessProgram(); if (program.length < PROGRAM_MIN_LENGTH || program.length > PROGRAM_MAX_LENGTH) throw new AddressFormatException("Invalid length: " + program.length); if (version == 0 && program.length != PROGRAM_LENGTH_PKH && program.length != PROGRAM_LENGTH_SH) throw new AddressFormatException( "Invalid length for address version 0: " + program.length); }
Example #21
Source File: KeyChainGroup.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys, KeyChainFactory factory) throws UnreadableWalletException { BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys); List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null, factory); EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null; if (!chains.isEmpty()) currentKeys = createCurrentKeysMap(chains); extractFollowingKeychains(chains); return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, null); }
Example #22
Source File: RpcServerModule.java From consensusj with Apache License 2.0 | 5 votes |
public RpcServerModule(NetworkParameters netParams) { super("BitcoinJMappingServer", new Version(1, 0, 0, null, null, null)); this.addDeserializer(Address.class, new AddressDeserializer(netParams)) // Null means use default list of netParams .addDeserializer(Coin.class, new CoinDeserializer()) .addDeserializer(ECKey.class, new ECKeyDeserializer()) .addDeserializer(Sha256Hash.class, new Sha256HashDeserializer()) .addSerializer(Address.class, new AddressSerializer()) .addSerializer(Coin.class, new CoinSerializer()) .addSerializer(ECKey.class, new ECKeySerializer()) .addSerializer(Peer.class, new PeerSerializer()) .addSerializer(Sha256Hash.class, new Sha256HashSerializer()) .addSerializer(Transaction.class, new TransactionSerializer()); }
Example #23
Source File: StratumClient.java From java-stratum with Apache License 2.0 | 5 votes |
public StratumClient(NetworkParameters params, List<InetSocketAddress> addresses, boolean isTls) { this.params = params; serverAddresses = (addresses != null) ? addresses : getDefaultAddresses(); mapper = new ObjectMapper(); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); currentId = new AtomicLong(1000); calls = Maps.newConcurrentMap(); subscriptions = Maps.newConcurrentMap(); lock = lockFactory.newReentrantLock("StratumClient-stream"); this.isTls = isTls; subscribedAddresses = Maps.newConcurrentMap(); }
Example #24
Source File: BinHelper.java From smartcoins-wallet with MIT License | 5 votes |
public void getBinBytesFromWif(final String pin, final String wif_key, final String accountName) { Log.d(TAG, "getBinBytesFromWif. pin: " + pin + ", wif_key: " + wif_key + ", accountName: " + accountName); //Fill with an invalid brainkey to not break the backup format (The presence of brainkey seems mandatory) BrainKey brainKey = new BrainKey("NOT A VALID BRAINKEY (PREVIOUSLY WIF IMPORTED ACCOUNT)", 0); try { ArrayList<Wallet> wallets = new ArrayList<>(); ArrayList<LinkedAccount> accounts = new ArrayList<>(); ArrayList<PrivateKeyBackup> keys = new ArrayList<>(); Wallet wallet = new Wallet(accountName, brainKey.getBrainKey(), brainKey.getSequenceNumber(), Chains.BITSHARES.CHAIN_ID, pin); wallets.add(wallet); String wif = Crypt.getInstance().decrypt_string(wif_key); ECKey key = DumpedPrivateKey.fromBase58(NetworkParameters.fromID(NetworkParameters.ID_MAINNET), wif).getKey(); PrivateKeyBackup keyBackup = new PrivateKeyBackup(key.getPrivKeyBytes(), brainKey.getSequenceNumber(), brainKey.getSequenceNumber(), wallet.getEncryptionKey(pin)); keys.add(keyBackup); LinkedAccount linkedAccount = new LinkedAccount(accountName, Chains.BITSHARES.CHAIN_ID); accounts.add(linkedAccount); WalletBackup backup = new WalletBackup(wallets, keys, accounts); byte[] results = FileBin.serializeWalletBackup(backup, pin); List<Integer> resultFile = new ArrayList<>(); for (byte result : results) { resultFile.add(result & 0xff); } saveBinContentToFile(resultFile, accountName); } catch (Exception e) { hideDialog(false); Log.e(TAG, "Exception. Msg: " + e.getMessage()); Toast.makeText(myActivity, myActivity.getResources().getString(R.string.unable_to_generate_bin_format_for_key), Toast.LENGTH_SHORT).show(); } }
Example #25
Source File: ExamplePaymentChannelServer.java From green_android with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { BriefLogFormatter.init(); OptionParser parser = new OptionParser(); OptionSpec<NetworkEnum> net = parser.accepts("net", "The network to run the examples on").withRequiredArg().ofType(NetworkEnum.class).defaultsTo(NetworkEnum.TEST); parser.accepts("help", "Displays program options"); OptionSet opts = parser.parse(args); if (opts.has("help") || !opts.has(net)) { System.err.println("usage: ExamplePaymentChannelServer --net=MAIN/TEST/REGTEST"); parser.printHelpOn(System.err); return; } NetworkParameters params = net.value(opts).get(); new ExamplePaymentChannelServer().run(params); }
Example #26
Source File: SendRequest.java From green_android with GNU General Public License v3.0 | 5 votes |
public static SendRequest toCLTVPaymentChannel(NetworkParameters params, BigInteger time, ECKey from, ECKey to, Coin value) { SendRequest req = new SendRequest(); Script output = ScriptBuilder.createCLTVPaymentChannelOutput(time, from, to); req.tx = new Transaction(params); req.tx.addOutput(value, output); return req; }
Example #27
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void setUTXO(List<UTXOItemDgb> utxoList) { Address a; if (restFromWif) { if (wallet.getImportedKeys().size() == 0) return; a = wallet.getImportedKeys().get(0).toAddress(params); } else { a = wallet.currentReceiveAddress(); } final List<UTXO> utxos = new ArrayList<>(); for (UTXOItemDgb 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 #28
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
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 #29
Source File: DefaultCoinSelector.java From green_android with GNU General Public License v3.0 | 5 votes |
public static boolean isSelectable(Transaction tx) { // Only pick chain-included transactions, or transactions that are ours and pending. TransactionConfidence confidence = tx.getConfidence(); TransactionConfidence.ConfidenceType type = confidence.getConfidenceType(); return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || type.equals(TransactionConfidence.ConfidenceType.PENDING) && confidence.getSource().equals(TransactionConfidence.Source.SELF) && // In regtest mode we expect to have only one peer, so we won't see transactions propagate. // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0 (confidence.numBroadcastPeers() > 1 || tx.getParams().getId().equals(NetworkParameters.ID_REGTEST)); }
Example #30
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
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); }