Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error when using Mapping<K,V,H> where V has no default constructor. #245

Open
ashutoshvarma opened this issue Jan 30, 2023 · 1 comment
Labels
good first issue Good for newcomers question Further information is requested

Comments

@ashutoshvarma
Copy link
Contributor

Problem

Error when build contracts when using Mapping<K,V,H> type where type V take more than one required constructor arguments.

Example contract

Using Uint8Array for mapping value, it takes length as mandatory constructor argument.

import {
    AccountId, HashKeccak256, Mapping
} from "ask-lang";

@spreadLayout()
class Data {
  map: Mapping<AccountId, Uint8Array, HashKeccak256> = new Mapping();
}

@contract()
export class Contract {
  data: Data;

  constructor() {
    this.data = new Data();
  }

  @constructor()
  default(): void {}

  @message()
  get(account: AccountId): Uint8Array {
    // return new Uint8Array(0);
    return this.data.map.get(account); // works if this line is commemted out.
  }
}

Error

$ ASK_CONFIG=./askconfig.json asc --config asconfig.json serialize.ts
ERROR TS2554: Expected 1 arguments, but got 0.

             return instantiate<T>();
                    ~~~~~~~~~~~~~~~~
 in ~lib/as-serde-scale/misc.ts(21,20)

FAILURE 1 compile error(s)
error Command failed with exit code 1.
@yjhmelody
Copy link
Contributor

yjhmelody commented Jan 30, 2023

Yeah, Because we need to construct this type first and then decode storage data into it.
You should wrap this type when it's used to be a storage type.
Now it's actually not good design. But it's not easy to design a better way in AssemblyScript.

Creates a class instance must need to call constructor(instantiate) of this class. But there is no good way to support different constructor

@yjhmelody yjhmelody added good first issue Good for newcomers question Further information is requested labels Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants