本文整理汇总了Java中org.bitcoinj.wallet.DeterministicSeed类的典型用法代码示例。如果您正苦于以下问题:Java DeterministicSeed类的具体用法?Java DeterministicSeed怎么用?Java DeterministicSeed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeterministicSeed类属于org.bitcoinj.wallet包,在下文中一共展示了DeterministicSeed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
/**
*
* @param callbacks
*/
@Override
public void execute(CoinActionCallback<CurrencyCoin>... callbacks) {
_callbacks = callbacks;
// reinitWallet();
final DeterministicSeed seed = createDeterministicSeed();
_bitcoinManager.getCurrencyCoin().getWalletManager().addListener(new Service.Listener() {
@Override
public void terminated(Service.State from) {
super.terminated(from);
WalletAppKit appKit = setupWallet();
appKit.setDownloadListener(BitcoinRecoverAction.this)
.setBlockingStartup(false)
.setUserAgent(ServiceConsts.SERVICE_APP_NAME, "0.1")
.restoreWalletFromSeed(seed);
_bitcoinManager.getCurrencyCoin().setWalletManager(appKit);
_bitcoinManager.getCurrencyCoin().getWalletManager().startAsync();
}
}, Executors.newSingleThreadExecutor());
_bitcoinManager.getCurrencyCoin().getWalletManager().stopAsync();
}
示例2: Bitcoin
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
private Bitcoin() {
BriefLogFormatter.initWithSilentBitcoinJ();
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.toLevel("info"));
// Context.enableStrictMode();
final NetworkParameters params = TestNet3Params.get();
context = new Context(params);
Context.propagate(context);
// read system property to check if broken wallet shall be recovered from backup automatically
automaticallyRecoverBrokenWallet = System.getProperty("automaticallyRecoverBrokenWallet").equalsIgnoreCase("true");
// prepare (unused) random seed to save time when constructing coupon wallets for invoices
byte[] seed = new byte[DeterministicSeed.DEFAULT_SEED_ENTROPY_BITS/8];
List<String> mnemonic = new ArrayList<>(0);
couponRandomSeed = new DeterministicSeed(seed, mnemonic, MnemonicCode.BIP39_STANDARDISATION_TIME_SECS);
}
示例3: setupWalletKit
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void setupWalletKit(@Nullable DeterministicSeed seed) {
// If seed is non-null it means we are restoring from backup.
bitcoin = new WalletAppKit(params, new File("."), WALLET_FILE_NAME) {
@Override
protected void onSetupCompleted() {
// Don't make the user wait for confirmations for now, as the intention is they're sending it
// their own money!
bitcoin.wallet().allowSpendingUnconfirmedTransactions();
Platform.runLater(controller::onBitcoinSetup);
}
};
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
// or progress widget to keep the user engaged whilst we initialise, but we don't.
if (params == RegTestParams.get()) {
bitcoin.connectToLocalHost(); // You should run a regtest mode bitcoind locally.
} else if (params == TestNet3Params.get()) {
// As an example!
bitcoin.useTor();
// bitcoin.setDiscovery(new HttpDiscovery(params, URI.create("http://localhost:8080/peers"), ECKey.fromPublicOnly(BaseEncoding.base16().decode("02cba68cfd0679d10b186288b75a59f9132b1b3e222f6332717cb8c4eb2040f940".toUpperCase()))));
}
bitcoin.setDownloadListener(controller.progressBarUpdater())
.setBlockingStartup(false)
.setUserAgent(APP_NAME, "1.0");
if (seed != null)
bitcoin.restoreWalletFromSeed(seed);
}
示例4: testSeeds
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
@Test
public void testSeeds() throws MnemonicLengthException, MnemonicWordException, MnemonicChecksumException {
int bits = 128;
byte [] entropy = getEntropy(bits);
List<String> mnemonic = MnemonicCode.INSTANCE.toMnemonic(entropy);
String passphrase = "";
long creationTimeSeconds = System.currentTimeMillis() / 1000;
DeterministicSeed ds1 = new DeterministicSeed(entropy, passphrase, creationTimeSeconds);
DeterministicSeed ds2 = new DeterministicSeed(mnemonic, null, passphrase, creationTimeSeconds);
byte [] ds1seed = ds1.getSeedBytes();
byte [] ds2seed = ds2.getSeedBytes();
Assert.assertArrayEquals(ds1seed, ds2seed);
List<String> ds1mnemonic = ds1.getMnemonicCode();
List<String> ds2mnemonic = ds2.getMnemonicCode();
assertEquals(mnemonic, ds1mnemonic);
assertEquals(ds1mnemonic, ds2mnemonic);
printMnemonic(mnemonic);
}
示例5: testHDAccountNxt
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
@Test
public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException {
DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0);
DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true);
NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null);
byte[] privateKey = nxtKey.getPrivateKey();
byte[] publicKey = nxtKey.getPublicKey();
NxtAddress address = new NxtAddress(NxtMain.get(), publicKey);
assertArrayEquals(nxtPrivateKey, privateKey);
assertArrayEquals(nxtPublicKey, publicKey);
assertEquals(nxtRsAddress, address.toString());
assertEquals(nxtAccountId, address.getAccountId());
}
示例6: setUp
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
params = NetworkParameters.fromID(NetworkParameters.ID_UNITTESTNET);
mapper = new ObjectMapper();
DeterministicSeed seed = new DeterministicSeed("correct battery horse staple", null, "", 0);
DeterministicKeyChain chain =
DeterministicKeyChain.builder()
.seed(seed)
.build();
KeyChainGroup group = new KeyChainGroup(params);
group.addAndActivateHDChain(chain);
wallet = new SmartWallet(params, group);
wallet.setKeychainLookaheadSize(10);
control = EasyMock.createStrictControl();
client = control.createMock(StratumClient.class);
expect(client.getConnectedAddresses()).andStubReturn(Lists.newArrayList(new InetSocketAddress(InetAddress.getLocalHost(), 0)));
expect(client.getPeerVersion()).andStubReturn("1.0");
store = control.createMock(HeadersStore.class);
stratumChain = control.createMock(StratumChain.class);
expect(stratumChain.getPeerHeight()).andStubReturn(100L);
expect(store.get(340242)).andStubReturn(params.getGenesisBlock().cloneAsHeader());
multiWallet = new ElectrumMultiWallet(wallet, BASE_DIRECTORY);
multiWallet.start(client, stratumChain, store);
}
示例7: setupWalletKit
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void setupWalletKit (@Nullable DeterministicSeed seed) {
// If seed is non-null it means we are restoring from backup.
bitcoin = new WalletAppKit(params, new File("."), APP_NAME + "-" + params.getPaymentProtocolId() + CLIENTID) {
@Override
protected void onSetupCompleted () {
// Don't make the user wait for confirmations for now, as the intention is they're sending it
// their own money!
bitcoin.wallet().allowSpendingUnconfirmedTransactions();
Platform.runLater(controller::onBitcoinSetup);
}
};
bitcoin.setDownloadListener(controller.progressBarUpdater())
.setBlockingStartup(false)
.setUserAgent(APP_NAME, "1.0");
if (seed != null) {
bitcoin.restoreWalletFromSeed(seed);
}
}
示例8: testSaveAndRetreiveMnemonic
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
@Test
public void testSaveAndRetreiveMnemonic() {
String mnemonicStr = "device seven always major morning present level order decline pizza order economy";
String[] mnemonic = mnemonicStr.split(" ");
List<String> mnemonicList = new ArrayList<String>(Arrays.asList(mnemonic));
WalletCore wc = new WalletCore();
MockingContext c = new MockingContext(getContext());
wc.saveMnemonic(c, mnemonic);
List<String> mnemonicListResult = null;
String mnemonicStrResult = null;
DeterministicSeed dsResult = null;
try {
mnemonicListResult = wc.getMnemonic(c);
mnemonicStrResult = wc.getMnemonicString(c);
dsResult = wc.getDeterministicSeed(c);
} catch (NoSeedOrMnemonicsFound e) {
e.printStackTrace();
assertTrue(false);
}
assertTrue(TestUtil.listEquals(mnemonicList, mnemonicListResult));
assertTrue(mnemonicStrResult.equals(mnemonicStr));
assertTrue(TestUtil.listEquals(dsResult.getMnemonicCode(), mnemonicList));
}
示例9: restoreSeedWords
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public static void restoreSeedWords(DeterministicSeed seed, WalletsManager walletsManager, File storageDir) {
try {
FileUtil.renameFile(new File(storageDir, "AddressEntryList"), new File(storageDir, "AddressEntryList_wallet_restore_" + System.currentTimeMillis()));
} catch (Throwable t) {
new Popup<>().error(Res.get("error.deleteAddressEntryListFailed", t)).show();
}
walletsManager.restoreSeedWords(
seed,
() -> UserThread.execute(() -> {
log.info("Wallets restored with seed words");
new Popup<>().feedback(Res.get("seed.restore.success"))
.useShutDownButton()
.show();
}),
throwable -> UserThread.execute(() -> {
log.error(throwable.toString());
new Popup<>().error(Res.get("seed.restore.error", Res.get("shared.errorMessageInline", throwable)))
.show();
}));
}
示例10: restoreSeedWords
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void restoreSeedWords(@Nullable DeterministicSeed seed, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
checkNotNull(seed, "Seed must be not be null.");
backupWallets();
Context ctx = Context.get();
new Thread(() -> {
try {
Context.propagate(ctx);
walletConfig.stopAsync();
walletConfig.awaitTerminated();
initialize(seed, resultHandler, exceptionHandler);
} catch (Throwable t) {
t.printStackTrace();
log.error("Executing task failed. " + t.getMessage());
}
}, "RestoreBTCWallet-%d").start();
}
示例11: setBackupMode
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void setBackupMode(Wallet wallet, DeterministicSeed seed){
backupMode = true;
this.wallet= wallet;
walletSeed = seed;
List<String> mnemoniclst = walletSeed.getMnemonicCode();
mnemonic = Joiner.on(" ").join(mnemoniclst);
lblSeed.setText(mnemonic);
MainPane.setVisible(false);
SetPasswordPane.setVisible(false);
BackupNewWalletPane.setVisible(true);
btnBack2.setVisible(false);
btnContinue2.setVisible(false);
ckSeed.setVisible(false);
btnSave.setDisable(false);
}
示例12: createWallet
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
private void createWallet(@Nullable DeterministicSeed seed) throws IOException{
String filePath = appParams.getApplicationDataFolderAbsolutePath() + appParams.getAppName() + ".wallet";
File f = new File(filePath);
assert(f.exists() == false);
if(seed == null){
//Generate a new Seed
SecureRandom secureRandom = null;
try {secureRandom = SecureRandom.getInstance("SHA1PRNG");}
catch (NoSuchAlgorithmException e) {e.printStackTrace();}
//byte[] bytes = new byte[16];
//secureRandom.nextBytes(bytes);
walletSeed = new DeterministicSeed(secureRandom, 8 * 16, "", Utils.currentTimeSeconds());
}
else
walletSeed = seed;
// set wallet
wallet = Wallet.fromSeed(params,walletSeed);
wallet.setKeychainLookaheadSize(0);
wallet.autosaveToFile(f, 200, TimeUnit.MILLISECONDS, null);
}
示例13: createPaperWallet
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
@SuppressWarnings("restriction")
public static void createPaperWallet(String mnemonic, DeterministicSeed seed, long creationTime) throws IOException{
PaperWalletQR maker = new PaperWalletQR();
BufferedImage bi = maker.generatePaperWallet(mnemonic, seed, creationTime);
// save
String filepath = new java.io.File( "." ).getCanonicalPath() + "/" + "paperwallet" + ".png";
File wallet = new File(filepath);
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Paper Wallet");
fileChooser.setInitialFileName("paperwallet.png");
File outputfile = fileChooser.showSaveDialog(Main.startup);
if(outputfile != null)
ImageIO.write(bi, "png", outputfile);
}
示例14: testSaveWalletSeedShouldSaveWalletToDiskAndReloadItFromMSeed
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void testSaveWalletSeedShouldSaveWalletToDiskAndReloadItFromMSeed() throws IOException, UnreadableWalletException {
controller = new WalletController(params, testDirectory, 1);
controller.setupWalletKit(null);
assertNotNull(controller.getRecieveAddress(false));
//then save a new wallet file. this one is unencrypted!
System.out.println("Saving Wallet");
String seedcode = controller.saveWalletSeed(testWalletDirectory+"testWallet1");
assertNotNull(seedcode);
System.out.println(seedcode);
//Load from file
String passphrase = "";
Long creationtime = System.currentTimeMillis();
DeterministicSeed seed = new DeterministicSeed(seedcode, null, passphrase, creationtime);
WalletController loadedController = new WalletController(params, testDirectory, 1);
loadedController.setupWalletKit(seed);
loadedController.getWallet().toString();
assertEquals(controller.getWallet().getWatchingKey(), loadedController.getWallet().getWatchingKey());
controller.shutdown();
loadedController.shutdown();
cleanup();
}
示例15: setupWalletKit
import org.bitcoinj.wallet.DeterministicSeed; //导入依赖的package包/类
public void setupWalletKit(@Nullable DeterministicSeed seed) {
// If seed is non-null it means we are restoring from backup.
bitcoin = new WalletAppKit(params, new File("."), WALLET_FILE_NAME) {
@Override
protected void onSetupCompleted() {
// Don't make the user wait for confirmations for now, as the intention is they're sending it
// their own money!
bitcoin.wallet().allowSpendingUnconfirmedTransactions();
Platform.runLater(controller::onBitcoinSetup);
}
};
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
// or progress widget to keep the user engaged whilst we initialise, but we don't.
if (params == RegTestParams.get()) {
bitcoin.connectToLocalHost(); // You should run a regtest mode bitcoind locally.
}
bitcoin.setDownloadListener(controller.progressBarUpdater())
.setBlockingStartup(false)
.setUserAgent(APP_NAME, "1.0");
if (seed != null)
bitcoin.restoreWalletFromSeed(seed);
}