-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (27 loc) · 801 Bytes
/
utils.py
File metadata and controls
37 lines (27 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import random
import string
import binascii
def generate_payment_id():
"""
Generate a random payment_id for transactions
"""
return ''.join(random.choices(string.hexdigits, k=64)).lower()
def format_amount(amount):
"""
Format amount into user-friendly format
For example 1000 will be 10.00
"""
return float(amount/100)
def parse_amount(amount):
"""
Format amount from user-friendly format to internal representation
For example 10.00 will be 1000
"""
return int(amount*100)
def convert_bytes_to_hex_str(data):
"""
Converts binary data into its hexadecimal representation and return
it's decoded string. This can be used in the `extra` field when
sending a transaction
"""
return binascii.hexlify(data).decode()