Simon Volpert gmipay / 6659d33
Add option to limit the time for which files will stay unlocked Default is no limit (files stay unlocked indefinitely) Simon Volpert 3 years ago
1 changed file(s) with 19 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
+19
-1
buy less more
4040 api_key_unconfirmed = ''
4141 api_unit = 'satoshi'
4242 address = '{address}'
43 unlock_time = 0
4344
4445 CONFIG_TEMPLATE = f'''# gmipay configuration file
4546 # Set this to the absolute path where your paywalled files are located. This
5253 # Set this to the default price any given file should be in BITs (1,000,000th
5354 # of a Bitcoin Cash):
5455 default_price={default_price}
56 # The period of time for which the files should stay unlocked, in days. If set
57 # to 0, the files will stay unlocked indefinitely.
58 unlock_time=0
5559
5660 # Block explorer API options
5761 # You can replace these with parameters for your preferred block explorer.
200204 xpub = line[5:]
201205 elif line.startswith('default_price='):
202206 default_price = round(float(line[14:]), 2)
207 elif line.startswith('unlock_time='):
208 unlock_time = int(line[12:])
203209 elif line.startswith('api_url='):
204210 api_url = line[8:]
205211 elif line.startswith('api_key_balance='):
258264 access_index = i
259265 break
260266
261 timestamp = datetime.datetime.now().isoformat(' ', timespec='seconds')
267 now = datetime.datetime.now()
268 timestamp = now.isoformat(' ', timespec='seconds')
262269 # First request to access file by this client
263270 if access_index == -1:
264271 # Create an invoice
269276 # Write to log file
270277 write_log(f'{timestamp} -- New invoice for {request_file.name} by {cert_hash} on address {address}\n')
271278 # Subsequent requests to access file by this client
279 # Check access expiry time for timed unlocks
280 if unlock_time > 0 and record[1] == 'paid':
281 old_timestamp = datetime.datetime.fromisoformat(record[4].replace(' ', 'T'))
282 delta = datetime.timedelta(days=unlock_time)
283 if now > old_timestamp + delta:
284 record[1] = 'expired'
285 record[3] = 'x'
286 # Check whether payment was received
272287 if len(record) > 1 and record[1] != 'paid':
273288 record[4] = timestamp
274289 address = record[2]
280295 balance = float(record[3])
281296 change = new_balance - balance
282297 if change < default_price:
298 if record[1] == 'expired':
299 write_log(f'{timestamp} -- Recreated invoice for {request_file.name} by {cert_hash} on address {address}\n')
300 record[1] = 'invoice'
283301 write_access_data()
284302 show_invoice()
285303 raise SystemExit