-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
429967f
commit db0e39a
Showing
82 changed files
with
1,410 additions
and
14,611 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 |
---|---|---|
|
@@ -137,4 +137,6 @@ dmypy.json | |
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
cython_debug/ | ||
|
||
.vscode |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
import os | ||
from pathlib import Path | ||
from pygate_grpc.client import PowerGateClient | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
hostName = "127.0.0.1:5002" | ||
|
||
# Create client | ||
c = PowerGateClient(hostName, False) | ||
|
||
# Create user | ||
user = c.admin.users.create() | ||
print("User created:") | ||
print(user) | ||
|
||
# Stage file | ||
print("Staging testfile.txt to IPFS storage") | ||
path = Path(os.path.abspath(__file__)) | ||
staged_file = c.data.stage_file(path.parent / "testfile.txt", user.token) | ||
print("Applying storage config...") | ||
|
||
# Apply the default storage config to the given file | ||
c.config.apply(staged_file.cid, override=False, token=user.token) | ||
|
||
# Override push with another config | ||
addresses = c.wallet.addresses(user.token) | ||
wallet = addresses[0].address | ||
new_config = { | ||
"hot": {"enabled": True, "allowUnfreeze": True, "ipfs": {"addTimeout": 30}}, | ||
"cold": { | ||
"enabled": True, | ||
"filecoin": { | ||
"replicationFactor": 1, | ||
"dealMinDuration": 518400, | ||
"excludedMiners": ["t01101"], | ||
"trustedMiners": ["t01000", "t02000"], | ||
"countryCodes": ["ca", "nl"], | ||
"renew": {"enabled": True, "threshold": 3}, | ||
"address": wallet, | ||
"maxPrice": 50, | ||
}, | ||
}, | ||
"repairable": True, | ||
} | ||
|
||
c.config.apply(staged_file.cid, override=True, config=new_config, token=user.token) | ||
|
||
# Check that CID is stored | ||
check = c.data.cid_info([staged_file.cid], user.token) | ||
print("Checking CID storage...") | ||
print(check) | ||
|
||
# Get the data back | ||
print("Retrieving file " + staged_file.cid) | ||
file_bytes = c.data.get(staged_file.cid, user.token) | ||
|
||
# Write to a file on disk | ||
print("Saving as 'testfile_copy.txt'") | ||
with open(path.parent / "testfile_copy.txt", "wb") as f: | ||
f.write(file_bytes) |
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,25 @@ | ||
{ | ||
"hot": { | ||
"enabled": true, | ||
"ipfs": { | ||
"addTimeout": "30" | ||
} | ||
}, | ||
"cold": { | ||
"enabled": true, | ||
"filecoin": { | ||
"replicationFactor": "1", | ||
"dealMinDuration": "518400", | ||
"excludedMiners": ["t01101"], | ||
"countryCodes": ["ca", "nl"], | ||
"renew": { | ||
"enabled": true, | ||
"threshold": "3" | ||
}, | ||
"address": "f3ugglyobkqbsi7m7vgcnvpk7mswinrv5s6wm2abrmeq6m5zw2i2xwknjxg566konp4esxfnxjaefaa3uy3waa", | ||
"maxPrice": "5" | ||
} | ||
}, | ||
"repairable": true | ||
|
||
} |
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,36 @@ | ||
from pygate_grpc.client import PowerGateClient | ||
|
||
import os | ||
import json | ||
from pathlib import Path | ||
|
||
|
||
client = PowerGateClient("127.0.0.1:5002", False) | ||
|
||
print("Creating a new user:") | ||
user = client.admin.users.create() | ||
tk = user.token | ||
print("Token: " + tk) | ||
print("Using the new user token to request the default config:") | ||
default_config = client.config.default(tk) | ||
|
||
wallets = client.wallet.addresses(token=tk) | ||
print("Addresses: {0}".format(default_config)) | ||
|
||
print("Loading new default config...") | ||
path = Path(os.path.abspath(__file__)) | ||
with open(path.parent / "cidconfig_example.json", "r") as f: | ||
config = json.load(f) | ||
config["cold"]["filecoin"]["address"] = wallets[0].address | ||
|
||
client.config.set_default(config, tk) | ||
|
||
default_config = client.config.default(tk) | ||
print("Updated default config:") | ||
print(default_config) | ||
|
||
test_bytes = b"These are some test bytes" | ||
staged_file = client.data.stage_bytes(test_bytes, user.token) | ||
print("StagedFile: ", staged_file) | ||
|
||
stage = client.config.apply(staged_file.cid, token=user.token, config=config) |
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,45 @@ | ||
import time | ||
|
||
from pygate_grpc.client import PowerGateClient | ||
|
||
if __name__ == "__main__": | ||
|
||
hostName = "127.0.0.1:5002" | ||
|
||
# Create client | ||
client = PowerGateClient(hostName) | ||
|
||
# Create user | ||
user = client.admin.users.create() | ||
print("User created:") | ||
print(user) | ||
|
||
print("Applying storage config...") | ||
stage_res = client.data.stage_bytes( | ||
b"These are the contents of a test file", token=user.token | ||
) | ||
apply_res = client.config.apply(stage_res.cid, token=user.token) | ||
|
||
# Check that cid is in the process of being stored by Powegate | ||
check = client.data.cid_info([stage_res.cid], user.token) | ||
print("Checking cid storage...") | ||
print(check) | ||
|
||
# Wait some time so that we can get some deals | ||
time.sleep(60) | ||
|
||
# Check information about the storage deal | ||
storage_deals = client.deals.storage_deal_records( | ||
include_pending=True, include_final=True, token=user.token | ||
) | ||
print("Storage deals: ") | ||
for record in storage_deals: | ||
print(record) | ||
|
||
# Check information about the retrieval deals | ||
retrieval_deals = client.deals.retrieval_deal_records( | ||
include_pending=True, include_final=True, token=user.token | ||
) | ||
print("Retrieval deals: ") | ||
for record in retrieval_deals: | ||
print(record) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.