Selecting Payment Address and Monitoring Transactions using bitcoinlib

235 Views Asked by At

I'm developing an order manager using bitcoinlib in Python. The objective is to create a new account for each order, determine which address should be used to receive payments, and implement a mechanism to monitor incoming transactions. Additionally, I would like to understand how to integrate this functionality into my existing code.

Here's the relevant code snippet:

from bitcoinlib.wallets import Wallet

wallet = Wallet(wallet_name)
print('-'*40)
print(wallet.info(5))
print('-'*40)
new_acc = wallet.new_account()
addresses = wallet.addresslist(new_acc.name[8:])
print(f"Addresses from this account: {addresses}")
print('-'*40)

This is the output i get:

----------------------------------------
=== WALLET ===
ID                             11
Name                           testwallet222222ww32
Owner
Scheme                         bip32
Multisig                       False
Witness type                   legacy
Main network                   bitcoin
Latest update                  None

= Wallet Master Key =
ID                             631
Private                        True
Depth                          0

- NETWORK: bitcoin -
- - Keys
  631 m                            1NzhGeMGhLpdjo4Cxbk7HzyMpRaBdKs1z2            testwallet222222ww32                   0.00000000 ₿
  632 m/44'                        1CV58WZz8VNGLDGjidsZKyUAwqvCYXb9AN            purpose 44                             0.00000000 ₿
  633 m/44'/0'                     1NXG5DCgnEgkDqEX6azMTq6FLmas311yba            coin type 0                            0.00000000 ₿
  634 m/44'/0'/0'                  1NqMoMaeerg6hPqMYTFntZ4kgi5iSaWXyM            account 0                              0.00000000 ₿
  635 m/44'/0'/0'/0                1Bk7cunL6EFheS2JuMR7XfXWyJ2ZaYPWVH            change 0                               0.00000000 ₿
  636 m/44'/0'/0'/0/0              1rgGSryRjoyRxSWSL1tLCAcmafU4JohEX             address index 0                        0.00000000 ₿

- - Transactions Account 0 (0)

= Balance Totals (includes unconfirmed) =

None
----------------------------------------
Addresses from this account: ['1Bh8kUgv7GHLZXGRBBNpEQBX7GfqkTeLb1', '19HkxF91wNtsmnsyYGW3ggDuid263PgFLq']
----------------------------------------

The SQL Query for the table:

CREATE TABLE IF NOT EXISTS PaymentRequests (
    ID INTEGER PRIMARY KEY,
    OrderID INTEGER,
    ClientID INTEGER,
    BitcoinAddress TEXT,
    AmountBitcoin REAL,
    TimePaid TIMESTAMP,
    AmountEUR REAL,
    ExChR REAL,
    Status TEXT,
    FOREIGN KEY (OrderID) REFERENCES Orders(ID),
    FOREIGN KEY (ClientID) REFERENCES Clients(UID)
);

I have the following questions:

  1. When creating a new account, multiple addresses are generated. Which address should I use to receive payments for the order?

  2. How can I implement a mechanism to monitor incoming transactions for a specific address and update an SQL table with the transaction details?

Any assistance would be greatly appreciated. Thank you!

0

There are 0 best solutions below