Skip to content

Commit

Permalink
funcgible-toke-lockable example fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Aug 31, 2022
1 parent f4499e5 commit 589f789
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
9 changes: 7 additions & 2 deletions examples/src/fungible-token-lockable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ class Account {

@NearBindgen({ initRequired: true })
class LockableFungibleToken {
constructor() {
this.accounts = new LookupMap('a') // Account ID -> Account mapping
this.totalSupply = 0 // Total supply of the all tokens
}

@initialize
init({ prefix, totalSupply }) {
this.accounts = new LookupMap(prefix) // Account ID -> Account mapping
this.totalSupply = totalSupply // Total supply of the all tokens
this.accounts = new LookupMap(prefix)
this.totalSupply = totalSupply
let ownerId = near.signerAccountId()
let ownerAccount = this.getAccount(ownerId)
ownerAccount.balance = this.totalSupply
Expand Down
2 changes: 1 addition & 1 deletion lib/build-tools/near-bindgen-exporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/near-bindgen.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/near-bindgen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/build-tools/near-bindgen-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default function () {
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_contract'), t.callExpression(t.memberExpression(classId, t.identifier('_create')), []))]),
contractMethods[method] === 'call' || contractMethods[method] === 'view' ?
// if (_state) { Object.assign(_contract, state); }
t.ifStatement(t.identifier('_state'), t.blockStatement([t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('assign')), [t.identifier('_contract'), t.identifier('_state')]))])) : t.emptyStatement(),
t.ifStatement(t.identifier('_state'), t.blockStatement([t.expressionStatement(
t.callExpression(t.memberExpression(classId, t.identifier('_reconstruct')), [t.identifier('_contract'), t.identifier('_state')]))])) : t.emptyStatement(),
// let _args = Counter._getArgs();
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_args'), t.callExpression(t.memberExpression(classId, t.identifier('_getArgs')), []))]),
// let _result = _contract.method(args);
Expand Down
11 changes: 11 additions & 0 deletions src/near-bindgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ export function NearBindgen({ requireInit = false }: { requireInit: boolean }) {
return JSON.parse(value);
}

static _reconstruct(classObject: any, plainObject: JSON) {
for (const item in classObject) {
if (classObject[item].constructor?.deserialize !== undefined) {
classObject[item] = classObject[item].constructor.deserialize(plainObject[item])
} else {
classObject[item] = plainObject[item]
}
}
return classObject
}

static _requireInit(): boolean {
return requireInit;
}
Expand Down

0 comments on commit 589f789

Please sign in to comment.