Added import/export to the demo app

- discovered private key length was wrong - fixed
- as things are broken anyway, refactored flyway migrations - you'll need to delete ~/jabit.*.db
This commit is contained in:
2015-07-03 11:28:06 +02:00
parent 65fdd7d408
commit 6f50c200ee
13 changed files with 80 additions and 29 deletions

View File

@ -22,6 +22,7 @@ dependencies {
compile project(':domain')
compile project(':networking')
compile project(':repositories')
compile project(':wif')
compile 'org.slf4j:slf4j-simple:1.7.12'
compile 'args4j:args4j:2.32'
testCompile 'junit:junit:4.11'

View File

@ -16,6 +16,16 @@
package ch.dissem.bitmessage.demo;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.networking.NetworkNode;
import ch.dissem.bitmessage.repository.*;
import ch.dissem.bitmessage.wif.WifExporter;
import ch.dissem.bitmessage.wif.WifImporter;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import java.io.File;
import java.io.IOException;
public class Main {
@ -25,6 +35,40 @@ public class Main {
if (System.getProperty("org.slf4j.simpleLogger.logFile") == null)
System.setProperty("org.slf4j.simpleLogger.logFile", "./jabit.log");
new Application();
CmdLineOptions options = new CmdLineOptions();
CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
parser.printUsage(System.err);
}
if (options.exportWIF != null || options.importWIF != null) {
JdbcConfig jdbcConfig = new JdbcConfig();
BitmessageContext ctx = new BitmessageContext.Builder()
.addressRepo(new JdbcAddressRepository(jdbcConfig))
.inventory(new JdbcInventory(jdbcConfig))
.nodeRegistry(new MemoryNodeRegistry())
.messageRepo(new JdbcMessageRepository(jdbcConfig))
.networkHandler(new NetworkNode())
.port(48444)
.build();
if (options.exportWIF != null) {
new WifExporter(ctx).addAll().write(options.exportWIF);
}
if (options.importWIF != null) {
new WifImporter(ctx, options.importWIF).importAll();
}
} else {
new Application();
}
}
private static class CmdLineOptions {
@Option(name = "-import", usage = "Import from keys.dat or other WIF file.")
private File importWIF;
@Option(name = "-export", usage = "Export to WIF file.")
private File exportWIF;
}
}