uuosio / ascdk

MIT License
12 stars 9 forks source link

Split up large contracts #69

Closed jafri closed 2 years ago

jafri commented 2 years ago

It would be useful if you could split up large contracts using the @contract decorator. Not sure how difficult this is

E.g.

a.ts

@contract("mycon")
class A {
  action1(){}
}

b.ts

@contract("mycon")
class B {
  action2(){}
}

The resulting contract would have both action1 and action2

learnforpractice commented 2 years ago

There is a constrain in the current code generation, only one contract class in one package is allowed.

To split up a large contract, use inherits:

class A {
  @action("action1")
  action1(): void
  {

  }
}

@contract("mycon")
class B extends A {
    constructor(
        public receiver: Name,
        public firstReceiver: Name,
        public action: Name) {
            super();
    }

    @action("action2")
    action2(): void
    {

    }
}