Coder Social home page Coder Social logo

monerophp's People

Contributors

brianhenryie avatar burnside avatar coval3nte avatar cryptochangements34 avatar danth avatar example123 avatar gnock avatar ibragimkb avatar itismadness avatar itssteven avatar livaa avatar mzk avatar ndcroos avatar olsm avatar oxmarco avatar pandabadger avatar quickbasic avatar recanman avatar rex4539 avatar serhack avatar shopglobal avatar sneurlax avatar vladyslavstartsev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monerophp's Issues

Use code stype

Thank you for the library. It's awesome because it helps me to work with monero more easily.

But during looking at the code, I've found that code does not look very pretty (at least to me).
What I want is to encourage use of code styles. The best one that I see at the moment is https://github.com/doctrine/coding-standard ( with we can configure)

Daemon RPC wrapper

Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/daemonRPC.php)

JSON RPC methods:

  • getblockcount
  • on_getblockhash
  • getblocktemplate
  • submitblock
  • getlastblockheader
  • getblockheaderbyhash
  • getblockheaderbyheight
  • getblock
  • get_connections
  • get_info
  • hard_fork_info

Testing:

  • getblockcount
  • on_getblockhash
  • getblocktemplate
  • getlastblockheader
  • getblockheaderbyhash
  • getblockheaderbyheight
  • getblock
  • get_connections
  • get_info
  • hard_fork_info

Note: testing for submitblock deferred

offline mnemonic support planned?

Is there any plan to support using mnemonics without an RPC connection? Specifically generating a new random mnemonic and reading/validating a mnemonic.

I see there is already offline support for creating addresses and sub-addresses.

Implement params

Actually if you pass params, the library will give an error! This hasn't implemented yet!

Use namespaces

I think it's not best thing to do to use global namespace, lets do it in our own

Include "get_transfer_by_txid" function

You can call the rpc with:

curl -X POST http://127.0.0.1:18082/json_rpc \-H 'Content-Type: application/json' \-d '{"jsonrpc":"2.0","id":"0","method":"get_transfer_by_txid","params":{"txid":"<TX_HASH>"}}'

Unlocked Balance always return "0" After first Payment

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?

Some base58.php fixes

Syntax errors:

Line 75:
if (!is_array($bin) {
should be:
if (!is_array($bin)) {

Line 97:
if (!is_string($str) {
should be:
if (!is_string($str)) {

Type check error:
Line 220, double is valid.
if (!is_int($index)) {
should be:
if (!is_int($index) && !is_float($index)) {

When autoloading, an exception will try to load a class named 'MoneroIntegrations\MoneroPhp\Exception' resulting in a class not found error.
After line 30:
namespace MoneroIntegrations\MoneroPhp;
re-add:
use Exception;

get_connections method not found

I have my daemon running and its currently downloading the blockchain. When I can run other commands like getlastblockheader() I get output.

"block_header" => array:20 [▼
    "block_size" => 0
    "cumulative_difficulty" => 0
    "cumulative_difficulty_top64" => 0
    "depth" => 0
    "difficulty" => 0
    "difficulty_top64" => 0
    "hash" => ""
    "height" => 0
    "major_version" => 0
    "miner_tx_hash" => ""
    "minor_version" => 0
    "nonce" => 0
    "num_txes" => 0
    "orphan_status" => false
    "pow_hash" => ""
    "prev_hash" => ""
    "reward" => 0
    "timestamp" => 0
    "wide_cumulative_difficulty" => ""
    "wide_difficulty" => ""
  ]
  "credits" => 0
  "status" => "BUSY"
  "top_hash" => ""
  "untrusted" => false

But when trying to run get_connections I get the following error..

Request have return error: Method not found; Request: {"jsonrpc":"2.0","method":"get_connections","params":null};

open/create wallet with viewkey

Does the RPC support this? Or would I need to shell_exec(?) my way through monero-wallet-cli --generate-from-view-key and then use the rpc to open_wallet?

What do I do after "getting started"?

so i followed the steps in the getting started section, and now i have a web page that looks like the example web page, but the rest of the docs are way above my head.

I dont know php. I just have a simple html apache website hosted on a debain 10 vps.

I just want a webpage that functions the same as the "merchent view" in the regular gui wallet. Or somethign like the wordpress woocommerce plugin.

Multiple open wallets can not be made

Multiple open wallets can not be made. This ridiculous is using the last purse
in the website;
Amy getbalance request
Jones getbalance request
Mark getbalance request
Lee getbalance request
At the same time, OpenWallet is involved

get_transfers refuses to work with or without parameters

It's really weird. I've tried with all sorts of combinations of parameters, but it only returns an empty array. I decided to settle on incoming_transfers for the time being, and that worked but it didn't seem to filter by subaddress, when I had the subaddress index, for example '3', fed to it.

Am I doing something wrong? I'm calling the functions with $WalletRPC->get_transfers().

I appreciate any help! :)

Input validation in several functions not working

monerophp/src/base58.php

Lines 181 to 185 in 68900c3

private function uint64_to_8_be($num, $size)
{
if (gettype($num) != ('integer' || 'double')) {
throw new Exception ('base58->uint64_to_8_be(): Invalid input type ($num must be a number)');
}

please see

http://sandbox.onlinephpfunctions.com/code/bbb3f59200711389962f0860e7df3b826a810c4b

Your input validation is always true, so you don't catch unwanted types.

use https://www.php.net/manual/en/function.is-float.php
and
https://www.php.net/manual/en/function.is-int.php

Make stable version on packagist

I think it will be nice to lock the package version. As first release, for example, you can set version to 0.1.0 and then if you want to break the things, do it in 0.2 branch (or master but don't do release unless it's stable)

v0.17 changes

Getting rid of response id as for changes in v0.17

Autoloading issues

Some issues after the recent autoloading changes:
psr-4 is case sensitive, i.e. cryptonote.php must be Cryptonote.php, or the class renamed. Same with Serialize, Varint.
Namespaced classes using the standard Exceptions class also now need 'use Exception;'

Example.php can't find daemonRPC class

Thanks for the API. I have cloned and run this code, but it seems that for some reason your example.php file cannot find the daemonRPC class? When running the code I get this error

Fatal error: Uncaught Error: Class 'daemonRPC' not found in /var/www/html/monerophp/example.php:11 Stack trace: #0 {main} thrown in /var/www/html/monerophp/example.php on line 11

Wallet RPC wrapper

Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/walletRPC.php)

JSON RPC methods:

  • getbalance
  • getaddress
  • getheight
  • transfer
  • transfer_split
  • sweep_dust
  • sweep_all
  • store
  • get_payments
  • get_bulk_payments
  • get_transfers
  • get_transfer_by_txid
  • incoming_transfers
  • query_key
  • make_integrated_address
  • split_integrated_address
  • stop_wallet
  • make_uri
  • parse_uri
  • rescan_blockchain
  • set_tx_notes
  • get_tx_notes
  • sign
  • verify
  • export_key_images
  • import_key_images
  • get_address_book
  • add_address_book
  • delete_address_book
  • rescan_spent
  • start_mining
  • stop_mining
  • get_languages
  • create_wallet
  • open_wallet

Testing:

  • getbalance
  • getaddress
  • getheight
  • transfer
  • transfer_split
  • sweep_dust
  • sweep_all
  • store
  • get_transfers
  • incoming_transfers
  • query_key
  • make_integrated_address
  • split_integrated_address
  • stop_wallet
  • make_uri
  • parse_uri
  • rescan_blockchain
  • set_tx_notes
  • get_tx_notes
  • sign
  • export_key_images
  • import_key_images
  • get_address_book
  • add_address_book
  • delete_address_book
  • rescan_spent
  • start_mining
  • stop_mining
  • get_languages
  • create_wallet
  • open_wallet

Passing array as parameter to get_transfers method causes exception

When calling the get_transfers method with an array parameter I get an "Undefined offset: 0" exception.

Example code:

$transfer_params = array(
    'input_types' => array('in', 'out'),
    'account_index' => 0,
);

$transfers = $walletRPC->get_transfers($transfer_params);    //<-- Exception here

Offending source line:

  1347|    $params = array('account_index' => $account_index, 'subaddr_indices' => $subaddr_indices, 'min_height' => $min_height, 'max_height' => $max_height);
  1347|      for ($i = 0; $i < count($input_types); $i++) {
> 1348|        $params[$input_types[$i]] = true;
  1349|      }
  1350|    }

If I change the following source line from:

  1324|      if (is_object($input_types)) { // Parameters passed in as object/dictionary`

to

  1324|      if (is_array($input_types)) { // Parameters passed in as array?`

then it works fine.

The documentation says that you can pass an object but the only way I could get it to work was by changing it to an array. Is there a better way to construct the $transfer_params parameter in my example?

Invalid public address

For some reason, the public addresses i am getting are not valid

$crypto_note = new Cryptonote;
$hex_seed = $crypto_note->gen_new_hex_seed();
$address = $crypto_note->address_from_seed($hex_seed);
$is_valid_address = $crypto_note->verify_checksum($address); //is false

Here is a detailed output :

hex seed: 73dd6d63f0078e5b22db04b5a4e95247b1620c12762c4f89edea51c76bcb5da8

public address: 47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT928

is valid address: verify_checksum returned false

private spend key: 3196d3c1e828d6eac2ba5857f2269d76b0620c12762c4f89edea51c76bcb5d08

private view key: 296a9ddb344a78a10e0b53bdc8855828b6aa72bff266beaea63a09729eea6906

public spend key: 9288f05f5464bf08785c9298d197908a57ca60858dd9e6380df6e441df55e2cf

public view key: 166eeca7dff4a7f634a507135edecade33dd2a8654a638ba613ad806177e2c41

Following the tool at https://xmr.llcoins.net/addresstests.html , all the spend/view keys are correct, but the address should be

47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT98QKbKku

not

47BBbiKw29U2RAvscPNny5Q96nWEScga9ANoMyKUGRdKbe1Ygzm8BaEiBWBbDMWqUdeAeKjNvE4kPYB7pW7WDdT928

It is like Cryptonote::encode_address() based on base58::encode is not correct.
Also i am able to generate a subaddress, i don't know how to verify it, but it may be erroneous as well as it is using base58::encode() too.

$sub = $crypto_note->generate_subaddress(0, 0, $private_view_key, $public_spend_key);

Which will generate (based on the hex seed from above)

89WJ3xCkoAoMzHXHGKhBxwA2sWXdeczfxESZtBnjA25pF7iXGAu7Ch99VSJeWfFSYdhVpFQhzt6vF3AySXDuNv9VVJfW2BK

System: Ubuntu 18.04
PHP: 7.3.9

How to use authorized rpc?

I have to use --disable-rpc-login in monero-wallet-rpc but i want to use authorized rpc. So how to use username and password in example.php? I have tried monero:password@ip instead of ip in example.php but it's didn't work. It show '401 Unauthorized' in browser. I want to make explorer and wallet website with free api. Is it safe to use rpc without login? Thanks.

Daemon RPC Wrapper: "Other Methods"

Work progressing in https://github.com/sneurlax/monerophp#feature/rpc (src/daemonRPC.php)

These methods are accessible via their own route (not /json_rpc. I haven't figured out how to access them using jsonRPCClient.php yet.)

Other JSON RPC Methods:

  • /getheight
  • /gettransactions
  • /is_key_image_spent
  • /sendrawtransaction
  • /get_transaction_pool
  • /stop_daemon

Testing:

  • /getheight
  • /gettransactions
  • /is_key_image_spent
  • /sendrawtransaction
  • /get_transaction_pool
  • /stop_daemon

Input validation:

  • /is_key_image_spent
  • /sendrawtransaction

Two request make this error.

After two request i start to get this error, did this not happen a few weeks ago?

018-11-29 00:41:46.706 [RPC0] ERROR wallet.wallet2 src/wallet/wallet2.cpp:4582 !is_keys_file_locked(). THROW EXCEPTION: error::wallet_internal_error

Unit testing

In #54 I let an errant $new_amount slip in, which was undefined and caused transfer calls to fail. A comprehensive unit testing suite (or at least having example.php test each and ever method) would have caught this issue.

Enable SSL validation by default for non loopback connections

Currently SSL validation is disabled via:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

I suggest to:

  1. have option to disable/enable SSL validation.
  2. disable validation by default if $this->url is loopback address (such as: 127.0.0.1 , localhost, ::1, etc..) as there is no need for SSL in this case (nothing leave the network...)
  3. enable validation by default via:

CURLOPT_SSL_VERIFYHOST, '2'
CURLOPT_SSL_VERIFYPEER, '1'

PHP 7.2 - json_encode() breaks transfer submission of certain amounts

I was having fits trying to get a certain transfer to go today. Tracking it down it turns out that an amount submitted for transfer as 0.06784267 was getting sent to the wallet daemon as 67842669999.99999.

Here's a log snippit:

Blockchain submitTransaction: address: xyz, amount: 0.06784267
...
{"jsonrpc":"2.0","method":"transfer","params":{"destinations":[{"amount":67842669999.99999,"address":"xyz"}],"mixin":6,"get_tx_key":true,"payment_id":"","account_index":0,"subaddr_indices":"","priority":1,"do_not_relay":false},"id":4}

Digging into it I discovered that PHP seems to like to take floats and do crazy things with them inside of json_encode(), so I figured somewhere along the line a conversion was happening and it was coming out a float before going into json_encode(). The culprit turned out to be walletRPC.php's _transform() method. Changing it from this:

public function _transform($amount = 0) { return $amount * 1000000000000; }

to this:

public function _transform($amount = 0) { return intval($amount * 1000000000000); }

managed to get me a transfer amount of 67842669999 ... still not right. So I ended up with this:

public function _transform($amount = 0) { return intval(bcmul($amount, 1000000000000)); }

and now everything works fine.

{"jsonrpc":"2.0","method":"transfer","params":{"destinations":[{"amount":67842670000,"address":"xyz"}],"mixin":6,"get_tx_key":true,"payment_id":"","account_index":0,"subaddr_indices":"","priority":1,"do_not_relay":false},"id":4}

Hope that helps someone!

monero wallet integaration

Hello,
I coudnt get the result from monero wallet after the installation of both wallet and this plug in. I changed the ip and port number in the example.php file.but i coudnt get the expected reply. how can i get the result.is there any additional settings is needed for the proper integration.

Transfer payments

Send monero to a number of recipients.

Inputs:

  • destinations
  • array of destinations to receive XMR:
  • amount - unsigned int; Amount to send to each destination, in atomic units.
  • address - string; Destination public address.
  • fee - unsigned int; Ignored, will be automatically calculated.
  • mixin - unsigned int; Number of outpouts from the blockchain to mix with (0 means no mixing).
  • unlock_time - unsigned int; Number of blocks before the monero can be spent (0 to not add a lock).
  • payment_id - string; (Optional) Random 32-byte/64-character hex string to identify a transaction.
  • get_tx_key - boolean; (Optional) Return the transaction key after sending.

Outputs:

  • fee - Integer value of the fee charged for the txn.
  • tx_hash - String for the publically searchable transaction hash
  • tx_key - String for the transaction key if get_tx_key is true, otherwise, blank string.

Add new wallet methods from 0.12.0.0 "Lithium Luna"

New methods were added in 0.12.0.0, especially regarding subaddresses. Here are the methods that aren't wrapped yet:

  • create_address
  • label_address
  • get_accounts
  • create_account
  • label_account
  • get_account_tags
  • tag_accounts
  • untag_accounts
  • set_account_tag_description
  • sweep_unmixable
  • sweep_all (parameter updates)
  • sweep_single
  • relay_tx
  • set_attribute
  • get_attribute
  • get_tx_key
  • check_tx_key
  • get_tx_proof
  • get_spend_proof
  • check_spend_proof
  • get_reserve_proof
  • check_reserve_proof
  • is_multisig
  • prepare_multisig
  • make_multisig
  • export_multisig_info
  • import_multisig_info
  • finalize_multisig
  • sign_multisig
  • submit_multisig

get_spend_proof & check_spend_proof

#1: There's a useful option for both of these commands in the CLI and GUI, but that's not reflected in the walletRPC.php.

#2: Checking check_spend_proof with a signature not created with the corresponding txid results in an error "incorrect signature size" (which throws an exception), rather than a "good=false" return which is what is given if it's the correct txid but bad signature.

Use guzzle instead of jsonRPCClient

I was looking at the code and noticed that it will be cool to use guzzle instead of/ inside of jsonRPCClient
since guzzle does all the dirty work that you need to do your self (doing all the stuff with curl_setopt)

sending with hard coded fees

Is there any way to use a 'hardcoded' fee, instead a dynamic one, when sending payments?

All the best;

jaheller

"No error" json_last_error_msg

jsonRPCClient.php on line 107 make false error when json_last_error_msg returns "No error" message.
fix:
$this->validate( !is_null($jsonErrorMsg) && $jsonErrorMsg !== 'No error' , $jsonErrorMsg . ': ' . $responseMessage);

walletRPC missing refresh() call

Might I suggest making the following addition to walletRPC.php:

  /**
   *
   * Refresh the wallet after opening
   *
   * @param  int  $start_height  Block height from which to start    (optional)
   *
   * @return object  Example: {
   *   // TODO example
   * }
   *
   */
  public function refresh($start_height = null)
  {
    $params = array('start_height' => $start_height);
    return $this->_run('refresh', $params);
  }

To support the refresh() RPC call as documented here: https://web.getmonero.org/resources/developer-guides/wallet-rpc.html#refresh

Cheers

Method not found “make_integrated_address" Laravel/PHP

My code is written in Laravel. Whenever I try to generate an address + payment ID using make_integrated_address, I always get the fallowing error in laravel.log:

[2021-02-09 18:32:42] local.ERROR: Request have return error: Method not found;
Request: {"jsonrpc":"2.0","method":"make_integrated_address","params":{"payment_id":null}};

My code:


Thank you!

Response Http Error - 401 Unauthorized

hello i have problem, when i using the getbalance function etc rpc work fine, but when i using the transfer function the result is eror Response Http Error - 401 Unauthorized but the transaction in wallet is successfull. how to fixed the error response ?

Thank you

Library returns NULL when it receives a blank response and error.

I am using $walletRPC->transfer() among other functions, and whenever I run this command, the function returns null instead of error messages or resulting information from the transfer() function.

For example, I ran the following command:

$result = $walletRPC->transfer(0.00001, '43CHhRBuqiPFevrGEnQeSR76CMhKnV21AfHDsp47oY3CH7dBLFE7egBT2vT3niBXWC8k4WzJ8zFkLdTYVKKuBpwhVXiq7ZS', 'd9e3f557812a49ddaaa096555b22e658d88052c09ec64bde9bcc2be905fb04a2');

$result was NULL, despite my monero-rpc log showing these errors.

ERROR wallet.wallet2 src/wallet/wallet2.cpp:8369 needed_moner + min_fee > unlocked_balance_subtotal. THROW EXCEPTION: error:not_enough_unlocked_money.

What is the correct way to see my error messages through this API?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.