Skip to content

Commit

Permalink
allow 'all' as parameter to get_transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
sneurlax committed Apr 2, 2018
1 parent ac5a347 commit e8a4d18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
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_types => $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

0 comments on commit e8a4d18

Please sign in to comment.