dashed-slug.net › Forums › TurtleCoin Adapter extension support › wallets_api_transactions filter returns empty result
Tagged: filter, internal transfer, move, php api, wallets_api_transactions
- This topic has 6 replies, 2 voices, and was last updated 3 years, 6 months ago by d3vnu77.
-
AuthorPosts
-
February 24, 2021 at 7:39 pm #10058d3vnu77Participant
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.February 25, 2021 at 7:56 am #10065alexgKeymasterHello,
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 thereceive
part (debit). If you were calling the PHP code from another user account, you would have to specify auser_id
argument towallets_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.February 25, 2021 at 2:52 pm #10077d3vnu77ParticipantPlease 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.February 25, 2021 at 2:55 pm #10081d3vnu77ParticipantUploads smaller than 500KB
Attachments:
You must be logged in to view attached files.February 25, 2021 at 3:00 pm #10084d3vnu77ParticipantSlightly larger screenshot that will not be scaled as much attached. Easier reading.
Attachments:
You must be logged in to view attached files.February 26, 2021 at 10:12 am #10091alexgKeymasterYes, this looks like it’s expected behavior.
The transaction with the tag
acr_burn_128
belongs to user_id540
, and the transaction with the tagacr_burn_8
belongs to user1
(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
February 28, 2021 at 2:33 am #10108d3vnu77ParticipantThat was it. Thank you sir.
-
AuthorPosts
- You must be logged in to reply to this topic.