Skip to content

Commit

Permalink
Added list storage deal api. (#39)
Browse files Browse the repository at this point in the history
* Added list storage deal api.

* Added more code set up file.

* Added github workflow.

* Removed redundant installation.

* Added back pipenv installation.

* Try.

* Fixed integration test failure.

* Fix.

* Improved error handling.

* Fixed bug.

* Fix.

* avoid remove.

* remove.

* fix missing import.

* Increase wait time.

* decrease wait time a bit.

* Added more wait time.

* Changed wait time to 20 seconds.

* change to inequality.

* WIP: add list deal info example

* feat: list storage/retrieval deals

* fix: reformat

* feat(test): add retrieval deals test

* feat(test): add retrieval deals test

Co-authored-by: Peter Van Garderen <[email protected]>
Co-authored-by: apogiatzis <[email protected]>

Closes #37
  • Loading branch information
leofisG authored Oct 6, 2020
1 parent aec758f commit c98019f
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
- name: Install CI dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
- name: Run Integration Tests
Expand Down
7 changes: 6 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ pytest-docker = "*"
grpcio-tools = "*"
secretstorage = {markers = "sys_platform == 'linux'"}
keyring = "==19.1.0"
flake8 = "*"
isort = "*"
pylint = "*"
mypy = "*"

[requires]
python_version = "3.7"

[scripts]
build = "python setup.py sdist bdist_wheel"
publish = "twine upload dist/*"
format = "bash -c \"python -m black $(git ls-files '*.py')\""
format = "bash -c \"python -m isort setup.py pygate_grpc tests && python -m black $(git ls-files '*.py')\""
lint = "bash -c \"python -m flake8\""
integration-test = "python -m pytest tests/integration/"
test-ffs = "python -m pytest tests/integration/test_ffs.py"

Expand Down
140 changes: 133 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/ffs_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from pygate_grpc.client import PowerGateClient

client = PowerGateClient("127.0.0.1:5002", False)
Expand Down
49 changes: 49 additions & 0 deletions examples/ffs_deals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import time

from io import BytesIO

from pygate_grpc.client import PowerGateClient
from pygate_grpc.ffs import bytes_to_chunks

if __name__ == "__main__":

hostName = "127.0.0.1:5002"

# Create client
client = PowerGateClient(hostName)

# Create FFS
ffs = client.ffs.create()
print("FFS created:")
print(ffs)

test_file = BytesIO(b"These are the contents of a test file")
stage_requests_iter = bytes_to_chunks(test_file)

print("Pushing file to FFS...")
stage_res = client.ffs.stage(stage_requests_iter, token=ffs.token)
push_res = client.ffs.push(stage_res.cid, token=ffs.token)

# Check that CID is pinned to FFS
check = client.ffs.info(stage_res.cid, ffs.token)
print("Checking FFS pins...")
print(check)

# Wait some time so that we can get some deals
time.sleep(5)

# Check information about the storage deal
storage_deals = client.ffs.list_storage_deal_records(
include_pending=True, include_final=True, token=ffs.token
)
print("Storage deals: ")
for record in storage_deals.records:
print(record)

# Check information about the retrieval deals
retrieval_deals = client.ffs.list_retrieval_deal_records(
include_pending=True, include_final=True, token=ffs.token
)
print("Retrieval deals: ")
for record in retrieval_deals.records:
print(record)
3 changes: 0 additions & 3 deletions examples/ffs_logs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import time

from io import BytesIO

from pygate_grpc.client import PowerGateClient
from pygate_grpc.ffs import bytes_to_chunks
from pygate_grpc.exceptions import GRPCTimeoutException
from pygate_grpc.errors import error_handler

client = PowerGateClient("127.0.0.1:5002", False)

Expand Down
7 changes: 2 additions & 5 deletions pygate_grpc/buildinfo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import grpc

from proto import buildinfo_rpc_pb2
from proto import buildinfo_rpc_pb2_grpc
from proto import buildinfo_rpc_pb2, buildinfo_rpc_pb2_grpc
from pygate_grpc.errors import ErrorHandlerMeta


class BuildinfoClient(object, metaclass=ErrorHandlerMeta):
## THIS USED AN OUTDATED PROTO SPECIFICATION IT NEEDS RE DEVELOPMENT
# THIS USED AN OUTDATED PROTO SPECIFICATION IT NEEDS RE DEVELOPMENT
def __init__(self, channel):
self.client = buildinfo_rpc_pb2_grpc.RPCServiceStub(channel)

Expand Down
2 changes: 1 addition & 1 deletion pygate_grpc/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import grpc

from pygate_grpc import health, faults, buildinfo, ffs, wallet, net
from pygate_grpc import buildinfo, faults, ffs, health, net, wallet
from pygate_grpc.errors import ErrorHandlerMeta


Expand Down
10 changes: 3 additions & 7 deletions pygate_grpc/errors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import grpc
import logging

from functools import wraps

from pygate_grpc.exceptions import (
GRPCNotAvailableException,
GRPCTimeoutException,
PyGateGenericException,
)
import grpc

from pygate_grpc.exceptions import GRPCNotAvailableException, GRPCTimeoutException

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pygate_grpc/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from grpc._channel import _MultiThreadedRendezvous, _InactiveRpcError
from grpc._channel import _MultiThreadedRendezvous


class GRPCNotAvailableException(Exception):
Expand Down
3 changes: 1 addition & 2 deletions pygate_grpc/faults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from proto import faults_rpc_pb2
from proto import faults_rpc_pb2_grpc
from proto import faults_rpc_pb2, faults_rpc_pb2_grpc
from pygate_grpc.errors import ErrorHandlerMeta


Expand Down
Loading

0 comments on commit c98019f

Please sign in to comment.