Coder Social home page Coder Social logo

phatstorage's Introduction

Phat Contract - S3 Phat Storage

Phat Contract is a Rust-based contract that allows you to interact with an S3 bucket using HTTP requests. This contract provides methods to perform GET, PUT, DELETE, and HEAD operations on an S3 bucket.

Please note that the endpoint URL must not include https://. For example, use endpoint.4everland.co instead of https://endpoint.4everland.co for the endpoint parameter.

Features

  • Set admin for the contract
  • Seal S3 bucket access and secret keys
  • Perform PUT, HEAD, GET, and DELETE operations on an S3 bucket
  • Test the contract with a predefined S3 bucket and object

Prerequisites

  • rustc 1.69.0
  • cargo-contract 3.0.1 or greater

Installation

Clone the repository and navigate to the directory:

git clone [email protected]:HashWarlock/PhatStorage.git
cd PhatStorage

Build the contract:

cargo contract build

Usage

Best way to interact with the contract is to load in https://phat.phala.network. You will:

  • Upload the compiled phat_storage.contract file to the Phala blockchain
  • Instantiate your Phat Contract
  • Activate your Phat Contract by adding staked PHA

Your dashboard will then look like as follows:

Set Admin

Set a new admin for the contract with the set_admin function. Only the current admin can perform this operation.

Seal Keys

Seal the S3 Bucket access and secret keys with the seal_keys function. Only the admin can perform this operation.

S3 Operations

Perform PUT, HEAD, GET, and DELETE operations on an S3 bucket with the s3_put, s3_head, s3_get, and s3_delete functions respectively. Only the admin can perform these operations and the keys must be configured.

Let's go through a user journey.

S3 PUT

S3 PUT Result

S3 GET

S3 GET Result

Check 4Everland UI Dashboard

S3 DELETE

S3 DELETE Result

Check 4Everland UI Dashboard

Test the Contract

Test the contract with a predefined S3 bucket and object with the it_works function. In the Phat UI, you can click the

Note: you will need to update the function to hardcode values to function correctly. If you have installed swanky phala and are running on a machine with x86 chip, you can execute the following:

swanky phala contract test -t phat_storage_bkup

Errors

The contract can return the following errors:

  • NoPermissions: The caller is not the admin
  • InvalidRequest: The S3 operation failed
  • KeysNotConfigured: The access and secret keys are not configured

phatstorage's People

Contributors

hashwarlock avatar

Stargazers

Leechael avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.