Add a few comments
This commit is contained in:
11
src/index.ts
11
src/index.ts
@@ -22,40 +22,49 @@ export class App {
|
|||||||
static async create(genesisData: WalletHDWatchGenesisData) {
|
static async create(genesisData: WalletHDWatchGenesisData) {
|
||||||
const debug = Debug('xpub');
|
const debug = Debug('xpub');
|
||||||
|
|
||||||
|
// Create the storage for the app.
|
||||||
debug('Creating storage...');
|
debug('Creating storage...');
|
||||||
const storage = await StorageSQLite.createOrOpen('xpub-backend.sqlite');
|
const storage = await StorageSQLite.createOrOpen('xpub-backend.sqlite');
|
||||||
|
|
||||||
|
// Create the blockchain cache for the app.
|
||||||
debug('Creating blockchain cache...');
|
debug('Creating blockchain cache...');
|
||||||
const blockchainCache = await storage.createOrGetStore('blockchain', {
|
const blockchainCache = await storage.createOrGetStore('blockchain', {
|
||||||
syncInMemory: false
|
syncInMemory: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create the wallet cache for the app.
|
||||||
debug('Creating wallet cache...');
|
debug('Creating wallet cache...');
|
||||||
const walletCache = await storage.createOrGetStore('wallet', {
|
const walletCache = await storage.createOrGetStore('wallet', {
|
||||||
syncInMemory: false
|
syncInMemory: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create the blockchain for the app.
|
||||||
debug('Creating blockchain...');
|
debug('Creating blockchain...');
|
||||||
const blockchain = await BlockchainElectrum.from({
|
const blockchain = await BlockchainElectrum.from({
|
||||||
store: blockchainCache,
|
store: blockchainCache,
|
||||||
servers: [ 'cashnode.bch.ninja' ]
|
servers: [ 'cashnode.bch.ninja' ]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create the wallet for the app.
|
||||||
debug('Creating wallet...');
|
debug('Creating wallet...');
|
||||||
const wallet = await WalletHDWatch.from({
|
const wallet = await WalletHDWatch.from({
|
||||||
blockchain,
|
blockchain,
|
||||||
cache: walletCache
|
cache: walletCache
|
||||||
}, genesisData);
|
}, genesisData);
|
||||||
|
|
||||||
|
// Create the routes for the app.
|
||||||
debug('Creating Routes...');
|
debug('Creating Routes...');
|
||||||
const routes = new WalletRoutes(wallet);
|
const routes = new WalletRoutes(wallet);
|
||||||
|
|
||||||
|
// Create the router for the app.
|
||||||
debug('Creating Router...');
|
debug('Creating Router...');
|
||||||
const router = new HTTPService({ routes: [routes], debug });
|
const router = new HTTPService({ routes: [routes], debug });
|
||||||
|
|
||||||
|
// Create the app.
|
||||||
debug('Creating App...');
|
debug('Creating App...');
|
||||||
const app = new App({ blockchain, wallet, httpService: router, debug });
|
const app = new App({ blockchain, wallet, httpService: router, debug });
|
||||||
|
|
||||||
|
// Start the app.
|
||||||
await app.start();
|
await app.start();
|
||||||
return app;
|
return app;
|
||||||
|
|
||||||
@@ -66,6 +75,7 @@ export class App {
|
|||||||
async start() {
|
async start() {
|
||||||
this.deps.debug('Starting app...');
|
this.deps.debug('Starting app...');
|
||||||
|
|
||||||
|
// Start the following services in parallel as they have no dependency on each other.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Start the blockchain
|
// Start the blockchain
|
||||||
this.deps.blockchain.start()
|
this.deps.blockchain.start()
|
||||||
@@ -80,6 +90,7 @@ export class App {
|
|||||||
.then(() => this.deps.debug('Router started')),
|
.then(() => this.deps.debug('Router started')),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Log the current RAM usage.
|
||||||
this.deps.debug(`Current RAM usage: ${getCurrentRamUsage()} MB`);
|
this.deps.debug(`Current RAM usage: ${getCurrentRamUsage()} MB`);
|
||||||
this.deps.debug('App started');
|
this.deps.debug('App started');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user