MultiBit HD / Technical library
INDEPENDENT KEYCHAINX RESOURCE
WalletTypeExtension: persisted wallet family
Stores the wallet-type extension used during loading and interpretation. Compare the enum values and their persistence requirements before assuming an unknown or older wallet has the same semantics as a newly created wallet.
Source inspection only. Historical Java code; not executed or security-audited for this publication.
mbhd-core/src/main/java/org/multibit/hd/core/extensions/WalletTypeExtension.java
View the exact upstream file · Read raw source · License notices
SHA-256: 0459d8dca9cd8c13b6a8832f0c67d0fca3f58557a180bdce93c3afc90595bf7e
1package org.multibit.hd.core.extensions;23import com.google.common.base.Charsets;4import org.bitcoinj.core.Wallet;5import org.bitcoinj.core.WalletExtension;6import org.multibit.hd.core.dto.WalletType;7import org.slf4j.Logger;8import org.slf4j.LoggerFactory;910/**11 * <p>Wallet Extension to provide the following to Wallet:</p>12 * <ul>13 * <li>Persistence of the wallet type</li>14 * </ul>15 *16 * @since 0.0.117 */18public class WalletTypeExtension implements WalletExtension {1920 private static final Logger log = LoggerFactory.getLogger(WalletTypeExtension.class);2122 public static final String WALLET_TYPE_WALLET_EXTENSION_ID = "org.multibit.hd.core.WalletTypeExtension";2324 private WalletType walletType;2526 public WalletTypeExtension() {27 this.walletType = null;28 }2930 public WalletTypeExtension(WalletType walletType) {31 this.walletType = walletType;32 }3334 @Override35 public String getWalletExtensionID() {36 return WALLET_TYPE_WALLET_EXTENSION_ID;37 }3839 @Override40 public boolean isWalletExtensionMandatory() {41 return false;42 }4344 @Override45 public byte[] serializeWalletExtension() {46 if (walletType != null) {47 return walletType.name().getBytes(Charsets.UTF_8);48 } else {49 return WalletType.UNKNOWN.name().getBytes(Charsets.UTF_8);50 }51 }5253 @Override54 public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {5556 String serialisedString = new String(data, Charsets.UTF_8);57 log.debug("Parsing wallet type string '{}'", serialisedString);5859 if (WalletType.MBHD_SOFT_WALLET.name().equals(serialisedString)) {60 walletType = WalletType.MBHD_SOFT_WALLET;61 } else if (WalletType.TREZOR_SOFT_WALLET.name().equals(serialisedString)) {62 walletType = WalletType.TREZOR_SOFT_WALLET;63 } else if (WalletType.MBHD_SOFT_WALLET_BIP32.name().equals(serialisedString)) {64 walletType = WalletType.MBHD_SOFT_WALLET_BIP32;65 } else if (WalletType.TREZOR_HARD_WALLET.name().equals(serialisedString)) {66 walletType = WalletType.TREZOR_HARD_WALLET;67 } else if (WalletType.UNKNOWN.name().equals(serialisedString)) {68 walletType = WalletType.UNKNOWN;69 } else {70 // Could not parse71 log.warn("The wallet type of '{}' could not be parsed. Wallet type set to UNKNOWN", serialisedString);72 walletType = WalletType.UNKNOWN;73 }74 }7576 public WalletType getWalletType() {77 return walletType;78 }7980 @Override81 public boolean equals(Object o) {82 if (this == o) return true;83 if (o == null || getClass() != o.getClass()) return false;8485 WalletTypeExtension that = (WalletTypeExtension) o;8687 if (walletType != that.walletType) return false;8889 return true;90 }9192 @Override93 public int hashCode() {94 return walletType != null ? walletType.hashCode() : 0;95 }9697 @Override98 public String toString() {99 return "WalletTypeExtension{" +100 "walletType=" + walletType +101 '}';102 }103}Read in context
Stores the wallet-type extension used during loading and interpretation. Compare the enum values and their persistence requirements before assuming an unknown or older wallet has the same semantics as a newly created wallet.
Compare the callers, dependency versions and corresponding tests. The pinned file is one part of a larger application. Do not execute write, prune or migration routines against your only copy of a wallet.