Code Monkey home page Code Monkey logo

wrap-cli's Introduction

polywrap-banner

Polywrap is a framework for developing software powered by Wraps. Wraps are software modules that are:

  • Portable - run in any environment
  • Composable - easily and safely call into one another

We believe that the future of software will be driven by a multitude of highly-specialized, platform-agnostic modules rather than monoliths.

Getting Started

To get started using the Polywrap CLI, follow the installation instructions.

If you haven't already, checkout Polywrap's developer documentation, where you'll find quick-starts & in-depth tutorials to help you accomplish your goals.

Contributing

If you're interested in contributing to this, or any Polywrap repository, checkout the contributing guide as well as join our Discord!

wrap-cli's People

Contributors

arcbjorn avatar benefacto avatar brioline avatar cbrzn avatar dependabot[bot] avatar dorgjelli avatar fetsorn avatar kev-ngo avatar kobby-pentangeli avatar krisbitney avatar morrigan avatar mpetrunic avatar n0cte avatar namesty avatar nerfzael avatar niraj-kamdar avatar philh avatar pileks avatar polywrap-build-bot avatar ramilexe avatar remscar avatar rishikumarray avatar sraver avatar vhurryharry avatar web3-api-build-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wrap-cli's Issues

Second Client Implementation

Implement a second client to accompany @web3api/client-js. This will prove that Web3APIs are in fact cross-platform.

Modularize the Web3API Class

[Retroactively created issue]

Most of the logic for Web3API is inside of a single class. The logic should be modularized out into discrete components which are leveraged as needed. This will reduce tech debt, code smell, and the time it takes for future iterations. Code will also be easier to test and maintain, making it easier to add on future features.

The proposed structure:

  • Client: This is the dev/user entry point into using Web3API's
  • URI Resolvers: This is what resolves a query URI into an actual Web3API
  • Web3API Definitions: This is a cache of data required to create an instance of a Web3API for usage.
  • Web3API: This is an actual Web3API, which can be queried by a user.

The end user will never interact with anything but the Client

2-Way Automated Test Harness For Every Client & Runtime

Create an automated test harness for Web3API implementations (clients & WASM runtimes). The idea is to be able to automatically:

  • Verify a client (host) supports all required Web3 WASM host interfaces (IPFS, ETH, etc).
  • Verify a new WASM runtime works with all clients.

Define user story for 3rd Party Web3API Extensions

Create a user story for how:

  • A developer would extend an existing Web3API with their own additions.
  • A protocol would define their Web3API allowing for a specific set of extensions.

Examples:

  • DAOstack supports Voting Machine & Scheme extensions
  • Aragon supports App extensions
  • Yearn supports Strategy extensions
  • Zerion supports RewardsProgram extensions

Optimized Manifest Schema

Option 1:

api:
  schema:
    file: ./src/schema.graphql
  mutation:
    language: wasm/assemblyscript
    file: ./src/mutation/index.ts
  query:
    language: wasm/assemblyscript
    file: ./src/query/index.ts

Option 2:

api:
  schemas:
    - file: ./src/mutation/schema.graphql
    - file: ./src/query/schema.graphql
  mutation:
    language: wasm/assemblyscript
    file: ./src/mutation/index.ts
  query:
    language: wasm/assemblyscript
    file: ./src/query/index.ts

Beyond GraphQL

In order to enable more features, I propose we move beyond GraphQL. We have flexibility here because we control the query resolution process.

Feature List:

Request Modules

a.k.a. custom root types

schema {
  cool: Cool
}

module Cool @read @write {
  beNice(
    a: String!
    b: Uint256
}

...

Compiler Modules

Create a module system for different Web3API compiler functionalities (WASM, Schema, Subgraph, etc).

Cross Module Dependencies

Modules can query other modules just like an application queries modules:

query({
  uri: "latest.ethereum.web3api.dev",
  query: `mutation { sendTransaction(
    address: "0x...",
    method: "foo(uint256,address)",
    args: [55, 0x...]
    ) { tx { hash } }
  }`
})

And in the client it can filter for these domains and choose to send them to local modules if it has some. This way we don't need to implement it in WASM, and can instead use a module in the client language to do these requests.

Web3API Manifest Validation

When building or loading a new project, we must validate that the manifest accurately describes all parts of the project.

Related: #17

Schema Sanitization

Ensure the following scenarios can be detected and properly reported:

  • Schema import namespace collisions
  • Type name collisions (post import + namespacing)
  • Unrecognized directives
  • Incorrect directive usage
  • Import directive must be on Schema or Mutation type
  • No underscores in user defined type names

Use Deno For All Tooling

Tooling that has access to the file-system and network should be written in TS and run using Deno to help improve security for the users of the tools.

CLI docgen

Create a CLI command for generate API docs.

Ability To Introspect Module RPC Serialization Type

When using a Web3API module, the client should be able to introspect what type of serialization format it expects. Hopefully this shouldn't have to be used, but it might be the case that in the future the preferred serialization format may change (msgpack currently), and the client will have to translate from the caller's format to the target's format. For example, msgpack => RLP

Initialize Web3API DAO

DAO Spec

  • Aragon DAO
  • Has the "Token Request" app, which allows an outside investor to send funds, and receive the DAO's token (voting rights) in return.
  • Has a non-transferable DAO token (can be made transferable in the future).
  • Voting Config: 7 day time period, minimum quorum 10%, pass threshold 60%
  • Governing the params (DAO governed JSON file?)

DAO Params

  • Investment Multiplier: 1.0 to start
  • Work Multiplier: 1.0 to start
  • Burn Rate: $5k / Month

Roll-out Plan

Test everything on Rinkeby

  1. Deployment
    DAO -> 100k credit to admin

  2. dOrg Seed Funding
    dOrg -> 15k$
    DAO -> 15k credit

  3. Worker Payouts (Spreadsheet W/ Claims)
    DAO -> $5k + 5k credits to worker A, B, C, D, etc

  4. Remove Admin
    DAO -> -100k credit from admin

Schema Imports

query/schema.graphql

type SimpleStorage @extension("subgraph") {
  id: ID!
  lastSetBy: Bytes
  setBy: [Bytes!]!
}

Verify that a resolver exists for a given query

I was writing a query like:

await api.query({
        query:
        gql`mutation callView($address: String!, $method: String!, $args: [String!]!) {
            callView(address: $address, method: $method, args: $args)
        }`,
        variables: {
            "address": storageAddress,
            "method": "function get() public view returns (uint256)",
            "args": []
        }
    });

and I was getting an empty object back.

The problem was that the callView method is not a mutation but a query in the schema. As a user I would've expected an error if I try to query/mutate on a method that isn't in the schema.

The code that fixed this issue was switching mutation to query:

await api.query({
        query:
        gql`query callView($address: String!, $method: String!, $args: [String!]!) {
            callView(address: $address, method: $method, args: $args)
        }`,
        variables: {
            "address": storageAddress,
            "method": "function get() public view returns (uint256)",
            "args": []
        }
    });

Document: Client Message Passing Protocols

Document all message passing protocols at play within the client. For example:

Action Path
_w3_query_api Host Call wasm[arguments]---wasm[msgpack]--->wasm_runner--->client...

Use Witx For Web3 WASM Interface Definitions

WASI has created a WASM interface definition markup language that allows you to describe portable interface definitions using WASM Interface Types. You can see WASI's Witx interfaces here: https://github.com/WebAssembly/WASI/tree/master/phases/snapshot/witx

and learn more about why Witx is necessary here: https://youtu.be/LCA9NnH7DxE

It's not currently clear to me if AssemblyScript supports WASM Interface Types, more available here: https://github.com/AssemblyScript/working-group/issues/13

I think the goal of "making the Web3API WASM interface runtime agnostic" can be achieved without the above... all TBD.

Manifest Formatting Options

Option 1:

api:
  schema:
    file: ./src/mutation/schema.graphql
  schemas:
    - file: ./src/mutation/schema.graphql
    - file: ./src/query/schema.graphql
  mutation:
    language: wasm/assemblyscript
    file: ./src/mutation/index.ts
  query:
    language: wasm/assemblyscript
    file: ./src/query/index.ts

Option 2:

apis:
  - namespace: "cool-storage"
    schemas:
      - file: ./src/mutation/schema.graphql
      - file: ./src/query/schema.graphql
    mutation:
      language: wasm/assemblyscript
      file: ./src/mutation/index.ts
    query:
      language: wasm/assemblyscript
      file: ./src/query/index.ts
  - namespace: "sub-storage"
    schemas:
      - file: ./src/mutation/schema.graphql
      - file: ./src/query/schema.graphql
    mutation:
      language: wasm/assemblyscript
      file: ./src/mutation/index.ts
    query:
      language: wasm/assemblyscript
      file: ./src/query/index.ts

Network Connection Permissions

For each network connection (Ethereum, IPFS, etc), allow the user to set permissions on each connection, and also override those network options on a per-API basis. For example, give Ethereum full permissions, but for "protocol Foo" give it only read permissions.

In order to enforce this, when instantiating a new Web3API module we'll need to check what permissions that module requires. If they can't be satisfied, we'll have to throw an exception. Being able to query modules for their required permissions is useful so that we can ask the user before-hand if they consent.

Some psuedo code:

const ipfs = new IPFS({
  access: IPFSAccess.ReadAndWrite | IPFSAccess.Pin,
  provider: "..."
})

const api = new Web3API({
  uri: "api.protocol.eth",
  connections: {
    ipfs
  },
  access: {
    ipfs: IPFSAccess.Read
  }
})

Define user story for Web3APIs dependencies

Create a user story for how developers would depend upon an external Web3API and use its functionality inside of a new Web3API. For example:

  • 1inch depends on Uniswap
  • Exchange depends on 0x
  • 1Hive depends on Aragon

Web3API Namespaces

NOTE: This is an optional feature. Specifying an API w/o a namespace should still work, and the root path should be assumed.

Manifest Change:

apis:
  - namespace: "foo"
    schema:
      - file: ./src/foo/schema.graphql
    mutation:
      language: wasm/assemblyscript
      file: ./src/foo/mutation/index.ts
    query:
      language: wasm/assemblyscript
      file: ./src/foo/query/index.ts
  - namespace: "bar"
    schemas:
      - file: ./src/bar/mutation/schema.graphql
      - file: ./src/bar/query/schema.graphql
    mutation:
      language: wasm/assemblyscript
      file: ./src/bar/mutation/index.ts
    query:
      language: wasm/assemblyscript
      file: ./src/bar/query/index.ts

Client Change:

client.query({
  uri: "example.eth/foo"
  query: gql`
    mutation {
      setData(
        address: "0x123..."
        value: 5
      )
    }`
})

Module Dependencies + Module Capabilities

Develop a better story around:

  • Determining the host interfaces the module depends on (web3_eth..., web3_ipfs..., etc).
  • Giving the module runner privileges as to what interfaces can be used. For example, if you're running a query, all web3_eth... signing capabilities should be shut off.

Refine Multi-Networks (ex: Rinkeby, Mainnet, etc)

Questions:

  • Should a single query or mutation be able to access multiple networks simultaneously?
  • How would switching between them work? A call from within WASM to switch the host-env's context?

Technical Specification Document

Create a clear tech spec for:

  1. Web3API Packages (Manifest, Schemas, Modules)
  2. Web3API Clients (Initialization, Querying)

And the WASM + GraphQL interface standards that bind the two.

Modularize JSON Schema types

Right now in the JSON Schema, we are sharing types between some fields (i.e: Query and Mutation) that are being repeated, this needs to be fixed

Allow for the usage of JavaScript based Web3API's

In some cases it may be easier for developers to create a Web3API that is actually in JavaScript instead of WASM. As far as the user is concerned, it is interacted with the same way that any other Web3API is, however in the backend, JavaScript code is actually ran instead.

Since runtime code execution is not allowed, the JavaScript Web3API's must be defined on build, and not during the runtime. This means that the end-user will have to configure which JavaScript Web3API's are allowed to be used. This can be done by linking a specific URI to a JavaScript Web3API.

Lazy & Upfront Loading

Support lazy loading & upfront loading, allowing apps to choose when an API's assets are fetched and loaded.

Custom Schema Base Types + Validators

Useful for things like JSON, EthAddress, QmHash, URL, and others.

New base types could be introduced in a Web3API's schema, and its validator could be defined in WASM. The serializer for args would utilize the validator.

CLI Automated Tests

  • Build Command
  • CodeGen Command
  • Create Command
  • Query Command
  • Test-Env Command
  • No Command Given
  • Help Option (all commands)

Node Request Middlewares

When developing the node / network interface for wasm modules, create a way for middlewares to be inserted as well. This will allow projects like Pocket Network to develop said middlewares and send requests to supported networks (Ethereum, Cosmos, Polkadot, etc) to a Pocket network node.

Define GraphQL Schema Inheritance

Make it clear how schemas inherit one another. Maybe leave it up to the user to add an include statement to do so, and all 3 schemas are isolated from one-another? Or is it best to go the monolith route...? Optimize for simplicity and flexibility, ensuring there aren't strange error cases that can come up from partial updates (etc).

Web3API Logging Interface

Create a host interface for logging, allowing client modules to:

  • log info, warnings, errors
  • start / end of a long running processes
  • total & current step for sequential step processes (1 ..., 2 ..., 3 ..., etc)

REST Support

Support REST queries in addition to GraphQL. Some examples...

Schema:

type Query {
  getSomething(arg: String!): String!
}

type Mutation {
  setSomething(arg: String!): String!
}

type Entity @entity {
  id: ID!
  value: String!
}

w3://protocol.eth/query/getSomething?arg=foo
w3://protocol.eth/mutation/setSomething?arg=foo
w3://protocol.eth/entity/0xID

Make WASM Interface Assemblyscript Agnostic

Follow what's done for WASI, for example, passing all strings as pointers + length. To validate the interfaces is agnostic, try creating a Web3API WASM module in Rust or another language.

Heap Manager: Two Way Marshaling Of WASM Types

Create a heap manager to handle the two way marshaling of types. The following cases must be supported for all WASM High Level Types (HLTs):

  • WASM <-> Host
  • Host <-> WASM
  • Host <-> WASM <-> Host

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.