当前位置: 首页>>代码示例>>Java>>正文


Java KeyCrypter.getUnderstoodEncryptionType方法代码示例

本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypter.getUnderstoodEncryptionType方法的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypter.getUnderstoodEncryptionType方法的具体用法?Java KeyCrypter.getUnderstoodEncryptionType怎么用?Java KeyCrypter.getUnderstoodEncryptionType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.crypto.KeyCrypter的用法示例。


在下文中一共展示了KeyCrypter.getUnderstoodEncryptionType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: walletToProto

import org.bitcoinj.crypto.KeyCrypter; //导入方法依赖的package包/类
/**
 * Converts the given wallet to the object representation of the protocol buffers. This can be modified, or
 * additional data fields set, before serialization takes place.
 */
public Protos.Wallet walletToProto(Wallet wallet) {
    Protos.Wallet.Builder walletBuilder = Protos.Wallet.newBuilder();
    walletBuilder.setNetworkIdentifier(wallet.getNetworkParameters().getId());
    if (wallet.getDescription() != null) {
        walletBuilder.setDescription(wallet.getDescription());
    }

    for (WalletTransaction wtx : wallet.getWalletTransactions()) {
        Protos.Transaction txProto = makeTxProto(wtx);
        walletBuilder.addTransaction(txProto);
    }

    walletBuilder.addAllKey(wallet.serializeKeyChainGroupToProtobuf());

    for (Script script : wallet.getWatchedScripts()) {
        Protos.Script protoScript =
                Protos.Script.newBuilder()
                        .setProgram(ByteString.copyFrom(script.getProgram()))
                        .setCreationTimestamp(script.getCreationTimeSeconds() * 1000)
                        .build();

        walletBuilder.addWatchedScript(protoScript);
    }

    // Populate the lastSeenBlockHash field.
    Sha256Hash lastSeenBlockHash = wallet.getLastBlockSeenHash();
    if (lastSeenBlockHash != null) {
        walletBuilder.setLastSeenBlockHash(hashToByteString(lastSeenBlockHash));
        walletBuilder.setLastSeenBlockHeight(wallet.getLastBlockSeenHeight());
    }
    if (wallet.getLastBlockSeenTimeSecs() > 0)
        walletBuilder.setLastSeenBlockTimeSecs(wallet.getLastBlockSeenTimeSecs());

    // Populate the scrypt parameters.
    KeyCrypter keyCrypter = wallet.getKeyCrypter();
    if (keyCrypter == null) {
        // The wallet is unencrypted.
        walletBuilder.setEncryptionType(EncryptionType.UNENCRYPTED);
    } else {
        // The wallet is encrypted.
        walletBuilder.setEncryptionType(keyCrypter.getUnderstoodEncryptionType());
        if (keyCrypter instanceof KeyCrypterScrypt) {
            KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) keyCrypter;
            walletBuilder.setEncryptionParameters(keyCrypterScrypt.getScryptParameters());
        } else {
            // Some other form of encryption has been specified that we do not know how to persist.
            throw new RuntimeException("The wallet has encryption of type '" + keyCrypter.getUnderstoodEncryptionType() + "' but this WalletProtobufSerializer does not know how to persist this.");
        }
    }

    if (wallet.getKeyRotationTime() != null) {
        long timeSecs = wallet.getKeyRotationTime().getTime() / 1000;
        walletBuilder.setKeyRotationTime(timeSecs);
    }

    populateExtensions(wallet, walletBuilder);

    for (Map.Entry<String, ByteString> entry : wallet.getTags().entrySet()) {
        Protos.Tag.Builder tag = Protos.Tag.newBuilder().setTag(entry.getKey()).setData(entry.getValue());
        walletBuilder.addTags(tag);
    }

    for (TransactionSigner signer : wallet.getTransactionSigners()) {
        // do not serialize LocalTransactionSigner as it's being added implicitly
        if (signer instanceof LocalTransactionSigner)
            continue;
        Protos.TransactionSigner.Builder protoSigner = Protos.TransactionSigner.newBuilder();
        protoSigner.setClassName(signer.getClass().getName());
        protoSigner.setData(ByteString.copyFrom(signer.serialize()));
        walletBuilder.addTransactionSigners(protoSigner);
    }

    // Populate the wallet version.
    walletBuilder.setVersion(wallet.getVersion());

    return walletBuilder.build();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:82,代码来源:WalletProtobufSerializer.java

示例2: walletToProto

import org.bitcoinj.crypto.KeyCrypter; //导入方法依赖的package包/类
/**
 * Converts the given wallet to the object representation of the protocol buffers. This can be modified, or
 * additional data fields set, before serialization takes place.
 */
public Protos.Wallet walletToProto(Wallet wallet) {
    Protos.Wallet.Builder walletBuilder = Protos.Wallet.newBuilder();
    walletBuilder.setNetworkIdentifier(wallet.getNetworkParameters().getId());
    if (wallet.getDescription() != null) {
        walletBuilder.setDescription(wallet.getDescription());
    }

    for (WalletTransaction wtx : wallet.getWalletTransactions()) {
        Protos.Transaction txProto = makeTxProto(wtx);
        walletBuilder.addTransaction(txProto);
    }

    walletBuilder.addAllKey(wallet.serializeKeychainToProtobuf());

    for (Script script : wallet.getWatchedScripts()) {
        Protos.Script protoScript =
                Protos.Script.newBuilder()
                        .setProgram(ByteString.copyFrom(script.getProgram()))
                        .setCreationTimestamp(script.getCreationTimeSeconds() * 1000)
                        .build();

        walletBuilder.addWatchedScript(protoScript);
    }

    // Populate the lastSeenBlockHash field.
    Sha256Hash lastSeenBlockHash = wallet.getLastBlockSeenHash();
    if (lastSeenBlockHash != null) {
        walletBuilder.setLastSeenBlockHash(hashToByteString(lastSeenBlockHash));
        walletBuilder.setLastSeenBlockHeight(wallet.getLastBlockSeenHeight());
    }
    if (wallet.getLastBlockSeenTimeSecs() > 0)
        walletBuilder.setLastSeenBlockTimeSecs(wallet.getLastBlockSeenTimeSecs());

    // Populate the scrypt parameters.
    KeyCrypter keyCrypter = wallet.getKeyCrypter();
    if (keyCrypter == null) {
        // The wallet is unencrypted.
        walletBuilder.setEncryptionType(EncryptionType.UNENCRYPTED);
    } else {
        // The wallet is encrypted.
        walletBuilder.setEncryptionType(keyCrypter.getUnderstoodEncryptionType());
        if (keyCrypter instanceof KeyCrypterScrypt) {
            KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) keyCrypter;
            walletBuilder.setEncryptionParameters(keyCrypterScrypt.getScryptParameters());
        } else {
            // Some other form of encryption has been specified that we do not know how to persist.
            throw new RuntimeException("The wallet has encryption of type '" + keyCrypter.getUnderstoodEncryptionType() + "' but this WalletProtobufSerializer does not know how to persist this.");
        }
    }

    if (wallet.getKeyRotationTime() != null) {
        long timeSecs = wallet.getKeyRotationTime().getTime() / 1000;
        walletBuilder.setKeyRotationTime(timeSecs);
    }

    populateExtensions(wallet, walletBuilder);

    for (Map.Entry<String, ByteString> entry : wallet.getTags().entrySet()) {
        Protos.Tag.Builder tag = Protos.Tag.newBuilder().setTag(entry.getKey()).setData(entry.getValue());
        walletBuilder.addTags(tag);
    }

    for (TransactionSigner signer : wallet.getTransactionSigners()) {
        // do not serialize LocalTransactionSigner as it's being added implicitly
        if (signer instanceof LocalTransactionSigner)
            continue;
        Protos.TransactionSigner.Builder protoSigner = Protos.TransactionSigner.newBuilder();
        protoSigner.setClassName(signer.getClass().getName());
        protoSigner.setData(ByteString.copyFrom(signer.serialize()));
        walletBuilder.addTransactionSigners(protoSigner);
    }

    // Populate the wallet version.
    walletBuilder.setVersion(wallet.getVersion());

    return walletBuilder.build();
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:82,代码来源:WalletProtobufSerializer.java


注:本文中的org.bitcoinj.crypto.KeyCrypter.getUnderstoodEncryptionType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。