feat: ✨ New methods
parent
c4eca58702
commit
6988bfd410
31
main.js
31
main.js
|
@ -11,7 +11,8 @@ module.exports = class Wallet {
|
||||||
password: settings.password,
|
password: settings.password,
|
||||||
})
|
})
|
||||||
} catch (openErr) {
|
} catch (openErr) {
|
||||||
// create wallet
|
|
||||||
|
// Create wallet
|
||||||
try {
|
try {
|
||||||
this.rpc('generate_from_keys', {
|
this.rpc('generate_from_keys', {
|
||||||
restore_height: settings.restoreHeight,
|
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 open wallet "${settings.filename}": ${openErr}`)
|
||||||
console.error(`Failed to create wallet "${settings.filename}": ${createErr}`)
|
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) {
|
async rpc(method, params=undefined) {
|
||||||
const res = await axios.post(`${this.url}/json_rpc`, {
|
const res = await axios.post(`${this.url}/json_rpc`, {
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
|
@ -45,4 +57,21 @@ module.exports = class Wallet {
|
||||||
else return res.data.result
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "monero-wallet-rpc-js",
|
"name": "monero-wallet-rpc-js",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "Javascript wrapper for monero-wallet-rpc calls",
|
"description": "Javascript wrapper for monero-wallet-rpc calls",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue