本文整理了Java中org.bitcoinj.wallet.Wallet.importKey()
方法的一些代码示例,展示了Wallet.importKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wallet.importKey()
方法的具体详情如下:
包路径:org.bitcoinj.wallet.Wallet
类名称:Wallet
方法名:importKey
[英]Imports the given ECKey to the wallet.
If the wallet is configured to auto save to a file, triggers a save immediately. Runs the onKeysAdded event handler. If the key already exists in the wallet, does nothing and returns false.
[中]将给定的ECKey导入钱包。
如果钱包配置为自动保存到文件,则会立即触发保存。运行onKeysAdded事件处理程序。如果钥匙已经存在于钱包中,则不执行任何操作并返回false。
代码示例来源:origin: greenaddress/GreenBits
/**
* <p>Deprecated alias for {@link #importKey(ECKey)}.</p>
*
* <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)}
* which does the same thing this method used to, but with a better name.</b></p>
*/
@Deprecated
public boolean addKey(ECKey key) {
return importKey(key);
}
代码示例来源:origin: HashEngineering/dashj
/**
* <p>Deprecated alias for {@link #importKey(ECKey)}.</p>
*
* <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)}
* which does the same thing this method used to, but with a better name.</b></p>
*/
@Deprecated
public boolean addKey(ECKey key) {
return importKey(key);
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* <p>Deprecated alias for {@link #importKey(ECKey)}.</p>
*
* <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)}
* which does the same thing this method used to, but with a better name.</b></p>
*/
@Deprecated
public boolean addKey(ECKey key) {
return importKey(key);
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* <p>Deprecated alias for {@link #importKey(ECKey)}.</p>
*
* <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)}
* which does the same thing this method used to, but with a better name.</b></p>
*/
@Deprecated
public boolean addKey(ECKey key) {
return importKey(key);
}
代码示例来源:origin: thinkmobiles/BitcoinJ-Wallet-Sample-Android
@Override
protected void onSetupCompleted() {
if (wallet().getImportedKeys().size() < 1) wallet().importKey(new ECKey());
wallet().allowSpendingUnconfirmedTransactions();
view.displayWalletPath(vWalletFile.getAbsolutePath());
setupWalletListeners(wallet());
Log.d("myLogs", "My address = " + wallet().freshReceiveAddress());
}
};
代码示例来源:origin: greenaddress/GreenBits
@Test(expected = IllegalArgumentException.class)
public void importOfHDKeyForbidden() throws Exception {
wallet.importKey(wallet.freshReceiveKey());
}
代码示例来源:origin: HashEngineering/dashj
appKit.wallet().importKey(myKey);
appKit.wallet().allowSpendingUnconfirmedTransactions();
代码示例来源:origin: HashEngineering/dashj
key = key.encrypt(checkNotNull(wallet.getKeyCrypter()), aesKey);
wallet.importKey(key);
System.out.println(key.toAddress(params) + " " + key);
} catch (KeyCrypterException kce) {
代码示例来源:origin: greenaddress/GreenBits
@Test(expected = KeyCrypterException.class)
public void addUnencryptedKeyToEncryptedWallet() throws Exception {
Wallet encryptedWallet = new Wallet(PARAMS);
encryptedWallet.encrypt(PASSWORD1);
ECKey key1 = new ECKey();
encryptedWallet.importKey(key1);
}
代码示例来源:origin: HashEngineering/dashj
wallet.importKey(key);
代码示例来源:origin: greenaddress/GreenBits
@Before
public void setUp() throws Exception {
BriefLogFormatter.initVerbose();
Context ctx = new Context(PARAMS);
myWatchedKey = new ECKey();
myWallet = new Wallet(PARAMS);
myKey = new ECKey();
myKey.setCreationTimeSeconds(123456789L);
myWallet.importKey(myKey);
myAddress = myKey.toAddress(PARAMS);
myWallet = new Wallet(PARAMS);
myWallet.importKey(myKey);
mScriptCreationTime = new Date().getTime() / 1000 - 1234;
myWallet.addWatchedAddress(myWatchedKey.toAddress(PARAMS), mScriptCreationTime);
myWallet.setDescription(WALLET_DESCRIPTION);
}
代码示例来源:origin: greenaddress/GreenBits
@Test(expected = KeyCrypterException.class)
public void addEncryptedKeyToUnencryptedWallet() throws Exception {
Wallet encryptedWallet = new Wallet(PARAMS);
encryptedWallet.encrypt(PASSWORD1);
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
ECKey key1 = new ECKey();
key1 = key1.encrypt(keyCrypter, keyCrypter.deriveKey("PASSWORD!"));
wallet.importKey(key1);
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testMultiSigOutputToString() throws Exception {
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN);
ECKey myKey = new ECKey();
this.wallet.importKey(myKey);
// Simulate another signatory
ECKey otherKey = new ECKey();
// Create multi-sig transaction
Transaction multiSigTransaction = new Transaction(PARAMS);
ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey);
Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
multiSigTransaction.addOutput(Coin.COIN, scriptPubKey);
SendRequest req = SendRequest.forTx(multiSigTransaction);
this.wallet.completeTx(req);
TransactionOutput multiSigTransactionOutput = multiSigTransaction.getOutput(0);
assertThat(multiSigTransactionOutput.toString(), CoreMatchers.containsString("CHECKMULTISIG"));
}
代码示例来源:origin: greenaddress/GreenBits
@Test(expected = KeyCrypterException.class)
public void mismatchedCrypter() throws Exception {
Wallet encryptedWallet = new Wallet(PARAMS);
encryptedWallet.encrypt(PASSWORD1);
KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter();
KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1);
// Try added an ECKey that was encrypted with a differenct ScryptParameters (i.e. a non-homogenous key).
// This is not allowed as the ScryptParameters is stored at the Wallet level.
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder()
.setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
Protos.ScryptParameters scryptParameters = scryptParametersBuilder.build();
KeyCrypter keyCrypterDifferent = new KeyCrypterScrypt(scryptParameters);
ECKey ecKeyDifferent = new ECKey();
ecKeyDifferent = ecKeyDifferent.encrypt(keyCrypterDifferent, aesKey);
encryptedWallet.importKey(ecKeyDifferent);
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testWalletCatchupTime() throws Exception {
// Check the fast catchup time was initialized to something around the current runtime minus a week.
// The wallet was already added to the peer in setup.
final int WEEK = 86400 * 7;
final long now = Utils.currentTimeSeconds();
peerGroup.start();
assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000);
Wallet w2 = new Wallet(PARAMS);
ECKey key1 = new ECKey();
key1.setCreationTimeSeconds(now - 86400); // One day ago.
w2.importKey(key1);
peerGroup.addWallet(w2);
peerGroup.waitForJobQueue();
assertEquals(peerGroup.getFastCatchupTimeSecs(), now - 86400 - WEEK);
// Adding a key to the wallet should update the fast catchup time, but asynchronously and in the background
// due to the need to avoid complicated lock inversions.
ECKey key2 = new ECKey();
key2.setCreationTimeSeconds(now - 100000);
w2.importKey(key2);
peerGroup.waitForJobQueue();
assertEquals(peerGroup.getFastCatchupTimeSecs(), now - WEEK - 100000);
}
代码示例来源:origin: greenaddress/GreenBits
Context context = new Context(PARAMS);
Wallet wallet = new Wallet(context);
wallet.importKey(miningKey);
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testKeys() throws Exception {
for (int i = 0 ; i < 20 ; i++) {
myKey = new ECKey();
myAddress = myKey.toAddress(PARAMS);
myWallet = new Wallet(PARAMS);
myWallet.importKey(myKey);
Wallet wallet1 = roundTrip(myWallet);
assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
}
}
代码示例来源:origin: greenaddress/GreenBits
@SuppressWarnings("ConstantConditions")
public void completeTxPartiallySigned(Wallet.MissingSigsMode missSigMode, byte[] expectedSig) throws Exception {
// Check the wallet will write dummy scriptSigs for inputs that we have only pubkeys for without the privkey.
ECKey priv = new ECKey();
ECKey pub = ECKey.fromPublicOnly(priv.getPubKeyPoint());
wallet.importKey(pub);
ECKey priv2 = wallet.freshReceiveKey();
// Send three transactions, with one being an address type and the other being a raw CHECKSIG type pubkey only,
// and the final one being a key we do have. We expect the first two inputs to be dummy values and the last
// to be signed correctly.
Transaction t1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub.toAddress(PARAMS));
Transaction t2 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub);
Transaction t3 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, priv2);
SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS);
req.missingSigsMode = missSigMode;
wallet.completeTx(req);
byte[] dummySig = TransactionSignature.dummy().encodeToBitcoin();
// Selected inputs can be in any order.
for (int i = 0; i < req.tx.getInputs().size(); i++) {
TransactionInput input = req.tx.getInput(i);
if (input.getConnectedOutput().getParentTransaction().equals(t1)) {
assertArrayEquals(expectedSig, input.getScriptSig().getChunks().get(0).data);
} else if (input.getConnectedOutput().getParentTransaction().equals(t2)) {
assertArrayEquals(expectedSig, input.getScriptSig().getChunks().get(0).data);
} else if (input.getConnectedOutput().getParentTransaction().equals(t3)) {
input.getScriptSig().correctlySpends(req.tx, i, t3.getOutput(0).getScriptPubKey());
}
}
assertTrue(TransactionSignature.isEncodingCanonical(dummySig));
}
代码示例来源:origin: greenaddress/GreenBits
results[0] = results[1] = null;
ECKey key2 = new ECKey();
wallet.importKey(key2);
代码示例来源:origin: greenaddress/GreenBits
ECKey key2 = new ECKey();
key2.setCreationTimeSeconds(Utils.currentTimeSeconds() - 86400);
wallet.importKey(key1);
wallet.importKey(key2);
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key1.toAddress(PARAMS));
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(PARAMS));
内容来源于网络,如有侵权,请联系作者删除!