monero-integrations / monerophp

Monero PHP library + JsonRPC Client
MIT License
118 stars 76 forks source link

Unlocked Balance always return "0" After first Payment #52

Closed QuantumLeaper closed 6 years ago

QuantumLeaper commented 6 years ago

Hi there, I have a script running on cronjob, and when sending a payment with this script everything works great. However, for the PHP/RPC to report the correct unlocked_balance again it needs the RPC daemon to be restarted (or the Monero daemon - either works). I'm uncertain why this is happening, the monero-wallet-cli seems to always show the correct unlocked_balance so I think it has something to do with this script and Monero RPC, or maybe just Monero RPC?

sneurlax commented 6 years ago

I would ask if you only have one output in your wallet, but if restarting monero-wallet-rpc or monerod refreshes your unlocked balance then that probably isn't that case. You can check with $walletRPC->export_key_images(); (use print_r(...) or similar...) though: you should have one key image per output. If you only have one key image, you only have one output, and thus every transfer should lock your entire balance.

You could also try calling rescan_spent() before checking your balance.

If neither of the above help, the latest walletRPC.php is made to 0.12.0.0 "Lithium Luna" specs. While this library should be backwards-compatible with 0.11.1.0 (except for the new calls, of course,) your issue might be a version mismatch issue... Are you running the latest monerod and monero-wallet-rpc?

If none of the above sounds relevant or makes any progress, just share as much info as you can: run monerod and/or monero-wallet-rpc with a higher-than-default --log-level and share some logs surrounding the transfer and balance lookups if you can; are you on mainnet, testnet, or stagenet? are you using a normal wallet or a multisig wallet? are you sending from a secondary account? or from subaddresses? could you share a code snippet like the transfer() call? are you running a local webserver? is this wrapper on the same machine as the node it uses? and so on.

QuantumLeaper commented 6 years ago

I was testing on the testnet with 0.12.0.0 and rolled back to mainnet for 0.11.1.0. I tried using rescan_spent()which wasn't changing anything. However, instead of running monerod and monero-wallet-rpc in standard GNU screen sessions, it seems to work flawlessly with PM2. Which is weird.. haha, anyhow, thanks!