Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Sep 27, 2023
1 parent 8df5438 commit 6e68d2a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ export class CoreClient {
if (!names.includes(label)) {
if (!files.includes(label)) {
await wallet._create()
} else {
await wallet._load()
}
await wallet._load()
}
wallets[label] = wallet
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const DUST_LIMIT = 1_000
export const FALLBACK_FEE = 5_000
export const FAUCET_MIN_BAL = 10_000_000_000
export const FAUCET_MIN_BAL = 100_000_000 * 50 * 25
export const INIT_BLOCK_CT = 125
export const MIN_TX_FEE = 1_000
export const RATE_LIMIT = 0
export const SAT_MULTI = 100_000_000
Expand Down
16 changes: 13 additions & 3 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {

import * as CONST from './const.js'

const { FALLBACK_FEE, FAUCET_MIN_BAL, SAT_MULTI, RANDOM_PORT } = CONST
const { FALLBACK_FEE, FAUCET_MIN_BAL, INIT_BLOCK_CT, SAT_MULTI, RANDOM_PORT } = CONST

export class CoreDaemon extends EventEmitter {
readonly _client : CoreClient
Expand Down Expand Up @@ -151,8 +151,18 @@ export class CoreDaemon extends EventEmitter {
}

async _init () {
this._faucet = await this.client.load_wallet('faucet')
return this.faucet.ensure_funds(FAUCET_MIN_BAL / SAT_MULTI)
const debug = this.opt.debug
const min_bal = FAUCET_MIN_BAL / SAT_MULTI
this._faucet = await this.client.load_wallet('faucet')
if (this.opt.network === 'regtest') {
const addr = await this.faucet.get_address('faucet')
let bal = await this.faucet.balance
while (bal <= min_bal) {
if (debug) console.log('[core] Faucet generating blocks. Balance:', bal)
await this.client.mine_blocks(INIT_BLOCK_CT, addr)
bal = await this.faucet.balance
}
}
}

async startup (params : string[] = []) {
Expand Down
14 changes: 7 additions & 7 deletions src/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ export class CoreWallet {
if (debug) console.log('[wallet] using cached address:', addr)
return addr
}
const addr_book = await this.cmd('getaddressesbylabel', label, { cache : true })
const addr_list = Object.keys(addr_book)

addr = (addr_list.length !== 0)
? addr_list[0]
: await this.gen_address({ label })

try {
const addr_book = await this.cmd('getaddressesbylabel', label, { cache : true })
const addr_list = Object.keys(addr_book)
addr = addr_list[0]
} catch {
addr = await this.gen_address({ label })
}
this._addrs.set(label, addr)
return addr
}
Expand Down

0 comments on commit 6e68d2a

Please sign in to comment.