Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions public/chain_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
]
}
30 changes: 22 additions & 8 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
}

Expand Down
20 changes: 15 additions & 5 deletions public/modules/walletManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
30 changes: 22 additions & 8 deletions public/modules/walletService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))) {
Expand Down
6 changes: 6 additions & 0 deletions src/CardData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]