Exemple #1
0
def confirm_transaction(client: Client, tx_sig: str) -> RPCResponse:
    """Confirm a transaction."""
    TIMEOUT = 30  # 30 seconds  pylint: disable=invalid-name
    elapsed_time = 0
    while elapsed_time < TIMEOUT:
        sleep_time = 3
        if not elapsed_time:
            sleep_time = 7
            time.sleep(sleep_time)
        else:
            time.sleep(sleep_time)

        resp = client.get_confirmed_transaction(tx_sig)
        if resp["result"]:
            break
        elapsed_time += sleep_time

    if not resp["result"]:
        raise RuntimeError("could not confirm transaction: ", tx_sig)
    return resp
Exemple #2
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
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"]))))

                    l1 = int(hex_data[2:4], 16)
                    start_data1 = 10
                    end_data1 = l1 * 2 + start_data1

                    l2 = int(hex_data[end_data1:end_data1 + 2], 16)
Exemple #4
0
SOLANA_ENDPOINT = "https://devnet.solana.com"

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']))))

                    l1 = int(hex_data[2:4], 16)
                    start_data1 = 10
                    end_data1 = l1 * 2 + start_data1

                    l2 = int(hex_data[end_data1:end_data1 + 2], 16)