wallet-v3cr3/scripts/manage.py

128 lines
4.8 KiB
Python

from asyncio import run
from tonsdk.boc import Cell, begin_cell
from tonsdk.utils import Address
from _auth import get_or_create_wallet_settings
from _core import unpack_wallet, serialize_command, perform_action, print_actions
async def main():
print('\n' * 30)
wallet_settings = get_or_create_wallet_settings()
wallet = unpack_wallet(wallet_settings)
print(f"=== Successfully loaded wallet {wallet.address.to_string(1, 1, 0)}")
# print(wallet_settings)
actions = []
while len(actions) < 4:
print_actions(actions)
print("Available actions:")
print("1) Send TON")
print("2) Send Jetton")
print("3) Send NFT")
print("4) Update wallet contract")
print("5) Export mnemonic phrase")
print("7) New decentralized note")
print("8) Read decentralized note")
print("0) View actions and exit | send transactions")
choice = input("Select an action (1/2/3/4/0): ")
if choice == "0":
break
elif choice in {"5"}:
print("=== Mnemonic phrase:")
print(wallet_settings['mnemonic'])
elif choice in {"1", "2", "3", "4", "7"}:
action_type = int(choice)
action = {"type": action_type, "args": []}
if action_type == 1:
destination = input("Enter the destination address: ")
Address(destination).to_string(1, 1, 1)
amount = float(input("Enter the amount in TON: "))
comment = input("Enter a comment (or leave it empty): ")
if comment:
raw_payload = (
begin_cell()
.store_uint(0, 32)
.store_bytes(comment.encode())
.end_cell()
)
else:
raw_payload = input("Enter raw_payload in HEX (or leave it empty): ")
try:
raw_payload = Cell.one_from_boc(raw_payload)
except:
raw_payload = None
action["args"] = {
"destination": destination,
"amount": int(amount * 10 ** 9),
"payload_cell": raw_payload
}
elif action_type == 2:
token_contract = input("Enter the token contract address: ")
recipient = input("Enter the recipient address: ")
Address(token_contract).to_string(1, 1, 1)
Address(recipient).to_string(1, 1, 1)
amount = float(input("Enter the amount in tokens: "))
decimals = int(input("Enter token decimals: "))
amount = int(amount * 10 ** decimals)
comment = input("Enter a comment: ")
action["args"] = {
"token_contract": token_contract,
"recipient": recipient,
"amount": amount,
"comment": comment
}
elif action_type == 3:
nft_address = input("Enter the NFT address: ")
recipient = input("Enter the recipient address: ")
Address(nft_address).to_string(1, 1, 1)
Address(recipient).to_string(1, 1, 1)
action["args"] = {
"nft_address": nft_address,
"recipient": recipient
}
elif action_type == 4:
hex_code = input("Enter the smart contract code in HEX: ")
hex_data = input("Enter smart contract data in HEX: ")
action["args"] = {
'new_code': Cell.one_from_boc(hex_code),
'new_data': Cell.one_from_boc(hex_data)
}
elif action_type == 7:
note_key = input("Enter the note key: ")
print(f"""[?] Please, enter plain text & input 0 for write the note:""")
plain_text = ""
while True:
new_input = input()
if new_input == '0':
break
plain_text += new_input + '\n'
action['args'] = {
'note_key': note_key.strip(),
'plain_text': plain_text.strip(),
'private_key': bytes.fromhex(wallet_settings['secret_key'])
}
actions.append(action)
if not actions:
print("No actions selected")
return
_commands = begin_cell()
for action in actions:
_commands = _commands.store_ref(
serialize_command(action, response_address=wallet.address)
)
await perform_action(wallet_settings, _commands.end_cell())
if __name__ == "__main__":
run(main())