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

Release/v1.7.0 #288

Merged
merged 7 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
126 changes: 126 additions & 0 deletions cli/test/stress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import aiohttp
import asyncio
from time import perf_counter


async def main():
c = StressClient()
await test_account_create(c)
await test_subaddresses(c)


async def test_account_create(c, n=10):
accounts = await c.get_all_accounts()
num_accounts_before = len(accounts)

account_ids = []
async def create_one(i):
account = await c.create_account(str(i))
account_ids.append(account['account_id'])

with Timer() as timer:
await asyncio.gather(*[
create_one(i)
for i in range(1, n+1)
])

accounts = await c.get_all_accounts()
assert len(accounts) == num_accounts_before + n

await asyncio.gather(*[
c.remove_account(account_id)
for account_id in account_ids
])

print('Created {} accounts in {:.3f}s'.format(n, timer.elapsed))


async def test_subaddresses(c, n=10):
account = await c.create_account()
account_id = account['account_id']

addresses = await c.get_addresses_for_account(account_id)
assert len(addresses) == 2

with Timer() as timer:
await asyncio.gather(*[
c.assign_address(account_id, str(i))
for i in range(1, n+1)
])

addresses = await c.get_addresses_for_account(account_id)
assert len(addresses) == 2 + n

await c.remove_account(account_id)

print('Created {} addresses in {:.3f}s'.format(n, timer.elapsed))


class StressClient:

async def _req(self, request_data):
default_params = {
"jsonrpc": "2.0",
"api_version": "2",
"id": 1,
}
request_data = {**request_data, **default_params}
async with aiohttp.ClientSession() as session:
async with session.post('http://localhost:9090/wallet', json=request_data) as response:
r = await response.json()
try:
return r['result']
except KeyError:
print(r)
raise

async def get_all_accounts(self):
r = await self._req({"method": "get_all_accounts"})
return r['account_map']

async def create_account(self, name=''):
r = await self._req({
"method": "create_account",
"params": {"name": name}
})
return r['account']

async def remove_account(self, account_id):
return await self._req({
"method": "remove_account",
"params": {"account_id": account_id}
})

async def assign_address(self, account_id, name=''):
return await self._req({
"method": "assign_address_for_account",
"params": {
"account_id": account_id,
"metadata": name,
},
})

async def get_addresses_for_account(self, account_id):
r = await self._req({
"method": "get_addresses_for_account",
"params": {
"account_id": account_id,
"offset": "0",
"limit": "1000",
},
})
return r['address_map']


class Timer:
def __enter__(self):
self._start_time = perf_counter()
return self

def __exit__(self, *_):
end_time = perf_counter()
self.elapsed = end_time - self._start_time


if __name__ == '__main__':
asyncio.run(main())
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
Loading