1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-29 08:07:51 +01:00
This commit is contained in:
Tim Daubenschütz 2017-05-11 17:24:34 +02:00
parent 53b9513206
commit c40927b4fc
15 changed files with 671 additions and 918 deletions

1009
dist/bundle/bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,18 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getApiUrls;
function getApiUrls(API_PATH) {
return {
'blocks': API_PATH + 'blocks',
'blocks_detail': API_PATH + 'blocks/%(blockId)s',
'outputs': API_PATH + 'outputs',
'statuses': API_PATH + 'statuses',
'transactions': API_PATH + 'transactions',
'transactions_detail': API_PATH + 'transactions/%(txId)s',
'votes': API_PATH + 'votes'
};
}
module.exports = exports['default'];

View File

@ -1,30 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getBlock;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param blockId
* @param API_PATH
*/
function getBlock(blockId, API_PATH) {
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['blocks_detail'], {
urlTemplateSpec: {
blockId: blockId
}
});
}
module.exports = exports['default'];

View File

@ -1,30 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getStatus;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param tx_id
* @param API_PATH
*/
function getStatus(tx_id, API_PATH) {
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['statuses'], {
query: {
tx_id: tx_id
}
});
}
module.exports = exports['default'];

View File

@ -1,30 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getTransaction;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param txId
* @param API_PATH
*/
function getTransaction(txId, API_PATH) {
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['transactions_detail'], {
urlTemplateSpec: {
txId: txId
}
});
}
module.exports = exports['default'];

View File

@ -1,54 +1,215 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.postTransaction = exports.pollStatusAndFetchTransaction = exports.listVotes = exports.listTransactions = exports.listOutputs = exports.listBlocks = exports.getStatus = exports.getTransaction = exports.getBlock = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _getBlock2 = require('./getBlock');
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getBlock3 = _interopRequireDefault(_getBlock2);
var _request = require('../request');
var _getTransaction2 = require('./getTransaction');
var _getTransaction3 = _interopRequireDefault(_getTransaction2);
var _getStatus2 = require('./getStatus');
var _getStatus3 = _interopRequireDefault(_getStatus2);
var _listBlocks2 = require('./listBlocks');
var _listBlocks3 = _interopRequireDefault(_listBlocks2);
var _listOutputs2 = require('./listOutputs');
var _listOutputs3 = _interopRequireDefault(_listOutputs2);
var _listTransactions2 = require('./listTransactions');
var _listTransactions3 = _interopRequireDefault(_listTransactions2);
var _listVotes2 = require('./listVotes');
var _listVotes3 = _interopRequireDefault(_listVotes2);
var _pollStatusAndFetchTransaction2 = require('./pollStatusAndFetchTransaction');
var _pollStatusAndFetchTransaction3 = _interopRequireDefault(_pollStatusAndFetchTransaction2);
var _postTransaction2 = require('./postTransaction');
var _postTransaction3 = _interopRequireDefault(_postTransaction2);
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.getBlock = _getBlock3.default;
exports.getTransaction = _getTransaction3.default;
exports.getStatus = _getStatus3.default;
exports.listBlocks = _listBlocks3.default;
exports.listOutputs = _listOutputs3.default;
exports.listTransactions = _listTransactions3.default;
exports.listVotes = _listVotes3.default;
exports.pollStatusAndFetchTransaction = _pollStatusAndFetchTransaction3.default;
exports.postTransaction = _postTransaction3.default;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Connection = function () {
function Connection(path, headers) {
_classCallCheck(this, Connection);
this.path = path;
this.headers = headers;
}
_createClass(Connection, [{
key: 'getApiUrls',
value: function getApiUrls(endpoints) {
return {
'blocks': this.path + 'blocks',
'blocks_detail': this.path + 'blocks/%(blockId)s',
'outputs': this.path + 'outputs',
'statuses': this.path + 'statuses',
'transactions': this.path + 'transactions',
'transactions_detail': this.path + 'transactions/%(txId)s',
'votes': this.path + 'votes'
}[endpoints];
}
}, {
key: 'req',
value: function req(path) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// NOTE: `options.headers` could be undefined, but that's OK.
options.headers = _extends({}, options.headers, this.headers);
return (0, _request2.default)(path, options);
}
/**
* @public
* @param blockId
*/
}, {
key: 'getBlock',
value: function getBlock(blockId) {
return this.req(this.getApiUrls('blocks_detail'), {
urlTemplateSpec: {
blockId: blockId
}
});
}
/**
* @public
* @param tx_id
*/
}, {
key: 'getStatus',
value: function getStatus(tx_id) {
return this.req(this.getApiUrls('statuses'), {
query: {
tx_id: tx_id
}
});
}
/**
* @public
* @param txId
*/
}, {
key: 'getTransaction',
value: function getTransaction(txId) {
return this.req(this.getApiUrls('transactions_detail'), {
urlTemplateSpec: {
txId: txId
}
});
}
/**
* @public
* @param tx_id
* @param status
*/
}, {
key: 'listBlocks',
value: function listBlocks(_ref) {
var tx_id = _ref.tx_id,
status = _ref.status;
return this.req(this.getApiUrls('blocks'), {
query: {
tx_id: tx_id,
status: status
}
});
}
/**
* @public
* @param public_key
* @param unspent
* @param onlyJsonResponse
*/
}, {
key: 'listOutputs',
value: function listOutputs(_ref2) {
var public_key = _ref2.public_key,
unspent = _ref2.unspent;
var onlyJsonResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return this.req(this.getApiUrls('outputs'), {
query: {
public_key: public_key,
unspent: unspent
}
}, onlyJsonResponse);
}
/**
* @public
* @param asset_id
* @param operation
*/
}, {
key: 'listTransactions',
value: function listTransactions(_ref3) {
var asset_id = _ref3.asset_id,
operation = _ref3.operation;
return this.req(this.getApiUrls('transactions'), {
query: {
asset_id: asset_id,
operation: operation
}
});
}
/**
* @public
* @param block_id
*/
}, {
key: 'listVotes',
value: function listVotes(block_id) {
return this.req(this.getApiUrls('votes'), {
query: {
block_id: block_id
}
});
}
/**
* @public
* @param tx_id
* @return {Promise}
*/
}, {
key: 'pollStatusAndFetchTransaction',
value: function pollStatusAndFetchTransaction(tx_id) {
var _this = this;
return new Promise(function (resolve, reject) {
var timer = setInterval(function () {
_this.getStatus(tx_id).then(function (res) {
console.log('Fetched transaction status:', res);
if (res.status === 'valid') {
clearInterval(timer);
_this.getTransaction(tx_id).then(function (res) {
console.log('Fetched transaction:', res);
resolve(res);
});
}
}).catch(function (err) {
clearInterval(timer);
reject(err);
});
}, 500);
});
}
/**
* @public
*
* @param transaction
*/
}, {
key: 'postTransaction',
value: function postTransaction(transaction) {
return this.req(this.getApiUrls('transactions'), {
method: 'POST',
jsonBody: transaction
});
}
}]);
return Connection;
}();

View File

@ -1,35 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = listBlocks;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param tx_id
* @param status
* @param API_PATH
*/
function listBlocks(_ref, API_PATH) {
var tx_id = _ref.tx_id,
status = _ref.status;
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['blocks'], {
query: {
tx_id: tx_id,
status: status
}
});
}
module.exports = exports['default'];

View File

@ -1,37 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = listOutputs;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param public_key
* @param unspent
* @param API_PATH
* @param onlyJsonResponse
*/
function listOutputs(_ref, API_PATH) {
var public_key = _ref.public_key,
unspent = _ref.unspent;
var onlyJsonResponse = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['outputs'], {
query: {
public_key: public_key,
unspent: unspent
}
}, onlyJsonResponse);
}
module.exports = exports['default'];

View File

@ -1,35 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = listTransactions;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param asset_id
* @param operation
* @param API_PATH
*/
function listTransactions(_ref, API_PATH) {
var asset_id = _ref.asset_id,
operation = _ref.operation;
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['transactions'], {
query: {
asset_id: asset_id,
operation: operation
}
});
}
module.exports = exports['default'];

View File

@ -1,30 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = listVotes;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
* @param block_id
* @param API_PATH
*/
function listVotes(block_id, API_PATH) {
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['votes'], {
query: {
block_id: block_id
}
});
}
module.exports = exports['default'];

View File

@ -1,44 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (tx_id, API_PATH) {
return new Promise(function (resolve, reject) {
var timer = setInterval(function () {
(0, _getStatus2.default)(tx_id, API_PATH).then(function (res) {
console.log('Fetched transaction status:', res);
if (res.status === 'valid') {
clearInterval(timer);
(0, _getTransaction2.default)(tx_id, API_PATH).then(function (res) {
console.log('Fetched transaction:', res);
resolve(res);
});
}
}).catch(function (err) {
clearInterval(timer);
reject(err);
});
}, 500);
});
};
var _getTransaction = require('./getTransaction');
var _getTransaction2 = _interopRequireDefault(_getTransaction);
var _getStatus = require('./getStatus');
var _getStatus2 = _interopRequireDefault(_getStatus);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports['default'];
/**
* @public
* @param tx_id
* @param API_PATH
* @return {Promise}
*/

View File

@ -1,30 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = postTransaction;
var _getApiUrls = require('./getApiUrls');
var _getApiUrls2 = _interopRequireDefault(_getApiUrls);
var _request = require('../request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @public
*
* @param transaction
* @param API_PATH
*/
function postTransaction(transaction, API_PATH) {
return (0, _request2.default)((0, _getApiUrls2.default)(API_PATH)['transactions'], {
method: 'POST',
jsonBody: transaction
});
}
module.exports = exports['default'];

View File

@ -26,8 +26,8 @@ var DEFAULT_REQUEST_CONFIG = {
};
/**
* Small wrapper around js-utility-belt's request that provides url resolving, default settings, and
* response handling.
* Small wrapper around js-utility-belt's request that provides url resolving,
* default settings, and response handling.
*/
function request(url) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};