-
Notifications
You must be signed in to change notification settings - Fork 10
Developer's Guide
Jabit is following the ports and adapters architecture, with the domain module containing all the basic functionality you need for a Bitmessage client and many easily replaceable modules - except for networking maybe, which should only be customized for very special cases such as mobile clients. Especially the adapters in module repositories you might want to replace with other means of persisting data. Also, you might want to add an alternative ProofOfWorkEngine, i.e. leveraging the GPU.
Add Jabit as Gradle dependency:
compile 'ch.dissem.jabit:jabit-domain:0.2.0'Unless you want to implement your own, also add the following:
compile 'ch.dissem.jabit:jabit-networking:0.2.0'
compile 'ch.dissem.jabit:jabit-repositories:0.2.0'And if you want to import from or export to the Wallet Import Format (used by PyBitmessage) you might also want to add:
compile 'ch.dissem.jabit:jabit-wif:0.2.0'First, you'll need to create a BitmessageContext:
JdbcConfig jdbcConfig = new JdbcConfig();
BitmessageContext ctx = new BitmessageContext.Builder()
.addressRepo(new JdbcAddressRepository(jdbcConfig))
.inventory(new JdbcInventory(jdbcConfig))
.messageRepo(new JdbcMessageRepository(jdbcConfig))
.nodeRegistry(new MemoryNodeRegistry())
.networkHandler(new NetworkNode())
.build();This creates a simple context using a H2 database that will be created in the user's home directory. Next you'll need to start the context and decide what happens if a message arrives:
ctx.startup(new BitmessageContext.Listener() {
@Override
public void receive(Plaintext plaintext) {
// TODO: Notify the user
}
});Then you might want to create an identity
BitmessageAddress identity = ctx.createIdentity(false, Pubkey.Feature.DOES_ACK);or add some contacts
BitmessageAddress contact = new BitmessageAddress("BM-2cTarrmjMdRicKZ4qQ8A13JhoR3Uq6Zh5j");
address.setAlias("Chris");
ctx.addContact(contact);to which you can send some messages
ctx.send(identity, contact, "Test", "Hello Chris, this is a message.");