Exemplo n.º 1
0
async def account(app):
    acc = Account.from_kwargs(address='mwHHRbLcC394T7vsLQZVh8FsB3QkDNRKK9',
                              notify_url='localhost:8080/notify')

    await app.accounts_repo.save(acc)

    return acc
Exemplo n.º 2
0
    async def process_account(self, raw_account, ex_session):
        account = Account(raw_account)
        script_hash = self.build_script_hash(account.address)

        list_unspent = await self.get_listunspent(script_hash, ex_session)

        return await paco.map(self.process_unspent,
                              list_unspent,
                              return_exceptions=True,
                              account=account,
                              ex_session=ex_session)
Exemplo n.º 3
0
    async def __call__(self, notify_url):
        child_id = await self.get_child_id()
        address = self.get_address(child_id)

        account = Account.from_kwargs(notify_url=notify_url,
                                      address=address,
                                      child_id=child_id)

        await self.app.accounts_repo.save(account)

        return account
Exemplo n.º 4
0
    async def get_accounts(self, accounts_batch_size, max_unused_days):
        accounts_cursor = self.app.accounts_repo.for_sync()
        accounts = await accounts_cursor.to_list(accounts_batch_size)

        count = 0
        for account in accounts:
            account = Account.from_kwargs(**account)
            days_unused = (datetime.now() - account.last_txn_at).days

            if days_unused > max_unused_days:
                account.sync = False
                await self.app.accounts_repo.save(account)
                count += 1

        return count
Exemplo n.º 5
0
async def test_update_accounts_last_txn_at(app, list_unspent_response,
                                           transaction_response):
    await app.tx_outputs_repo.save(
        TxOutput({
            'block_hash':
            '000000004c3604d758cba41c30c1f2be2ffa3e730a3017ded08078dc422a614e',
            'blocktime': 1536681241,
            'confirmations': 0,
            'locktime': 1412987,
            'position': 1,
            'tx_hash':
            '5f7d66d9f36dacf150320bedd35d2f601754a31be78ccc7b6be795ed8a518b46',
            'tx_id':
            '25705000a564b7852947faa1fea2987143410bb3ada53458b6eead67e7469d60',
            'address': 'mwHHRbLcC394T7vsLQZVh8FsB3QkDNRKK9',
            'value': 0.39654376
        }))
    acc = Account.from_kwargs(address='mwHHRbLcC394T7vsLQZVh8FsB3QkDNRKK9',
                              notify_url='localhost:8080/notify',
                              last_txn_at=datetime.now() - timedelta(days=6))

    account = await app.accounts_repo.save(acc)

    ElectrumxSessionStub.stub_server_version()
    ElectrumxSessionStub.stub_request(
        'blockchain.scripthash.listunspent',
        ['da22c9488b0d4828b4bc96ad6ff41c274bc9e1632482673cc4c07a0a1a8fcebc'],
        list_unspent_response)
    ElectrumxSessionStub.stub_request('blockchain.transaction.get', [
        '25705000a564b7852947faa1fea2987143410bb3ada53458b6eead67e7469d60',
        True
    ], transaction_response)

    await SyncTxOutputs(app=app)()

    assert await app.tx_outputs_repo.count() == 1
    assert await app.accounts_repo.count() == 1

    account = await app.accounts_repo.find_one({'_id': account.id})
    assert account.last_txn_at == datetime.now()