Skip to content

Commit

Permalink
Implement Auto-rewards claims full AFIT Pay
Browse files Browse the repository at this point in the history
- Implemented a new functionality to automated beneficiary rewards claims for the full AFIT beneficiary account so that every hour a check is made if beneficiary rewards are available, and hence to claim them.
  • Loading branch information
mcfarhat authored Nov 9, 2018
1 parent 07eb87c commit d7b1e46
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions delegations.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function runRewards(steemOnlyReward){
//grab steem prices and proceed checking for beneficiary payouts to AFIT token reward account (full_pay_benef_account)
setInterval(loadSteemPrices,5 * 60 * 1000);

//claim rewards once per hour
setInterval(claimRewards,60 * 60 * 1000);

} else {
utils.log(err, 'delegations')
Expand Down Expand Up @@ -729,3 +731,44 @@ async function updateUserTokens() {
console.log('>>save data error:'+err.message);
}
}
//function handles fetching account details for later use when claiming rewards
async function grabAccountDetails(){
console.log('grabbing fund account details');
let account = await client.database.call('get_accounts', [[config.full_pay_benef_account]]);
console.log(account);
return account[0];
}
//function handles claiming pending account rewards
async function claimRewards(){
//sign key properly to function with dsteem requirement
let privateKey = dsteem.PrivateKey.fromString(
config.full_pay_posting_key
);
//fetch account details first to use correct values for claim
let funds_account = await grabAccountDetails();
console.log(funds_account.reward_steem_balance);
console.log(funds_account.reward_sbd_balance);
console.log(funds_account.reward_vesting_balance);
//if we have any value to claim, proceed
if (parseFloat(funds_account.reward_steem_balance) > 0 || parseFloat(funds_account.reward_sbd_balance) > 0 || parseFloat(funds_account.reward_vesting_balance) > 0) {
const op = [
'claim_reward_balance',
{
account: config.full_pay_benef_account,
reward_steem: funds_account.reward_steem_balance.split(' ')[0] + ' STEEM',
reward_sbd: funds_account.reward_sbd_balance.split(' ')[0] + ' SBD',
reward_vests: funds_account.reward_vesting_balance.split(' ')[0] + ' VESTS',
},
];
client.broadcast.sendOperations([op], privateKey).then(
function(result) {
console.log(result);
},
function(error) {
console.log(error);
}
)
}else{
console.log('no rewards to claim for now');
}
}

0 comments on commit d7b1e46

Please sign in to comment.