diff --git a/main.js b/main.js index f25a0f9..d0d89a0 100644 --- a/main.js +++ b/main.js @@ -11,7 +11,8 @@ module.exports = class Wallet { password: settings.password, }) } catch (openErr) { - // create wallet + + // Create wallet try { this.rpc('generate_from_keys', { restore_height: settings.restoreHeight, @@ -25,10 +26,21 @@ module.exports = class Wallet { console.error(`Failed to open wallet "${settings.filename}": ${openErr}`) console.error(`Failed to create wallet "${settings.filename}": ${createErr}`) } + + } + + // Refresh wallet + try { + this.rpc('refresh', { + start_height: settings.restoreHeight || 0, + }) + } catch (err) { + console.error(`Failed to refresh wallet: ${err}`) } } + // Arbitrary RPC call async rpc(method, params=undefined) { const res = await axios.post(`${this.url}/json_rpc`, { jsonrpc: '2.0', @@ -45,4 +57,21 @@ module.exports = class Wallet { else return res.data.result } + // Get wallet synced height + async getHeight() { + return await this.rpc('get_height') + } + // Get wallet balance + async getBalance() { + return await this.rpc('get_balance') + } + // Save wallet + async store() { + return await this.rpc('store') + } + // Save and close wallet + async close() { + return await this.rpc('close_wallet') + } + } diff --git a/package.json b/package.json index d401913..e3022ac 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "monero-wallet-rpc-js", "type": "commonjs", - "version": "1.2.1", + "version": "1.2.2", "description": "Javascript wrapper for monero-wallet-rpc calls", "main": "main.js", "scripts": {