diff --git a/src/connection/getApiUrls.js b/src/connection/getApiUrls.js deleted file mode 100644 index 1c6cb65..0000000 --- a/src/connection/getApiUrls.js +++ /dev/null @@ -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' - }; -} \ No newline at end of file diff --git a/src/connection/getBlock.js b/src/connection/getBlock.js deleted file mode 100644 index 252ac84..0000000 --- a/src/connection/getBlock.js +++ /dev/null @@ -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 - } - }); -} - - diff --git a/src/connection/getStatus.js b/src/connection/getStatus.js deleted file mode 100644 index dd30b29..0000000 --- a/src/connection/getStatus.js +++ /dev/null @@ -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 - } - }); -} \ No newline at end of file diff --git a/src/connection/getTransaction.js b/src/connection/getTransaction.js deleted file mode 100644 index 20c89dc..0000000 --- a/src/connection/getTransaction.js +++ /dev/null @@ -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 - } - }); -} diff --git a/src/connection/index.js b/src/connection/index.js index e5718ae..7ad5b8e 100644 --- a/src/connection/index.js +++ b/src/connection/index.js @@ -1,9 +1,154 @@ -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 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' + }; +} + +/** + * @public + * @param blockId + * @param API_PATH + */ +export default function getBlock(blockId, API_PATH) { + return request(getApiUrls(API_PATH)['blocks_detail'], { + urlTemplateSpec: { + blockId + } + }); +} + +/** + * @public + * @param tx_id + * @param API_PATH + */ +export default function getStatus(tx_id, API_PATH) { + return request(getApiUrls(API_PATH)['statuses'], { + query: { + tx_id + } + }); +} + +/** + * @public + * @param txId + * @param API_PATH + */ +export default function getTransaction(txId, API_PATH) { + return request(getApiUrls(API_PATH)['transactions_detail'], { + urlTemplateSpec: { + txId + } + }); +} + +/** + * @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 + } + }); +} + +/** + * @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) +} + +/** + * @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 + } + }) +} + +/** + * @public + * @param block_id + * @param API_PATH + */ +export default function listVotes(block_id, API_PATH) { + return request(getApiUrls(API_PATH)['votes'], { + query: { + block_id + } + }); +} + +/** + * @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) + }) +} + +/** + * @public + * + * @param transaction + * @param API_PATH + */ +export default function postTransaction(transaction, API_PATH) { + return request(getApiUrls(API_PATH)['transactions'], { + method: 'POST', + jsonBody: transaction + }) +} diff --git a/src/connection/listBlocks.js b/src/connection/listBlocks.js deleted file mode 100644 index d391433..0000000 --- a/src/connection/listBlocks.js +++ /dev/null @@ -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 - } - }); -} diff --git a/src/connection/listOutputs.js b/src/connection/listOutputs.js deleted file mode 100644 index 6a1839a..0000000 --- a/src/connection/listOutputs.js +++ /dev/null @@ -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) -} \ No newline at end of file diff --git a/src/connection/listTransactions.js b/src/connection/listTransactions.js deleted file mode 100644 index ab4d509..0000000 --- a/src/connection/listTransactions.js +++ /dev/null @@ -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 - } - }) -} \ No newline at end of file diff --git a/src/connection/listVotes.js b/src/connection/listVotes.js deleted file mode 100644 index 51091bc..0000000 --- a/src/connection/listVotes.js +++ /dev/null @@ -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 - } - }); -} - diff --git a/src/connection/pollStatusAndFetchTransaction.js b/src/connection/pollStatusAndFetchTransaction.js deleted file mode 100644 index 0ba4dc3..0000000 --- a/src/connection/pollStatusAndFetchTransaction.js +++ /dev/null @@ -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) - }) -} diff --git a/src/connection/postTransaction.js b/src/connection/postTransaction.js deleted file mode 100644 index e654640..0000000 --- a/src/connection/postTransaction.js +++ /dev/null @@ -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 - }) -} -