mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-27 18:42:07 +00:00
Host API stubs (#12)
This commit is contained in:
parent
1421ba5a9b
commit
889e96572d
@ -2,9 +2,10 @@
|
|||||||
"name": "watcher-ts",
|
"name": "watcher-ts",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": [
|
"workspaces": {
|
||||||
"packages/*"
|
"packages": ["packages/*"],
|
||||||
],
|
"nohoist": ["**/@graphprotocol/graph-ts"]
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"depcheck": "^1.4.2",
|
"depcheck": "^1.4.2",
|
||||||
"husky": "^7.0.2",
|
"husky": "^7.0.2",
|
||||||
|
@ -1,5 +1,39 @@
|
|||||||
// The entry file of your WebAssembly module.
|
import {
|
||||||
|
// ethereum,
|
||||||
|
// store,
|
||||||
|
log
|
||||||
|
// ipfs,
|
||||||
|
// json,
|
||||||
|
// crypto,
|
||||||
|
|
||||||
export function add (a: i32, b: i32): i32 {
|
// dataSource,
|
||||||
return a + b;
|
// ens,
|
||||||
|
|
||||||
|
// typeConversion,
|
||||||
|
|
||||||
|
// bigDecimal,
|
||||||
|
// bigInt,
|
||||||
|
|
||||||
|
// Address,
|
||||||
|
// BigDecimal,
|
||||||
|
// BigInt,
|
||||||
|
// ByteArray,
|
||||||
|
// Bytes,
|
||||||
|
// DataSourceContext,
|
||||||
|
// DataSourceTemplate,
|
||||||
|
// Entity,
|
||||||
|
// JSONValue,
|
||||||
|
// JSONValueKind,
|
||||||
|
// JSONValuePayload,
|
||||||
|
// Result,
|
||||||
|
// TypedMap,
|
||||||
|
// TypedMapEntry,
|
||||||
|
// Value,
|
||||||
|
// ValueKind,
|
||||||
|
// ValuePayload,
|
||||||
|
// Wrapped
|
||||||
|
} from '@graphprotocol/graph-ts';
|
||||||
|
|
||||||
|
export function callGraphAPI (): void {
|
||||||
|
log.debug('hello {}', ['world']);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@graphprotocol/graph-ts": "^0.22.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||||
"@typescript-eslint/parser": "^4.25.0",
|
"@typescript-eslint/parser": "^4.25.0",
|
||||||
"assemblyscript": "^0.19.16",
|
"assemblyscript": "^0.19.16",
|
||||||
@ -14,17 +15,17 @@
|
|||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"eslint-plugin-promise": "^5.1.0",
|
"eslint-plugin-promise": "^5.1.0",
|
||||||
"eslint-plugin-standard": "^5.0.0",
|
"eslint-plugin-standard": "^5.0.0",
|
||||||
"typescript": "^4.3.2",
|
|
||||||
"nodemon": "^2.0.7",
|
"nodemon": "^2.0.7",
|
||||||
"ts-node": "^10.0.0"
|
"ts-node": "^10.0.0",
|
||||||
|
"typescript": "^4.3.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"asbuild:debug": "asc assembly/index.ts --target debug",
|
"asbuild:debug": "asc assembly/index.ts --lib ./node_modules --target debug",
|
||||||
"asbuild:release": "asc assembly/index.ts --target release",
|
"asbuild:release": "asc assembly/index.ts --lib ./node_modules --target release",
|
||||||
"asbuild": "yarn asbuild:debug && yarn asbuild:release",
|
"asbuild": "yarn asbuild:debug && yarn asbuild:release",
|
||||||
"test": "mocha src/**/*.test.ts"
|
"test": "yarn asbuild:debug && mocha src/**/*.test.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@assemblyscript/loader": "^0.19.16"
|
"@assemblyscript/loader": "^0.19.16"
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
// Copyright 2021 Vulcanize, Inc.
|
// Copyright 2021 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
import { expect } from 'chai';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import 'mocha';
|
|
||||||
|
|
||||||
import { getExports } from './index';
|
import { instantiate } from './index';
|
||||||
|
|
||||||
const WASM_FILE_PATH = '../build/debug.wasm';
|
const WASM_FILE_PATH = '../build/debug.wasm';
|
||||||
|
|
||||||
it('should execute exported function', async () => {
|
it('should execute exported function', async () => {
|
||||||
const filePath = path.resolve(__dirname, WASM_FILE_PATH);
|
const filePath = path.resolve(__dirname, WASM_FILE_PATH);
|
||||||
const { exports } = await getExports(filePath);
|
const { exports } = await instantiate(filePath);
|
||||||
expect(exports.add(1, 2)).to.equal(3);
|
exports.callGraphAPI();
|
||||||
});
|
});
|
||||||
|
@ -5,9 +5,76 @@
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import loader from '@assemblyscript/loader';
|
import loader from '@assemblyscript/loader';
|
||||||
|
|
||||||
const imports = { /* imports go here */ };
|
const imports = {
|
||||||
|
index: {
|
||||||
|
'store.get': () => {
|
||||||
|
console.log('store.get');
|
||||||
|
},
|
||||||
|
'store.set': () => {
|
||||||
|
console.log('store.set');
|
||||||
|
},
|
||||||
|
|
||||||
export const getExports = async (filePath: string): Promise<loader.ResultObject & { exports: any }> => {
|
'typeConversion.stringToH160': () => {
|
||||||
|
console.log('typeConversion.stringToH160');
|
||||||
|
},
|
||||||
|
'typeConversion.bytesToHex': () => {
|
||||||
|
console.log('typeConversion.bytesToHex');
|
||||||
|
},
|
||||||
|
'typeConversion.bytesToString': () => {
|
||||||
|
console.log('typeConversion.bytesToString');
|
||||||
|
},
|
||||||
|
'typeConversion.bigIntToString': () => {
|
||||||
|
console.log('typeConversion.bigIntToString');
|
||||||
|
},
|
||||||
|
|
||||||
|
'bigDecimal.fromString': () => {
|
||||||
|
console.log('bigDecimal.fromString');
|
||||||
|
},
|
||||||
|
'bigDecimal.times': () => {
|
||||||
|
console.log('bigDecimal.times');
|
||||||
|
},
|
||||||
|
'bigDecimal.dividedBy': () => {
|
||||||
|
console.log('bigDecimal.dividedBy');
|
||||||
|
},
|
||||||
|
'bigDecimal.plus': () => {
|
||||||
|
console.log('bigDecimal.plus');
|
||||||
|
},
|
||||||
|
'bigDecimal.minus': () => {
|
||||||
|
console.log('bigDecimal.minus');
|
||||||
|
},
|
||||||
|
|
||||||
|
'bigInt.plus': () => {
|
||||||
|
console.log('bigInt.plus');
|
||||||
|
},
|
||||||
|
'bigInt.minus': () => {
|
||||||
|
console.log('bigInt.minus');
|
||||||
|
},
|
||||||
|
'bigInt.times': () => {
|
||||||
|
console.log('bigInt.times');
|
||||||
|
},
|
||||||
|
'bigInt.dividedBy': () => {
|
||||||
|
console.log('bigInt.dividedBy');
|
||||||
|
},
|
||||||
|
'bigInt.mod': () => {
|
||||||
|
console.log('bigInt.mod');
|
||||||
|
},
|
||||||
|
|
||||||
|
'log.log': () => {
|
||||||
|
console.log('log.log');
|
||||||
|
},
|
||||||
|
|
||||||
|
'dataSource.create': () => {
|
||||||
|
console.log('dataSource.create');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ethereum: {
|
||||||
|
'ethereum.call': () => {
|
||||||
|
console.log('ethereum.call');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const instantiate = async (filePath: string): Promise<loader.ResultObject & { exports: any }> => {
|
||||||
const buffer = await fs.readFile(filePath);
|
const buffer = await fs.readFile(filePath);
|
||||||
return loader.instantiate(buffer, imports);
|
return loader.instantiate(buffer, imports);
|
||||||
};
|
};
|
||||||
|
20
yarn.lock
20
yarn.lock
@ -1100,6 +1100,13 @@
|
|||||||
"@ethersproject/properties" "^5.3.0"
|
"@ethersproject/properties" "^5.3.0"
|
||||||
"@ethersproject/strings" "^5.3.0"
|
"@ethersproject/strings" "^5.3.0"
|
||||||
|
|
||||||
|
"@graphprotocol/graph-ts@^0.22.0":
|
||||||
|
version "0.22.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.22.0.tgz#5280513d1c8a162077f82ce7f9a492bb5783d6f4"
|
||||||
|
integrity sha512-kJIBL73xBxj0+NJdRABukAtcrc3Mb8jt31s0tCLPe6c57rQXEf7KR9oYrFdzE1ZsJCP6j+MX+A2+sj1Pj3aJtQ==
|
||||||
|
dependencies:
|
||||||
|
assemblyscript "0.19.10"
|
||||||
|
|
||||||
"@graphql-typed-document-node/core@^3.0.0":
|
"@graphql-typed-document-node/core@^3.0.0":
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.0.tgz#0eee6373e11418bfe0b5638f654df7a4ca6a3950"
|
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.0.tgz#0eee6373e11418bfe0b5638f654df7a4ca6a3950"
|
||||||
@ -3465,6 +3472,14 @@ asn1@~0.2.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
safer-buffer "~2.1.0"
|
safer-buffer "~2.1.0"
|
||||||
|
|
||||||
|
assemblyscript@0.19.10:
|
||||||
|
version "0.19.10"
|
||||||
|
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.10.tgz#7ede6d99c797a219beb4fa4614c3eab9e6343c8e"
|
||||||
|
integrity sha512-HavcUBXB3mBTRGJcpvaQjmnmaqKHBGREjSPNsIvnAk2f9dj78y4BkMaSSdvBQYWcDDzsHQjyUC8stICFkD1Odg==
|
||||||
|
dependencies:
|
||||||
|
binaryen "101.0.0-nightly.20210723"
|
||||||
|
long "^4.0.0"
|
||||||
|
|
||||||
assemblyscript@^0.19.16:
|
assemblyscript@^0.19.16:
|
||||||
version "0.19.16"
|
version "0.19.16"
|
||||||
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.16.tgz#fc06c9892755775e8e31a59249fbc361fd49e1d1"
|
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.16.tgz#fc06c9892755775e8e31a59249fbc361fd49e1d1"
|
||||||
@ -4161,6 +4176,11 @@ bindings@^1.2.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
file-uri-to-path "1.0.0"
|
file-uri-to-path "1.0.0"
|
||||||
|
|
||||||
|
binaryen@101.0.0-nightly.20210723:
|
||||||
|
version "101.0.0-nightly.20210723"
|
||||||
|
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210723.tgz#b6bb7f3501341727681a03866c0856500eec3740"
|
||||||
|
integrity sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA==
|
||||||
|
|
||||||
binaryen@101.0.0-nightly.20210904:
|
binaryen@101.0.0-nightly.20210904:
|
||||||
version "101.0.0-nightly.20210904"
|
version "101.0.0-nightly.20210904"
|
||||||
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210904.tgz#58a7990d6d64b16567f376a1fe47d8aea6698b14"
|
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210904.tgz#58a7990d6d64b16567f376a1fe47d8aea6698b14"
|
||||||
|
Loading…
Reference in New Issue
Block a user