diff --git a/public/chain_config.json b/public/chain_config.json index f12aa4b..64f80ae 100644 --- a/public/chain_config.json +++ b/public/chain_config.json @@ -255,12 +255,62 @@ "win32": "bitnames-latest-x86_64-pc-windows-gnu.exe" }, "network": { - "port": 0 + "port": 6002 }, "chain_type": 2, "chain_layer": 2, "slot": "2" }, + { + "id": "bitassets", + "enabled": true, + "version": "", + "display_name": "Bitassets", + "description": "A sidechain for digital assets (ERC-20 / NFT / ICO / etc)", + "repo_url": "https://github.com/LayerTwo-Labs/plain-bitassets.git", + "released": "yes", + "directories": { + "base": { + "linux": ".local/share/plain_bitassets", + "darwin": "Library/Application Support/plain_bitassets", + "win32": "AppData/Roaming/plain_bitassets" + }, + "wallet": "wallet.mdb" + }, + "extract_dir": { + "linux": "Drivechain-Launcher-Downloads/bitassets", + "darwin": "Drivechain-Launcher-Downloads/bitassets", + "win32": "Drivechain-Launcher-Downloads/bitassets" + }, + "download": { + "urls": { + "linux": "https://releases.drivechain.info/L2-S4-BitAssets-latest-x86_64-unknown-linux-gnu.zip", + "darwin": "https://releases.drivechain.info/L2-S4-BitAssets-latest-x86_64-apple-darwin.zip", + "win32": "https://releases.drivechain.info/L2-S4-BitAssets-latest-x86_64-pc-windows-gnu.zip" + }, + "sizes": { + "linux": "", + "darwin": "", + "win32": "" + }, + "hashes": { + "linux": "", + "darwin": "", + "win32": "" + } + }, + "binary": { + "linux": "bitassets-latest-x86_64-unknown-linux-gnu", + "darwin": "bitassets-latest-x86_64-apple-darwin", + "win32": "bitassets-latest-x86_64-pc-windows-gnu.exe" + }, + "network": { + "port": 6004 + }, + "chain_type": 2, + "chain_layer": 2, + "slot": "4" + }, { "id": "thunder-orchard", "enabled": { @@ -353,11 +403,11 @@ "win32": "ethside-latest-x86_64-pc-windows-gnu.exe" }, "network": { - "port": 6004 + "port": 8545 }, "chain_type": 2, "chain_layer": 2, - "slot": "4" + "slot": "6" } ] } diff --git a/public/electron.js b/public/electron.js index 6e66848..c045a08 100644 --- a/public/electron.js +++ b/public/electron.js @@ -258,23 +258,37 @@ function setupIPCHandlers() { const chain = config.chains.find(c => c.id === chainId); let args = []; - // Only for Thunder and Bitnames (layer 2 chains) + // For all layer 2 chains with a slot number if (chain && chain.chain_layer === 2 && chain.slot) { - const walletPath = path.join( + // Determine the correct wallet path based on chain configuration + const baseDir = path.join( app.getPath("home"), - chain.directories.base[process.platform], - "wallet.mdb" + chain.directories.base[process.platform] ); + // Get the wallet path, which might be a subdirectory or direct file based on chain config + let walletPath; + if (chain.directories.wallet) { + walletPath = path.join(baseDir, chain.directories.wallet); + } else { + walletPath = path.join(baseDir, "wallet.mdb"); + } + const walletExists = await fs.pathExists(walletPath); - console.log(`[${chainId}] Checking wallet.mdb at: ${walletPath}`); + console.log(`[${chainId}] Checking wallet at: ${walletPath}`); if (!walletExists) { + // Get mnemonic path using slot (not chain ID) const mnemonicPath = walletManager.walletService.getMnemonicPath(chain.slot); - args = ['--mnemonic-seed-phrase-path', mnemonicPath]; - console.log(`[${chainId}] First run detected - passing mnemonic arg: ${mnemonicPath}`); + + if (!mnemonicPath) { + console.error(`[${chainId}] No mnemonic file found for slot ${chain.slot}`); + } else { + args = ['--mnemonic-seed-phrase-path', mnemonicPath]; + console.log(`[${chainId}] First run detected - passing mnemonic arg: ${mnemonicPath}`); + } } else { - console.log(`[${chainId}] wallet.mdb exists - skipping mnemonic arg`); + console.log(`[${chainId}] Wallet exists at ${walletPath} - skipping mnemonic arg`); } } diff --git a/public/modules/walletManager.js b/public/modules/walletManager.js index e0d08cc..59e9d13 100644 --- a/public/modules/walletManager.js +++ b/public/modules/walletManager.js @@ -82,8 +82,11 @@ class WalletManager extends EventEmitter { return await this.walletService.deriveL1Starter(); } // For sidechains - else { - return await this.walletService.deriveSidechainStarter(chain.id); + else if (chain.slot) { + console.log(`Deriving sidechain wallet for chain ${chainId} with slot ${chain.slot}`); + return await this.walletService.deriveSidechainStarter(parseInt(chain.slot)); + } else { + throw new Error(`Chain ${chainId} has no slot number`); } } catch (error) { console.error(`Error deriving wallet for chain ${chainId}:`, error); @@ -97,9 +100,16 @@ class WalletManager extends EventEmitter { try { const walletDir = this.walletService.walletDir; - const walletPath = chain.chain_layer === 1 - ? path.join(walletDir, 'l1_starter.json') - : path.join(walletDir, `sidechain_${chainId}_starter.json`); + let walletPath; + + if (chain.chain_layer === 1) { + walletPath = path.join(walletDir, 'l1_starter.json'); + } else if (chain.slot) { + walletPath = path.join(walletDir, `sidechain_${chain.slot}_starter.json`); + } else { + console.error(`Chain ${chainId} has no slot number`); + return null; + } if (await fs.pathExists(walletPath)) { return await fs.readJson(walletPath); diff --git a/public/modules/walletService.js b/public/modules/walletService.js index 56796c9..26c9d70 100644 --- a/public/modules/walletService.js +++ b/public/modules/walletService.js @@ -246,13 +246,15 @@ class WalletService extends EventEmitter { derivation_path: sidechainPath }; - const chainNames = { - 9: 'Thunder', - 2: 'Bitnames', - 3: 'ZSide' - }; - const chainName = chainNames[sidechainSlot] || 'Unknown'; - console.log(`Generated new sidechain starter for slot ${sidechainSlot} (${chainName})`); + // Get chain name from config + const slotString = sidechainSlot.toString(); + const chain = this.config.chains.find(c => c.slot === slotString); + + if (!chain || !chain.display_name) { + throw new Error(`No chain configuration found for slot ${sidechainSlot}`); + } + + console.log(`Generated new sidechain starter for slot ${sidechainSlot} (${chain.display_name})`); await this.saveSidechainStarter(sidechainSlot, sidechainStarter); return sidechainStarter; @@ -476,8 +478,20 @@ class WalletService extends EventEmitter { } } + // Find all sidechain slots from the configuration + const sidechainSlots = []; + for (const chain of this.config.chains) { + if (chain.slot && !isNaN(parseInt(chain.slot))) { + const slot = parseInt(chain.slot); + if (!sidechainSlots.includes(slot)) { + sidechainSlots.push(slot); + } + } + } + + console.log(`Found sidechain slots in configuration: ${sidechainSlots.join(', ')}`); + // Check and generate sidechain starters if needed - const sidechainSlots = [9, 2, 3]; // Thunder, Bitnames, and ZSide respectively for (const slot of sidechainSlots) { const sidechainPath = path.join(this.walletDir, `sidechain_${slot}_starter.json`); if (!(await fs.pathExists(sidechainPath))) { diff --git a/src/CardData.json b/src/CardData.json index 67d135f..4fb41f5 100644 --- a/src/CardData.json +++ b/src/CardData.json @@ -34,5 +34,11 @@ "display_name": "ZSide", "description": "Privacy sidechain based on zCash", "dependencies": ["bitwindow"] + }, + { + "id": "bitassets", + "display_name": "Bitassets", + "description": "A sidechain for digital assets (ERC-20 / NFT / ICO / etc)", + "dependencies": ["bitwindow"] } ]