/** * Called by a {@link Peer} when a transaction is pending and announced by a peer. The more peers announce the * transaction, the more peers have validated it (assuming your internet connection is not being intercepted). * If confidence is currently unknown, sets it to {@link ConfidenceType#PENDING}. Does not run listeners. * * @param address IP address of the peer, used as a proxy for identity. * @return true if marked, false if this address was already seen */ public boolean markBroadcastBy(PeerAddress address) { lastBroadcastedAt = Utils.now(); if (!broadcastBy.addIfAbsent(address)) return false; // Duplicate. synchronized (this) { if (getConfidenceType() == ConfidenceType.UNKNOWN) { this.confidenceType = ConfidenceType.PENDING; } } return true; }
/** * Called by a {@link Peer} when a transaction is pending and announced by a peer. The more peers announce the * transaction, the more peers have validated it (assuming your internet connection is not being intercepted). * If confidence is currently unknown, sets it to {@link ConfidenceType#PENDING}. Does not run listeners. * * @param address IP address of the peer, used as a proxy for identity. * @return true if marked, false if this address was already seen */ public boolean markBroadcastBy(PeerAddress address) { lastBroadcastedAt = Utils.now(); if (!broadcastBy.addIfAbsent(address)) return false; // Duplicate. synchronized (this) { if (getConfidenceType() == ConfidenceType.UNKNOWN) { this.confidenceType = ConfidenceType.PENDING; } } return true; }
/** * Called by a {@link Peer} when a transaction is pending and announced by a peer. The more peers announce the * transaction, the more peers have validated it (assuming your internet connection is not being intercepted). * If confidence is currently unknown, sets it to {@link ConfidenceType#PENDING}. Does not run listeners. * * @param address IP address of the peer, used as a proxy for identity. * @return true if marked, false if this address was already seen */ public boolean markBroadcastBy(PeerAddress address) { lastBroadcastedAt = Utils.now(); if (!broadcastBy.addIfAbsent(address)) return false; // Duplicate. synchronized (this) { if (getConfidenceType() == ConfidenceType.UNKNOWN) { this.confidenceType = ConfidenceType.PENDING; } } return true; }
/** * Called by a {@link Peer} when a transaction is pending and announced by a peer. The more peers announce the * transaction, the more peers have validated it (assuming your internet connection is not being intercepted). * If confidence is currently unknown, sets it to {@link ConfidenceType#PENDING}. Does not run listeners. * * @param address IP address of the peer, used as a proxy for identity. * @return true if marked, false if this address was already seen */ public boolean markBroadcastBy(PeerAddress address) { lastBroadcastedAt = Utils.now(); if (!broadcastBy.addIfAbsent(address)) return false; // Duplicate. synchronized (this) { if (getConfidenceType() == ConfidenceType.UNKNOWN) { this.confidenceType = ConfidenceType.PENDING; } } return true; }
/** * Constructor an HD address. * * @param params NetworkParameters * @param cKey deterministic key for this address * @param child index of this address in its chain */ public HDAddress(NetworkParameters params, DeterministicKey cKey, int child) { this.params = params; childNum = child; DeterministicKey dk = HDKeyDerivation.deriveChildKey(cKey, new ChildNumber(childNum, false)); // compressed WIF private key format if (dk.hasPrivKey()) { byte[] prepended0Byte = ArrayUtils.addAll(new byte[1], dk.getPrivKeyBytes()); ecKey = ECKey.fromPrivate(new BigInteger(prepended0Byte), true); } else { ecKey = ECKey.fromPublicOnly(dk.getPubKey()); } long now = Utils.now().getTime() / 1000; // use Unix time (in seconds) ecKey.setCreationTimeSeconds(now); pubKey = ecKey.getPubKey(); pubKeyHash = ecKey.getPubKeyHash(); strPath = dk.getPathAsString(); }
log.info("commitTx of {}", tx.getHashAsString()); Coin balance = getBalance(); tx.setUpdateTime(Utils.now());
log.info("commitTx of {}", tx.getHashAsString()); Coin balance = getBalance(); tx.setUpdateTime(Utils.now());
log.info("commitTx of {}", tx.getHashAsString()); Coin balance = getBalance(); tx.setUpdateTime(Utils.now());
@Test public void serializationUnencrypted() throws UnreadableWalletException { Utils.setMockClock(); Date now = Utils.now(); final ECKey key1 = new ECKey(); Utils.rollMockClock(5000); final ECKey key2 = new ECKey(); chain.importKeys(ImmutableList.of(key1, key2)); List<Protos.Key> keys = chain.serializeToProtobuf(); assertEquals(2, keys.size()); assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray()); assertArrayEquals(key2.getPubKey(), keys.get(1).getPublicKey().toByteArray()); assertArrayEquals(key1.getPrivKeyBytes(), keys.get(0).getSecretBytes().toByteArray()); assertArrayEquals(key2.getPrivKeyBytes(), keys.get(1).getSecretBytes().toByteArray()); long normTime = (long) (Math.floor(now.getTime() / 1000) * 1000); assertEquals(normTime, keys.get(0).getCreationTimestamp()); assertEquals(normTime + 5000 * 1000, keys.get(1).getCreationTimestamp()); chain = BasicKeyChain.fromProtobufUnencrypted(keys); assertEquals(2, chain.getKeys().size()); assertEquals(key1, chain.getKeys().get(0)); assertEquals(key2, chain.getKeys().get(1)); }
log.info("commitTx of {}", tx.getHashAsString()); Coin balance = getBalance(); tx.setUpdateTime(Utils.now());
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()); }
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(PARAMS)); sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(PARAMS)); Date compromiseTime = Utils.now(); assertEquals(0, broadcaster.size()); assertFalse(wallet.isKeyRotating(key1));