Java Code Examples for org.bitcoinj.wallet.Wallet#addExtension()
The following examples show how to use
org.bitcoinj.wallet.Wallet#addExtension() .
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 bcm-android with GNU General Public License v3.0 | 6 votes |
@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 2
Source File: WalletProtobufSerializerTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: WalletProtobufSerializerTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@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 |
@Override @Before public void setUp() throws Exception { super.setUp(); Utils.setMockClock(); // Use mock clock Context.propagate(new Context(UNITTEST, 3, Coin.ZERO, false)); // Shorter event horizon for unit tests. sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster)); serverWallet = new Wallet(UNITTEST); serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster)); serverWallet.freshReceiveKey(); // Use an atomic boolean to indicate failure because fail()/assert*() dont work in network threads fail = new AtomicBoolean(false); // Set up a way to monitor broadcast transactions. When you expect a broadcast, you must release a permit // to the broadcastTxPause semaphore so state can be queried in between. broadcasts = new LinkedBlockingQueue<>(); broadcastTxPause = new Semaphore(0); mockBroadcaster = new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { broadcastTxPause.acquireUninterruptibly(); SettableFuture<Transaction> future = SettableFuture.create(); future.set(tx); broadcasts.add(tx); return TransactionBroadcast.createMockBroadcast(tx, future); } }; // Because there are no separate threads in the tests here (we call back into client/server in server/client // handlers), we have lots of lock cycles. A normal user shouldn't have this issue as they are probably not both // client+server running in the same thread. Threading.warnOnLockCycles(); ECKey.FAKE_SIGNATURES = true; }
Example 5
Source File: ChannelConnectionTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); Utils.setMockClock(); // Use mock clock Context.propagate(new Context(PARAMS, 3, Coin.ZERO, false)); // Shorter event horizon for unit tests. sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster)); serverWallet = new Wallet(PARAMS); serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster)); serverWallet.freshReceiveKey(); // Use an atomic boolean to indicate failure because fail()/assert*() dont work in network threads fail = new AtomicBoolean(false); // Set up a way to monitor broadcast transactions. When you expect a broadcast, you must release a permit // to the broadcastTxPause semaphore so state can be queried in between. broadcasts = new LinkedBlockingQueue<>(); broadcastTxPause = new Semaphore(0); mockBroadcaster = new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { broadcastTxPause.acquireUninterruptibly(); SettableFuture<Transaction> future = SettableFuture.create(); future.set(tx); broadcasts.add(tx); return TransactionBroadcast.createMockBroadcast(tx, future); } }; // Because there are no separate threads in the tests here (we call back into client/server in server/client // handlers), we have lots of lock cycles. A normal user shouldn't have this issue as they are probably not both // client+server running in the same thread. Threading.warnOnLockCycles(); ECKey.FAKE_SIGNATURES = true; }
Example 6
Source File: ChannelConnectionTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); Utils.setMockClock(); // Use mock clock Context.propagate(new Context(PARAMS, 3, Coin.ZERO, false)); // Shorter event horizon for unit tests. sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster)); serverWallet = new Wallet(PARAMS); serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster)); serverWallet.freshReceiveKey(); // Use an atomic boolean to indicate failure because fail()/assert*() dont work in network threads fail = new AtomicBoolean(false); // Set up a way to monitor broadcast transactions. When you expect a broadcast, you must release a permit // to the broadcastTxPause semaphore so state can be queried in between. broadcasts = new LinkedBlockingQueue<>(); broadcastTxPause = new Semaphore(0); mockBroadcaster = new TransactionBroadcaster() { @Override public TransactionBroadcast broadcastTransaction(Transaction tx) { broadcastTxPause.acquireUninterruptibly(); SettableFuture<Transaction> future = SettableFuture.create(); future.set(tx); broadcasts.add(tx); return TransactionBroadcast.createMockBroadcast(tx, future); } }; // Because there are no separate threads in the tests here (we call back into client/server in server/client // handlers), we have lots of lock cycles. A normal user shouldn't have this issue as they are probably not both // client+server running in the same thread. Threading.warnOnLockCycles(); ECKey.FAKE_SIGNATURES = true; }