예제 #1
0
    def test_load_and_save_wallet(self):
        wallet_dict = {
            'version': 1,
            'name': 'Main Wallet',
            'accounts': [
                {
                    'name': 'An Account',
                    'ledger': 'btc_mainnet',
                    'seed':
                        "carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
                        "h absent",
                    'encrypted': False,
                    'private_key':
                        'xprv9s21ZrQH143K3TsAz5efNV8K93g3Ms3FXcjaWB9fVUsMwAoE3Z'
                        'T4vYymkp5BxKKfnpz8J6sHDFriX1SnpvjNkzcks8XBnxjGLS83BTyfpna',
                    'public_key':
                        'xpub661MyMwAqRbcFwwe67Bfjd53h5WXmKm6tqfBJZZH3pQLoy8Nb6'
                        'mKUMJFc7UbpVNzmwFPN2evn3YHnig1pkKVYcvCV8owTd2yAcEkJfCX53g',
                    'address_generator': {
                        'name': 'deterministic-chain',
                        'receiving': {'gap': 17, 'maximum_uses_per_address': 3},
                        'change': {'gap': 10, 'maximum_uses_per_address': 3}
                    }
                }
            ]
        }

        storage = WalletStorage(default=wallet_dict)
        wallet = Wallet.from_storage(storage, self.manager)
        self.assertEqual(wallet.name, 'Main Wallet')
        self.assertEqual(len(wallet.accounts), 1)
        account = wallet.default_account
        self.assertIsInstance(account, BTCLedger.account_class)
        self.maxDiff = None
        self.assertDictEqual(wallet_dict, wallet.to_dict())
예제 #2
0
 def from_config(cls, config: dict) -> 'BaseWalletManager':
     manager = cls()
     for ledger_id, ledger_config in config.get('ledgers', {}).items():
         manager.get_or_create_ledger(ledger_id, ledger_config)
     for wallet_path in config.get('wallets', []):
         wallet_storage = WalletStorage(wallet_path)
         wallet = Wallet.from_storage(wallet_storage, manager)
         manager.wallets.append(wallet)
     return manager
예제 #3
0
파일: manager.py 프로젝트: hackrush01/torba
 def from_config(cls, config):  # type: (Dict) -> WalletManager
     wallets = []
     manager = cls(wallets)
     for coin_id, ledger_config in config.get('ledgers', {}).items():
         manager.get_or_create_ledger(coin_id, ledger_config)
     for wallet_path in config.get('wallets', []):
         wallet_storage = WalletStorage(wallet_path)
         wallet = Wallet.from_storage(wallet_storage, manager)
         wallets.append(wallet)
     return manager
예제 #4
0
    def test_read_write(self):
        manager = WalletManager()
        config = {'wallet_path': '/tmp/wallet'}
        ledger = manager.get_or_create_ledger(BTCLedger.get_id(), config)

        with tempfile.NamedTemporaryFile(suffix='.json') as wallet_file:
            wallet_file.write(b'{}')
            wallet_file.seek(0)

            # create and write wallet to a file
            wallet_storage = WalletStorage(wallet_file.name)
            wallet = Wallet.from_storage(wallet_storage, manager)
            account = wallet.generate_account(ledger)
            wallet.save()

            # read wallet from file
            wallet_storage = WalletStorage(wallet_file.name)
            wallet = Wallet.from_storage(wallet_storage, manager)

            self.assertEqual(account.public_key.address,
                             wallet.default_account.public_key.address)
예제 #5
0
    def test_load_and_save_wallet(self):
        wallet_dict = {
            'name':
            'Main Wallet',
            'accounts': [{
                'ledger':
                'btc_mainnet',
                'seed':
                "carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
                "h absent",
                'encrypted':
                False,
                'private_key':
                'xprv9s21ZrQH143K2dyhK7SevfRG72bYDRNv25yKPWWm6dqApNxm1Zb1m5gGcBWYfbsPjTr2v5joit8Af2Zp5P'
                '6yz3jMbycrLrRMpeAJxR8qDg8',
                'public_key':
                'xpub661MyMwAqRbcF84AR8yfHoMzf4S2ct6mPJtvBtvNeyN9hBHuZ6uGJszkTSn5fQUCdz3XU17eBzFeAUwV6f'
                'iW44g14WF52fYC5J483wqQ5ZP',
                'receiving_gap':
                10,
                'receiving_maximum_use_per_address':
                2,
                'change_gap':
                10,
                'change_maximum_use_per_address':
                2,
            }]
        }

        storage = WalletStorage(default=wallet_dict)
        wallet = Wallet.from_storage(storage, self.manager)
        self.assertEqual(wallet.name, 'Main Wallet')
        self.assertEqual(len(wallet.accounts), 1)
        account = wallet.default_account
        self.assertIsInstance(account, BTCLedger.account_class)
        self.maxDiff = None
        self.assertDictEqual(wallet_dict, wallet.to_dict())
예제 #6
0
파일: manager.py 프로젝트: hackrush01/torba
 def create_wallet(self, path):
     storage = WalletStorage(path)
     wallet = Wallet.from_storage(storage, self)
     self.wallets.append(wallet)
     return wallet