@neo-one/client-node
Version:
NEO•ONE client APIs for interacting with the NEO blockchain on Node.
176 lines (153 loc) • 4.69 kB
JavaScript
import fs from 'fs-extra';
import path from 'path';
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _next(value) {
step("next", value);
}
function _throw(err) {
step("throw", err);
}
_next();
});
};
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var LocalFileStore =
/*#__PURE__*/
function () {
function LocalFileStore(_ref) {
var dataPath = _ref.dataPath;
_classCallCheck(this, LocalFileStore);
this.type = 'file';
this._dataPath = dataPath;
}
_createClass(LocalFileStore, [{
key: "getWallets",
value: function () {
var _getWallets = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var _this = this;
var files;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return fs.ensureDir(this._dataPath);
case 2:
_context.next = 4;
return fs.readdir(this._dataPath);
case 4:
files = _context.sent;
return _context.abrupt("return", Promise.all(files.map(function (file) {
return fs.readJSON(path.resolve(_this._dataPath, file));
})));
case 6:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return function getWallets() {
return _getWallets.apply(this, arguments);
};
}()
}, {
key: "saveWallet",
value: function () {
var _saveWallet = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2(wallet) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return fs.writeJSON(this._getWalletPath(wallet), wallet);
case 2:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
return function saveWallet(_x) {
return _saveWallet.apply(this, arguments);
};
}()
}, {
key: "deleteWallet",
value: function () {
var _deleteWallet = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee3(wallet) {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return fs.remove(this._getWalletPath(wallet));
case 2:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
return function deleteWallet(_x2) {
return _deleteWallet.apply(this, arguments);
};
}()
}, {
key: "_getWalletPath",
value: function _getWalletPath(_ref2) {
var _ref2$account$id = _ref2.account.id,
network = _ref2$account$id.network,
address = _ref2$account$id.address;
return path.resolve(this._dataPath, "".concat(network, "-").concat(address, ".json"));
}
}]);
return LocalFileStore;
}();
// eslint-disable-next-line
export { LocalFileStore };
//# sourceMappingURL=es.js.map