monero-rpc-rs icon indicating copy to clipboard operation
monero-rpc-rs copied to clipboard

Implement RPC api calls for integrated address

Open qqqqqvb4 opened this issue 1 year ago • 3 comments

Hello. I am new to Monero, but I was measuring myself today with the implementation of the payment system. I looked through the monero-wallet-rpc documentation and these two features were missing, so I added them. Perhaps it is possible to do it "around". but after adding these functions the payment prototype looks more or less like this:

pub async fn payments_system_xmr_test() -> anyhow::Result<()> {
    //start this before rust application: ./monero-wallet-rpc --disable-rpc-login --wallet-file /home/user/Monero/test_wallet --password 123123 --rpc-bind-port 18089 --daemon-address http://node.monerooutreach.org:18081 --untrusted-daemon --rpc-bind-ip 127.0.0.1 --confirm-external-bind --log-level 4
    
    let rpc_client = monero_rpc::RpcClientBuilder::new()
        .build("http://127.0.0.1:18089")?;

    let wallet_client = rpc_client.wallet();

    let price = Amount::from_xmr(1.0)?;

    let invoice = wallet_client.make_integrated_address(None, None).await?;
    let integrated_address = invoice.0;
    let payment_id = invoice.1;
    
    loop {
        let typed_payment_id = PaymentId::from_str(&payment_id)?;

        let payments = wallet_client.get_payments(typed_payment_id).await?;

        let mut paid = false;

        for payment in payments {
            if payment.amount.as_xmr() >= price.as_xmr() {
                paid = true;
                break;
            }
        }

        if paid {
            println!("invoice has been paid");
        } else {
            println!("send {}xmr to {}", price.as_xmr(), integrated_address);
        }
        
        tokio::time::sleep(Duration::from_millis(5000)).await;
    }
}

Some types may not quite match, but I'm not very familiar with this project yet.

qqqqqvb4 avatar May 20 '24 19:05 qqqqqvb4

done. should be okay.

ghost avatar May 30 '24 12:05 ghost

done. should be okay.

Is this new API good in your use case ? If yes then LGTM and we can go ahead with this impl

h4sh3d avatar May 30 '24 12:05 h4sh3d

done. should be okay.

Is this new API good in your use case ? If yes then LGTM and we can go ahead with this impl

rather good, but I haven't yet used any code related to it in production. in general, it's a bit of a shame that you can't receive information about new payments via websocket and just setting up monero-wallet-rpc is bothersome but it's probably my fault because I didn't use docker

ghost avatar May 30 '24 13:05 ghost