当前位置: 首页>>代码示例>>Java>>正文


Java Protos.Wallet方法代码示例

本文整理汇总了Java中org.bitcoinj.wallet.Protos.Wallet方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.Wallet方法的具体用法?Java Protos.Wallet怎么用?Java Protos.Wallet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.wallet.Protos的用法示例。


在下文中一共展示了Protos.Wallet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extensions

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@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());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:24,代码来源:WalletProtobufSerializerTest.java

示例2: attemptHexConversion

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
private static Protos.Wallet attemptHexConversion(Protos.Wallet proto) {
    // Try to convert any raw hashes and such to textual equivalents for easier debugging. This makes it a bit
    // less "raw" but we will just abort on any errors.
    try {
        Protos.Wallet.Builder builder = proto.toBuilder();
        for (Protos.Transaction.Builder tx : builder.getTransactionBuilderList()) {
            tx.setHash(bytesToHex(tx.getHash()));
            for (int i = 0; i < tx.getBlockHashCount(); i++)
                tx.setBlockHash(i, bytesToHex(tx.getBlockHash(i)));
            for (Protos.TransactionInput.Builder input : tx.getTransactionInputBuilderList())
                input.setTransactionOutPointHash(bytesToHex(input.getTransactionOutPointHash()));
            for (Protos.TransactionOutput.Builder output : tx.getTransactionOutputBuilderList()) {
                if (output.hasSpentByTransactionHash())
                    output.setSpentByTransactionHash(bytesToHex(output.getSpentByTransactionHash()));
            }
            // TODO: keys, ip addresses etc.
        }
        return builder.build();
    } catch (Throwable throwable) {
        log.error("Failed to do hex conversion on wallet proto", throwable);
        return proto;
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:24,代码来源:WalletTool.java

示例3: testExtensions

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void testExtensions() throws Exception {
    myWallet.addExtension(new SomeFooExtension("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 SomeFooExtension("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 SomeFooExtension("com.whatever.optional", false));
    Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
    Wallet wallet5 = new WalletProtobufSerializer().readWallet(params, null, proto2);
    assertEquals(0, wallet5.getExtensions().size());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:24,代码来源:WalletProtobufSerializerTest.java

示例4: loadExtensions

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
private void loadExtensions(Wallet wallet, Protos.Wallet walletProto) throws UnreadableWalletException {
    final Map<String, WalletExtension> extensions = wallet.getExtensions();
    for (Protos.Extension extProto : walletProto.getExtensionList()) {
        String id = extProto.getId();
        WalletExtension extension = extensions.get(id);
        if (extension == null) {
            if (extProto.getMandatory()) {
                if (requireMandatoryExtensions)
                    throw new UnreadableWalletException("Unknown mandatory extension in wallet: " + id);
                else
                    log.error("Unknown extension in wallet {}, ignoring", id);
            }
        } else {
            log.info("Loading wallet extension {}", id);
            try {
                extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
            } catch (Exception e) {
                if (extProto.getMandatory() && requireMandatoryExtensions)
                    throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);
                else
                    log.error("Error whilst reading extension {}, ignoring: {}", id, e);
            }
        }
    }
}
 
开发者ID:pavel4n,项目名称:wowdoge.org,代码行数:26,代码来源:WalletProtobufSerializer.java

示例5: oneTx

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void oneTx() throws Exception {
    // Check basic tx serialization.
    Coin v1 = COIN;
    Transaction t1 = createFakeTx(PARAMS, v1, myAddress);
    t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("1.2.3.4")));
    t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("5.6.7.8")));
    t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    myWallet.receivePending(t1, null);
    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(1, wallet1.getTransactions(true).size());
    assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
    Transaction t1copy = wallet1.getTransaction(t1.getHash());
    assertArrayEquals(t1.unsafeBitcoinSerialize(), t1copy.unsafeBitcoinSerialize());
    assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
    assertNotNull(t1copy.getConfidence().getLastBroadcastedAt());
    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());
    assertEquals(1, walletProto.getTransactionCount());
    assertEquals(6, walletProto.getKeyCount());
    
    Protos.Transaction t1p = walletProto.getTransaction(0);
    assertEquals(0, t1p.getBlockHashCount());
    assertArrayEquals(t1.getHash().getBytes(), t1p.getHash().toByteArray());
    assertEquals(Protos.Transaction.Pool.PENDING, t1p.getPool());
    assertFalse(t1p.hasLockTime());
    assertFalse(t1p.getTransactionInput(0).hasSequence());
    assertArrayEquals(t1.getInputs().get(0).getOutpoint().getHash().getBytes(),
            t1p.getTransactionInput(0).getTransactionOutPointHash().toByteArray());
    assertEquals(0, t1p.getTransactionInput(0).getTransactionOutPointIndex());
    assertEquals(t1p.getTransactionOutput(0).getValue(), v1.value);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:36,代码来源:WalletProtobufSerializerTest.java

示例6: testLastBlockSeenHash

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@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());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:28,代码来源:WalletProtobufSerializerTest.java

示例7: extensionsWithError

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@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());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:29,代码来源:WalletProtobufSerializerTest.java

示例8: oneTx

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void oneTx() throws Exception {
    // Check basic tx serialization.
    Coin v1 = COIN;
    Transaction t1 = createFakeTx(params, v1, myAddress);
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
    t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    myWallet.receivePending(t1, null);
    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(1, wallet1.getTransactions(true).size());
    assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
    Transaction t1copy = wallet1.getTransaction(t1.getHash());
    assertArrayEquals(t1.bitcoinSerialize(), t1copy.bitcoinSerialize());
    assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
    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());
    assertEquals(1, walletProto.getTransactionCount());
    assertEquals(6, walletProto.getKeyCount());
    
    Protos.Transaction t1p = walletProto.getTransaction(0);
    assertEquals(0, t1p.getBlockHashCount());
    assertArrayEquals(t1.getHash().getBytes(), t1p.getHash().toByteArray());
    assertEquals(Protos.Transaction.Pool.PENDING, t1p.getPool());
    assertFalse(t1p.hasLockTime());
    assertFalse(t1p.getTransactionInput(0).hasSequence());
    assertArrayEquals(t1.getInputs().get(0).getOutpoint().getHash().getBytes(),
            t1p.getTransactionInput(0).getTransactionOutPointHash().toByteArray());
    assertEquals(0, t1p.getTransactionInput(0).getTransactionOutPointIndex());
    assertEquals(t1p.getTransactionOutput(0).getValue(), v1.value);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:35,代码来源:WalletProtobufSerializerTest.java

示例9: testLastBlockSeenHash

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@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 = new Block(params, 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());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:28,代码来源:WalletProtobufSerializerTest.java

示例10: readWallet

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
/**
 * <p>Parses a wallet from the given stream, using the provided Wallet instance to load data into. This is primarily
 * used when you want to register extensions. Data in the proto will be added into the wallet where applicable and
 * overwrite where not.</p>
 *
 * <p>A wallet can be unreadable for various reasons, such as inability to open the file, corrupt data, internally
 * inconsistent data, a wallet extension marked as mandatory that cannot be handled and so on. You should always
 * handle {@link UnreadableWalletException} and communicate failure to the user in an appropriate manner.</p>
 *
 * @throws UnreadableWalletException thrown in various error conditions (see description).
 */
public Wallet readWallet(InputStream input) throws UnreadableWalletException {
    try {
        Protos.Wallet walletProto = parseToProto(input);
        final String paramsID = walletProto.getNetworkIdentifier();
        NetworkParameters params = NetworkParameters.fromID(paramsID);
        if (params == null)
            throw new UnreadableWalletException("Unknown network parameters ID " + paramsID);
        return readWallet(params, null, walletProto);
    } catch (IOException e) {
        throw new UnreadableWalletException("Could not parse input stream to protobuf", e);
    }
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:24,代码来源:WalletProtobufSerializer.java

示例11: oneTx

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void oneTx() throws Exception {
    // Check basic tx serialization.
    Coin v1 = COIN;
    Transaction t1 = createFakeTx(params, v1, myAddress);
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
    t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    myWallet.receivePending(t1, null);
    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(1, wallet1.getTransactions(true).size());
    assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
    Transaction t1copy = wallet1.getTransaction(t1.getHash());
    assertArrayEquals(t1.bitcoinSerialize(), t1copy.bitcoinSerialize());
    assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
    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());
    assertEquals(1, walletProto.getTransactionCount());
    // ALICE
    //assertEquals(6, walletProto.getKeyCount());
    
    Protos.Transaction t1p = walletProto.getTransaction(0);
    assertEquals(0, t1p.getBlockHashCount());
    assertArrayEquals(t1.getHash().getBytes(), t1p.getHash().toByteArray());
    assertEquals(Protos.Transaction.Pool.PENDING, t1p.getPool());
    assertFalse(t1p.hasLockTime());
    assertFalse(t1p.getTransactionInput(0).hasSequence());
    assertArrayEquals(t1.getInputs().get(0).getOutpoint().getHash().getBytes(),
            t1p.getTransactionInput(0).getTransactionOutPointHash().toByteArray());
    assertEquals(0, t1p.getTransactionInput(0).getTransactionOutPointIndex());
    assertEquals(t1p.getTransactionOutput(0).getValue(), v1.value);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:36,代码来源:WalletProtobufSerializerTest.java

示例12: testExtensions

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void testExtensions() throws Exception {
    myWallet.addExtension(new SomeFooExtension("com.whatever.required", true));
    Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
    Wallet wallet2 = new Wallet(params);
    // Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
    try {
        new WalletProtobufSerializer().readWallet(proto, wallet2);
        fail();
    } catch (UnreadableWalletException e) {
        assertTrue(e.getMessage().contains("mandatory"));
    }
    Wallet wallet3 = new Wallet(params);
    // This time it works.
    wallet3.addExtension(new SomeFooExtension("com.whatever.required", true));
    new WalletProtobufSerializer().readWallet(proto, wallet3);
    assertTrue(wallet3.getExtensions().containsKey("com.whatever.required"));


    // Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
    Wallet wallet4 = new Wallet(params);
    wallet4.addExtension(new SomeFooExtension("com.whatever.optional", false));
    Protos.Wallet proto4 = new WalletProtobufSerializer().walletToProto(wallet4);
    Wallet wallet5 = new Wallet(params);
    new WalletProtobufSerializer().readWallet(proto4, wallet5);
    assertEquals(0, wallet5.getExtensions().size());
}
 
开发者ID:cannabiscoindev,项目名称:cannabiscoinj,代码行数:28,代码来源:WalletProtobufSerializerTest.java

示例13: oneTx

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
@Test
public void oneTx() throws Exception {
    // Check basic tx serialization.
    BigInteger v1 = Utils.toNanoCoins(1, 0);
    Transaction t1 = createFakeTx(params, v1, myAddress);
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
    t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
    t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
    myWallet.receivePending(t1, null);
    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(1, wallet1.getTransactions(true).size());
    assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
    Transaction t1copy = wallet1.getTransaction(t1.getHash());
    assertArrayEquals(t1.bitcoinSerialize(), t1copy.bitcoinSerialize());
    assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
    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());
    assertEquals(1, walletProto.getTransactionCount());
    assertEquals(1, walletProto.getKeyCount());
    
    Protos.Transaction t1p = walletProto.getTransaction(0);
    assertEquals(0, t1p.getBlockHashCount());
    assertArrayEquals(t1.getHash().getBytes(), t1p.getHash().toByteArray());
    assertEquals(Protos.Transaction.Pool.PENDING, t1p.getPool());
    assertFalse(t1p.hasLockTime());
    assertFalse(t1p.getTransactionInput(0).hasSequence());
    assertArrayEquals(t1.getInputs().get(0).getOutpoint().getHash().getBytes(),
            t1p.getTransactionInput(0).getTransactionOutPointHash().toByteArray());
    assertEquals(0, t1p.getTransactionInput(0).getTransactionOutPointIndex());
    assertEquals(t1p.getTransactionOutput(0).getValue(), v1.longValue());
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:35,代码来源:WalletProtobufSerializerTest.java

示例14: loadExtensions

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
private static void loadExtensions(Wallet wallet, Protos.Wallet walletProto) throws UnreadableWalletException {
    final Map<String, WalletExtension> extensions = wallet.getExtensions();
    for (Protos.Extension extProto : walletProto.getExtensionList()) {
        String id = extProto.getId();
        WalletExtension extension = extensions.get(id);
        if (extension == null) {
            if (extProto.getMandatory()) {
                // If the extension is the ORG_MULTIBIT_WALLET_PROTECT or ORG_MULTIBIT_WALLET_PROTECT_2 then we know about that.
                // This is a marker extension to prevent earlier versions of multibit loading encrypted wallets.
                
                // Unfortunately I merged the recognition of the ORG_MULTIBIT_WALLET_PROTECT mandatory extension into the v0.4 code
                // so it could load encrypted wallets mistakenly.
                
                // Hence the v0.5 code now writes ORG_MULTIBIT_WALLET_PROTECT_2.
                if (!(extProto.getId().equals(MultiBitWalletProtobufSerializer.ORG_MULTIBIT_WALLET_PROTECT) || 
                        extProto.getId().equals(MultiBitWalletProtobufSerializer.ORG_MULTIBIT_WALLET_PROTECT_2))) {
                    throw new UnreadableWalletException("Did not understand a mandatory extension in the wallet of '" + extProto.getId() + "'");
                }
            }
        } else {
            log.info("Loading wallet extension {}", id);
            try {
                extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
            } catch (Exception e) {
                if (extProto.getMandatory())
                    throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);
            }
        }
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:31,代码来源:MultiBitWalletProtobufSerializer.java

示例15: walletToProto

import org.bitcoinj.wallet.Protos; //导入方法依赖的package包/类
/**
 * 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.
 */
public Protos.Wallet walletToProto(Wallet wallet) {
    Protos.Wallet.Builder walletBuilder = Protos.Wallet.newBuilder();
    walletBuilder.setNetworkIdentifier(wallet.getNetworkParameters().getId());
    if (wallet.getDescription() != null) {
        walletBuilder.setDescription(wallet.getDescription());
    }

    for (WalletTransaction wtx : wallet.getWalletTransactions()) {
        Protos.Transaction txProto = makeTxProto(wtx);
        walletBuilder.addTransaction(txProto);
    }

    walletBuilder.addAllKey(wallet.serializeKeychainToProtobuf());

    for (Script script : wallet.getWatchedScripts()) {
        Protos.Script protoScript =
                Protos.Script.newBuilder()
                        .setProgram(ByteString.copyFrom(script.getProgram()))
                        .setCreationTimestamp(script.getCreationTimeSeconds() * 1000)
                        .build();

        walletBuilder.addWatchedScript(protoScript);
    }

    // Populate the lastSeenBlockHash field.
    Sha256Hash lastSeenBlockHash = wallet.getLastBlockSeenHash();
    if (lastSeenBlockHash != null) {
        walletBuilder.setLastSeenBlockHash(hashToByteString(lastSeenBlockHash));
        walletBuilder.setLastSeenBlockHeight(wallet.getLastBlockSeenHeight());
    }
    if (wallet.getLastBlockSeenTimeSecs() > 0)
        walletBuilder.setLastSeenBlockTimeSecs(wallet.getLastBlockSeenTimeSecs());

    // Populate the scrypt parameters.
    KeyCrypter keyCrypter = wallet.getKeyCrypter();
    if (keyCrypter == null) {
        // The wallet is unencrypted.
        walletBuilder.setEncryptionType(EncryptionType.UNENCRYPTED);
    } else {
        // The wallet is encrypted.
        walletBuilder.setEncryptionType(keyCrypter.getUnderstoodEncryptionType());
        if (keyCrypter instanceof KeyCrypterScrypt) {
            KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) keyCrypter;
            walletBuilder.setEncryptionParameters(keyCrypterScrypt.getScryptParameters());
        } else {
            // Some other form of encryption has been specified that we do not know how to persist.
            throw new RuntimeException("The wallet has encryption of type '" + keyCrypter.getUnderstoodEncryptionType() + "' but this WalletProtobufSerializer does not know how to persist this.");
        }
    }

    if (wallet.getKeyRotationTime() != null) {
        long timeSecs = wallet.getKeyRotationTime().getTime() / 1000;
        walletBuilder.setKeyRotationTime(timeSecs);
    }

    populateExtensions(wallet, walletBuilder);

    for (Map.Entry<String, ByteString> entry : wallet.getTags().entrySet()) {
        Protos.Tag.Builder tag = Protos.Tag.newBuilder().setTag(entry.getKey()).setData(entry.getValue());
        walletBuilder.addTags(tag);
    }

    for (TransactionSigner signer : wallet.getTransactionSigners()) {
        // do not serialize LocalTransactionSigner as it's being added implicitly
        if (signer instanceof LocalTransactionSigner)
            continue;
        Protos.TransactionSigner.Builder protoSigner = Protos.TransactionSigner.newBuilder();
        protoSigner.setClassName(signer.getClass().getName());
        protoSigner.setData(ByteString.copyFrom(signer.serialize()));
        walletBuilder.addTransactionSigners(protoSigner);
    }

    // Populate the wallet version.
    walletBuilder.setVersion(wallet.getVersion());

    return walletBuilder.build();
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:82,代码来源:WalletProtobufSerializer.java


注:本文中的org.bitcoinj.wallet.Protos.Wallet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。