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

Fix get_transfers to allow (backwards-compatible) single string as input #28

Merged
merged 5 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/walletRPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ Look up transfers

Parameters:

- `$input_types <Array>` Array of transfer type strings; possible values include 'all', in', 'out', 'pending', 'failed', and 'pool' *(optional)*
- `$input_types <Array>` Array of transfer type strings; possible values include 'all', 'in', 'out', 'pending', 'failed', and 'pool' *(optional)*
- `$account_index <number>` Index of account to look *(optional)*
- `$subaddr_indices <String>` Comma-seperated list of subaddress indices to look up *(optional)*
- `$min_height <number>` Minimum block height to use when looking up *(optional)*
Expand Down
28 changes: 22 additions & 6 deletions src/walletRPC.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,11 @@ public function check_reserve_proof($address, $signature)
*
* Look up transfers
*
* @param array $input_types Array of transfer type strings; possible values include 'all', in', 'out', 'pending', 'failed', and 'pool' (optional)
* @param number $account_index Index of account to look up (optional)
* @param string $subaddr_indices Comma-seperated list of subaddress indices to look up (optional)
* @param number $min_height Minimum block height to use when looking up transfers (optional)
* @param number $max_height Maximum block height to use when looking up transfers (optional)
* @param array $input_types Array of transfer type strings; possible values include 'all', 'in', 'out', 'pending', 'failed', and 'pool' (optional)
* @param number $account_index Index of account to look up (optional)
* @param string $subaddr_indices Comma-seperated list of subaddress indices to look up (optional)
* @param number $min_height Minimum block height to use when looking up transfers (optional)
* @param number $max_height Maximum block height to use when looking up transfers (optional)
*
* OR
*
Expand All @@ -1272,7 +1272,14 @@ public function check_reserve_proof($address, $signature)
public function get_transfers($input_types = ['all'], $account_index = 0, $subaddr_indices = '', $min_height = 0, $max_height = 4206931337)
{
if (is_string($input_types)) { // If user is using old method
$params = array($input_type => $account_index); // $params = array($input_type => $input_value);
$params = array('subaddr_indices' => $subaddr_indices, 'min_height' => $min_height, 'max_height' => $max_height);
if (is_bool($account_index)) { // If user passed eg. get_transfers('in', true)
$params['account_index'] = 0;
$params[$input_types] = $account_index; // $params = array($input_type => $input_value);
} else { // If user passed eg. get_transfers('in')
$params['account_index'] = $account_index;
$params[$input_types] = true;
}
} else {
if (is_object($input_types)) { // Parameters passed in as object/dictionary
$params = $input_types;
Expand Down Expand Up @@ -1302,6 +1309,15 @@ public function get_transfers($input_types = ['all'], $account_index = 0, $subad
}
}

if (array_key_exists('all', $params)) {
unset($params['all']);
$params['in'] = true;
$params['out'] = true;
$params['pending'] = true;
$params['failed'] = true;
$params['pool'] = true;
}

if (($min_height || $max_height) && $max_height != 4206931337) {
$params['filter_by_height'] = true;
}
Expand Down