-
Notifications
You must be signed in to change notification settings - Fork 1
/
bcoin_wallet.js
50 lines (36 loc) · 1007 Bytes
/
bcoin_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
47
48
49
50
'use strict';
var crypto = require('bcoin/lib/crypto/crypto');
var WalletDB = require('bcoin/lib/wallet/walletdb');
var MTX = require('bcoin/lib/primitives/mtx');
var Outpoint = require('bcoin/lib/primitives/outpoint');
var walletdb;
function dummy() {
var hash = crypto.randomBytes(32).toString('hex');
return new Outpoint(hash, 0);
}
walletdb = new WalletDB({
network: 'simnet',
db: 'memory',
nodes: ['10.7.64.53', 'redsquad.dev.purse.io']
});
async function main() {
var wallet, acct, mtx, tx, wtx;
await walletdb.open();
wallet = await walletdb.create();
console.log('Created wallet');
console.log(wallet);
acct = await wallet.createAccount({
name: 'foo'
});
console.log('Created account');
console.log(acct);
mtx = new MTX();
mtx.addOutpoint(dummy());
mtx.addOutput(acct.getReceive(), 50460);
tx = mtx.toTX();
await walletdb.addTX(tx);
wtx = await wallet.getTX(tx.hash('hex'));
console.log('Added transaction');
console.log(wtx);
}
main();