gpt4 book ai didi

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

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

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

WalletProtobufSerializer.walletToProto介绍

[英]Converts the given wallet to the object representation of the protocol buffers. This can be modified, or additional data fields set, before serialization takes place.
[中]将给定钱包转换为协议缓冲区的对象表示形式。在进行序列化之前,可以对其进行修改或设置其他数据字段。

代码示例

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

/**
 * Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.<p>
 *
 * Equivalent to <tt>walletToProto(wallet).writeTo(output);</tt>
 */
public void writeWallet(Wallet wallet, OutputStream output) throws IOException {
  Protos.Wallet walletProto = walletToProto(wallet);
  walletProto.writeTo(output);
}

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

/**
 * Returns the given wallet formatted as text. The text format is that used by protocol buffers and although it
 * can also be parsed using {@link TextFormat#merge(CharSequence, com.google.protobuf.Message.Builder)},
 * it is designed more for debugging than storage. It is not well specified and wallets are largely binary data
 * structures anyway, consisting as they do of keys (large random numbers) and {@link Transaction}s which also
 * mostly contain keys and hashes.
 */
public String walletToText(Wallet wallet) {
  Protos.Wallet walletProto = walletToProto(wallet);
  return TextFormat.printToString(walletProto);
}

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

/**
 * Returns the given wallet formatted as text. The text format is that used by protocol buffers and although it
 * can also be parsed using {@link TextFormat#merge(CharSequence, com.google.protobuf.Message.Builder)},
 * it is designed more for debugging than storage. It is not well specified and wallets are largely binary data
 * structures anyway, consisting as they do of keys (large random numbers) and {@link Transaction}s which also
 * mostly contain keys and hashes.
 */
public String walletToText(Wallet wallet) {
  Protos.Wallet walletProto = walletToProto(wallet);
  return TextFormat.printToString(walletProto);
}

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

/**
 * Returns the given wallet formatted as text. The text format is that used by protocol buffers and although it
 * can also be parsed using {@link TextFormat#merge(CharSequence, com.google.protobuf.Message.Builder)},
 * it is designed more for debugging than storage. It is not well specified and wallets are largely binary data
 * structures anyway, consisting as they do of keys (large random numbers) and {@link Transaction}s which also
 * mostly contain keys and hashes.
 */
public String walletToText(Wallet wallet) {
  Protos.Wallet walletProto = walletToProto(wallet);
  return TextFormat.printToString(walletProto);
}

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

/**
 * Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.<p>
 *
 * Equivalent to <tt>walletToProto(wallet).writeTo(output);</tt>
 */
public void writeWallet(Wallet wallet, OutputStream output) throws IOException {
  Protos.Wallet walletProto = walletToProto(wallet);
  walletProto.writeTo(output);
}

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

/**
 * Returns the given wallet formatted as text. The text format is that used by protocol buffers and although it
 * can also be parsed using {@link TextFormat#merge(CharSequence, com.google.protobuf.Message.Builder)},
 * it is designed more for debugging than storage. It is not well specified and wallets are largely binary data
 * structures anyway, consisting as they do of keys (large random numbers) and {@link Transaction}s which also
 * mostly contain keys and hashes.
 */
public String walletToText(Wallet wallet) {
  Protos.Wallet walletProto = walletToProto(wallet);
  return TextFormat.printToString(walletProto);
}

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

/**
 * Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.<p>
 *
 * Equivalent to <tt>walletToProto(wallet).writeTo(output);</tt>
 */
public void writeWallet(Wallet wallet, OutputStream output) throws IOException {
  Protos.Wallet walletProto = walletToProto(wallet);
  final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, this.walletWriteBufferSize);
  walletProto.writeTo(codedOutput);
  codedOutput.flush();
}

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

/**
 * Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.<p>
 *
 * Equivalent to <tt>walletToProto(wallet).writeTo(output);</tt>
 */
public void writeWallet(Wallet wallet, OutputStream output) throws IOException {
  Protos.Wallet walletProto = walletToProto(wallet);
  final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, this.walletWriteBufferSize);
  walletProto.writeTo(codedOutput);
  codedOutput.flush();
}

代码示例来源: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

@Test
public void extensionsWithError() throws Exception {
  WalletExtension extension = new WalletExtension() {
    @Override
    public String getWalletExtensionID() {
      return "test";
    }
    @Override
    public boolean isWalletExtensionMandatory() {
      return false;
    }
    @Override
    public byte[] serializeWalletExtension() {
      return new byte[0];
    }
    @Override
    public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {
      throw new NullPointerException();  // Something went wrong!
    }
  };
  myWallet.addExtension(extension);
  Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
  Wallet wallet = new WalletProtobufSerializer().readWallet(PARAMS, new WalletExtension[]{extension}, proto);
  assertEquals(0, wallet.getExtensions().size());
}

代码示例来源: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());
}

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

assertEquals(TransactionConfidence.Source.NETWORK, t1copy.getConfidence().getSource());
Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(myWallet);
assertEquals(Protos.Key.Type.ORIGINAL, walletProto.getKey(0).getType());
assertEquals(0, walletProto.getExtensionCount());

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