Testing the code

It's testing time, but before running the project, we need to define a trusted keystore for Java in order to validate the server's certificate, and for that we use the Java keytool (further usage details on keytool can be found in Oracle's documentation):

keytool -import -keystore clientkeystore -file /path_to/cert.der -alias bip70.com -storepass changeit

Then import the resulting clientkeystore file into the Eclipse project. Afterwards, click Run as then Run Configurations to define the parameter  -Djavax.net.ssl.trustStore=clientkeystore—in the Arguments tab in the VM arguments box:

A good alternative way to use a custom trust store is to use createFromBitcoinUri(BitcoinURI uri, boolean verifyPki, TrustStoreLoader trustStoreLoader), where the third argument is a TrustStoreLoader that loads the local KeyStore. When it's not defined, the system default trust store is used.

When you finish, compile and run your code. If everything runs correctly, you will be able to visualize in the Eclipse log viewer the SVP wallet activity, the merchant's payment request details, and the memo from the merchant when the payment is successfully processed, along with the invoice ID:

At this point, we have reached our goal of building a Java client to send a payment over the testnet network using the BIP 70 protocol. As you have witnessed, BitcoinJ is an easy-to-use and powerful framework. I would definitely recommend you spend time reading their official documentation and compiling the code samples provided therein. 

Finally, I would note that, for the sake of brevity, the overall server and client code is intentionally unoptimized and lacks many features. You could probably go back over the code and try to include new improvements, such as building a GUI. I'll be waiting for your pull requests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset