Exemple #1
0
class BlockchainsAccountsResource(BaseResource):

    get_schema = BlockchainAccountsGetSchema()

    def make_put_schema(self) -> BlockchainAccountsPutSchema:
        return BlockchainAccountsPutSchema(
            self.rest_api.rotkehlchen.chain_manager.ethereum, )

    def make_patch_schema(self) -> BlockchainAccountsPatchSchema:
        return BlockchainAccountsPatchSchema(
            self.rest_api.rotkehlchen.chain_manager.ethereum, )

    def make_delete_schema(self) -> BlockchainAccountsDeleteSchema:
        return BlockchainAccountsDeleteSchema(
            self.rest_api.rotkehlchen.chain_manager.ethereum, )

    @use_kwargs(get_schema, location='view_args')  # type: ignore
    def get(self, blockchain: SupportedBlockchain) -> Response:
        return self.rest_api.get_blockchain_accounts(blockchain)

    @resource_parser.use_kwargs(make_put_schema,
                                location='json_and_view_args')  # type: ignore
    def put(
        self,
        blockchain: SupportedBlockchain,
        accounts: List[Dict[str, Any]],
        async_query: bool,
    ) -> Response:
        account_data = [
            BlockchainAccountData(
                address=entry['address'],
                label=entry['label'],
                tags=entry['tags'],
            ) for entry in accounts
        ]
        return self.rest_api.add_blockchain_accounts(
            blockchain=blockchain,
            account_data=account_data,
            async_query=async_query,
        )

    @resource_parser.use_kwargs(make_patch_schema,
                                location='json_and_view_args')  # type: ignore
    def patch(
        self,
        blockchain: SupportedBlockchain,
        accounts: List[Dict[str, Any]],
    ) -> Response:
        account_data = [
            BlockchainAccountData(
                address=entry['address'],
                label=entry['label'],
                tags=entry['tags'],
            ) for entry in accounts
        ]
        return self.rest_api.edit_blockchain_accounts(
            blockchain=blockchain,
            account_data=account_data,
        )

    @resource_parser.use_kwargs(make_delete_schema,
                                location='json_and_view_args')  # type: ignore
    def delete(
        self,
        blockchain: SupportedBlockchain,
        accounts: ListOfBlockchainAddresses,
        async_query: bool,
    ) -> Response:
        return self.rest_api.remove_blockchain_accounts(
            blockchain=blockchain,
            accounts=accounts,
            async_query=async_query,
        )
Exemple #2
0
class BlockchainsAccountsResource(BaseResource):

    get_schema = BlockchainAccountsGetSchema()
    put_schema = BlockchainAccountsPutSchema()
    patch_schema = BlockchainAccountsPatchSchema()
    delete_schema = BlockchainAccountsDeleteSchema()

    @use_kwargs(get_schema, locations=('view_args',))
    def get(self, blockchain: SupportedBlockchain) -> Response:
        return self.rest_api.get_blockchain_accounts(blockchain)

    @use_kwargs(put_schema, locations=('json', 'view_args'))
    def put(
            self,
            blockchain: SupportedBlockchain,
            accounts: List[Dict[str, str]],
            async_query: bool,
    ) -> Response:
        account_data = [
            BlockchainAccountData(
                address=entry['address'],
                label=entry['label'],
                tags=entry['tags'],
            ) for entry in accounts
        ]
        return self.rest_api.add_blockchain_accounts(
            blockchain=blockchain,
            account_data=account_data,
            async_query=async_query,
        )

    @use_kwargs(patch_schema, locations=('json', 'view_args'))
    def patch(
            self,
            blockchain: SupportedBlockchain,
            accounts: List[Dict[str, str]],
    ) -> Response:
        account_data = [
            BlockchainAccountData(
                address=entry['address'],
                label=entry['label'],
                tags=entry['tags'],
            ) for entry in accounts
        ]
        return self.rest_api.edit_blockchain_accounts(
            blockchain=blockchain,
            account_data=account_data,
        )

    @use_kwargs(delete_schema, locations=('json', 'view_args'))
    def delete(
            self,
            blockchain: SupportedBlockchain,
            accounts: ListOfBlockchainAddresses,
            async_query: bool,
    ) -> Response:
        return self.rest_api.remove_blockchain_accounts(
            blockchain=blockchain,
            accounts=accounts,
            async_query=async_query,
        )