Skip to content

Commit

Permalink
feature/limit offset optional (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-oudard authored Apr 30, 2022
1 parent 05507b5 commit b230a52
Show file tree
Hide file tree
Showing 27 changed files with 121 additions and 528 deletions.
4 changes: 2 additions & 2 deletions cli/mobilecoin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def history(self, account_id):
account = self._load_account_prefix(account_id)
account_id = account['account_id']

transactions = self.client.get_all_transaction_logs_for_account(account_id)
transactions = self.client.get_transaction_logs_for_account(account_id, limit=1000)

def block_key(t):
submitted = t['submitted_block_index']
Expand Down Expand Up @@ -585,7 +585,7 @@ def address(self, action, **args):

def address_list(self, account_id):
account = self._load_account_prefix(account_id)
addresses = self.client.get_addresses_for_account(account['account_id'])
addresses = self.client.get_addresses_for_account(account['account_id'], limit=1000)

print()
print(_format_account_header(account))
Expand Down
26 changes: 18 additions & 8 deletions cli/mobilecoin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ def _req(self, request_data):
except ConnectionError:
raise ConnectionError(f'Could not connect to wallet server at {self.url}.')

raw_response = None
try:
response_data = json.load(r)
raw_response = r.read()
response_data = json.loads(raw_response)
except ValueError:
raise ValueError('API returned invalid JSON:', r.text)
raise ValueError('API returned invalid JSON:', raw_response)

if self.verbose:
print(r.status, http.client.responses[r.status])
print(repr(raw_response))
print(len(raw_response), 'bytes')
print(json.dumps(response_data, indent=2))
print()

Expand Down Expand Up @@ -147,10 +151,14 @@ def export_account_secrets(self, account_id):
})
return r['account_secrets']

def get_all_txos_for_account(self, account_id):
def get_txos_for_account(self, account_id, offset=0, limit=100):
r = self._req({
"method": "get_all_txos_for_account",
"params": {"account_id": account_id}
"method": "get_txos_for_account",
"params": {
"account_id": account_id,
"offset": offset,
"limit": limit,
}
})
return r['txo_map']

Expand Down Expand Up @@ -200,7 +208,7 @@ def assign_address_for_account(self, account_id, metadata=None):
})
return r['address']

def get_addresses_for_account(self, account_id, offset=0, limit=1000):
def get_addresses_for_account(self, account_id, offset=0, limit=100):
r = self._req({
"method": "get_addresses_for_account",
"params": {
Expand Down Expand Up @@ -259,11 +267,13 @@ def submit_transaction(self, tx_proposal, account_id=None):
})
return r['transaction_log']

def get_all_transaction_logs_for_account(self, account_id):
def get_transaction_logs_for_account(self, account_id, offset=0, limit=100):
r = self._req({
"method": "get_all_transaction_logs_for_account",
"method": "get_transaction_logs_for_account",
"params": {
"account_id": account_id,
"offset": str(int(offset)),
"limit": str(int(limit)),
},
})
return r['transaction_log_map']
Expand Down
4 changes: 2 additions & 2 deletions cli/test/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def tests_with_wallet(c, source_wallet):
# Check its balance and make sure it has txos.
balance = c.poll_balance(source_account_id, seconds=60)
assert pmob2mob(balance['unspent_pmob']) >= 1
txos = c.get_all_txos_for_account(source_account_id)
txos = c.get_txos_for_account(source_account_id)
assert len(txos) > 0

try:
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_transaction(c, source_account_id):
assert pmob2mob(balance['unspent_pmob']) == Decimal('0.0')

# Check transaction logs.
transaction_log_map = c.get_all_transaction_logs_for_account(dest_account_id)
transaction_log_map = c.get_transaction_logs_for_account(dest_account_id)
amounts = [ pmob2mob(t['value_pmob']) for t in transaction_log_map.values() ]
assert sorted( float(a) for a in amounts ) == [0.0996, 0.1], str(amounts)
assert all( t['status'] == 'tx_status_succeeded' for t in transaction_log_map.values() )
Expand Down
3 changes: 0 additions & 3 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* [Export View Only Account Secrets](accounts/account-secrets/export_view_only_account_secrets.md)
* [Address](accounts/address/README.md)
* [Assign Address For Account](accounts/address/assign_address_for_account.md)
* [Get All Addresses For Account](accounts/address/get_all_addresses_for_account.md)
* [Get Addresses For Account](accounts/address/get_addresses_for_account.md)
* [Verify Address](accounts/address/verify_address.md)
* [Balance](accounts/balance/README.md)
Expand All @@ -42,7 +41,6 @@
* [Get TXO](transactions/txo/get_txo.md)
* [Get MobileCoin Protocol TXO](transactions/txo/get_mc_protocol_txo.md)
* [Get TXOs For Account](transactions/txo/get_txos_for_account.md)
* [Get All TXOs For Account](transactions/txo/get_all_txos_for_account.md)
* [Get TXOs For Account](transactions/txo/get_txos_for_account.md)
* [Get TXOs For View Only Account](transactions/txo/get_txos_for_view_only_account.md)
* [Get All TXOs For Address](transactions/txo/get_txo_object.md)
Expand All @@ -55,7 +53,6 @@
* [Transaction Log](transactions/transaction-log/README.md)
* [Get Transaction Object](transactions/transaction-log/get_transaction_object.md)
* [Get Transaction Log](transactions/transaction-log/get_transaction_log.md)
* [Get All Transaction Logs For Account](transactions/transaction-log/get_all_transaction_logs_for_account.md)
* [Get Transaction Logs For Account](transactions/transaction-log/get_transaction_logs_for_account.md)
* [Get All Transaction Logs For Block](transactions/transaction-log/get_all_transaction_logs_for_block.md)
* [Get All Transaction Logs Ordered By Block](transactions/transaction-log/get_all_transaction_logs_ordered_by_block.md)
Expand Down
2 changes: 0 additions & 2 deletions docs/accounts/address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Important: If you receive funds at a subaddress that has not yet been assigned,
| `account_id` | string | A unique identifier for the assigned associated account. |
| `metadata` | string | An arbitrary string attached to the object. |
| `subaddress_index` | string \(uint64\) | The assigned subaddress index on the associated account. |
| `offset` | integer | The value to offset pagination requests. Requests will exclude all list items up to and including this object. |
| `limit` | integer | The limit of returned results. |

## Example

Expand Down
4 changes: 2 additions & 2 deletions docs/accounts/address/get_addresses_for_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description: Get assigned addresses for an account.
| Required Param | Purpose | Requirements |
| :--- | :--- | :--- |
| `account_id` | The account on which to perform this action. | The account must exist in the wallet. |
| `offset` | integer | The value to offset pagination requests. Requests will exclude all list items up to and including this object. |
| `limit` | integer | The limit of returned results. This has a max value of 1000, and will return an error if exceeded. |
| `offset` | The pagination offset. Results start at the offset index. Optional, defaults to 0. | |
| `limit` | Limit for the number of results. Optional, defaults to 100 | |

## Example

Expand Down
71 changes: 0 additions & 71 deletions docs/accounts/address/get_all_addresses_for_account.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/gift-codes/gift-code/build_gift_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: Build a gift code in a tx_proposal that you can fund and submit to

| Optional Param | Purpose | Requirements |
| :--- | :--- | :--- |
| `input_txo_ids` | The specific TXOs to use as inputs to this transaction. | TXO IDs \(obtain from `get_all_txos_for_account`\) |
| `input_txo_ids` | The specific TXOs to use as inputs to this transaction. | TXO IDs \(obtain from `get_txos_for_account`\) |
| `fee` | The fee amount to submit with this transaction. | If not provided, uses `MINIMUM_FEE` = .01 MOB. |
| `tombstone_block` | The block after which this transaction expires. | If not provided, uses `cur_height` + 10. |
| `max_spendable_value` | The maximum amount for an input TXO selected for this transaction. | |
Expand Down
1 change: 0 additions & 1 deletion docs/transactions/transaction-log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Due to the privacy properties of the MobileCoin ledger, transactions are ephemer
| `comment` | string | An arbitrary string attached to the object. |
| `failure_code` | integer | Code representing the cause of "failed" status. |
| `failure_message` | string | Human parsable explanation of "failed" status. |
| `offset` | integer | The value to offset pagination requests for `transaction_log` list. Requests will exclude all list items up to and including this object. |

## Example

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
| Required Param | Purpose | Requirement |
| :--- | :--- | :--- |
| `transaction_log_id` | The transaction log ID to get. | Transaction log must exist in the wallet. |
| `offset` | integer | The value to offset pagination requests. Requests will exclude all list items up to and including this object. |
| `limit` | integer | The limit of returned results. This has a max value of 1000, and will return an error if exceeded. |
| `offset` | The pagination offset. Results start at the offset index. Optional, defaults to 0. | |
| `limit` | Limit for the number of results. Optional, defaults to 100 | |

## Example

Expand Down Expand Up @@ -118,4 +118,4 @@
}
```
{% endtab %}
{% endtabs %}
{% endtabs %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: >-
| `recipient_public_address` | The recipient for this transaction | b58-encoded public address bytes |
| `value_pmob` | The amount of MOB to send in this transaction | |
| `addresses_and_values` | An array of public addresses and value tuples | addresses are b58-encoded public addresses, value is in pmob |
| `input_txo_ids` | Specific TXOs to use as inputs to this transaction | TXO IDs \(obtain from `get_all_txos_for_account`\) |
| `input_txo_ids` | Specific TXOs to use as inputs to this transaction | TXO IDs \(obtain from `get_txos_for_account`\) |
| `fee` | The fee amount to submit with this transaction | If not provided, uses `MINIMUM_FEE` = .01 MOB |
| `tombstone_block` | The block after which this transaction expires | If not provided, uses `cur_height` + 10 |
| `max_spendable_value` | The maximum amount for an input TXO selected for this transaction | |
Expand Down
2 changes: 1 addition & 1 deletion docs/transactions/transaction/build_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: >-
| `recipient_public_address` | The recipient for this transaction | b58-encoded public address bytes |
| `value_pmob` | The amount of MOB to send in this transaction | |
| `addresses_and_values` | An array of public addresses and value tuples | addresses are b58-encoded public addresses, value is in pmob |
| `input_txo_ids` | Specific TXOs to use as inputs to this transaction | TXO IDs (obtain from `get_all_txos_for_account`) |
| `input_txo_ids` | Specific TXOs to use as inputs to this transaction | TXO IDs (obtain from `get_txos_for_account`) |
| `fee` | The fee amount to submit with this transaction | If not provided, uses `MINIMUM_FEE` = .01 MOB |
| `tombstone_block` | The block after which this transaction expires | If not provided, uses `cur_height` + 10 |
| `max_spendable_value` | The maximum amount for an input TXO selected for this transaction | |
Expand Down
4 changes: 1 addition & 3 deletions docs/transactions/txo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ In order to construct a transaction, the wallet will select "Unspent Transaction
| `assigned_address` | string \(uint64\) | The address corresponding to the subaddress index which was assigned as an intended sender for this TXO. |
| `key_image` \(only on pending/spent\) | string \(hex\) | A fingerprint of the TXO derived from your private spend key materials, required to spend a TXO |
| `confirmation` | string \(hex\) | A confirmation that the sender of the TXO can provide to validate that they participated in the construction of this TXO. |
| `offset` | integer | The value to offset pagination requests. Requests will exclude all list items up to and including this object. |
| `limit` | integer | The limit of returned results. |

## Example <a id="object_method"></a>

Expand Down Expand Up @@ -109,4 +107,4 @@ a minimal txo entity useful for view-only-accounts
| `spent` | string | Whether or not this txo has been manually marked as spent. |
| `txo_id_hex` | string | A synthetic ID created from properties of the TXO. This will be the same for a given TXO across systems. |

## Example <a id="object_method"></a>
## Example <a id="object_method"></a>
Loading

0 comments on commit b230a52

Please sign in to comment.