-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9591ef9
commit 7ba6212
Showing
18 changed files
with
467 additions
and
82 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Pull request checks | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
verify_build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
cache: 'npm' | ||
|
||
- name: 📥 Install dependencies | ||
run: npm ci | ||
|
||
- name: 🔨 Build projects | ||
run: npm run build | ||
|
||
- name: 🧪 Run unit tests | ||
run: npm run test | ||
|
||
- name: 📄 Setup Pages | ||
uses: actions/configure-pages@v3 | ||
|
||
- name: 📚 Create docs | ||
run: npm run docs | ||
|
||
- name: 🆙 Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: './docs' | ||
|
||
- name: 📄 Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 | ||
|
||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
dist | ||
tmp | ||
/out-tsc | ||
docs | ||
|
||
# dependencies | ||
node_modules | ||
|
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 |
---|---|---|
@@ -1,17 +1,105 @@ | ||
<p align="center"> | ||
<a href="https://seda.xyz/"> | ||
<img width="90%" alt="seda-overlay" src="https://www.seda.xyz/images/footer/footer-image.png"> | ||
<img width="90%" alt="seda-sdk" src="https://www.seda.xyz/images/footer/footer-image.png"> | ||
</a> | ||
</p> | ||
|
||
<h1 align="center"> | ||
SEDA SDK | ||
</h1> | ||
|
||
[![Build Status][actions-badge]][actions-url] | ||
[![GitHub Stars][github-stars-badge]](https://github.com/sedaprotocol/seda-sdk) | ||
[![GitHub Contributors][github-contributors-badge]](https://github.com/sedaprotocol/seda-sdk/graphs/contributors) | ||
[![Discord chat][discord-badge]][discord-url] | ||
[![Twitter][twitter-badge]][twitter-url] | ||
|
||
[actions-badge]: https://github.com/sedaprotocol/seda-sdk/actions/workflows/push.yml/badge.svg | ||
[actions-url]: https://github.com/sedaprotocol/seda-sdk/actions/workflows/push.yml+branch%3Amain | ||
[github-stars-badge]: https://img.shields.io/github/stars/sedaprotocol/seda-sdk.svg?style=flat-square&label=github%20stars | ||
[github-contributors-badge]: https://img.shields.io/github/contributors/sedaprotocol/seda-sdk.svg?style=flat-square | ||
[discord-badge]: https://img.shields.io/discord/500028886025895936.svg?logo=discord&style=flat-square | ||
[discord-url]: https://discord.gg/seda | ||
[twitter-badge]: https://img.shields.io/twitter/url/https/twitter.com/SedaProtocol.svg?style=social&label=Follow%20%40SedaProtocol | ||
[twitter-url]: https://twitter.com/SedaProtocol | ||
|
||
Collection of packages which allow you to build SEDA Data Requests: | ||
|
||
* `vm` - Virtual Machine which can run Data Request WASM binaries | ||
* `as-sdk` - [AssemblyScript](https://www.assemblyscript.org/) SDK | ||
* [vm](./libs/vm/README.md) - Virtual Machine which can run Data Request WASM binaries | ||
* [as-sdk](./libs/as-sdk/README.md) - [AssemblyScript](https://www.assemblyscript.org/) SDK | ||
* [cli](./libs/cli/README.md) - Command Line Interface for uploading and listing Data Request binaries | ||
|
||
# Quick getting started | ||
|
||
The easiest way to get started it by using our [starter kit](https://github.com/sedaprotocol/seda-sdk-starter-template) this has all the tools installed that you need: | ||
|
||
* AssemblyScript | ||
* SEDA SDK | ||
* SEDA CLI | ||
* SEDA VM | ||
* WASI | ||
|
||
In our `assembly/index.ts` we have the following example: | ||
|
||
```TypeScript | ||
import { Process, httpFetch } from "@seda-protocol/as-sdk/assembly"; | ||
import { JSON } from "json-as/assembly"; | ||
|
||
// Our SWAPI JSON schema, since in AssemblyScript we need to define our shape beforehand | ||
// @ts-expect-error | ||
@json | ||
class SwPlanet { | ||
name!: string | ||
} | ||
|
||
function main(): void { | ||
// HTTP Fetch to the SWAPI | ||
const response = httpFetch("https://swapi.dev/api/planets/1/"); | ||
|
||
// Returns either fulfilled or rejected based on the status code | ||
const fulfilled = response.fulfilled; | ||
|
||
if (fulfilled !== null) { | ||
// Converts our buffer to a string | ||
const data = String.UTF8.decode(fulfilled.bytes.buffer); | ||
|
||
// Parses the JSON to our schema | ||
const planet = JSON.parse<SwPlanet>(data); | ||
|
||
// Exits the program (with an exit code of 0) and sets the Data Request result to the planet name | ||
Process.exit_with_message(0, planet.name); | ||
} else { | ||
Process.exit_with_message(1, "Error while fetching"); | ||
} | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
And in order to test this we have to use a JS testing suite (In our starting kit we use Jest, but any suite should work). We use the `@seda-protocol/vm` package for this. Which runs the binary in the context of a SEDA Data Request: | ||
|
||
```JavaScript | ||
import { callVm } from "@seda-protocol/vm"; | ||
import { readFile } from "node:fs/promises"; | ||
|
||
const WASM_PATH = "build/debug.wasm"; | ||
|
||
describe("index.ts", () => { | ||
it("should be able to run", async () => { | ||
const wasmBinary = await readFile(WASM_PATH); | ||
|
||
// Calls our SEDA VM | ||
const vmResult = await callVm({ | ||
// Arguments passed to the VM | ||
args: [], | ||
// Environment variables passed to the VM | ||
envs: {}, | ||
// The WASM binary in bytes | ||
binary: new Uint8Array(wasmBinary), | ||
}); | ||
|
||
expect(vmResult.exitCode).toBe(0); | ||
expect(vmResult.resultAsString).toBe("Tatooine"); | ||
}); | ||
}); | ||
``` |
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.
2 changes: 1 addition & 1 deletion
2
libs/as-sdk/assembly/test-utils.ts → ...-integration-tests/assembly/test-utils.ts
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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../../../node_modules/assemblyscript/std/assembly.json", | ||
"include": ["./**/*.ts"] | ||
"include": ["./**/*.ts", "../../as-sdk/assembly/json-utils.ts"] | ||
} |
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 |
---|---|---|
@@ -1,3 +1,34 @@ | ||
# AssemblyScript SDK | ||
|
||
SDK for creating Data Requests on the SEDA chain | ||
|
||
For API documentation please see our docs: https://sedaprotocol.github.io/seda-sdk/ | ||
|
||
## Example | ||
|
||
```ts | ||
import { Process, httpFetch } from "@seda-protocol/as-sdk/assembly"; | ||
import { JSON } from "json-as/assembly"; | ||
|
||
// @ts-expect-error | ||
@json | ||
class SwPlanet { | ||
name!: string | ||
} | ||
|
||
function main(): void { | ||
const response = httpFetch("https://swapi.dev/api/planets/1/"); | ||
const fulfilled = response.fulfilled; | ||
|
||
if (fulfilled !== null) { | ||
const data = String.UTF8.decode(fulfilled.bytes.buffer); | ||
const planet = JSON.parse<SwPlanet>(data); | ||
|
||
Process.exit_with_message(0, planet.name); | ||
} else { | ||
Process.exit_with_message(1, "Error while fetching"); | ||
} | ||
} | ||
|
||
main(); | ||
``` |
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 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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import Process from './process'; | ||
import * as testutils from './test-utils'; | ||
|
||
export { JSON, JSONDecoder, JSONEncoder, DecoderState, JSONHandler, ThrowingJSONHandler } from 'assemblyscript-json/assembly'; | ||
export { httpFetch, HttpFetchMethod, HttpFetchOptions, HttpResponse } from './http'; | ||
export { PromiseStatus } from './promise'; | ||
export { Process, testutils }; | ||
export { jsonArrToUint8Array } from './json-utils'; | ||
export { Process }; |
Oops, something went wrong.