federicociro / bitcoin_bus_bot

Telegram bot for Bitcoin GroupHug
GNU General Public License v3.0
4 stars 1 forks source link

Open a branch for Signet #3

Open federicociro opened 1 month ago

federicociro commented 1 month ago

Hi @polespinasa , would you please help me differentiate Signet vs Mainnet transactions in order to develop a Signet version of the bot?

I mainly need help with the validate_transaction function.

Thanks!

polespinasa commented 1 month ago

That check is done in the backend and there's no need for the frontend to do it. All checks are done by the server indeed.

In order to differentiate to which network a transaction belongs what the GroupHug server does is ask to the electrum server if the previous transaction (the input) exists in the network. If it's not found means that the transaction is not from that network.

In order to simplify the process I recommend a few things:

  1. On the send_to_server function, when you establish a new connection with the GroupHug server it first sends a message saying which network is using so you may want to use that information. https://github.com/federicociro/bitcoin_bus_bot/blob/90c4bc4d6e4d8c0b85e74255534beaf31c4151a0/grouphug.py#L33-L34 The format of these messages can be found here:
    if &crate::CONFIG.network.name == "testnet" {
        stream.write(b"TESTNET\n").unwrap();
    }
    else if &crate::CONFIG.network.name == "mainnet" {
        stream.write(b"MAINNET\n").unwrap();
    }
    else if &crate::CONFIG.network.name == "signet" {
        stream.write(b"SIGNET\n").unwrap();
    } 
  2. In case you send a transaction that does not belong to the correct network (the one that the GroupHug is running) you will receive a message like: The tx you provided is not from SIGNET network. So you should be able to handle the different networks just listening to the GroupHug server response. For references you can check: How GroupHug detects if it's the correct network and How GroupHug respond if the network is incorrect