本文整理汇总了Java中org.bitcoinj.wallet.Protos类的典型用法代码示例。如果您正苦于以下问题:Java Protos类的具体用法?Java Protos怎么用?Java Protos使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Protos类属于org.bitcoinj.wallet包,在下文中一共展示了Protos类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializationUnencrypted
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void serializationUnencrypted() throws UnreadableWalletException {
Utils.setMockClock();
Date now = Utils.now();
final ECKey key1 = new ECKey();
Utils.rollMockClock(5000);
final ECKey key2 = new ECKey();
chain.importKeys(ImmutableList.of(key1, key2));
List<Protos.Key> keys = chain.serializeToProtobuf();
assertEquals(2, keys.size());
assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray());
assertArrayEquals(key2.getPubKey(), keys.get(1).getPublicKey().toByteArray());
assertArrayEquals(key1.getPrivKeyBytes(), keys.get(0).getSecretBytes().toByteArray());
assertArrayEquals(key2.getPrivKeyBytes(), keys.get(1).getSecretBytes().toByteArray());
long normTime = (long) (Math.floor(now.getTime() / 1000) * 1000);
assertEquals(normTime, keys.get(0).getCreationTimestamp());
assertEquals(normTime + 5000 * 1000, keys.get(1).getCreationTimestamp());
chain = BasicKeyChain.fromProtobufUnencrypted(keys);
assertEquals(2, chain.getKeys().size());
assertEquals(key1, chain.getKeys().get(0));
assertEquals(key2, chain.getKeys().get(1));
}
示例2: extensions
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void extensions() throws Exception {
myWallet.addExtension(new FooWalletExtension("com.whatever.required", true));
Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
// Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
try {
new WalletProtobufSerializer().readWallet(PARAMS, null, proto);
fail();
} catch (UnreadableWalletException e) {
assertTrue(e.getMessage().contains("mandatory"));
}
Wallet wallet = new WalletProtobufSerializer().readWallet(PARAMS,
new WalletExtension[]{ new FooWalletExtension("com.whatever.required", true) },
proto);
assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
// Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
Wallet wallet2 = new Wallet(PARAMS);
wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
Wallet wallet5 = new WalletProtobufSerializer().readWallet(PARAMS, null, proto2);
assertEquals(0, wallet5.getExtensions().size());
}
示例3: onPostExecute
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
protected void onPostExecute(Void aVoid) {
passwordTestTask = null;
if (Dialogs.dismissAllowingStateLoss(getFragmentManager(), PROCESSING_DIALOG_TAG)) return;
String yes = getString(com.fillerino.wallet.R.string.yes);
String no = getString(com.fillerino.wallet.R.string.no);
String message = getString(com.fillerino.wallet.R.string.debugging_test_wallet_password_results,
result.isUnlockSuccess ? yes : no, result.inputFingerprint, result.keyFingerprint);
if (result.scryptParams != null) {
Protos.ScryptParameters sp = result.scryptParams;
message += "\n\nScrypt:" +
"\nS = " + Hex.toHexString(sp.getSalt().toByteArray()) +
"\nN = " + sp.getN() +
"\nP = " + sp.getP() +
"\nR = " + sp.getR();
}
if (result.error != null) {
message += "\n\n" + result.error;
}
DialogBuilder.warn(getActivity(), com.fillerino.wallet.R.string.debugging_test_wallet_password)
.setMessage(message)
.setPositiveButton(com.fillerino.wallet.R.string.button_ok, null).create().show();
}
示例4: protoFromTransactionExtension
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Override
public Protos.TransactionExtension protoFromTransactionExtension(TransactionExtension txExtension) {
final DashTransactionExtension dashTxExt = CommonUtils.extractTransactionExtension(txExtension);
final Protos.TransactionExtension.Builder builder = Protos.TransactionExtension.newBuilder();
final DashTransactionWireStrategy wireStrategy = dashTxExt.getWireStrategy();
final Protos.TransactionExtension.WireStrategy protoWireStrategy;
if (wireStrategy != null) {
switch (wireStrategy) {
case INSTANT_X:
protoWireStrategy = Protos.TransactionExtension.WireStrategy.INSTANT_X; break;
case INSTANT_X_LOCKED:
protoWireStrategy = Protos.TransactionExtension.WireStrategy.INSTANT_X_LOCKED; break;
case STANDARD:
// fall down
default:
protoWireStrategy = Protos.TransactionExtension.WireStrategy.STANDARD;
}
} else {
protoWireStrategy = Protos.TransactionExtension.WireStrategy.STANDARD;
}
builder.setWireStrategy(protoWireStrategy);
builder.setLockTime(dashTxExt.getLockingTime());
return builder.build();
}
示例5: transactionExtensionFromProto
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Override
public DashTransactionExtension transactionExtensionFromProto(Protos.TransactionExtension txExtension, Transaction tx) {
final DashTransactionExtension dashTxExt = CommonUtils.extractDefinition(tx.getParams()).createTransactionExtension(tx);
final Protos.TransactionExtension.WireStrategy wireStrategy = txExtension.getWireStrategy();
final DashTransactionWireStrategy dashWireStrategy;
switch (wireStrategy) {
case INSTANT_X:
dashWireStrategy = DashTransactionWireStrategy.INSTANT_X;
break;
case INSTANT_X_LOCKED:
dashWireStrategy = DashTransactionWireStrategy.INSTANT_X_LOCKED;
break;
case STANDARD:
// fall down
default:
dashWireStrategy = DashTransactionWireStrategy.STANDARD;
}
dashTxExt.setWireStrategy(dashWireStrategy);
if (dashWireStrategy != DashTransactionWireStrategy.STANDARD)
dashTxExt.setLockingTime(txExtension.getLockTime());
return dashTxExt;
}
示例6: attemptHexConversion
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
private static Protos.Wallet attemptHexConversion(Protos.Wallet proto) {
// Try to convert any raw hashes and such to textual equivalents for easier debugging. This makes it a bit
// less "raw" but we will just abort on any errors.
try {
Protos.Wallet.Builder builder = proto.toBuilder();
for (Protos.Transaction.Builder tx : builder.getTransactionBuilderList()) {
tx.setHash(bytesToHex(tx.getHash()));
for (int i = 0; i < tx.getBlockHashCount(); i++)
tx.setBlockHash(i, bytesToHex(tx.getBlockHash(i)));
for (Protos.TransactionInput.Builder input : tx.getTransactionInputBuilderList())
input.setTransactionOutPointHash(bytesToHex(input.getTransactionOutPointHash()));
for (Protos.TransactionOutput.Builder output : tx.getTransactionOutputBuilderList()) {
if (output.hasSpentByTransactionHash())
output.setSpentByTransactionHash(bytesToHex(output.getSpentByTransactionHash()));
}
// TODO: keys, ip addresses etc.
}
return builder.build();
} catch (Throwable throwable) {
log.error("Failed to do hex conversion on wallet proto", throwable);
return proto;
}
}
示例7: testExtensions
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void testExtensions() throws Exception {
myWallet.addExtension(new SomeFooExtension("com.whatever.required", true));
Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
// Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
try {
new WalletProtobufSerializer().readWallet(params, null, proto);
fail();
} catch (UnreadableWalletException e) {
assertTrue(e.getMessage().contains("mandatory"));
}
Wallet wallet = new WalletProtobufSerializer().readWallet(params,
new WalletExtension[]{ new SomeFooExtension("com.whatever.required", true) },
proto);
assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
// Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
Wallet wallet2 = new Wallet(params);
wallet2.addExtension(new SomeFooExtension("com.whatever.optional", false));
Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
Wallet wallet5 = new WalletProtobufSerializer().readWallet(params, null, proto2);
assertEquals(0, wallet5.getExtensions().size());
}
示例8: testExtensions
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void testExtensions() throws Exception {
myWallet.addExtension(new FooWalletExtension("com.whatever.required", true));
Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
// Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
try {
new WalletProtobufSerializer().readWallet(params, null, proto);
fail();
} catch (UnreadableWalletException e) {
assertTrue(e.getMessage().contains("mandatory"));
}
Wallet wallet = new WalletProtobufSerializer().readWallet(params,
new WalletExtension[]{ new FooWalletExtension("com.whatever.required", true) },
proto);
assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
// Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
Wallet wallet2 = new Wallet(params);
wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
Wallet wallet5 = new WalletProtobufSerializer().readWallet(params, null, proto2);
assertEquals(0, wallet5.getExtensions().size());
}
示例9: readWallet
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
/**
* <p>Parses a wallet from the given stream, using the provided Wallet instance to load data into. This is primarily
* used when you want to register extensions. Data in the proto will be added into the wallet where applicable and
* overwrite where not.</p>
*
* <p>A wallet can be unreadable for various reasons, such as inability to open the file, corrupt data, internally
* inconsistent data, a wallet extension marked as mandatory that cannot be handled and so on. You should always
* handle {@link UnreadableWalletException} and communicate failure to the user in an appropriate manner.</p>
*
* @throws UnreadableWalletException thrown in various error conditions (see description).
*/
public Wallet readWallet(InputStream input) throws UnreadableWalletException {
Protos.Wallet walletProto = null;
try {
walletProto = parseToProto(input);
} catch (IOException e) {
throw new UnreadableWalletException("Could not load wallet file", e);
}
// System.out.println(TextFormat.printToString(walletProto));
NetworkParameters params = NetworkParameters.fromID(walletProto.getNetworkIdentifier());
Wallet wallet = new Wallet(params);
readWallet(walletProto, wallet);
return wallet;
}
示例10: loadExtensions
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
private void loadExtensions(Wallet wallet, Protos.Wallet walletProto) throws UnreadableWalletException {
final Map<String, WalletExtension> extensions = wallet.getExtensions();
for (Protos.Extension extProto : walletProto.getExtensionList()) {
String id = extProto.getId();
WalletExtension extension = extensions.get(id);
if (extension == null) {
if (extProto.getMandatory()) {
if (requireMandatoryExtensions)
throw new UnreadableWalletException("Unknown mandatory extension in wallet: " + id);
else
log.error("Unknown extension in wallet {}, ignoring", id);
}
} else {
log.info("Loading wallet extension {}", id);
try {
extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
} catch (Exception e) {
if (extProto.getMandatory() && requireMandatoryExtensions)
throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);
else
log.error("Error whilst reading extension {}, ignoring: {}", id, e);
}
}
}
}
示例11: setUp
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
super.setUp();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
encryptedWallet = new Wallet(params, keyCrypter);
aesKey = keyCrypter.deriveKey(PASSWORD1);
wrongAesKey = keyCrypter.deriveKey(WRONG_PASSWORD);
ECKey myEncryptedKey = encryptedWallet.addNewEncryptedKey(keyCrypter, aesKey);
myEncryptedAddress = myEncryptedKey.toAddress(params);
}
示例12: setUp
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder()
.setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
scryptParameters = scryptParametersBuilder.build();
BriefLogFormatter.init();
}
示例13: serializationEncrypted
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void serializationEncrypted() throws UnreadableWalletException {
ECKey key1 = new ECKey();
chain.importKeys(key1);
chain = chain.toEncrypted("foo bar");
key1 = chain.getKeys().get(0);
List<Protos.Key> keys = chain.serializeToProtobuf();
assertEquals(1, keys.size());
assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray());
assertFalse(keys.get(0).hasSecretBytes());
assertTrue(keys.get(0).hasEncryptedData());
chain = BasicKeyChain.fromProtobufEncrypted(keys, checkNotNull(chain.getKeyCrypter()));
assertEquals(key1.getEncryptedPrivateKey(), chain.getKeys().get(0).getEncryptedPrivateKey());
assertTrue(chain.checkPassword("foo bar"));
}
示例14: watching
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Test
public void watching() throws UnreadableWalletException {
ECKey key1 = new ECKey();
ECKey pub = ECKey.fromPublicOnly(key1.getPubKeyPoint());
chain.importKeys(pub);
assertEquals(1, chain.numKeys());
List<Protos.Key> keys = chain.serializeToProtobuf();
assertEquals(1, keys.size());
assertTrue(keys.get(0).hasPublicKey());
assertFalse(keys.get(0).hasSecretBytes());
chain = BasicKeyChain.fromProtobufUnencrypted(keys);
assertEquals(1, chain.numKeys());
assertFalse(chain.findKeyFromPubKey(pub.getPubKey()).hasPrivKey());
}
示例15: setUp
import org.bitcoinj.wallet.Protos; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
BriefLogFormatter.init();
}