fix: 🐛 IIAFE for async constructor
parent
69c9b19c10
commit
afc930e3a4
36
README.md
36
README.md
|
@ -4,22 +4,23 @@ Simple wrapper for monero-wallet-rpc calls.
|
|||
|
||||
```javascript
|
||||
import Wallet from 'monero-wallet-rpc-js'
|
||||
(async () => {
|
||||
|
||||
// Load wallet
|
||||
let wallet; try {
|
||||
wallet = new Wallet({
|
||||
url: 'http://localhost:18082',
|
||||
filename: 'mywallet',
|
||||
password: 'secretpassword',
|
||||
address: '4....',
|
||||
viewKey: 'XXXXXXX...',
|
||||
spendKey: 'XXXXXXX...',
|
||||
restoreHeight: '573936',
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(`Failed to open wallet: ${err}`)
|
||||
}
|
||||
// Load wallet
|
||||
let loadedWallet; try {
|
||||
loadedWallet = new Wallet({
|
||||
url: 'http://localhost:18082',
|
||||
filename: 'mywallet',
|
||||
password: 'secretpassword',
|
||||
address: '4....',
|
||||
viewKey: 'XXXXXXX...',
|
||||
spendKey: 'XXXXXXX...',
|
||||
restoreHeight: '573936',
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(`Failed to open wallet: ${err}`)
|
||||
}
|
||||
|
||||
(async (wallet) => {
|
||||
|
||||
// Save wallet
|
||||
await wallet.store()
|
||||
|
@ -40,4 +41,9 @@ import Wallet from 'monero-wallet-rpc-js'
|
|||
console.log((await wallet.rpc('get_address', {
|
||||
account_index: 2
|
||||
})).address)
|
||||
|
||||
// Save and close wallet
|
||||
await wallet.close()
|
||||
|
||||
})(loadedWallet)
|
||||
```
|
||||
|
|
8
main.js
8
main.js
|
@ -1,7 +1,8 @@
|
|||
const axios = require('axios')
|
||||
|
||||
module.exports = class Wallet {
|
||||
constructor (settings) {
|
||||
// IIAFE https://stackoverflow.com/a/50885340
|
||||
constructor (settings) { return (async () => {
|
||||
this.url = settings.url
|
||||
|
||||
// Open wallet
|
||||
|
@ -37,8 +38,9 @@ module.exports = class Wallet {
|
|||
} catch (err) {
|
||||
console.error(`Failed to refresh wallet: ${err}`)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
})() }
|
||||
|
||||
// Arbitrary RPC call
|
||||
async rpc(method, params=undefined) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "monero-wallet-rpc-js",
|
||||
"type": "commonjs",
|
||||
"version": "1.2.9",
|
||||
"version": "1.2.10",
|
||||
"description": "Javascript wrapper for monero-wallet-rpc calls",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue