org.bitcoinj.core.Utils.now()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.bitcoinj.core.Utils.now()方法的一些代码示例,展示了Utils.now()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.now()方法的具体详情如下:
包路径:org.bitcoinj.core.Utils
类名称:Utils
方法名:now

Utils.now介绍

[英]Returns the current time, or a mocked out equivalent.
[中]返回当前时间或模拟的等效时间。

代码示例

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/**
 * 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;
}

代码示例来源:origin: greenaddress/GreenBits

/**
 * 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;
}

代码示例来源:origin: fr.acinq/bitcoinj-core

/**
 * 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;
}

代码示例来源:origin: HashEngineering/dashj

/**
 * 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;
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

/**
 * 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();
}

代码示例来源:origin: fr.acinq/bitcoinj-core

log.info("commitTx of {}", tx.getHashAsString());
Coin balance = getBalance();
tx.setUpdateTime(Utils.now());

代码示例来源:origin: greenaddress/GreenBits

log.info("commitTx of {}", tx.getHashAsString());
Coin balance = getBalance();
tx.setUpdateTime(Utils.now());

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

log.info("commitTx of {}", tx.getHashAsString());
Coin balance = getBalance();
tx.setUpdateTime(Utils.now());

代码示例来源:origin: greenaddress/GreenBits

@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));
}

代码示例来源:origin: HashEngineering/dashj

log.info("commitTx of {}", tx.getHashAsString());
Coin balance = getBalance();
tx.setUpdateTime(Utils.now());

代码示例来源:origin: greenaddress/GreenBits

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());
}

代码示例来源:origin: greenaddress/GreenBits

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));

相关文章