-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheasyraikit_ext.py
More file actions
147 lines (113 loc) · 3.62 KB
/
easyraikit_ext.py
File metadata and controls
147 lines (113 loc) · 3.62 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import re
import math
from time import sleep, time
from easyraikit_config import *
from easyraikit import Rai
rai = Rai()
def raiblocks_account_validate(account):
if isinstance(account, str):
if ("xrb_1" in account) or ("xrb_3" in account) and (len(account) == 64):
account = account[4:]
char_validation = re.search("^[13456789abcdefghijkmnopqrstuwxyz]+$", account)
if char_validation is not None:
return True
else:
return False
else:
return False
else:
return False
def raiblocks_mrai_from_raw(raw):
return int(math.floor(raw / (10 ** 30)))
def raiblocks_mrai_to_raw(mrai):
return int(math.floor(mrai * (10 ** 30)))
def raiblocks_rai_from_raw(raw):
return int(math.floor(raw / (10 ** 24)))
def raiblocks_rai_to_raw(rai):
return int(math.floor(rai * (10 ** 24)))
def raiblocks_krai_from_raw(raw):
return int(math.floor(raw / (10 ** 27)))
def raiblocks_krai_to_raw(krai):
return int(math.floor(krai * (10 ** 27)))
def raiblocks_unlock():
global rai
global wallet
global wallet_password
valid = rai.password_enter({ "wallet": wallet, "password": wallet_password })
if valid is not None:
return valid["valid"]
else:
return "Wallet unlock failed."
def raiblocks_balance_wallet():
global rai
global wallet
accounts_balances = { "accounts": {}, "sum_balance_rai": 0, "sum_pending_rai": 0, "n_accounts": 0 }
ret2 = rai.account_list({"wallet": wallet});
for account in ret2["accounts"]:
ret2 = rai.account_balance({"account": account})
accounts_balances["accounts"][account] = {
'balance_rai': raiblocks_rai_from_raw(ret2["balance"]),
'pending_rai': raiblocks_rai_from_raw(ret2["pending"])
}
accounts_balances["sum_balance_rai"] += accounts_balances["accounts"][account]["balance_rai"]
accounts_balances["sum_pending_rai"] += accounts_balances["accounts"][account]["pending_rai"]
accounts_balances["n_accounts"] += 1
return accounts_balances
def raiblocks_send_wallet(destination, amount):
global rai
global wallet
payment_hashes = { "accounts": {}, "status": "ok", "sum_paid_rai": 0 }
selected_accounts = {}
diff_amount = amount
sum = 0
account_list = raiblocks_balance_wallet()
for account, balance in account_list["accounts"].items():
if account is not None:
if balance["balance_rai"] > 0:
selected_accounts[account] = balance["balance_rai"]
sum += balance["balance_rai"]
else:
continue
if sum >= amount:
break
if sum < amount:
payment_hashes["sum_paid_rai"] = 0
payment_hashes["status"] = "not enough funds."
return payment_hashes
for selected_account, balance in selected_accounts.items():
if selected_accounts is not None:
if diff_amount - balance < 0:
balance = diff_amount
args = {
'wallet': wallet,
'source': selected_account,
'destination': destination,
'amount': raiblocks_rai_to_raw(balance)
}
ret = rai.send(args)
if ret["block"] != "0000000000000000000000000000000000000000000000000000000000000000":
payment_hashes["accounts"][selected_account] = {
"hash": ret["block"],
"amount_rai": balance
}
payment_hashes["sum_paid_rai"] += balance
diff_amount -= balance
else:
payment_hashes["accounts"][selected_account] = {
"hash": "error",
"amount_rai": balance
}
payment_hashes["status"] = "error"
return payment_hashes
def raiblocks_n_accounts(n):
global rai
global wallet
accounts_created = { "accounts": [], "n": n, "n_generated": 0 }
i = 0
while i < n:
ret = rai.account_create({ "wallet": wallet })
if ret["account"] != "":
accounts_created["n_generated"] += 1
accounts_created["accounts"].append(ret["account"])
i += 1
return accounts_created