|
| 1 | +from idlelib.configdialog import changes |
| 2 | +import asyncio |
| 3 | + |
| 4 | +from bsv import ( |
| 5 | + Transaction, |
| 6 | + TransactionInput, |
| 7 | + TransactionOutput, |
| 8 | + PrivateKey, |
| 9 | + P2PKH, |
| 10 | + BroadcastResponse, |
| 11 | + ARC,ARCConfig |
| 12 | +) |
| 13 | + |
| 14 | +""" |
| 15 | +Simple example of synchronous ARC broadcasting and status checking. |
| 16 | +""" |
| 17 | +# ARC_URL='https://api.taal.com/arc' |
| 18 | + |
| 19 | +async def main(): |
| 20 | +# def main(): |
| 21 | + |
| 22 | + arc_config = ARCConfig(api_key="mainnet_2e3a7d0f845a5049b35e9dde98fc4271") |
| 23 | + url = 'https://api.taal.com/arc' |
| 24 | + arc = ARC(url, arc_config) |
| 25 | + # Setup ARC broadcaster |
| 26 | + |
| 27 | + |
| 28 | + # Create a simple transaction |
| 29 | + private_key = PrivateKey("Kzpr5a6TmrXNw2NxSzt6GUonvcP8ABtfU17bdGEjxCufyxGMo9xV") |
| 30 | + public_key = private_key.public_key() |
| 31 | + |
| 32 | + source_tx = Transaction.from_hex( |
| 33 | + "01000000013462125ff05a9150c25693bbb474a5cde58c0d4ce6ab265e746f523791e01462000000006a4730440220447ac5232e8eb25db0e004bc704a19bc33c9c7ef86070781078bce74e089be44022029195e8cc392bf7c5577dc477a90d157be0356d8fbb52eb66521f4eabe00dcf9412103e23c79a29b5e5f20127ec2286413510662d0e6befa29d669a623035122753d3affffffff013d000000000000001976a914047f8e69ca8eadec1b327d1b232cdaaffa200d1688ac00000000" |
| 34 | + ) |
| 35 | + |
| 36 | + tx = Transaction( |
| 37 | + [ |
| 38 | + TransactionInput( |
| 39 | + source_transaction=source_tx, |
| 40 | + source_txid=source_tx.txid(), |
| 41 | + source_output_index=0, |
| 42 | + unlocking_script_template=P2PKH().unlock(private_key), |
| 43 | + ) |
| 44 | + ], |
| 45 | + [ |
| 46 | + TransactionOutput( |
| 47 | + locking_script=P2PKH().lock("1QnWY1CWbWGeqobBBoxdZZ3DDeWUC2VLn"), |
| 48 | + change=True |
| 49 | + ) |
| 50 | + ], |
| 51 | + ) |
| 52 | + |
| 53 | + tx.fee() |
| 54 | + tx.sign() |
| 55 | + txid = tx.txid() |
| 56 | + txhex = tx.hex() |
| 57 | + print(f"Transaction ID: {txid}") |
| 58 | + print(f"Transaction hex: {txhex}") |
| 59 | + # Broadcast transaction |
| 60 | + result = await arc.broadcast(tx) |
| 61 | + # result = arc.sync_broadcast(tx) |
| 62 | + |
| 63 | + if isinstance(result, BroadcastResponse): |
| 64 | + print(f"Broadcast successful: {result.txid}") |
| 65 | + |
| 66 | + # Check status |
| 67 | + status = arc.check_transaction_status(result.txid) |
| 68 | + print(f"Status: {status.get('txStatus', 'Unknown')}") |
| 69 | + |
| 70 | + # Categorize status |
| 71 | + category = arc.categorize_transaction_status(status) |
| 72 | + print(f"Category: {category.get('status_category')}") |
| 73 | + |
| 74 | + else: |
| 75 | + print(f"Broadcast failed: {result.description}") |
| 76 | + |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + # main() |
| 80 | + asyncio.run(main()) |
0 commit comments