mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 09:46:58 +01:00
Merge pull request #6 from bigchaindb/add-ipdb-auth-headers
Add ipdb auth headers
This commit is contained in:
commit
0fbde113fc
23
API.md
23
API.md
@ -14,8 +14,8 @@
|
||||
- [ccJsonLoad](#ccjsonload)
|
||||
- [ccJsonify](#ccjsonify)
|
||||
- [getBlock](#getblock)
|
||||
- [getTransaction](#gettransaction)
|
||||
- [getStatus](#getstatus)
|
||||
- [getTransaction](#gettransaction)
|
||||
- [listBlocks](#listblocks)
|
||||
- [listOutputs](#listoutputs)
|
||||
- [listTransactions](#listtransactions)
|
||||
@ -153,21 +153,18 @@ Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
**Parameters**
|
||||
|
||||
- `blockId`
|
||||
- `API_PATH`
|
||||
|
||||
## getTransaction
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `txId`
|
||||
- `API_PATH`
|
||||
|
||||
## getStatus
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `tx_id`
|
||||
- `API_PATH`
|
||||
|
||||
## getTransaction
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `txId`
|
||||
|
||||
## listBlocks
|
||||
|
||||
@ -176,7 +173,6 @@ Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
||||
- `$0.tx_id`
|
||||
- `$0.status`
|
||||
- `API_PATH`
|
||||
- `tx_id`
|
||||
- `status`
|
||||
|
||||
@ -187,7 +183,6 @@ Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
||||
- `$0.public_key`
|
||||
- `$0.unspent`
|
||||
- `API_PATH`
|
||||
- `onlyJsonResponse`
|
||||
- `public_key`
|
||||
- `unspent`
|
||||
@ -199,7 +194,6 @@ Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
||||
- `$0.asset_id`
|
||||
- `$0.operation`
|
||||
- `API_PATH`
|
||||
- `asset_id`
|
||||
- `operation`
|
||||
|
||||
@ -208,14 +202,12 @@ Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
**Parameters**
|
||||
|
||||
- `block_id`
|
||||
- `API_PATH`
|
||||
|
||||
## pollStatusAndFetchTransaction
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `tx_id`
|
||||
- `API_PATH`
|
||||
|
||||
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
|
||||
|
||||
@ -224,4 +216,3 @@ Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe
|
||||
**Parameters**
|
||||
|
||||
- `transaction`
|
||||
- `API_PATH`
|
||||
|
15
HACKING.rst
15
HACKING.rst
@ -1,15 +0,0 @@
|
||||
Installing latest master with pip
|
||||
---------------------------------
|
||||
In order to work with the latest BigchainDB (server) master branch:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install --process-dependency-links git+https://github.com/bigchaindb/bigchaindb-driver.git
|
||||
|
||||
Point to some BigchainDB node, which is running BigchainDB server ``master``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from bigchaindb_driver import BigchainDB
|
||||
|
||||
bdb = BigchainDB('http://here.be.dragons:9984')
|
11
README.md
11
README.md
@ -75,13 +75,10 @@ const tx = driver.Transaction.makeCreateTransaction(
|
||||
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey);
|
||||
|
||||
// send it off to BigchainDB
|
||||
driver.Connection
|
||||
.postTransaction(txSigned, API_PATH)
|
||||
.then((res) => {
|
||||
// request the status of the transaction
|
||||
driver.Connection
|
||||
.getStatus(txSigned.id, API_PATH)
|
||||
.then((res) => console.log('Transaction status:', res.status))});
|
||||
let conn = new driver.Connection(PATH, { 'Content-Type': 'application/json' });
|
||||
conn.postTransaction(txSigned)
|
||||
.then(() => conn.getStatus(txSigned.id))
|
||||
.then((res) => console.log('Transaction status:', res.status));
|
||||
```
|
||||
|
||||
You may also be interested in some [long-form tutorials with actual code](https://github.com/bigchaindb/kyber).
|
||||
|
840
dist/bundle/bundle.js
vendored
840
dist/bundle/bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/bundle/bundle.min.js
vendored
2
dist/bundle/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/bundle/bundle.min.js.map
vendored
2
dist/bundle/bundle.min.js.map
vendored
File diff suppressed because one or more lines are too long
18
dist/node/connection/getApiUrls.js
vendored
18
dist/node/connection/getApiUrls.js
vendored
@ -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'];
|
30
dist/node/connection/getBlock.js
vendored
30
dist/node/connection/getBlock.js
vendored
@ -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'];
|
30
dist/node/connection/getStatus.js
vendored
30
dist/node/connection/getStatus.js
vendored
@ -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'];
|
30
dist/node/connection/getTransaction.js
vendored
30
dist/node/connection/getTransaction.js
vendored
@ -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'];
|
252
dist/node/connection/index.js
vendored
252
dist/node/connection/index.js
vendored
@ -3,52 +3,220 @@
|
||||
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 _getBlock2 = require('./getBlock');
|
||||
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 _getBlock3 = _interopRequireDefault(_getBlock2);
|
||||
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 _getTransaction2 = require('./getTransaction');
|
||||
var _request = require('../request');
|
||||
|
||||
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;
|
||||
}();
|
||||
|
||||
exports.default = Connection;
|
||||
module.exports = exports['default'];
|
35
dist/node/connection/listBlocks.js
vendored
35
dist/node/connection/listBlocks.js
vendored
@ -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'];
|
37
dist/node/connection/listOutputs.js
vendored
37
dist/node/connection/listOutputs.js
vendored
@ -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'];
|
35
dist/node/connection/listTransactions.js
vendored
35
dist/node/connection/listTransactions.js
vendored
@ -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'];
|
30
dist/node/connection/listVotes.js
vendored
30
dist/node/connection/listVotes.js
vendored
@ -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'];
|
@ -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}
|
||||
*/
|
30
dist/node/connection/postTransaction.js
vendored
30
dist/node/connection/postTransaction.js
vendored
@ -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'];
|
4
dist/node/index.js
vendored
4
dist/node/index.js
vendored
@ -15,7 +15,7 @@ var _Transaction = _interopRequireWildcard(_transaction);
|
||||
|
||||
var _connection = require('./connection');
|
||||
|
||||
var _Connection = _interopRequireWildcard(_connection);
|
||||
var _connection2 = _interopRequireDefault(_connection);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
@ -23,4 +23,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
||||
|
||||
exports.Ed25519Keypair = _Ed25519Keypair3.default;
|
||||
exports.Transaction = _Transaction;
|
||||
exports.Connection = _Connection;
|
||||
exports.Connection = _connection2.default;
|
4
dist/node/request.js
vendored
4
dist/node/request.js
vendored
@ -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] : {};
|
||||
|
@ -1,11 +0,0 @@
|
||||
export default 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'
|
||||
};
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param blockId
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function getBlock(blockId, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['blocks_detail'], {
|
||||
urlTemplateSpec: {
|
||||
blockId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function getStatus(tx_id, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['statuses'], {
|
||||
query: {
|
||||
tx_id
|
||||
}
|
||||
});
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param txId
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function getTransaction(txId, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['transactions_detail'], {
|
||||
urlTemplateSpec: {
|
||||
txId
|
||||
}
|
||||
});
|
||||
}
|
@ -1,9 +1,158 @@
|
||||
export getBlock from './getBlock';
|
||||
export getTransaction from './getTransaction';
|
||||
export getStatus from './getStatus';
|
||||
export listBlocks from './listBlocks';
|
||||
export listOutputs from './listOutputs';
|
||||
export listTransactions from './listTransactions';
|
||||
export listVotes from './listVotes';
|
||||
export pollStatusAndFetchTransaction from './pollStatusAndFetchTransaction';
|
||||
export postTransaction from './postTransaction';
|
||||
import request from '../request';
|
||||
|
||||
|
||||
export default class Connection {
|
||||
constructor(path, headers) {
|
||||
this.path = path;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
_req(path, options={}) {
|
||||
// NOTE: `options.headers` could be undefined, but that's OK.
|
||||
options.headers = Object.assign({}, options.headers, this.headers)
|
||||
return request(path, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param blockId
|
||||
*/
|
||||
getBlock(blockId) {
|
||||
return this._req(this.getApiUrls('blocks_detail'), {
|
||||
urlTemplateSpec: {
|
||||
blockId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
*/
|
||||
getStatus(tx_id) {
|
||||
return this._req(this.getApiUrls('statuses'), {
|
||||
query: {
|
||||
tx_id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param txId
|
||||
*/
|
||||
getTransaction(txId) {
|
||||
return this._req(this.getApiUrls('transactions_detail'), {
|
||||
urlTemplateSpec: {
|
||||
txId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
* @param status
|
||||
*/
|
||||
listBlocks({ tx_id, status }) {
|
||||
return this._req(this.getApiUrls('blocks'), {
|
||||
query: {
|
||||
tx_id,
|
||||
status
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param public_key
|
||||
* @param unspent
|
||||
* @param onlyJsonResponse
|
||||
*/
|
||||
listOutputs({ public_key, unspent }, onlyJsonResponse=true) {
|
||||
return this._req(this.getApiUrls('outputs'), {
|
||||
query: {
|
||||
public_key,
|
||||
unspent
|
||||
}
|
||||
}, onlyJsonResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param asset_id
|
||||
* @param operation
|
||||
*/
|
||||
listTransactions({ asset_id, operation }) {
|
||||
return this._req(this.getApiUrls('transactions'), {
|
||||
query: {
|
||||
asset_id,
|
||||
operation
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param block_id
|
||||
*/
|
||||
listVotes(block_id) {
|
||||
return this._req(this.getApiUrls('votes'), {
|
||||
query: {
|
||||
block_id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
* @return {Promise}
|
||||
*/
|
||||
pollStatusAndFetchTransaction(tx_id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timer = setInterval(() => {
|
||||
this.getStatus(tx_id)
|
||||
.then((res) => {
|
||||
console.log('Fetched transaction status:', res);
|
||||
if (res.status === 'valid') {
|
||||
clearInterval(timer);
|
||||
this.getTransaction(tx_id)
|
||||
.then((res) => {
|
||||
console.log('Fetched transaction:', res);
|
||||
resolve(res);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
clearInterval(timer);
|
||||
reject(err);
|
||||
});
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param transaction
|
||||
*/
|
||||
postTransaction(transaction) {
|
||||
return this._req(this.getApiUrls('transactions'), {
|
||||
method: 'POST',
|
||||
jsonBody: transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
* @param status
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function listBlocks({tx_id, status}, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['blocks'], {
|
||||
query: {
|
||||
tx_id,
|
||||
status
|
||||
}
|
||||
});
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param public_key
|
||||
* @param unspent
|
||||
* @param API_PATH
|
||||
* @param onlyJsonResponse
|
||||
*/
|
||||
export default function listOutputs({ public_key, unspent }, API_PATH, onlyJsonResponse=true) {
|
||||
return request(getApiUrls(API_PATH)['outputs'], {
|
||||
query: {
|
||||
public_key,
|
||||
unspent
|
||||
}
|
||||
}, onlyJsonResponse)
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param asset_id
|
||||
* @param operation
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function listTransactions({ asset_id, operation }, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['transactions'], {
|
||||
query: {
|
||||
asset_id,
|
||||
operation
|
||||
}
|
||||
})
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param block_id
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function listVotes(block_id, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['votes'], {
|
||||
query: {
|
||||
block_id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
import getTransaction from './getTransaction';
|
||||
import getStatus from './getStatus';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param tx_id
|
||||
* @param API_PATH
|
||||
* @return {Promise}
|
||||
*/
|
||||
export default function (tx_id, API_PATH) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timer = setInterval(() => {
|
||||
getStatus(tx_id, API_PATH)
|
||||
.then((res) => {
|
||||
console.log('Fetched transaction status:', res);
|
||||
if (res.status === 'valid') {
|
||||
clearInterval(timer);
|
||||
getTransaction(tx_id, API_PATH)
|
||||
.then((res) => {
|
||||
console.log('Fetched transaction:', res);
|
||||
resolve(res);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
clearInterval(timer);
|
||||
reject(err);
|
||||
});
|
||||
}, 500)
|
||||
})
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import getApiUrls from './getApiUrls';
|
||||
import request from '../request';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param transaction
|
||||
* @param API_PATH
|
||||
*/
|
||||
export default function postTransaction(transaction, API_PATH) {
|
||||
return request(getApiUrls(API_PATH)['transactions'], {
|
||||
method: 'POST',
|
||||
jsonBody: transaction
|
||||
})
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
export Ed25519Keypair from './Ed25519Keypair';
|
||||
|
||||
export * as Transaction from './transaction';
|
||||
export * as Connection from './connection';
|
||||
export Connection from './connection';
|
||||
|
@ -10,8 +10,8 @@ const 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.
|
||||
*/
|
||||
export default function request(url, config = {}, onlyJsonResponse=true) {
|
||||
// Load default fetch configuration and remove any falsy query parameters
|
||||
@ -42,4 +42,3 @@ export default function request(url, config = {}, onlyJsonResponse=true) {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user