gpt4 book ai didi

org.bitcoinj.wallet.WalletProtobufSerializer.()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-24 23:23:05 28 4
gpt4 key购买 nike

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

WalletProtobufSerializer.<init>介绍

暂无

代码示例

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

/**
 * Uses protobuf serialization to save the wallet to the given file stream. To learn more about this file format, see
 * {@link WalletProtobufSerializer}.
 */
public void saveToFileStream(OutputStream f) throws IOException {
  lock.lock();
  try {
    new WalletProtobufSerializer().writeWallet(this, f);
  } finally {
    lock.unlock();
  }
}

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

/**
 * Uses protobuf serialization to save the wallet to the given file stream. To learn more about this file format, see
 * {@link WalletProtobufSerializer}.
 */
public void saveToFileStream(OutputStream f) throws IOException {
  lock.lock();
  try {
    new WalletProtobufSerializer().writeWallet(this, f);
  } finally {
    lock.unlock();
  }
}

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

/**
 * Uses protobuf serialization to save the wallet to the given file stream. To learn more about this file format, see
 * {@link WalletProtobufSerializer}.
 */
public void saveToFileStream(OutputStream f) throws IOException {
  lock.lock();
  try {
    new WalletProtobufSerializer().writeWallet(this, f);
  } finally {
    lock.unlock();
  }
}

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

/**
 * Uses protobuf serialization to save the wallet to the given file stream. To learn more about this file format, see
 * {@link WalletProtobufSerializer}.
 */
public void saveToFileStream(OutputStream f) throws IOException {
  lock.lock();
  try {
    new WalletProtobufSerializer().writeWallet(this, f);
  } finally {
    lock.unlock();
  }
}

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

/** Returns a wallet deserialized from the given input stream and wallet extensions. */
public static Wallet loadFromFileStream(InputStream stream, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
  Wallet wallet = new WalletProtobufSerializer().readWallet(stream, walletExtensions);
  if (!wallet.isConsistent()) {
    log.error("Loaded an inconsistent wallet");
  }
  return wallet;
}

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

/** Returns a wallet deserialized from the given input stream and wallet extensions. */
public static Wallet loadFromFileStream(InputStream stream, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
  Wallet wallet = new WalletProtobufSerializer().readWallet(stream, walletExtensions);
  if (!wallet.isConsistent()) {
    log.error("Loaded an inconsistent wallet");
  }
  return wallet;
}

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

/** Returns a wallet deserialized from the given input stream and wallet extensions. */
public static Wallet loadFromFileStream(InputStream stream, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
  Wallet wallet = new WalletProtobufSerializer().readWallet(stream, walletExtensions);
  if (!wallet.isConsistent()) {
    log.error("Loaded an inconsistent wallet");
  }
  return wallet;
}

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

/** Returns a wallet deserialized from the given input stream and wallet extensions. */
public static Wallet loadFromFileStream(InputStream stream, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
  Wallet wallet = new WalletProtobufSerializer().readWallet(stream, walletExtensions);
  if (!wallet.isConsistent()) {
    log.error("Loaded an inconsistent wallet");
  }
  return wallet;
}

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

private Wallet loadWallet(boolean shouldReplayWallet) throws Exception {
  Wallet wallet;
  FileInputStream walletStream = new FileInputStream(vWalletFile);
  try {
    List<WalletExtension> extensions = provideWalletExtensions();
    WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
    Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
    final WalletProtobufSerializer serializer;
    if (walletFactory != null)
      serializer = new WalletProtobufSerializer(walletFactory);
    else
      serializer = new WalletProtobufSerializer();
    wallet = serializer.readWallet(params, extArray, proto);
    if (shouldReplayWallet)
      wallet.reset();
  } finally {
    walletStream.close();
  }
  return wallet;
}

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

private Wallet loadWallet(boolean shouldReplayWallet) throws Exception {
  Wallet wallet;
  FileInputStream walletStream = new FileInputStream(vWalletFile);
  try {
    List<WalletExtension> extensions = provideWalletExtensions();
    WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
    Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
    final WalletProtobufSerializer serializer;
    if (walletFactory != null)
      serializer = new WalletProtobufSerializer(walletFactory);
    else
      serializer = new WalletProtobufSerializer();
    wallet = serializer.readWallet(params, extArray, proto);
    if (shouldReplayWallet)
      wallet.reset();
  } finally {
    walletStream.close();
  }
  return wallet;
}

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

private Wallet loadWallet(boolean shouldReplayWallet) throws Exception {
  Wallet wallet;
  FileInputStream walletStream = new FileInputStream(vWalletFile);
  try {
    List<WalletExtension> extensions = provideWalletExtensions();
    WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
    Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
    final WalletProtobufSerializer serializer;
    if (walletFactory != null)
      serializer = new WalletProtobufSerializer(walletFactory);
    else
      serializer = new WalletProtobufSerializer();
    wallet = serializer.readWallet(params, extArray, proto);
    if (shouldReplayWallet)
      wallet.reset();
  } finally {
    walletStream.close();
  }
  return wallet;
}

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

private Wallet loadWallet(boolean shouldReplayWallet) throws Exception {
  Wallet wallet;
  FileInputStream walletStream = new FileInputStream(vWalletFile);
  try {
    List<WalletExtension> extensions = provideWalletExtensions();
    WalletExtension[] extArray = extensions.toArray(new WalletExtension[extensions.size()]);
    Protos.Wallet proto = WalletProtobufSerializer.parseToProto(walletStream);
    final WalletProtobufSerializer serializer;
    if (walletFactory != null)
      serializer = new WalletProtobufSerializer(walletFactory);
    else
      serializer = new WalletProtobufSerializer();
    wallet = serializer.readWallet(params, extArray, proto);
    if (shouldReplayWallet)
      wallet.reset();
  } finally {
    walletStream.close();
  }
  return wallet;
}

代码示例来源:origin: uncleleonfan/FunWallet

private Wallet readWallet(File walletFile) throws FileNotFoundException, UnreadableWalletException {
  InputStream inputStream = new FileInputStream(walletFile);
  Wallet wallet  = new WalletProtobufSerializer().readWallet(inputStream);
  wallet.autosaveToFile(walletFile, 3 * 1000, TimeUnit.MILLISECONDS, null);
  wallet.cleanup();
  return wallet;
}

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

private Wallet roundTrip(Wallet wallet) throws UnreadableWalletException {
  Protos.Wallet protos = new WalletProtobufSerializer().walletToProto(wallet);
  return new WalletProtobufSerializer().readWallet(PARAMS, null, protos);
}

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

private static Wallet roundTrip(Wallet wallet) throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  new WalletProtobufSerializer().writeWallet(wallet, output);
  ByteArrayInputStream test = new ByteArrayInputStream(output.toByteArray());
  assertTrue(WalletProtobufSerializer.isWallet(test));
  ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
  return new WalletProtobufSerializer().readWallet(input);
}

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

private static Wallet roundTripClientWallet(Wallet wallet) throws Exception {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  new WalletProtobufSerializer().writeWallet(wallet, bos);
  org.bitcoinj.wallet.Protos.Wallet proto = WalletProtobufSerializer.parseToProto(new ByteArrayInputStream(bos.toByteArray()));
  StoredPaymentChannelClientStates state = new StoredPaymentChannelClientStates(null, failBroadcaster);
  return new WalletProtobufSerializer().readWallet(wallet.getParams(), new WalletExtension[] { state }, proto);
}

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

private static Wallet roundTripServerWallet(Wallet wallet) throws Exception {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  new WalletProtobufSerializer().writeWallet(wallet, bos);
  StoredPaymentChannelServerStates state = new StoredPaymentChannelServerStates(null, failBroadcaster);
  org.bitcoinj.wallet.Protos.Wallet proto = WalletProtobufSerializer.parseToProto(new ByteArrayInputStream(bos.toByteArray()));
  return new WalletProtobufSerializer().readWallet(wallet.getParams(), new WalletExtension[] { state }, proto);
}

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

@Test(expected = UnreadableWalletException.FutureVersion.class)
  public void versions() throws Exception {
    Protos.Wallet.Builder proto = Protos.Wallet.newBuilder(new WalletProtobufSerializer().walletToProto(myWallet));
    proto.setVersion(2);
    new WalletProtobufSerializer().readWallet(PARAMS, null, proto.build());
  }
}

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

@Test
public void extensions() throws Exception {
  myWallet.addExtension(new FooWalletExtension("com.whatever.required", true));
  Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
  // Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
  try {
    new WalletProtobufSerializer().readWallet(PARAMS, null, proto);
    fail();
  } catch (UnreadableWalletException e) {
    assertTrue(e.getMessage().contains("mandatory"));
  }
  Wallet wallet = new WalletProtobufSerializer().readWallet(PARAMS,
      new WalletExtension[]{ new FooWalletExtension("com.whatever.required", true) },
      proto);
  assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
  // Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
  Wallet wallet2 = new Wallet(PARAMS);
  wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
  Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
  Wallet wallet5 = new WalletProtobufSerializer().readWallet(PARAMS, null, proto2);
  assertEquals(0, wallet5.getExtensions().size());
}

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

@Test
public void testLastBlockSeenHash() throws Exception {
  // Test the lastBlockSeenHash field works.
  // LastBlockSeenHash should be empty if never set.
  Wallet wallet = new Wallet(PARAMS);
  Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(wallet);
  ByteString lastSeenBlockHash = walletProto.getLastSeenBlockHash();
  assertTrue(lastSeenBlockHash.isEmpty());
  // Create a block.
  Block block = PARAMS.getDefaultSerializer().makeBlock(BlockTest.blockBytes);
  Sha256Hash blockHash = block.getHash();
  wallet.setLastBlockSeenHash(blockHash);
  wallet.setLastBlockSeenHeight(1);
  // Roundtrip the wallet and check it has stored the blockHash.
  Wallet wallet1 = roundTrip(wallet);
  assertEquals(blockHash, wallet1.getLastBlockSeenHash());
  assertEquals(1, wallet1.getLastBlockSeenHeight());
  // Test the Satoshi genesis block (hash of all zeroes) is roundtripped ok.
  Block genesisBlock = MainNetParams.get().getGenesisBlock();
  wallet.setLastBlockSeenHash(genesisBlock.getHash());
  Wallet wallet2 = roundTrip(wallet);
  assertEquals(genesisBlock.getHash(), wallet2.getLastBlockSeenHash());
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com