db option.
This commit is contained in:
parent
a3720bd42d
commit
1898b38c49
@ -42,6 +42,11 @@ function Environment(options) {
|
|||||||
|| options.prefix
|
|| options.prefix
|
||||||
|| process.env.HOME + '/.bcoin';
|
|| process.env.HOME + '/.bcoin';
|
||||||
|
|
||||||
|
this.db = options.db;
|
||||||
|
|
||||||
|
if (process.env.BCOIN_DB != null)
|
||||||
|
this.db = process.env.BCOIN_DB;
|
||||||
|
|
||||||
this.debugLogs = options.debug;
|
this.debugLogs = options.debug;
|
||||||
|
|
||||||
if (process.env.BCOIN_DEBUG != null)
|
if (process.env.BCOIN_DEBUG != null)
|
||||||
|
|||||||
@ -5,13 +5,12 @@
|
|||||||
* https://github.com/indutny/bcoin
|
* https://github.com/indutny/bcoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var db = {};
|
|
||||||
|
|
||||||
module.exports = function(bcoin) {
|
module.exports = function(bcoin) {
|
||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var network = bcoin.protocol.network;
|
var network = bcoin.protocol.network;
|
||||||
|
var db = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LDB
|
* LDB
|
||||||
@ -55,15 +54,18 @@ function ldb(options) {
|
|||||||
function getLocation(options) {
|
function getLocation(options) {
|
||||||
if (options.location)
|
if (options.location)
|
||||||
return options.location;
|
return options.location;
|
||||||
return bcoin.prefix + '/' + options.name + '-' + network.type + '.db';
|
|
||||||
|
return bcoin.prefix
|
||||||
|
+ '/'
|
||||||
|
+ options.name
|
||||||
|
+ '-'
|
||||||
|
+ network.type
|
||||||
|
+ '.db';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBackend(backend) {
|
function getBackend(backend) {
|
||||||
if (bcoin.isBrowser)
|
|
||||||
return require('level-js');
|
|
||||||
|
|
||||||
if (typeof backend !== 'string')
|
if (typeof backend !== 'string')
|
||||||
backend = process.env.BCOIN_DB;
|
backend = bcoin.db;
|
||||||
|
|
||||||
if (!backend || backend === 'leveldb')
|
if (!backend || backend === 'leveldb')
|
||||||
backend = 'leveldown';
|
backend = 'leveldown';
|
||||||
@ -77,6 +79,9 @@ function getBackend(backend) {
|
|||||||
if (backend === 'bst')
|
if (backend === 'bst')
|
||||||
return require('./bst');
|
return require('./bst');
|
||||||
|
|
||||||
|
if (bcoin.isBrowser)
|
||||||
|
return require('level-js');
|
||||||
|
|
||||||
bcoin.ensurePrefix();
|
bcoin.ensurePrefix();
|
||||||
|
|
||||||
return require(backend);
|
return require(backend);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
"bin": "./bin/node",
|
"bin": "./bin/node",
|
||||||
"preferGlobal": false,
|
"preferGlobal": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "rm -rf ~/.bcoin-test && BCOIN_PREFIX=~/.bcoin-test mocha --reporter spec test/*-test.js"
|
"test": "mocha --reporter spec test/*-test.js"
|
||||||
},
|
},
|
||||||
"repository": "git://github.com/bcoin-org/bcoin.git",
|
"repository": "git://github.com/bcoin-org/bcoin.git",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var bcoin = require('../')();
|
var bcoin = require('../')({ db: 'memory' });
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var opcodes = constants.opcodes;
|
var opcodes = constants.opcodes;
|
||||||
|
|
||||||
describe('Wallet', function() {
|
describe('Wallet', function() {
|
||||||
process.env.BCOIN_DB = 'bst';
|
|
||||||
var node = new bcoin.fullnode();
|
var node = new bcoin.fullnode();
|
||||||
node.on('error', function() {});
|
node.on('error', function() {});
|
||||||
|
|
||||||
@ -15,7 +14,6 @@ describe('Wallet', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have wallet', function(cb) {
|
it('should have wallet', function(cb) {
|
||||||
delete process.env.BCOIN_DB;
|
|
||||||
node.getWallet('primary', function(err, wallet) {
|
node.getWallet('primary', function(err, wallet) {
|
||||||
if (err)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var bcoin = require('../')();
|
var bcoin = require('../')({ db: 'memory' });
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
@ -24,8 +24,11 @@ var dummyInput = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('Wallet', function() {
|
describe('Wallet', function() {
|
||||||
var wdb = new bcoin.walletdb();
|
var wdb = new bcoin.walletdb({ verify: true });
|
||||||
wdb.tx.options.verify = true;
|
|
||||||
|
it('should open walletdb', function(cb) {
|
||||||
|
wdb.open(cb);
|
||||||
|
});
|
||||||
|
|
||||||
it('should generate new key and address', function() {
|
it('should generate new key and address', function() {
|
||||||
var w = bcoin.wallet();
|
var w = bcoin.wallet();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user