Skip to content

Commit db0e39a

Browse files
apogiatzisasutulaAntreas Pogiatzis
authored
Powergate v1.2.1 + design updates (#52)
* new client api Signed-off-by: Aaron Sutula <hi@asutula.com> * update to latest proto file Signed-off-by: Aaron Sutula <hi@asutula.com> * update integration tests and examples Signed-off-by: Aaron Sutula <hi@asutula.com> * import iterable Signed-off-by: Aaron Sutula <hi@asutula.com> * fix some imports Signed-off-by: Aaron Sutula <hi@asutula.com> * update to powergate 1.1.2, use published grpc bindings Signed-off-by: Aaron Sutula <hi@asutula.com> * feat: powergate v1 update * fix: examples * fix: linting + formating * chore: readme update Co-authored-by: Aaron Sutula <hi@asutula.com> Co-authored-by: Antreas Pogiatzis <antreas@deplatformer.io>
1 parent 429967f commit db0e39a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1410
-14611
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,6 @@ dmypy.json
137137
.pytype/
138138

139139
# Cython debug symbols
140-
cython_debug/
140+
cython_debug/
141+
142+
.vscode

Pipfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pytest = "*"
1414
docker = "*"
1515
gitpython = "*"
1616
pytest-docker = "*"
17-
grpcio-tools = "*"
1817
secretstorage = {markers = "sys_platform == 'linux'"}
1918
keyring = "==19.1.0"
2019
flake8 = "*"
2120
isort = "*"
2221
pylint = "*"
2322
mypy = "*"
23+
pygate-grpc = {editable = true,path = "."}
2424

2525
[requires]
2626
python_version = "3.7"
@@ -31,10 +31,8 @@ publish = "twine upload dist/*"
3131
format = "bash -c \"python -m isort setup.py pygate_grpc tests && python -m black $(git ls-files '*.py')\""
3232
lint = "bash -c \"python -m flake8\""
3333
integration-test = "python -m pytest tests/integration/"
34-
test-ffs = "python -m pytest tests/integration/test_ffs.py"
3534

3635
[packages]
37-
grpcio = "*"
38-
protobuf = "*"
39-
six = "*"
36+
grpc-powergate-client = "==1.1.2"
37+
mypy-extensions = "*"
4038
deprecated = "*"

Pipfile.lock

Lines changed: 289 additions & 281 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![CodeFactor](https://www.codefactor.io/repository/github/pygate/pygate-grpc/badge)](https://www.codefactor.io/repository/github/pygate/pygate-grpc)
44
[![PyPI version](https://badge.fury.io/py/pygate-grpc.svg)](https://badge.fury.io/py/pygate-grpc)
55
![Tests](https://github.com/pygate/pygate-gRPC/workflows/Tests/badge.svg)
6+
[![Downloads](https://pepy.tech/badge/pygate-grpc)](https://pepy.tech/project/pygate-grpc)
67
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
78

89
A Python interface to [Textile](https://textile.io/)'s [Powergate](https://docs.textile.io/powergate/) [Filecoin](https://filecoin.io/) API
@@ -28,7 +29,7 @@ from pygate_grpc.client import PowerGateClient
2829

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

31-
healthcheck = client.health.check()
32+
build_info = client.build_info()
3233
```
3334

3435
Simple as that!

cidconfig.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/apply_pull_file.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
from pathlib import Path
3+
from pygate_grpc.client import PowerGateClient
4+
5+
6+
if __name__ == "__main__":
7+
8+
hostName = "127.0.0.1:5002"
9+
10+
# Create client
11+
c = PowerGateClient(hostName, False)
12+
13+
# Create user
14+
user = c.admin.users.create()
15+
print("User created:")
16+
print(user)
17+
18+
# Stage file
19+
print("Staging testfile.txt to IPFS storage")
20+
path = Path(os.path.abspath(__file__))
21+
staged_file = c.data.stage_file(path.parent / "testfile.txt", user.token)
22+
print("Applying storage config...")
23+
24+
# Apply the default storage config to the given file
25+
c.config.apply(staged_file.cid, override=False, token=user.token)
26+
27+
# Override push with another config
28+
addresses = c.wallet.addresses(user.token)
29+
wallet = addresses[0].address
30+
new_config = {
31+
"hot": {"enabled": True, "allowUnfreeze": True, "ipfs": {"addTimeout": 30}},
32+
"cold": {
33+
"enabled": True,
34+
"filecoin": {
35+
"replicationFactor": 1,
36+
"dealMinDuration": 518400,
37+
"excludedMiners": ["t01101"],
38+
"trustedMiners": ["t01000", "t02000"],
39+
"countryCodes": ["ca", "nl"],
40+
"renew": {"enabled": True, "threshold": 3},
41+
"address": wallet,
42+
"maxPrice": 50,
43+
},
44+
},
45+
"repairable": True,
46+
}
47+
48+
c.config.apply(staged_file.cid, override=True, config=new_config, token=user.token)
49+
50+
# Check that CID is stored
51+
check = c.data.cid_info([staged_file.cid], user.token)
52+
print("Checking CID storage...")
53+
print(check)
54+
55+
# Get the data back
56+
print("Retrieving file " + staged_file.cid)
57+
file_bytes = c.data.get(staged_file.cid, user.token)
58+
59+
# Write to a file on disk
60+
print("Saving as 'testfile_copy.txt'")
61+
with open(path.parent / "testfile_copy.txt", "wb") as f:
62+
f.write(file_bytes)

examples/cidconfig_example.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"hot": {
3+
"enabled": true,
4+
"ipfs": {
5+
"addTimeout": "30"
6+
}
7+
},
8+
"cold": {
9+
"enabled": true,
10+
"filecoin": {
11+
"replicationFactor": "1",
12+
"dealMinDuration": "518400",
13+
"excludedMiners": ["t01101"],
14+
"countryCodes": ["ca", "nl"],
15+
"renew": {
16+
"enabled": true,
17+
"threshold": "3"
18+
},
19+
"address": "f3ugglyobkqbsi7m7vgcnvpk7mswinrv5s6wm2abrmeq6m5zw2i2xwknjxg566konp4esxfnxjaefaa3uy3waa",
20+
"maxPrice": "5"
21+
}
22+
},
23+
"repairable": true
24+
25+
}

examples/config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pygate_grpc.client import PowerGateClient
2+
3+
import os
4+
import json
5+
from pathlib import Path
6+
7+
8+
client = PowerGateClient("127.0.0.1:5002", False)
9+
10+
print("Creating a new user:")
11+
user = client.admin.users.create()
12+
tk = user.token
13+
print("Token: " + tk)
14+
print("Using the new user token to request the default config:")
15+
default_config = client.config.default(tk)
16+
17+
wallets = client.wallet.addresses(token=tk)
18+
print("Addresses: {0}".format(default_config))
19+
20+
print("Loading new default config...")
21+
path = Path(os.path.abspath(__file__))
22+
with open(path.parent / "cidconfig_example.json", "r") as f:
23+
config = json.load(f)
24+
config["cold"]["filecoin"]["address"] = wallets[0].address
25+
26+
client.config.set_default(config, tk)
27+
28+
default_config = client.config.default(tk)
29+
print("Updated default config:")
30+
print(default_config)
31+
32+
test_bytes = b"These are some test bytes"
33+
staged_file = client.data.stage_bytes(test_bytes, user.token)
34+
print("StagedFile: ", staged_file)
35+
36+
stage = client.config.apply(staged_file.cid, token=user.token, config=config)

examples/deals.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import time
2+
3+
from pygate_grpc.client import PowerGateClient
4+
5+
if __name__ == "__main__":
6+
7+
hostName = "127.0.0.1:5002"
8+
9+
# Create client
10+
client = PowerGateClient(hostName)
11+
12+
# Create user
13+
user = client.admin.users.create()
14+
print("User created:")
15+
print(user)
16+
17+
print("Applying storage config...")
18+
stage_res = client.data.stage_bytes(
19+
b"These are the contents of a test file", token=user.token
20+
)
21+
apply_res = client.config.apply(stage_res.cid, token=user.token)
22+
23+
# Check that cid is in the process of being stored by Powegate
24+
check = client.data.cid_info([stage_res.cid], user.token)
25+
print("Checking cid storage...")
26+
print(check)
27+
28+
# Wait some time so that we can get some deals
29+
time.sleep(60)
30+
31+
# Check information about the storage deal
32+
storage_deals = client.deals.storage_deal_records(
33+
include_pending=True, include_final=True, token=user.token
34+
)
35+
print("Storage deals: ")
36+
for record in storage_deals:
37+
print(record)
38+
39+
# Check information about the retrieval deals
40+
retrieval_deals = client.deals.retrieval_deal_records(
41+
include_pending=True, include_final=True, token=user.token
42+
)
43+
print("Retrieval deals: ")
44+
for record in retrieval_deals:
45+
print(record)

examples/ffs_config.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/ffs_deals.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

examples/ffs_push_pull_file.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)