Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RPC api calls for integrated address #134

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

qqqqqvb4
Copy link

@qqqqqvb4 qqqqqvb4 commented May 20, 2024

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 qqqqqvb4 mentioned this pull request May 21, 2024
src/lib.rs Outdated
pub async fn make_integrated_address(
&self,
standard_address: Option<String>,
payment_id: Option<String>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other functions are using types from monero-rs when available. Same for the return types, parse them in make_integrated_address and return monero-rs types.

@qqqqqvb4
Copy link
Author

done. should be okay.

@h4sh3d
Copy link
Member

h4sh3d commented May 30, 2024

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

@qqqqqvb4
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants