+ account.modified_on

This commit is contained in:
Lex Berezhny 2019-03-11 22:24:57 -04:00
parent cdd25e3b0f
commit a021ddeffd
3 changed files with 18 additions and 3 deletions

View file

@ -143,6 +143,7 @@ class TestHierarchicalDeterministicAccount(AsyncioTestCase):
async def test_load_and_save_account(self): async def test_load_and_save_account(self):
account_data = { account_data = {
'name': 'My Account', 'name': 'My Account',
'modified_on': 123.456,
'seed': 'seed':
"carbon smart garage balance margin twelve chest sword toast envelope bottom stomac" "carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
"h absent", "h absent",
@ -302,6 +303,7 @@ class TestSingleKeyAccount(AsyncioTestCase):
async def test_load_and_save_account(self): async def test_load_and_save_account(self):
account_data = { account_data = {
'name': 'My Account', 'name': 'My Account',
'modified_on': 123.456,
'seed': 'seed':
"carbon smart garage balance margin twelve chest sword toast envelope bottom stomac" "carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
"h absent", "h absent",

View file

@ -1,4 +1,5 @@
import tempfile import tempfile
from binascii import hexlify
from torba.testcase import AsyncioTestCase from torba.testcase import AsyncioTestCase
@ -35,6 +36,7 @@ class TestWalletCreation(AsyncioTestCase):
{ {
'name': 'An Account', 'name': 'An Account',
'ledger': 'btc_mainnet', 'ledger': 'btc_mainnet',
'modified_on': 123.456,
'seed': 'seed':
"carbon smart garage balance margin twelve chest sword toast envelope bottom stomac" "carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
"h absent", "h absent",
@ -57,12 +59,19 @@ class TestWalletCreation(AsyncioTestCase):
storage = WalletStorage(default=wallet_dict) storage = WalletStorage(default=wallet_dict)
wallet = Wallet.from_storage(storage, self.manager) wallet = Wallet.from_storage(storage, self.manager)
self.assertEqual(wallet.name, 'Main Wallet') self.assertEqual(wallet.name, 'Main Wallet')
self.assertEqual(
hexlify(wallet.hash), b'9f462b8dd802eb8c913e54f09a09827ebc14abbc13f33baa90d8aec5ae920fc7'
)
self.assertEqual(len(wallet.accounts), 1) self.assertEqual(len(wallet.accounts), 1)
account = wallet.default_account account = wallet.default_account
self.assertIsInstance(account, BTCLedger.account_class) self.assertIsInstance(account, BTCLedger.account_class)
self.maxDiff = None self.maxDiff = None
self.assertDictEqual(wallet_dict, wallet.to_dict()) self.assertDictEqual(wallet_dict, wallet.to_dict())
encrypted = wallet.pack('password')
decrypted = Wallet.unpack('password', encrypted)
self.assertEqual(decrypted['accounts'][0]['name'], 'An Account')
def test_read_write(self): def test_read_write(self):
manager = BaseWalletManager() manager = BaseWalletManager()
config = {'data_path': '/tmp/wallet'} config = {'data_path': '/tmp/wallet'}

View file

@ -1,4 +1,5 @@
import json import json
import time
import asyncio import asyncio
import random import random
import typing import typing
@ -198,12 +199,13 @@ class BaseAccount:
def __init__(self, ledger: 'baseledger.BaseLedger', wallet: 'basewallet.Wallet', name: str, def __init__(self, ledger: 'baseledger.BaseLedger', wallet: 'basewallet.Wallet', name: str,
seed: str, private_key_string: str, encrypted: bool, seed: str, private_key_string: str, encrypted: bool,
private_key: Optional[PrivateKey], public_key: PubKey, private_key: Optional[PrivateKey], public_key: PubKey,
address_generator: dict) -> None: address_generator: dict, modified_on: float) -> None:
self.ledger = ledger self.ledger = ledger
self.wallet = wallet self.wallet = wallet
self.id = public_key.address self.id = public_key.address
self.name = name self.name = name
self.seed = seed self.seed = seed
self.modified_on = modified_on
self.private_key_string = private_key_string self.private_key_string = private_key_string
self.password: Optional[str] = None self.password: Optional[str] = None
self.private_key_encryption_init_vector: Optional[bytes] = None self.private_key_encryption_init_vector: Optional[bytes] = None
@ -269,7 +271,8 @@ class BaseAccount:
encrypted=d.get('encrypted', False), encrypted=d.get('encrypted', False),
private_key=private_key, private_key=private_key,
public_key=public_key, public_key=public_key,
address_generator=d.get('address_generator', {}) address_generator=d.get('address_generator', {}),
modified_on=d.get('modified_on', time.time())
) )
def to_dict(self): def to_dict(self):
@ -289,7 +292,8 @@ class BaseAccount:
'encrypted': self.serialize_encrypted, 'encrypted': self.serialize_encrypted,
'private_key': private_key_string, 'private_key': private_key_string,
'public_key': self.public_key.extended_key_string(), 'public_key': self.public_key.extended_key_string(),
'address_generator': self.address_generator.to_dict(self.receiving, self.change) 'address_generator': self.address_generator.to_dict(self.receiving, self.change),
'modified_on': self.modified_on
} }
@property @property