Skip to content

Commit

Permalink
add basic manasharing contract
Browse files Browse the repository at this point in the history
  • Loading branch information
roaminro committed Oct 2, 2023
1 parent 123baea commit 74ea745
Show file tree
Hide file tree
Showing 53 changed files with 18,025 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18
FROM --platform=linux/amd64 node:18

# Install basic development tools
RUN apt update && apt install -y less man-db sudo
Expand All @@ -12,7 +12,7 @@ RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
ENV DEVCONTAINER=true

# install AS SDK
RUN yarn global add @roamin/sdk-as-cli
RUN yarn global add @roamin/sdk-as-cli@1.1.1

# install AS SDK
RUN yarn global add @roamin/local-koinos
# install Local Koinos
RUN yarn global add @roamin/local-koinos@0.4.9
6 changes: 1 addition & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
"remoteUser": "node",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"docker-from-docker": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v2"
}
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
}
}
3 changes: 3 additions & 0 deletions manasharing/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/assembly/proto/**
**/assembly/*.boilerplate.ts
**/assembly/index.ts
194 changes: 194 additions & 0 deletions manasharing/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {}
},

// === General rules =========================================================

rules: {
// Omitted semicolons are hugely popular, yet within the compiler it makes
// sense to be better safe than sorry.
"semi": "error",

// Our code bases uses 2 spaces for indentation, and we enforce it here so
// files don't mix spaces, tabs or different indentation levels.
"indent": ["error", 2, {
"SwitchCase": 1,
"VariableDeclarator": "first",
"offsetTernaryExpressions": true,
"ignoredNodes": [ // FIXME: something's odd here
"ConditionalExpression > *",
"ConditionalExpression > * > *",
"ConditionalExpression > * > * > *"
]
}],

// This is mostly visual style, making comments look uniform.
"spaced-comment": ["error", "always", {
"markers": ["/"], // triple-slash
"exceptions": ["/"] // all slashes
}],

// This tends to be annoying as it encourages developers to make everything
// that is never reassigned a 'const', sometimes semantically incorrect so,
// typically leading to huge diffs in follow-up PRs modifying affected code.
"prefer-const": "off",

// It is perfectly fine to declare top-level variables with `var`, yet this
// rule doesn't provide configuration options that would help.
"no-var": "off",

// Quite often, dealing with multiple related cases at once or otherwise
// falling through is exactly the point of using a switch.
"no-fallthrough": "off",

// Typical false-positives here are `do { ... } while (true)` statements or
// similar, but the only option provided here is not checking any loops.
"no-constant-condition": ["error", { checkLoops: false }],

// Functions are nested in blocks occasionally, and there haven't been any
// problems with this so far, so turning the check off.
"no-inner-declarations": "off",

// Quite common in scenarios where an iteration starts at `current = this`.
"@typescript-eslint/no-this-alias": "off",

// Disabled here, but enabled again for JavaScript files.
"no-unused-vars": "off",

// Disabled here, but enabled again for TypeScript files.
"@typescript-eslint/no-unused-vars": "off"
},
overrides: [

// === TypeScript rules ====================================================

{
files: [
"**/assembly/**/*.ts"
],
rules: {
// Enforcing to remove function parameters on stubs makes code less
// maintainable, so we instead allow unused function parameters.
"@typescript-eslint/no-unused-vars": [
"warn", {
"vars": "local",
"varsIgnorePattern": "^_|^[A-Z](?:From|To)?$", // ignore type params
"args": "none",
"ignoreRestSiblings": false
}
],

// Namespaces are quite useful in AssemblyScript
"@typescript-eslint/no-namespace": "off",

// There is actually codegen difference here
"@typescript-eslint/no-array-constructor": "off",

// Sometimes it can't be avoided to add a @ts-ignore
"@typescript-eslint/ban-ts-comment": "off",

// Utilized to achieve portability in some cases
"@typescript-eslint/no-non-null-assertion": "off",
}
},

// === Compiler rules (extends AssemblyScript rules) =======================

{
files: [
"**/assembly/**/*.ts"
],
rules: {
// There is an actual codegen difference here - TODO: revisit
"no-cond-assign": "off",

// Not all types can be omitted in AS yet - TODO: revisit
"@typescript-eslint/no-inferrable-types": "off",

// Used rarely to reference internals that are not user-visible
"@typescript-eslint/triple-slash-reference": "off",

// The compiler has its own `Function` class for example
"no-shadow-restricted-names": "off",
"@typescript-eslint/ban-types": "off"
}
},

// === Standard Library rules (extends AssemblyScript rules) ===============

{
files: [
"**/assembly/**/*.ts"
],
rules: {
// We are implementing with --noLib, so we shadow all the time
"no-shadow-restricted-names": "off",

// Similarly, sometimes we need the return type to be String, not string
"@typescript-eslint/ban-types": "off"
}
},

// === Standard Definition rules (extends TypeScript rules) ================

{
files: [
"**/assembly/**/*.d.ts"
],
rules: {
// Often required to achieve compatibility with TypeScript
"@typescript-eslint/no-explicit-any": "off",

// Interfaces can be stubs here, i.e. not yet fully implemented
"@typescript-eslint/no-empty-interface": "off",

// Definitions make use of `object` to model rather unusual constraints
"@typescript-eslint/ban-types": "off"
}
},



// === Test rules (extends TypeScript rules) ===============================

{
files: [
"**/assembly/__tests__/**/*.ts"
],
rules: {
// Tests typically include unusual code patterns on purpose. This is
// very likely not an extensive list, but covers what's there so far.
"no-empty": "off",
"no-cond-assign": "off",
"no-compare-neg-zero": "off",
"no-inner-declarations": "off",
"no-constant-condition": "off",
"use-isnan": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-extra-non-null-assertion": "off",
"@typescript-eslint/no-empty-interface": "off"
}
},
]
};
21 changes: 21 additions & 0 deletions manasharing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Manasharing

## Build
```sh
# build the debug version
yarn build:debug
# or
yarn exec koinos-sdk-as-cli build-all debug 0 manasharing.proto

# build the release version
yarn build:release
# or
yarn exec koinos-sdk-as-cli build-all release 0 manasharing.proto
```

## Test
```sh
yarn test
# or
yarn exec koinos-sdk-as-cli run-tests
```
1 change: 1 addition & 0 deletions manasharing/abi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.gitignore
4 changes: 4 additions & 0 deletions manasharing/abi/manasharing-abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"methods": {},
"types": ""
}
4 changes: 4 additions & 0 deletions manasharing/abi/manasharing.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"methods": {},
"types": ""
}
24 changes: 24 additions & 0 deletions manasharing/as-pect.asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"targets": {
"coverage": {
"lib": ["./node_modules/@as-covers/assembly/index.ts"],
"transform": ["@as-covers/transform", "@as-pect/transform"]
},
"noCoverage": {
"transform": ["@as-pect/transform"]
}
},
"options": {
"exportMemory": true,
"outFile": "output.wasm",
"textFile": "output.wat",
"bindings": "raw",
"exportStart": "_start",
"exportRuntime": true,
"use": ["RTRACE=1"],
"debug": true,
"exportTable": true
},
"extends": "./asconfig.json",
"entries": ["./node_modules/@as-pect/assembly/assembly/index.ts"]
}
61 changes: 61 additions & 0 deletions manasharing/as-pect.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { MockVM } from '@koinos/mock-vm';

export default {
/**
* A set of globs passed to the glob package that qualify typescript files for testing.
*/
include: [
"assembly/__tests__/**/*.include.ts",
],
/**
* A set of regexp that will disclude source files from testing.
*/
disclude: [/node_modules/i],
entries: ["assembly/__tests__/**/*.spec.ts"],

/**
* Add your required AssemblyScript imports here.
*/
async instantiate(memory, createImports, instantiate, binary) {
let instance; // Imports can reference this
const mockVM = new MockVM();

const myImports = {
wasi_snapshot_preview1: {
fd_write: () => {},
proc_exit: () => {}
},
// put your web assembly imports here, and return the module
env: {
...mockVM.getImports()
}
};
instance = instantiate(binary, createImports(myImports));

instance.then(function (result) {
result.exports.memory.grow(512);
mockVM.setInstance(result);
});

return instance;
},
// wasi: {
// // pass args here
// args: [],
// // inherit from env
// env: process.env,
// preopens: {
// // put your preopen's here
// },
// // let as-pect finish what it needs to finish
// returnOnExit: false,
// },
/** Enable code coverage. */
coverage: [
'assembly/*.ts'
],
/**
* Specify if the binary wasm file should be written to the file system.
*/
outputBinary: false,
};
22 changes: 22 additions & 0 deletions manasharing/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"targets": {
"debug": {
"outFile": "build/debug/contract.wasm",
"textFile": "build/debug/contract.wat",
"sourceMap": true,
"debug": true
},
"release": {
"outFile": "build/release/contract.wasm",
"textFile": "build/release/contract.wat",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0,
"converge": false,
"noAssert": false
}
},
"options": {
"bindings": "esm"
}
}
16 changes: 16 additions & 0 deletions manasharing/assembly/Manasharing.boilerplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { System, Protobuf, authority } from "@koinos/sdk-as";
import { manasharing } from "./proto/manasharing";

export class Manasharing {
authorize(args: authority.authorize_arguments): authority.authorize_result {
// const call = args.call;
// const type = args.type;

// YOUR CODE HERE

const res = new authority.authorize_result();
res.value = true;

return res;
}
}
Loading

0 comments on commit 74ea745

Please sign in to comment.