|
|
@ -4,18 +4,20 @@ import com.sparrowwallet.drongo.ExtendedKey; |
|
|
|
import com.sparrowwallet.drongo.KeyPurpose; |
|
|
|
import com.sparrowwallet.drongo.policy.PolicyType; |
|
|
|
import com.sparrowwallet.drongo.protocol.ScriptType; |
|
|
|
import com.sparrowwallet.drongo.wallet.Keystore; |
|
|
|
import com.sparrowwallet.drongo.wallet.Wallet; |
|
|
|
import com.sparrowwallet.drongo.wallet.WalletModel; |
|
|
|
import com.sparrowwallet.drongo.wallet.WalletNode; |
|
|
|
import com.sparrowwallet.drongo.wallet.*; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
public class ElectrumPersonalServer implements WalletExport { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(ElectrumPersonalServer.class); |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getName() { |
|
|
|
return "Electrum Personal Server"; |
|
|
@ -37,6 +39,24 @@ public class ElectrumPersonalServer implements WalletExport { |
|
|
|
writer.write("# Electrum Personal Server configuration file fragments\n"); |
|
|
|
writer.write("# Copy the lines below into the relevant sections in your EPS config.ini file\n\n"); |
|
|
|
writer.write("# Copy into [master-public-keys] section\n"); |
|
|
|
Wallet masterWallet = wallet.isMasterWallet() ? wallet : wallet.getMasterWallet(); |
|
|
|
writeWalletXpub(masterWallet, writer); |
|
|
|
for(Wallet childWallet : masterWallet.getChildWallets()) { |
|
|
|
if(!childWallet.isNested()) { |
|
|
|
writeWalletXpub(childWallet, writer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
writeBip47Addresses(masterWallet, writer); |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
} catch(Exception e) { |
|
|
|
log.error("Could not export EPS wallet", e); |
|
|
|
throw new ExportException("Could not export EPS wallet", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void writeWalletXpub(Wallet wallet, BufferedWriter writer) throws IOException { |
|
|
|
writer.write(wallet.getFullName().replace(' ', '_') + " = "); |
|
|
|
|
|
|
|
ExtendedKey.Header xpubHeader = ExtendedKey.Header.fromScriptType(wallet.getScriptType(), false); |
|
|
@ -54,7 +74,9 @@ public class ElectrumPersonalServer implements WalletExport { |
|
|
|
} |
|
|
|
|
|
|
|
writer.newLine(); |
|
|
|
} |
|
|
|
|
|
|
|
private static void writeBip47Addresses(Wallet wallet, BufferedWriter writer) throws IOException { |
|
|
|
if(wallet.hasPaymentCode()) { |
|
|
|
writer.write("\n# Copy into [watch-only-addresses] section\n"); |
|
|
|
WalletNode notificationNode = wallet.getNotificationWallet().getNode(KeyPurpose.NOTIFICATION); |
|
|
@ -85,11 +107,6 @@ public class ElectrumPersonalServer implements WalletExport { |
|
|
|
|
|
|
|
writer.write("\n# Important: If this wallet receives any BIP47 payments, redo this export"); |
|
|
|
} |
|
|
|
|
|
|
|
writer.flush(); |
|
|
|
} catch(Exception e) { |
|
|
|
throw new ExportException("Could not export wallet", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -111,4 +128,9 @@ public class ElectrumPersonalServer implements WalletExport { |
|
|
|
public boolean walletExportRequiresDecryption() { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean exportsAllWallets() { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|