Пример #1
0
from solana.rpc.api import Client
from solana.transaction import Transaction
from solana.system_program import decode_transfer as sol_decode_transfer
from spl.token.instructions import decode_transfer as spl_decode_transfer
from solana.system_program import TransferParams as SOLTransferParams
from spl.token.instructions import TransferParams as SPLTransferParams
from solana.transaction import Transaction, TransactionInstruction
from solana._layouts.system_instructions import SYSTEM_INSTRUCTIONS_LAYOUT, InstructionType as SOLInstructionType
from spl.token._layouts import INSTRUCTIONS_LAYOUT, InstructionType as SPLInstructionType
import base64
# solana_client = Client("https://api.mainnet-beta.solana.com")
solana_client = Client("https://devnet.solana.com")
address = ""
transactions = solana_client.get_confirmed_signature_for_address2(address)["result"]
for tx in transactions:
	tx_result = solana_client.get_confirmed_transaction(tx_sig=tx["signature"], encoding="base64")

	raw_tx_str = tx_result['result']['transaction'][0]

	raw_tx_base64_bytes = raw_tx_str.encode('ascii')
	raw_tx_bytes = base64.b64decode(raw_tx_base64_bytes)

	des_tx: Transaction = Transaction.deserialize(raw_tx_bytes)
	tx_instruction: TransactionInstruction = des_tx.instructions.pop()
	# program id will be a bunch of ones if it's a transaction involving SOL
	if tx_instruction.program_id.__str__() == "11111111111111111111111111111111":
		if SYSTEM_INSTRUCTIONS_LAYOUT.parse(tx_instruction.data).instruction_type == SOLInstructionType.Transfer:
			transfer_params: SOLTransferParams = sol_decode_transfer(tx_instruction)
			print(tx["slot"]) # blockheight
			print(f'from:{transfer_params.from_pubkey}') # from
			print(f'to:{transfer_params.to_pubkey}') # to
Пример #2
0
SECP_PROGRAM = "KeccakSecp256k11111111111111111111111111111"

SLEEP_TIME = 3

# SOLANA_ENDPOINT = "https://devnet.solana.com"
SOLANA_ENDPOINT = "http://localhost:8899"

http_client = Client(SOLANA_ENDPOINT)

slot_from = None

while True:
    if not slot_from:
        slot_from = http_client.get_slot()["result"]

    transaction = http_client.get_confirmed_signature_for_address2(
        AUDIUS_PROGRAM, limit=1)

    if transaction["result"][0]["slot"] > slot_from:
        slot_from = transaction["result"][0]["slot"]
        tx_info = http_client.get_confirmed_transaction(
            transaction["result"][0]["signature"])
        if SECP_PROGRAM in tx_info["result"]["transaction"]["message"][
                "accountKeys"]:
            audius_program_index = tx_info["result"]["transaction"]["message"][
                "accountKeys"].index(AUDIUS_PROGRAM)
            for instruction in tx_info["result"]["transaction"]["message"][
                    "instructions"]:
                if instruction["programIdIndex"] == audius_program_index:
                    hex_data = binascii.hexlify(
                        bytearray(list(base58.b58decode(instruction["data"]))))