1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00

Combine files

This commit is contained in:
Tim Daubenschütz 2017-05-11 12:45:19 +02:00
parent 9bc4a3b03a
commit 862ad6e4e6
11 changed files with 154 additions and 182 deletions

View File

@ -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'
};
}

View File

@ -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
}
});
}

View File

@ -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
}
});
}

View File

@ -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
}
});
}

View File

@ -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
})
}

View File

@ -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
}
});
}

View File

@ -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)
}

View File

@ -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
}
})
}

View File

@ -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
}
});
}

View File

@ -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)
})
}

View File

@ -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
})
}