public BitcoinCrypto(NetworkParameters networkParameters, DeterministicSeed seed) throws Exception, NoSuchAlgorithmException { this.params = NetworkParameters.fromID(networkParameters.getId()); this.keyChainGroup = new KeyChainGroup(networkParameters, seed); Security.insertProviderAt(new BouncyCastleProvider(), 1); crashIfJCEMissing(); //this.sr = SecureRandom.getInstance("SHA1PRNG", new BouncyCastleProvider()); this.sr = SecureRandom.getInstance("SHA1PRNG"); this.keyPG = KeyPairGenerator.getInstance("ECIES", new BouncyCastleProvider()); //this.kit = initKit(seed); //this.wallet = kit.wallet(); }
@Override public boolean equals(ValueType obj) { return super.equals(obj); }
private static byte[] getBytes(final NetworkParameters params, final int version, final byte[] hash) { if (version == params.getAddressHeader()) return hash; if (version == params.getP2SHHeader()) return hash; if (version == params.getP2WPKHHeader() || version == params.getP2WSHHeader()) { final byte[] bytes = new byte[hash.length + 2]; System.arraycopy(hash, 0, bytes, 2, hash.length); return bytes; } throw new IllegalArgumentException("Could not figure out how to serialize address"); } }
public Btcd(NetworkParameters netParams, String rpcuser, String rpcpass) throws MalformedURLException { super(netParams, 0); this.rpcuser = rpcuser; this.rpcpass = rpcpass; if (netParams.equals(NetworkParameters.fromID(NetworkParameters.ID_MAINNET))) { url = new URL("http://127.0.0.1:8334"); } else if (netParams.equals(NetworkParameters.fromID(NetworkParameters.ID_TESTNET))) { url = new URL("http://127.0.0.1:18334"); } else { throw new IllegalArgumentException("Invalid network parameters passed to btcd. "); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); params = NetworkParameters.fromID(in.readUTF()); } }
params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (params.hasMaxMoney() && totalValue.compareTo(params.getMaxMoney()) > 0) throw new PaymentProtocolException.InvalidOutputs("The outputs are way too big."); } catch (InvalidProtocolBufferException e) {
/** * Constructs a peer address from the given IP address. Port is default for * Bitcoin mainnet, version number is default for the given parameters. */ public PeerAddress(NetworkParameters params, InetAddress addr) { this(params, addr, params.getPort()); }
/** * Set the serializer for this message when deserialized by Java. */ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (null != params) { this.serializer = params.getDefaultSerializer(); } } }
boolean filtered = filteredTxHashList != null && filteredTxn != null; if (!params.passesCheckpoint(storedPrev.getHeight() + 1, block.getHash())) throw new VerificationException("Block failed checkpoint lockin at " + (storedPrev.getHeight() + 1)); if (shouldVerifyTransactions()) { final Integer count = versionTally.getCountAtOrAbove(block.getVersion() + 1); if (count != null && count >= params.getMajorityRejectBlockOutdated()) { throw new VerificationException.BlockVersionOutOfDate(block.getVersion());
public MemoryBlockStore(NetworkParameters params) { // Insert the genesis block. try { Block genesisHeader = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesisHeader, genesisHeader.getWork(), 0); put(storedGenesis); setChainHead(storedGenesis); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
/** * Construct an address from parameters and the hash160 form. Example:<p> * * <pre>new Address(MainNetParams.get(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));</pre> */ public Address(NetworkParameters params, byte[] hash160) { super(params.getAddressHeader(), hash160); checkArgument(hash160.length == 20, "Addresses are 160-bit hashes, so you must provide 20 bytes"); this.params = params; }
final int UNDOABLE_BLOCKS_STORED = PARAMS.getMajorityEnforceBlockUpgrade() + 1; store = createStore(PARAMS, UNDOABLE_BLOCKS_STORED); try { ECKey outKey = new ECKey(); int height = 1; Block chainHead = PARAMS.getGenesisBlock(); for (height = 1; height <= (PARAMS.getMajorityWindow() - PARAMS.getMajorityEnforceBlockUpgrade()); height++) { chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height); for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_BIP34, outKey.getPubKey(), height);
/** * The flags indicating which block validation tests should be applied to * the given block. Enables support for alternative blockchains which enable * tests based on different criteria. * * @param block block to determine flags for. * @param height height of the block, if known, null otherwise. Returned * tests should be a safe subset if block height is unknown. */ public EnumSet<Block.VerifyFlag> getBlockVerificationFlags(final Block block, final VersionTally tally, final Integer height) { final EnumSet<Block.VerifyFlag> flags = EnumSet.noneOf(Block.VerifyFlag.class); if (block.isBIP34()) { final Integer count = tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP34); if (null != count && count >= getMajorityEnforceBlockUpgrade()) { flags.add(Block.VerifyFlag.HEIGHT_IN_COINBASE); } } return flags; }
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion) throws Exception { final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS); final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore); // Build a historical chain of version 3 blocks long timeSeconds = 1231006505; int height = 0; FakeTxBuilder.BlockPair chainHead = null; // Put in just enough v2 blocks to be a minority for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } // Fill the rest of the window with v3 blocks for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); // Trying to add a new v2 block should result in rejection thrown.expect(VerificationException.BlockVersionOutOfDate.class); try { versionChain.add(chainHead.block); } catch(final VerificationException ex) { throw (Exception) ex.getCause(); } }
params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork());
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); params = NetworkParameters.fromID(in.readUTF()); } }
params = MainNetParams.get(); else params = NetworkParameters.fromPmtProtocolID(paymentDetails.getNetwork()); if (params == null) throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork()); if (params.hasMaxMoney() && totalValue.compareTo(params.getMaxMoney()) > 0) throw new PaymentProtocolException.InvalidOutputs("The outputs are way too big."); } catch (InvalidProtocolBufferException e) {
/** * Constructs a peer address from the given IP address. Port and version number are default for the given * parameters. */ public PeerAddress(NetworkParameters params, InetAddress addr) { this(params, addr, params.getPort()); }
/** * Set the serializer for this message when deserialized by Java. */ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (null != params) { this.serializer = params.getDefaultSerializer(); } } }