ask-lang / ask-old Goto Github PK
View Code? Open in Web Editor NEWAsk! is a framework to write Wasm smart contracts for Substrate Frame Pallet-Contracts in AssemblyScript
License: MIT License
Ask! is a framework to write Wasm smart contracts for Substrate Frame Pallet-Contracts in AssemblyScript
License: MIT License
I followed the instructions of the Ask! quickstart over here to create a simple contract, and when I want to compile it, I get the following error:
❯ npx pl-ask-cli compile contracts/index.ts
Build Starting ······
Build progressing. Generating target files ······
ERROR TS2304: Cannot find name 'ASC_RUNTIME'.
if (ASC_RUNTIME != Runtime.Incremental) {
~~~~~~~~~~~
in ~lib/array.ts(74,9)
ERROR TS2304: Cannot find name 'ASC_RUNTIME'.
if (ASC_RUNTIME != Runtime.Incremental) {
~~~~~~~~~~~
in ~lib/array.ts(28,9)
ERROR TS2304: Cannot find name 'ASC_RUNTIME'.
if (ASC_RUNTIME != Runtime.Incremental) {
~~~~~~~~~~~
in ~lib/arraybuffer.ts(21,9)
FAILURE 3 compile error(s)
Build Done. Targets generated. Target directory: /home/steve/Dev/walchain/flipper-ask/build.
Event message, Hard to interpret the raw bytes, better to decode it.
Complete Report & review form
https://docs.google.com/spreadsheets/d/1lcaPa_cEp912ntmRIY03GtEEh8LESUzIkSLCew206PE/edit?usp=sharing
https://docs.google.com/document/d/1H4d_qOCWEzY_W1Pr8_jdP0uMUcrrkVR4utZbKL-yCRg/edit?usp=sharing
having this example code
···
import { PackedStorableArray} from "ask-lang";
@contract
class Flipper {
@State flag: bool;
@state
@packed({ "capacity": 128 })
packeArr: PackedStorableArray<UInt128> = new PackedStorableArray<UInt128>();
@state
aArr: PackedStorableArray<UInt128> = new PackedStorableArray<UInt128>();
constructor() {
}
@constructor
default(initFlag: bool): void {
this.flag = initFlag;
}
@message
flip(): void {
const v = this.flag;
this.flag = !v;
}
@message({"mutates": false})
get(): bool {
return this.flag;
}
}
···
Since we do not import UInt128, this code will not compile.
However, in debug
FAILURE TypeError: Cannot read property 'kind' of null
at NamedTypeNodeDef.getTypeKind (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/typedef.js:206:21)
at new NamedTypeNodeDef (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/typedef.js:58:32)
at FieldDef.resolveField (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/elementdef.js:92:25)
at new FieldDef (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/elementdef.js:82:15)
at /home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/classdef.js:52:39
at Map.forEach (<anonymous>)
at ContractInterpreter.ClassInterpreter.resolveFieldMembers (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/classdef.js:50:42)
at ContractInterpreter.ClassInterpreter [as constructor] (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/classdef.js:44:15)
at new ContractInterpreter (/home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/classdef.js:87:28)
at /home/bonan/repos/ask/ask-cli-test/node_modules/ask-transform/dist/contract/contract.js:44:28
I think this is caused by 2 step transform as the way of compilation
ask!
code from the as
compiler internal. At present, it can be completely written as an independent ts
project, in my personal opinion.metadata.json
's spec class rather than generate it by template engine. It's hard to maintain and test it.When the contract code contains error, the compiler will still generate .wasm
file but missing metadata.json
. Ideally, no file shall be generated when compilation failed
protected _transfer(sender: AccountId, recipient: AccountId, amount: u128): void {
assert(sender.notEq(AccountId.Null), "ERC20: transfer from the zero address");
assert(recipient.notEq(AccountId.Null), "ERC20: transfer to the zero address");
let spenderBalance =this.balanceOf(sender);
assert(spenderBalance >= amount, "ERC20: transfer amount exceeds balance");
let senderLeft = spenderBalance - amount;
this.balances.set(sender, new UInt128(senderLeft));
let recipientLeft = this.balanceOf(recipient) + amount;
this.balances.set(recipient, new UInt128(recipientLeft));
(new Transfer(sender, recipient, amount)).emit();
}
In function parameters, ask uses u128
but when saving to data storage, it requires casting to UInt128
.
$ asc --importMemory --initialMemory 2 --maximumMemory 16 --noExportMemory --runtime none --use abort= flipper.ts -O2 -b flipper.wasm -t flipper.wast
ERROR TS2554: Expected 1 arguments, but got 2.
v.populateFromBytes(readbuf.valueBytes, 0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
in ../../src/primitives/readbuffer.ts(18,5)
FAILURE 1 compile error(s)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.