mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Update .new_address() method to return subaddress index
This commit is contained in:
parent
6bf97ddca2
commit
c2af7acc31
8 changed files with 75 additions and 6 deletions
|
@ -6,6 +6,12 @@ Release Notes
|
|||
|
||||
With version 0.6 the package name on PyPi has changed from `monero-python` to just `monero`.
|
||||
|
||||
Backward-incompatible changes:
|
||||
|
||||
1. The ``.new_address()`` method of both ``Wallet`` and ``Account`` returns a 2-element tuple of
|
||||
(`subaddress`, `index`) where the additional element is the index of the subaddress within
|
||||
current account.
|
||||
|
||||
0.5
|
||||
---
|
||||
|
||||
|
|
|
@ -50,12 +50,13 @@ Creating accounts and addresses
|
|||
|
||||
Every wallet can have separate accounts and each account can have numerous
|
||||
addresses. The ``Wallet.new_account()`` and ``Account.new_address()`` will
|
||||
create new instances.
|
||||
create new instances, then return a tuple consisting of the subaddress itself,
|
||||
and the subaddress index within the account.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
In [9]: w.new_address()
|
||||
Out[9]: BenuGf8eyVhjZwdcxEJY1MHrUfqHjPvE3d7Pi4XY5vQz53VnVpB38bCBsf8AS5rJuZhuYrqdG9URc2eFoCNPwLXtLENT4R7
|
||||
Out[9]: (BenuGf8eyVhjZwdcxEJY1MHrUfqHjPvE3d7Pi4XY5vQz53VnVpB38bCBsf8AS5rJuZhuYrqdG9URc2eFoCNPwLXtLENT4R7, 1)
|
||||
|
||||
In [10]: w.get_addresses()
|
||||
Out[10]:
|
||||
|
@ -72,7 +73,7 @@ create new instances.
|
|||
Out[13]: Bhd3PRVCnq5T5jjNey2hDSM8DxUgFpNjLUrKAa2iYVhYX71RuCGTekDKZKXoJPAGL763kEXaDSAsvDYb8bV77YT7Jo19GKY
|
||||
|
||||
In [14]: w.accounts[1].new_address()
|
||||
Out[14]: Bbz5uCtnn3Gaj1YAizaHw1FPeJ6T7kk7uQoeY48SWjezEAyrWScozLxYbqGxsV5L6VJkvw5VwECAuLVJKQtHpA3GFXJNPYu
|
||||
Out[14]: (Bbz5uCtnn3Gaj1YAizaHw1FPeJ6T7kk7uQoeY48SWjezEAyrWScozLxYbqGxsV5L6VJkvw5VwECAuLVJKQtHpA3GFXJNPYu, 1)
|
||||
|
||||
In [15]: w.accounts[1].get_addresses()
|
||||
Out[15]:
|
||||
|
|
|
@ -64,7 +64,8 @@ class Account(object):
|
|||
Creates a new address.
|
||||
|
||||
:param label: address label as `str`
|
||||
:rtype: :class:`SubAddress <monero.address.SubAddress>`
|
||||
:rtype: tuple of subaddress, subaddress index (minor):
|
||||
(:class:`SubAddress <monero.address.SubAddress>`, `int`)
|
||||
"""
|
||||
return self._backend.new_address(account=self.index, label=label)
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ class JSONRPCWallet(object):
|
|||
def new_address(self, account=0, label=None):
|
||||
_address = self.raw_request(
|
||||
'create_address', {'account_index': account, 'label': label})
|
||||
return SubAddress(_address['address'])
|
||||
return SubAddress(_address['address']), _address['address_index']
|
||||
|
||||
def balances(self, account=0):
|
||||
_balance = self.raw_request('getbalance', {'account_index': account})
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"id": 0,
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
"subaddress_accounts": [
|
||||
{
|
||||
"account_index": 0,
|
||||
"balance": 111141601989972,
|
||||
"base_address": "56cXYWG13YKaT9z1aEy2hb9TZNnxrW3zE9S4nTQVDux5Qq7UYsmjuux3Zstxkorj9HAufyWLU3FwHW4uERQF6tkeUVogGN3",
|
||||
"label": "Primary account",
|
||||
"tag": "",
|
||||
"unlocked_balance": 111141601989972
|
||||
},
|
||||
{
|
||||
"account_index": 1,
|
||||
"balance": 1000000000000,
|
||||
"base_address": "79kTZg96pMf2Dt9rLEWnLzTUB8XC1wMhxaJyxa79hJu6bK9CfFnfbSL1GJNZbqhv9xPqJhRj2Yfb7QUWa2zeEw56H4KiUfN",
|
||||
"label": "Untitled account",
|
||||
"tag": "",
|
||||
"unlocked_balance": 1000000000000
|
||||
}
|
||||
],
|
||||
"total_balance": 112141601989972,
|
||||
"total_unlocked_balance": 112141601989972
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": 0,
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
"address": "7AEBRUmNcjhUjiqdVpeKKYiAVZ216AYdhBFx8UUfjPhWdKujoosnsUtHCohLcYWUXFdNiqnBsMmCFCyDkSmat3Ys4H4yHUp",
|
||||
"address_index": 232
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": 0,
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
"address": "74PY6ZcC4N5U4MN4aTPQE58d35zGsFYK17NBx9GA66Bc37V5q6UU7eG6uLExg5m2TH5DJZc9BuEs64jEStTSV2PNLt2Y3wb",
|
||||
"address_index": 3
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ except ImportError:
|
|||
from mock import patch, Mock
|
||||
|
||||
from monero.wallet import Wallet
|
||||
from monero.address import BaseAddress, Address
|
||||
from monero.address import BaseAddress, Address, SubAddress
|
||||
from monero.seed import Seed
|
||||
from monero.transaction import IncomingPayment, OutgoingPayment, Transaction
|
||||
from monero.backends.jsonrpc import JSONRPCWallet
|
||||
|
@ -165,6 +165,25 @@ class JSONRPCWalletTestCase(JSONTestCase):
|
|||
self.assertEqual('account 1', w.accounts[1].label)
|
||||
self.assertEqual([acc0, acc1], w.accounts)
|
||||
|
||||
@responses.activate
|
||||
def test_new_address(self):
|
||||
responses.add(responses.POST, self.jsonrpc_url,
|
||||
json=self._read('test_new_address-00-get_accounts.json'),
|
||||
status=200)
|
||||
responses.add(responses.POST, self.jsonrpc_url,
|
||||
json=self._read('test_new_address-10-new_address_account_0.json'),
|
||||
status=200)
|
||||
responses.add(responses.POST, self.jsonrpc_url,
|
||||
json=self._read('test_new_address-20-new_address_account_1.json'),
|
||||
status=200)
|
||||
w = Wallet(JSONRPCWallet())
|
||||
subaddr, index = w.new_address()
|
||||
self.assertIsInstance(subaddr, SubAddress)
|
||||
self.assertIsInstance(index, int)
|
||||
subaddr, index = w.accounts[1].new_address()
|
||||
self.assertIsInstance(subaddr, SubAddress)
|
||||
self.assertIsInstance(index, int)
|
||||
|
||||
@patch('monero.backends.jsonrpc.requests.post')
|
||||
def test_incoming_confirmed(self, mock_post):
|
||||
mock_post.return_value.status_code = 200
|
||||
|
|
Loading…
Reference in a new issue