org.bitcoinj.wallet.WalletProtobufSerializer Java Examples

The following examples show how to use org.bitcoinj.wallet.WalletProtobufSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@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(UNITTEST, null, proto);
        fail();
    } catch (UnreadableWalletException e) {
        assertTrue(e.getMessage().contains("mandatory"));
    }
    Wallet wallet = new WalletProtobufSerializer().readWallet(UNITTEST,
            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(UNITTEST);
    wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
    Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
    Wallet wallet5 = new WalletProtobufSerializer().readWallet(UNITTEST, null, proto2);
    assertEquals(0, wallet5.getExtensions().size());
}
 
Example #3
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: ChannelConnectionTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #6
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #8
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: ChannelConnectionTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: ChannelConnectionTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #14
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: ChannelConnectionTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: ChannelConnectionTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@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(UNITTEST, new WalletExtension[]{extension}, proto);
    assertEquals(0, wallet.getExtensions().size());
}
 
Example #18
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #19
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLastBlockSeenHash() throws Exception {
    // Test the lastBlockSeenHash field works.

    // LastBlockSeenHash should be empty if never set.
    Wallet wallet = new Wallet(UNITTEST);
    Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(wallet);
    ByteString lastSeenBlockHash = walletProto.getLastSeenBlockHash();
    assertTrue(lastSeenBlockHash.isEmpty());

    // Create a block.
    Block block = UNITTEST.getDefaultSerializer()
            .makeBlock(ByteStreams.toByteArray(BlockTest.class.getResourceAsStream("block_testnet700000.dat")));
    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 = MAINNET.getGenesisBlock();
    wallet.setLastBlockSeenHash(genesisBlock.getHash());
    Wallet wallet2 = roundTrip(wallet);
    assertEquals(genesisBlock.getHash(), wallet2.getLastBlockSeenHash());
}
 
Example #20
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void oneTx() throws Exception {
    // Check basic tx serialization.
    Coin v1 = COIN;
    Transaction t1 = createFakeTx(UNITTEST, v1, myAddress);
    t1.getConfidence().markBroadcastBy(new PeerAddress(UNITTEST, InetAddress.getByName("1.2.3.4")));
    t1.getConfidence().markBroadcastBy(new PeerAddress(UNITTEST, 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);
}
 
Example #21
Source File: ChannelConnectionTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #22
Source File: WalletProtobufSerializerTest.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
@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());
}
 
Example #23
Source File: WalletProtobufSerializerTest.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@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(UNITTEST, null, proto.build());
}
 
Example #24
Source File: WalletProtobufSerializerTest.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
@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());
}