forked from bcoin-org/bcash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.js
46 lines (33 loc) · 881 Bytes
/
wallet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const bcoin = require('../..');
const random = require('bcrypto/lib/random');
function dummy() {
const hash = random.randomBytes(32);
return new bcoin.Outpoint(hash, 0);
}
const walletdb = new bcoin.wallet.WalletDB({
network: 'testnet',
db: 'memory'
});
(async () => {
await walletdb.open();
const wallet = await walletdb.create();
console.log('Created wallet');
console.log(wallet);
const acct = await wallet.createAccount({
name: 'foo'
});
console.log('Created account');
console.log(acct);
const mtx = new bcoin.MTX();
mtx.addOutpoint(dummy());
mtx.addOutput(acct.receiveAddress(), 50460);
const tx = mtx.toTX();
await walletdb.addTX(tx);
const wtx = await wallet.getTX(tx.hash());
console.log('Added transaction');
console.log(wtx);
})().catch((err) => {
console.error(err.stack);
process.exit(1);
});