forked from volaradlp/minercli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Volara
committed
Jul 1, 2024
0 parents
commit 1d01a3f
Showing
26 changed files
with
7,272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
.idea/ | ||
|
||
# Temporary file used to communicate with a validator via API | ||
cli.json | ||
|
||
account.cookies | ||
.vscode | ||
.DS_Store | ||
*.data | ||
*.zip | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Volara Miner | ||
|
||
Miner for the Volara X DLP | ||
|
||
# About | ||
|
||
Volara is a decentralized data marketplace for X data, built on the robust Vana network. We empower users by giving them ownership of their data and enabling them to earn from it. | ||
|
||
The Volara Miner is a software package which allows users to contribute X data to the network for rewards. | ||
|
||
# Credentials | ||
|
||
Volara uses two credentials to perform mining on Vana: | ||
|
||
1. X username and password, for access to the Twitter API | ||
2. Google OAUTH, for storing your mined X data in Google Drive. | ||
|
||
# Install | ||
|
||
## Prerequisites | ||
|
||
Volara uses several dependencies to operate. | ||
|
||
- Python 3.12 | ||
- Poetry | ||
|
||
```shell | ||
brew install python | ||
curl -sSL https://install.python-poetry.org | python3 - | ||
``` | ||
|
||
## Quick Start | ||
|
||
```shell | ||
git clone <this-repo> | ||
cd <this-repo> | ||
poetry install | ||
export PATH=$(pwd)/bin:$PATH | ||
``` | ||
|
||
For convenience, add our bin to your path in ~/.bashrc | ||
|
||
```shell | ||
export PATH=$(pwd)/bin:$PATH | ||
``` | ||
|
||
# Interface | ||
|
||
The interface can be accessed via the CLI at `./bin/volara` | ||
|
||
## Mining | ||
|
||
#### Start Mining | ||
|
||
```shell | ||
volara mine start | ||
``` | ||
|
||
#### Stop Mining | ||
|
||
```shell | ||
volara mine start | ||
``` | ||
|
||
#### See Mining Logs | ||
|
||
```shell | ||
volara mine logs | ||
``` | ||
|
||
## Auth | ||
|
||
### Google Drive | ||
|
||
#### Login to Drive | ||
|
||
```shell | ||
volara auth drive login | ||
``` | ||
|
||
#### Logout to Drive | ||
|
||
```shell | ||
volara auth drive logout | ||
``` | ||
|
||
### X | ||
|
||
#### Login to X | ||
|
||
```shell | ||
volara auth drive login | ||
``` | ||
|
||
#### Logout to X | ||
|
||
```shell | ||
volara auth drive logout | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
poetry run python -m cli.entry $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
poetry run python -m miner.run $@ |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._impl import get_active_account, set_active_account, remove_active_account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import typing as T | ||
import os | ||
import click | ||
import requests | ||
import json | ||
import datetime as dt | ||
|
||
from google.auth.transport.requests import Request | ||
from google.oauth2.credentials import Credentials | ||
|
||
from constants import TMP_DRIVE_AUTH, VOLARA_API | ||
|
||
SCOPES = ["https://www.googleapis.com/auth/drive.file"] | ||
|
||
|
||
def get_active_account() -> T.Optional[Credentials]: | ||
if os.path.exists(TMP_DRIVE_AUTH): | ||
with open(TMP_DRIVE_AUTH, "r") as token: | ||
code = json.load(token) | ||
code["expiry"] = dt.datetime.fromisoformat(code["expiry"][:-1]).replace( | ||
tzinfo=None | ||
) | ||
creds = Credentials(**code) | ||
if creds.expired: | ||
click.echo("Current session is expired... requesting new credentials") | ||
creds = _call_volara_api_server_refresh(creds) | ||
if creds is not None: | ||
_persist_credentials(creds) | ||
return creds | ||
if creds.valid: | ||
return creds | ||
return None | ||
|
||
|
||
def set_active_account() -> T.Optional[Credentials]: | ||
if os.path.exists(TMP_DRIVE_AUTH): | ||
os.remove(TMP_DRIVE_AUTH) | ||
click.echo("Removed existing active account.") | ||
click.echo("Setting active account...") | ||
creds = _call_volara_api_server() | ||
if not creds: | ||
click.echo("Failed to get the drive auth code from Volara's auth server.") | ||
return | ||
_persist_credentials(creds) | ||
click.echo("Active account set.") | ||
return creds | ||
|
||
|
||
def remove_active_account() -> None: | ||
click.echo("Removing active account...") | ||
if os.path.exists(TMP_DRIVE_AUTH): | ||
os.remove(TMP_DRIVE_AUTH) | ||
click.echo("Active account removed.") | ||
else: | ||
click.echo("No active account found.") | ||
|
||
|
||
def _persist_credentials(creds: Credentials) -> None: | ||
os.makedirs(os.path.dirname(TMP_DRIVE_AUTH), exist_ok=True) | ||
with open(TMP_DRIVE_AUTH, "w") as token: | ||
token.write(creds.to_json()) | ||
|
||
|
||
def _call_volara_api_server() -> T.Optional[Credentials]: | ||
url_response = requests.get(f"{VOLARA_API}/auth/get-url") | ||
if url_response.status_code != 200: | ||
return | ||
url = url_response.json()["url"] | ||
click.echo(f"Copy and paste this URL into your browser: {url}") | ||
code = click.prompt("Paste your code") | ||
code_response = requests.get(f"{VOLARA_API}/auth/callback?code={code}") | ||
code_response.raise_for_status() | ||
if code_response.status_code != 200: | ||
return | ||
resp = code_response.json()["tokens"] | ||
return _form_credentials_from_token(resp) | ||
|
||
|
||
def _call_volara_api_server_refresh(creds: Credentials) -> T.Optional[Credentials]: | ||
url_response = requests.get(f"{VOLARA_API}/auth/refresh?refreshToken={creds.token}") | ||
if url_response.status_code != 200: | ||
return | ||
resp = url_response.json()["tokens"] | ||
return _form_credentials_from_token(resp) | ||
|
||
|
||
def _form_credentials_from_token(resp: T.Dict[str, T.Any]) -> Credentials: | ||
code = { | ||
"token": resp["access_token"], | ||
"scopes": [resp["scope"]], | ||
"expiry": dt.datetime.fromtimestamp( | ||
resp["expiry_date"] / 1000, dt.timezone.utc | ||
), | ||
} | ||
return Credentials(**code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._impl import set_active_account, get_active_account, remove_active_account |
Oops, something went wrong.