I reply to all queries on the forums and via email, once per day, Monday to Friday (not weekends).

If you are new here, please see some information on how to ask for support. Thank you!

wallets_api_transactions filter returns empty result

dashed-slug.net Forums TurtleCoin Adapter extension support wallets_api_transactions filter returns empty result

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10058
    d3vnu77
    Participant

    results…

    In some code I am writing… I move some ARMS with the following code:

    do_action('wallets_api_move', array(
    		              'symbol' => 'ARMS',
    		              'amount' => $recentRedemption->creds,
    		              'from_user_id' => $this->acr->acrUserId,
    		              'to_user_id' => $recentRedemption->ref_id,
    		              'fee' => 0,
    		              'comment' => 'Cash out of ARMS Rewards to 2ACoin (ARMS)!',
    		              'skip_confirm' => true,
    		              'tags' => $this->acr->burnRef . ' ' . $this->acr->burnRef . '_' . $recentRedemption->id
    			        ));

    That move exists in the database. (see attached screenshot.)

    However, when I go to confirm that the move is in fact in the database with the following code…

    	public function isTurned($recentRedemption)
    	{		
    		$args = array(
    			'symbol' => 'ARMS',
                'categories' => array('move'),
                'tags' => array('acr_burn_128') //$this->acr->burnRef.'_'.$recentRedemption->id
    		);
    
    		$armsPayout = apply_filters('wallets_api_transactions', array(), $args);
    		echo '<pre>';
            var_dump($args); 
            var_dump($armsPayout); //It's empty?  It's should not be empty
            echo '/pre>';
    
            die('payout');
            return $armsPayout;
    	}

    Any reason you see that $armsPayout should be empty, because it is in the database and showing up in the backend in transactions.

    Attachments:
    You must be logged in to view attached files.
    #10065
    alexg
    Keymaster

    Hello,

    I’m not sure why you get back an empty array.

    I tried to recreate your example and it works fine.

    I first placed an internal transfer:

    do_action('wallets_api_move', array(
    	'symbol' => 'ARMS',
    	'amount' => 5,
    	'from_user_id' => 1,
    	'to_user_id' => 2,
    	'fee' => 0,
    	'comment' => 'Cash out of ARMS Rewards to 2ACoin (ARMS)!',
    	'skip_confirm' => true,
    	'tags' => 'acr_burn acr_burn_128',
    ));

    Then I tried to retrieve it in a similar way to yours:

    $args = array(
    	'symbol' => 'ARMS',
    	'categories' => array('move'),
    	'tags' => array('acr_burn'),
    );
    
    apply_filters('wallets_api_transactions', array(), $args);

    The result contains the transfer, as you can see in the attached screenshots.

    The PHP API by default retrieves transactions owned by the current user. This is why in my test I get the send part of the transaction (credit) but not the receive part (debit). If you were calling the PHP code from another user account, you would have to specify a user_id argument to wallets_api_transactions. This will get you the transactions belonging to a specific user. See the docs for this.

    Can you try the exact code I pasted above, to see what happens? I ran both snippets from the same account, (user_id 1), with an ARMS balance.

    Let me know what you found.

    with regards

    P.S. As a sidenote, you don’t need to dump debug data to the frontend, because your debug output can break your HTML. A cleaner way to inspect your debug prints is to write to the debug logs using error_log(). Or simply use WP-Console, I find it very useful for these types of tests.

    Attachments:
    You must be logged in to view attached files.
    #10077
    d3vnu77
    Participant

    Please look at the two attached screenshots.

    The only difference is I change the $args tag from ‘acr_burn_8’ to ‘acr_burn_128’

    It finds the acr_burn_8 which is why I assumed the code worked and went on to further coding.

    However when I attempted to test the code a second time and was looking for ‘acr_burn_128’ the filter does not locate the transaction. If I change the tag back to ‘acr_burn_8’, it can find that transaction. Very strange.

    It should also be noted when I change the tag to ‘acr_burn’, it only finds the ‘acr_burn_8’ transaction, not both.

    Attachments:
    You must be logged in to view attached files.
    #10081
    d3vnu77
    Participant

    Uploads smaller than 500KB

    Attachments:
    You must be logged in to view attached files.
    #10084
    d3vnu77
    Participant

    Slightly larger screenshot that will not be scaled as much attached. Easier reading.

    Attachments:
    You must be logged in to view attached files.
    #10091
    alexg
    Keymaster

    Yes, this looks like it’s expected behavior.

    The transaction with the tag acr_burn_128 belongs to user_id 540, and the transaction with the tag acr_burn_8 belongs to user 1 (the admin).

    When you call the filter, if you don’t specify a user_id, it uses the current user id (see here). The filter always retrieves transactions for a specific user. This is explained in this phpDoc line.

    If you do the following call, you will see the other transaction:

    $args = array(
    	'symbol' => 'ARMS',
    	'categories' => array('move'),
    	'tags' => array('acr_burn'),
    	'user_id' => 540,
    );
    
    apply_filters('wallets_api_transactions', array(), $args);

    Hope this helps. Let me know if you have any further questions.

    with regards

    #10108
    d3vnu77
    Participant

    That was it. Thank you sir.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.