feat: New methods

main
Keith Irwin 2024-04-21 13:10:22 -06:00
parent c4eca58702
commit 6988bfd410
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
2 changed files with 31 additions and 2 deletions

31
main.js
View File

@ -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')
}
}

View File

@ -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": {