Coder Social home page Coder Social logo

ask-lang / ask-old Goto Github PK

View Code? Open in Web Editor NEW
47.0 7.0 8.0 2.79 MB

Ask! is a framework to write Wasm smart contracts for Substrate Frame Pallet-Contracts in AssemblyScript

License: MIT License

TypeScript 85.84% JavaScript 14.16%
ink wasm assemblyscript frame-contracts-pallet patract

ask-old's Issues

Error when trying to compile Flipper contract

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.

ask does not print debug info precisely

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

Some points need to improve

  • We need to explore some ways to extract the ask! code from the as compiler internal. At present, it can be completely written as an independent ts project, in my personal opinion.
  • We should define the metadata.json's spec class rather than generate it by template engine. It's hard to maintain and test it.
  • The code in some places is hard-coded, and parameterization and configuration should be considered.
  • Consider to add some prefix for contract decorator, for avoiding name conflicts.
  • Add more unit tests.

inconsistent data types for function variable and storage variable

  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.

Meet a strange compile error when compile flipper example

$ 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)

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.