-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
55 lines (48 loc) · 1.86 KB
/
test.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
import asyncio
from solana.rpc.commitment import Confirmed
from solders.message import MessageV0
from solders.pubkey import Pubkey
from solders.transaction import VersionedTransaction
from spl.token.instructions import close_account, CloseAccountParams
from settings.global_variables import GlobalVariables
from solana_dex.common.constants import TOKEN_PROGRAM_ID, LAMPORTS_PER_SOL
from solana_dex.layout.solana_layout import MINT_LAYOUT
from solana_dex.solana.solana_client import SolanaRPCClient
from solana_dex.solana.wallet import Wallet
import solders.system_program as sp
async def test1():
wallet = Wallet("2CpVUWrFP51Njq441oJAbe2dLcSPMhXkcc2Wu1GVfVQ5vaHp8c5SQ8mS4AXKdv4FTpQAyb7mnQW3zsR1ReZyX8s")
await wallet.update_token_accounts()
no_account = wallet.get_no_balance_account()
try:
recent_blockhash = GlobalVariables.SolaraClient.blockhash_cache.get()
except:
recent_blockhash = (await GlobalVariables.SolaraClient.get_latest_blockhash()).value
instructions = []
#
for account in no_account:
instructions.append(close_account(
CloseAccountParams(
account=account,
dest=wallet.pubkey,
owner=wallet.pubkey,
program_id=TOKEN_PROGRAM_ID,
)
))
compiled_message = MessageV0.try_compile(
wallet.pubkey,
instructions,
[], # lookup tables
recent_blockhash.blockhash,
)
keypairs = [wallet.keypair]
# transaction = VersionedTransaction(compiled_message, keypairs)
# txn_signature = (await GlobalVariables.SolaraClient.send_transaction(transaction)).value
# print("开始发送", txn_signature)
# resp = await SolanaRPCClient.confirm_transaction(
# txn_signature,
# Confirmed,
# )
# print("完成", txn_signature)
if __name__ == '__main__':
asyncio.run(test1())