Skip to content

Commit

Permalink
Enforcing reward correction when redeeming a code
Browse files Browse the repository at this point in the history
  • Loading branch information
MEDVEDx64 committed Jan 9, 2022
1 parent 0c76f03 commit a05dbe1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _proc(code, db, login):
# Fake key data
entry = {}
entry['left'] = 1
entry['value'] = compute_reward(db)
entry['value'] = compute_reward(db, True)

if not entry['left']:
out['status'] = SCKV['SC_EXPIRED_CODE']
Expand Down Expand Up @@ -341,7 +341,7 @@ def create_freeform_voucher(db, head_digit, origin, data, owner, value, left):
def get_dt_seconds(dt):
return (dt - epoch).total_seconds()

def compute_reward(db):
def compute_reward(db, force_correction=False):
if not 'mining' in config:
return 0
if not 'allowDynamicReward' in config['mining'] or not config['mining']['allowDynamicReward']:
Expand All @@ -357,9 +357,10 @@ def compute_reward(db):
current = get_dt_seconds(datetime.now())

# Fetching last computed reward
for x in db.reward.find().sort('timestamp', -1).limit(1):
if get_dt_seconds(x['timestamp']) + config['mining']['rewardCorrectionInterval'] > current:
return x['value']
if not force_correction:
for x in db.reward.find().sort('timestamp', -1).limit(1):
if get_dt_seconds(x['timestamp']) + config['mining']['rewardCorrectionInterval'] > current:
return x['value']

value = config['mining']['reward'] * math.exp(-(db.accepted.count() / ((current - first) * 0.0001)))
value = float('{0:.8f}'.format(value))
Expand Down

0 comments on commit a05dbe1

Please sign in to comment.