Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ For more examples, please see the [SDK documentation.](https://docs.filswan.com/

This SDK has the following functionalities:

### For Onchain Storage

---

- **POST** Upload file to Filswan IPFS gateway
- **GET** List of files uploaded
- **GET** Files by cid
- **GET** Status from filecoin
- **CONTRACT** Make payment to swan filecoin storage gateway
- **CONTRACT** Mint asset as NFT

### For Buckets Storage

---
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web3==5.31.1
web3==6.15.1
requests==2.28.1
requests_toolbelt==0.10.1
tqdm==4.64.1
14 changes: 14 additions & 0 deletions sample/single_organization_design/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source code for [Single Organization Design](https://docs.filswan.com/multichain.storage/best-practice/use-mcs-as-platform-storage-solution/single-organization-design)

### To Install
```
pip install python-mcs-sdk
```
### Setup Credentials

api_key/access_token can be found in https://www.multichain.storage/#/api_key, make sure save your APIKey and Access Token after you have generated it, you will not find it again after you created it

### Run the script
```
python main.py
```
1 change: 1 addition & 0 deletions sample/single_organization_design/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Folder for data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions sample/single_organization_design/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

from mcs import APIClient, BucketAPI


def upload_replace_file(file_path, bucket_name, dest_file_path):
"""
Upload a file by file path, bucket name and the target path
:param file_path: the source file path
:param bucket_name: the bucket name user want to upload
:param dest_file_path: the destination of the file you want to store exclude the bucket name
:return: File Object
"""
mcs_api = APIClient(api_key, access_token,network)
bucket_client = BucketAPI(mcs_api)
# check if file exist
file_data = bucket_client.get_file(bucket_name, dest_file_path)
if file_data:
print("File exist,replace file: %s" % file_path)
bucket_client.delete_file(bucket_name, dest_file_path)
file_data = bucket_client.upload_file(bucket_name, dest_file_path, file_path)
return file_data


if __name__ == '__main__':
api_key = "XXXX"
access_token = "xxxxxxx"
network = "polygon.mainnet"
file_path = 'data/apple.jpeg'
# file_path is the path relative to the current file
# object_name is your target path
mcs_file = upload_replace_file(file_path, "swan",
os.path.join("0x165CD37b4C644C2921454429E7F9358d18A45e14", "apple.jpeg"))
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
version="0.3.2",
author="daniel8088",
author_email="danilew8088@gmail.com",
install_requires=["web3==5.31.1", "requests==2.28.1", "requests_toolbelt==0.10.1", "tqdm==4.64.1"],
install_requires=["web3==6.15.1", "requests==2.28.1", "requests_toolbelt==0.10.1", "tqdm==4.64.1","eth_typing==4.1.0"],
packages=["swan_mcs", "swan_mcs.api", "swan_mcs.contract", "swan_mcs.contract.abi", "swan_mcs.common", "swan_mcs.object"],
license="MIT",
include_package_data=True,
description="A python software development kit for the Multi-Chain Storage",
long_description=long_description,
long_description_content_type='text/markdown',
)
)
5 changes: 3 additions & 2 deletions swan_mcs/api/bucket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ def download_file(self, bucket_name, object_name, local_filename):
ipfs_url = file.ipfs_url
with open(local_filename, 'wb') as f:
if file.size > 0:
logging.error('\033[31mThe file ipfs url: '+ipfs_url+'\033[0m')
logging.error('\033[31mThe file gateway: '+file.gateway+'\033[0m')
data = urllib.request.urlopen(ipfs_url)
if data:
f.write(data.read())
logging.info(
"\033[32mFile downloaded successfully\033[0m")
logging.info("\033[32mFile downloaded successfully\033[0m")
return True
else:
logging.error('\033[31mDownload failed\033[0m')
Expand Down
2 changes: 1 addition & 1 deletion swan_mcs/api_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from swan_mcs.common.constants import *
from swan_mcs.common.params import Params
import requests
import requests
import json
import logging
from swan_mcs.common import utils, exceptions
Expand Down
2 changes: 1 addition & 1 deletion swan_mcs/object/bucket_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, file_data, gateway = 'https://ipfs.io'):
self.prefix = file_data["prefix"]
self.size = file_data["size"]
self.payloadCid = file_data["payload_cid"]
self.ipfs_url = gateway + '/ipfs/' + file_data["payload_cid"]
self.ipfs_url = gateway + '/ipfs/' + file_data["payload_cid"] # think there is an issue here
self.pin_status = file_data["pin_status"]
self.is_deleted = file_data["is_deleted"]
self.is_folder = file_data["is_folder"]
Expand Down
4 changes: 3 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def shared_mock_api_client():
"data": {"jwt_token": "sample_token"}})
api_client = APIClient(api_key="sample_api_key", access_token="sample_access_token",
chain_name="polygon.mumbai", is_calibration=True)
api_client.token=api_client.token['jwt_token']
return api_client


Expand Down Expand Up @@ -221,6 +222,7 @@ def temp_dir():
shutil.rmtree(dirpath)



@pytest.fixture(scope="module", autouse=True)
def delete_all_buckets():
bucket_api = BucketAPI(APIClient(api_key, access_token, chain_name))
Expand All @@ -231,4 +233,4 @@ def delete_all_buckets():


def pytest_sessionfinish(session, exitstatus):
delete_all_buckets()
delete_all_buckets()
2 changes: 1 addition & 1 deletion test/test_mock_api_key_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_api_key_login_success(self, mock_requests):
"data": {"jwt_token": "sample_token"}})
api_client = APIClient(api_key="sample_api_key", access_token="sample_access_token",
chain_name="polygon.mumbai", is_calibration=True)
token = api_client.token
token = api_client.token['jwt_token']
assert compare_digest(token, "sample_token")

@pytest.mark.parametrize("api_key, access_token, chain_name", [
Expand Down