-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend.py
214 lines (155 loc) · 7.47 KB
/
send.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from classes.common import (
check_version
)
from constants.constants import (
FULL_COIN_LOOKUP,
ULUNA,
USER_ACTION_CONTINUE,
USER_ACTION_QUIT,
)
from classes.wallet import UserWallet, UserParameters
from classes.wallets import UserWallets
from classes.send_transaction import send_transaction
from classes.transaction_core import TransactionResult
from terra_classic_sdk.core.coin import Coin
def get_send_to_address(user_wallets:UserWallet) -> list[str, str]:
"""
Show a simple list address from what is found in the user_config file
"""
label_widths:list = []
label_widths.append(len('Number'))
label_widths.append(len('Wallet name'))
for wallet_name in user_wallets:
if len(wallet_name) > label_widths[1]:
label_widths[1] = len(wallet_name)
# Generic string we use for padding purposes
padding_str:str = ' ' * 100
header_string:str = ' Number |'
if label_widths[1] > len('Wallet name'):
header_string += ' Wallet name' + padding_str[0:label_widths[1] - len('Wallet name')] + ' | Address '
else:
header_string += ' Wallet name | Address '
horizontal_spacer:str = '-' * len(header_string)
# Create default variables and values
wallets_to_use:dict = {}
user_wallet:dict = {}
recipient_address:str = ''
while True:
count:int = 0
wallet_numbers:dict = {}
wallets_by_name:dict = {}
print ('\n' + horizontal_spacer)
print (header_string)
print (horizontal_spacer)
for wallet_name in user_wallets:
wallet:UserWallet = user_wallets[wallet_name]
count += 1
wallet_numbers[count] = wallet
wallets_by_name[wallet.name.lower()] = count
if wallet_name in wallets_to_use:
glyph = '✅'
else:
glyph = ' '
count_str = f' {count}' + padding_str[0:6 - (len(str(count)) + 2)]
wallet_name_str = wallet_name + padding_str[0:label_widths[1] - len(wallet_name)]
wallet_address:str = wallet.address
print (f"{count_str}{glyph} | {wallet_name_str} | {wallet_address}")
print (horizontal_spacer + '\n')
print ('You can send to an address in your config file by typing the wallet name or number.')
print ('You can also send to a completely new address by entering the wallet address.\n')
answer:str = input("What is the address you are sending to? (or type 'X' to continue, or 'Q' to quit) ").lower()
# Check if someone typed the name of a wallet
if answer in wallets_by_name.keys():
answer = str(wallets_by_name[answer])
if answer.isdigit() and int(answer) in wallet_numbers:
wallets_to_use:dict = {}
key:str = wallet_numbers[int(answer)].name
if key not in wallets_to_use:
wallets_to_use[key] = wallet_numbers[int(answer)]
else:
wallets_to_use.pop(key)
else:
# check if this is an address we support:
prefix:str = wallet.getPrefix(answer)
if prefix in wallet.getSupportedPrefixes():
recipient_address:str = answer
break
if answer == USER_ACTION_CONTINUE:
if len(wallets_to_use) > 0:
break
else:
print ('\nPlease select a wallet first.\n')
if answer == USER_ACTION_QUIT:
break
# Get the first (and only) wallet from the list
if len(wallets_to_use) > 0:
for item in wallets_to_use:
user_wallet:UserWallet = wallets_to_use[item]
recipient_address:str = user_wallet.address
break
return recipient_address, answer
def main():
# Check if there is a new version we should be using
check_version()
# Get the user wallets
wallets = UserWallets()
user_wallets:dict = wallets.loadUserWallets()
#user_wallets:dict = wallets.wallets
user_addresses:dict = wallets.addresses
if len(user_wallets) > 0:
print (f'You can send LUNC, USTC, and minor coins on the following wallets:')
wallet, answer = wallets.getUserSinglechoice(f"Select a wallet number 1 - {str(len(user_wallets))}, 'X' to continue, or 'Q' to quit: ")
if answer == USER_ACTION_QUIT:
print (' 🛑 Exiting...\n')
exit()
else:
print (" 🛑 This password couldn't decrypt any wallets. Make sure it is correct, or rebuild the wallet list by running the configure_user_wallet.py script again.\n")
exit()
denom, answer, null_value = wallet.getCoinSelection(f"Select a coin number 1 - {str(len(FULL_COIN_LOOKUP))} that you want to send, 'X' to continue, or 'Q' to quit: ", wallet.balances)
if answer == USER_ACTION_QUIT:
print (' 🛑 Exiting...\n')
exit()
print (f"The {wallet.name} wallet holds {wallet.formatUluna(wallet.balances[denom], denom)} {FULL_COIN_LOOKUP[denom]}")
print (f"NOTE: You can send the entire value of this wallet by typing '100%' - no minimum amount will be retained.")
user_params:UserParameters = UserParameters()
user_params.max_number = float(wallet.formatUluna(wallet.balances[denom], denom, False))
user_params.percentages_allowed = True
user_params.target_amount = wallet.formatUluna(wallet.balances[denom], denom)
user_params.target_denom = denom
uluna_amount:str = wallet.getUserNumber('How much are you sending (Q to quit)? ', user_params)
if uluna_amount == USER_ACTION_QUIT:
print (' 🛑 Exiting...\n')
exit()
else:
uluna_amount = float(uluna_amount)
# Print a list of the addresses in the user_config.yml file:
recipient_address, answer = get_send_to_address(user_addresses)
if answer == USER_ACTION_QUIT:
print (' 🛑 Exiting...\n')
exit()
# This is what we will be sending
send_coin:Coin = wallet.createCoin(uluna_amount, denom)
# NOTE: I'm pretty sure the memo size is int64, but I've capped it at 255 so python doens't panic
memo:str = wallet.getUserText('Provide a memo (optional): ', 255, True)
print (f'\n ➜ Accessing the {wallet.name} wallet...')
if ULUNA in wallet.balances:
#print (f'Sending {wallet.formatUluna(send_coin.amount, send_coin.denom)} {FULL_COIN_LOOKUP[send_coin.denom]}')
#recipient_wallet:UserWallet = UserWallet().create('target', recipient_address)
#recipient_balance = recipient_wallet.getBalances()
transaction_result:TransactionResult = send_transaction(wallet, recipient_address, send_coin, memo)
# Now check the balance to see if it's arrived at the recipient wallet
#if send_coin.denom in recipient_balance:
# current_balance:int = recipient_balance[send_coin.denom]
#else:
# current_balance:int = 0
#recipient_wallet.getBalances()
transaction_result.wallet_denom = wallet.denom
transaction_result.showResults()
else:
print (" 🛑 This wallet has no LUNC - you need a small amount to be present to pay for fees.")
print (' 💯 Done!\n')
if __name__ == "__main__":
""" This is executed when run from the command line """
main()