Add lbry.getCostInfoForName()

This commit is contained in:
Alex Liebowitz 2016-12-09 01:54:18 -05:00
parent d59c5c2a1c
commit d9a4442cc3

View file

@ -1,3 +1,5 @@
import lighthouse from './lighthouse.js';
var lbry = {
isConnected: false,
rootPath: '.',
@ -194,6 +196,44 @@ lbry.getPeersForBlobHash = function(blobHash, callback) {
lbry.call('get_peers_for_hash', { blob_hash: blobHash }, callback)
}
lbry.getCostInfoForName = function(name, callback) {
/**
* Takes a LBRY name; will first try and calculate a total cost using
* Lighthouse. If Lighthouse can't be reached, it just retrives the
* key fee.
*
* Returns an object with members:
* - cost: Number; the calculated cost of the name
* - includes_data: Boolean; indicates whether or not the data fee info
* from Lighthouse is included.
*/
function getCostWithData(size, callback) {
lbry.getTotalCost(name, size, (cost) => {
callback({
cost: cost,
includesData: true,
});
});
}
function getCostNoData(name, callback) {
lbry.getKeyFee(name, (cost) => {
callback({
cost: cost,
includesData: false,
});
});
}
lighthouse.getSizeForName(name, (size) => {
getCostWithData(name, size, callback);
}, () => {
getCostNoData(name, callback);
}, () => {
getCostNoData(name, callback);
});
}
lbry.getFileStatus = function(name, callback) {
lbry.call('get_lbry_file', { 'name': name }, callback);
}