Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions appFastNG.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ var config = {
filename: 'payments.json',
node: '',
percentageOfFeesToDistribute: 90,
blockStorage: 'blocks.json'
blockStorage: 'blocks.json',
dAppFunctions: [
'leasing'
]
};

var payments = [];
Expand All @@ -50,7 +53,7 @@ async function start() {
fs.unlinkSync(config.blockStorage);
}
console.log('preparing datastructures...');
prepareDataStructure(blocks);
await prepareDataStructure(blocks);
blocks.forEach(function(block) {
var transactions = [];

Expand Down Expand Up @@ -95,17 +98,33 @@ async function start() {
*
* @param blocks all blocks that should be considered
*/
var prepareDataStructure = function(blocks) {
var prepareDataStructure = async function(blocks) {
var previousBlock;
blocks.forEach(function(block) {
for (const block of blocks) {
var wavesFees = 0;

if (block.generator === config.address) {
myForgedBlocks.push(block);
}

block.transactions.forEach(function(transaction) {
// type 8 are leasing tx
for (const transaction of block.transactions) {
// type 16 for dApp leasing
if (transaction.type === 16 && transaction.call && transaction.call.function && config.dAppFunctions.includes(transaction.call.function)) {
const tx = await getTransactionInfo(transaction.id);
const state = tx.stateChanges;
for (const lease of state.leases) {
if (lease.recipient === config.address && block.height >= lease.height) {
lease.block = block.height;
myLeases[lease.id] = lease;
}
}
for (const leaseCancel of state.leaseCancels) {
if (leaseCancel.recipient === config.address && block.height >= leaseCancel.height) {
leaseCancel.block = block.height;
myCanceledLeases[leaseCancel.id] = leaseCancel;
}
}
}
if (transaction.type === 8 && (transaction.recipient === config.address || transaction.recipient === "address:" + config.address || transaction.recipient === 'alias:W:' + config.alias)) {
transaction.block = block.height;
myLeases[transaction.id] = transaction;
Expand All @@ -121,13 +140,13 @@ var prepareDataStructure = function(blocks) {
} else if (block.height > 1090000 && (transaction.type === 4 || transaction.type === 16)) {
wavesFees += 100000;
}
});
}
if (previousBlock) {
block.previousBlockWavesFees = previousBlock.wavesFees;
}
block.wavesFees = wavesFees;
previousBlock = block;
});
}
};

async function getBlocks(from, to) {
Expand All @@ -143,7 +162,22 @@ async function getBlocks(from, to) {
}
});
});
};
}

async function getTransactionInfo(transactionId) {
return new Promise(function(resolve, reject){
request(config.node + '/transactions/info/' + transactionId, function (error, response, body) {
// in addition to parsing the value, deal with possible errors
if (error) return reject(error);
try {
// JSON.parse() can throw an exception if not valid JSON
resolve(JSON.parse(body));
} catch(e) {
reject(e);
}
});
});
}

/**
* Method that returns all relevant blocks.
Expand Down