org.bitcoinj.wallet.WalletExtension Java Examples
The following examples show how to use
org.bitcoinj.wallet.WalletExtension.
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 |
@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: PaymentChannelClientTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void shouldSendTimeWindowInClientVersion() throws Exception { final long timeWindow = 4000; KeyParameter userKey = null; PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, userKey, new PaymentChannelClient.DefaultClientChannelProperties() { @Override public long timeWindow() { return timeWindow; } @Override public PaymentChannelClient.VersionSelector versionSelector() { return clientChannelProperties.versionSelector(); } }, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(4000); }
Example #3
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 #4
Source File: PaymentChannelClientTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@Test public void shouldSendTimeWindowInClientVersion() throws Exception { final long timeWindow = 4000; KeyParameter userKey = null; PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, userKey, new PaymentChannelClient.DefaultClientChannelProperties() { @Override public long timeWindow() { return timeWindow; } @Override public PaymentChannelClient.VersionSelector versionSelector() { return clientChannelProperties.versionSelector(); } }, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(4000); }
Example #5
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 #6
Source File: PaymentChannelClientTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@Test public void shouldSendTimeWindowInClientVersion() throws Exception { final long timeWindow = 4000; KeyParameter userKey = null; PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, userKey, new PaymentChannelClient.DefaultClientChannelProperties() { @Override public long timeWindow() { return timeWindow; } @Override public PaymentChannelClient.VersionSelector versionSelector() { return clientChannelProperties.versionSelector(); } }, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(4000); }
Example #7
Source File: ChannelConnectionTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
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 #8
Source File: WalletProtobufSerializerTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@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 #9
Source File: PaymentChannelClientTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void shouldSendClientVersionOnChannelOpen() throws Exception { PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, null, clientChannelProperties, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(defaultTimeWindow); }
Example #10
Source File: ChannelConnectionTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
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 #11
Source File: ChannelConnectionTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
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 #12
Source File: ExamplePaymentChannelServer.java From GreenBits with GNU General Public License v3.0 | 5 votes |
public void run(NetworkParameters params) throws Exception { // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so // the plugin that knows how to parse all the additional data is present during the load. appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") { @Override protected List<WalletExtension> provideWalletExtensions() { // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting // the refund transaction if its lock time has expired. It also persists channels so we can resume them // after a restart. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelServerStates(null)); } }; // Broadcasting can take a bit of time so we up the timeout for "real" networks final int timeoutSeconds = params.getId().equals(NetworkParameters.ID_REGTEST) ? 15 : 150; if (params == RegTestParams.get()) { appKit.connectToLocalHost(); } appKit.startAsync(); appKit.awaitRunning(); System.out.println(appKit.wallet()); // We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and // an implementation of HandlerFactory, which we just implement ourselves. new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), timeoutSeconds, Coin.valueOf(100000), this).bindAndStart(4242); }
Example #13
Source File: WalletProtobufSerializerTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@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 #14
Source File: PaymentChannelClientTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Test public void shouldSendClientVersionOnChannelOpen() throws Exception { PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, null, clientChannelProperties, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(defaultTimeWindow); }
Example #15
Source File: ChannelConnectionTest.java From green_android with GNU General Public License v3.0 | 5 votes |
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 |
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: ExamplePaymentChannelServer.java From green_android with GNU General Public License v3.0 | 5 votes |
public void run(NetworkParameters params) throws Exception { // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so // the plugin that knows how to parse all the additional data is present during the load. appKit = new WalletAppKit(params, new File("."), "payment_channel_example_server") { @Override protected List<WalletExtension> provideWalletExtensions() { // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting // the refund transaction if its lock time has expired. It also persists channels so we can resume them // after a restart. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelServerStates(null)); } }; // Broadcasting can take a bit of time so we up the timeout for "real" networks final int timeoutSeconds = params.getId().equals(NetworkParameters.ID_REGTEST) ? 15 : 150; if (params == RegTestParams.get()) { appKit.connectToLocalHost(); } appKit.startAsync(); appKit.awaitRunning(); System.out.println(appKit.wallet()); // We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and // an implementation of HandlerFactory, which we just implement ourselves. new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), timeoutSeconds, Coin.valueOf(100000), this).bindAndStart(4242); }
Example #18
Source File: WalletProtobufSerializerTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@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 #19
Source File: PaymentChannelClientTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void shouldSendClientVersionOnChannelOpen() throws Exception { PaymentChannelClient dut = new PaymentChannelClient(wallet, ecKey, maxValue, serverHash, null, clientChannelProperties, connection); connection.sendToServer(capture(clientVersionCapture)); EasyMock.expect(wallet.getExtensions()).andReturn(new HashMap<String, WalletExtension>()); replay(connection, wallet); dut.connectionOpen(); assertClientVersion(defaultTimeWindow); }
Example #20
Source File: ChannelConnectionTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
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 #21
Source File: ExamplePaymentChannelClient.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public void run(final String host, IPaymentChannelClient.ClientChannelProperties clientChannelProperties, final NetworkParameters params) throws Exception { // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so // the plugin that knows how to parse all the additional data is present during the load. appKit = new WalletAppKit(params, new File("."), "payment_channel_example_client") { @Override protected List<WalletExtension> provideWalletExtensions() { // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting // the refund transaction if its lock time has expired. It also persists channels so we can resume them // after a restart. // We should not send a PeerGroup in the StoredPaymentChannelClientStates constructor // since WalletAppKit will find it for us. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelClientStates(null)); } }; // Broadcasting can take a bit of time so we up the timeout for "real" networks final int timeoutSeconds = params.getId().equals(NetworkParameters.ID_REGTEST) ? 15 : 150; if (params == RegTestParams.get()) { appKit.connectToLocalHost(); } appKit.startAsync(); appKit.awaitRunning(); // We now have active network connections and a fully synced wallet. // Add a new key which will be used for the multisig contract. appKit.wallet().importKey(myKey); appKit.wallet().allowSpendingUnconfirmedTransactions(); System.out.println(appKit.wallet()); // Create the object which manages the payment channels protocol, client side. Tell it where the server to // connect to is, along with some reasonable network timeouts, the wallet and our temporary key. We also have // to pick an amount of value to lock up for the duration of the channel. // // Note that this may or may not actually construct a new channel. If an existing unclosed channel is found in // the wallet, then it'll re-use that one instead. final InetSocketAddress server = new InetSocketAddress(host, 4242); waitForSufficientBalance(channelSize); final String channelID = host; // Do this twice as each one sends 1/10th of a bitcent 5 times, so to send a bitcent, we do it twice. This // demonstrates resuming a channel that wasn't closed yet. It should close automatically once we run out // of money on the channel. log.info("Round one ..."); openAndSend(timeoutSeconds, server, channelID, 5, clientChannelProperties); log.info("Round two ..."); log.info(appKit.wallet().toString()); openAndSend(timeoutSeconds, server, channelID, 4, clientChannelProperties); // 4 times because the opening of the channel made a payment. log.info("Stopping ..."); appKit.stopAsync(); appKit.awaitTerminated(); }
Example #22
Source File: ExamplePaymentChannelClient.java From green_android with GNU General Public License v3.0 | 4 votes |
public void run(final String host, IPaymentChannelClient.ClientChannelProperties clientChannelProperties, final NetworkParameters params) throws Exception { // Bring up all the objects we need, create/load a wallet, sync the chain, etc. We override WalletAppKit so we // can customize it by adding the extension objects - we have to do this before the wallet file is loaded so // the plugin that knows how to parse all the additional data is present during the load. appKit = new WalletAppKit(params, new File("."), "payment_channel_example_client") { @Override protected List<WalletExtension> provideWalletExtensions() { // The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting // the refund transaction if its lock time has expired. It also persists channels so we can resume them // after a restart. // We should not send a PeerGroup in the StoredPaymentChannelClientStates constructor // since WalletAppKit will find it for us. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelClientStates(null)); } }; // Broadcasting can take a bit of time so we up the timeout for "real" networks final int timeoutSeconds = params.getId().equals(NetworkParameters.ID_REGTEST) ? 15 : 150; if (params == RegTestParams.get()) { appKit.connectToLocalHost(); } appKit.startAsync(); appKit.awaitRunning(); // We now have active network connections and a fully synced wallet. // Add a new key which will be used for the multisig contract. appKit.wallet().importKey(myKey); appKit.wallet().allowSpendingUnconfirmedTransactions(); System.out.println(appKit.wallet()); // Create the object which manages the payment channels protocol, client side. Tell it where the server to // connect to is, along with some reasonable network timeouts, the wallet and our temporary key. We also have // to pick an amount of value to lock up for the duration of the channel. // // Note that this may or may not actually construct a new channel. If an existing unclosed channel is found in // the wallet, then it'll re-use that one instead. final InetSocketAddress server = new InetSocketAddress(host, 4242); waitForSufficientBalance(channelSize); final String channelID = host; // Do this twice as each one sends 1/10th of a bitcent 5 times, so to send a bitcent, we do it twice. This // demonstrates resuming a channel that wasn't closed yet. It should close automatically once we run out // of money on the channel. log.info("Round one ..."); openAndSend(timeoutSeconds, server, channelID, 5, clientChannelProperties); log.info("Round two ..."); log.info(appKit.wallet().toString()); openAndSend(timeoutSeconds, server, channelID, 4, clientChannelProperties); // 4 times because the opening of the channel made a payment. log.info("Stopping ..."); appKit.stopAsync(); appKit.awaitTerminated(); }
Example #23
Source File: WalletConfig.java From bisq-core with GNU Affero General Public License v3.0 | 2 votes |
/** * <p>Override this to return wallet extensions if any are necessary.</p> * <p> * <p>When this is called, chain(), store(), and peerGroup() will return the created objects, however they are not * initialized/started.</p> */ private List<WalletExtension> provideWalletExtensions() { return ImmutableList.of(); }
Example #24
Source File: WalletConfig.java From bisq with GNU Affero General Public License v3.0 | 2 votes |
/** * <p>Override this to return wallet extensions if any are necessary.</p> * <p> * <p>When this is called, chain(), store(), and peerGroup() will return the created objects, however they are not * initialized/started.</p> */ private List<WalletExtension> provideWalletExtensions() { return ImmutableList.of(); }