From f067ed70d2d2f4fc06654e92158bd3b0a6e971e1 Mon Sep 17 00:00:00 2001 From: polyprogrammist Date: Sat, 13 Jan 2024 20:03:02 -0500 Subject: [PATCH] tmp --- src/ast.ts | 5 +++-- src/astbuilder/handle_type.ts | 13 +++++++++++- test/generated_files/generated_block.ts | 28 +++++++++++++++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index f5aece5..36b3d49 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -93,8 +93,9 @@ export type TLBVarIntegerType = { export type TLBHashmapType = { kind: "TLBHashmapType"; - key: TLBMathExprType, - value: TLBFieldType + key: TLBMathExprType; + value: TLBFieldType; + extra?: TLBFieldType; } export type TLBCellType = { diff --git a/src/astbuilder/handle_type.ts b/src/astbuilder/handle_type.ts index ea9af99..808de93 100644 --- a/src/astbuilder/handle_type.ts +++ b/src/astbuilder/handle_type.ts @@ -163,7 +163,7 @@ export function getType( }; } else if (expr.name == "HashmapE") { if (expr.args.length != 2) { - throw new Error('') + throw new Error('Not enough arguments for HashmapE') } let key = getType(expr.args[0], constructor, fieldTypeName) let value = getType(expr.args[1], constructor, fieldTypeName) @@ -171,6 +171,17 @@ export function getType( throw new Error('Hashmap key should be number') } return { kind: "TLBHashmapType", key: key, value: value }; + } else if (expr.name == "HashmapAugE") { + if (expr.args.length != 3) { + throw new Error('Not enough arguments for HashmapAugE') + } + let key = getType(expr.args[0], constructor, fieldTypeName) + let value = getType(expr.args[1], constructor, fieldTypeName) + let extra = getType(expr.args[2], constructor, fieldTypeName) + if (key.kind != 'TLBExprMathType') { + throw new Error('Hashmap key should be number') + } + return { kind: "TLBHashmapType", key: key, value: value, extra: extra }; } else if ( expr.name == "VarUInteger" && (expr.args[0] instanceof MathExpr || diff --git a/test/generated_files/generated_block.ts b/test/generated_files/generated_block.ts index 7be492d..42a53a1 100644 --- a/test/generated_files/generated_block.ts +++ b/test/generated_files/generated_block.ts @@ -7,6 +7,7 @@ import { Address } from 'ton' import { ExternalAddress } from 'ton' import { Dictionary } from 'ton' import { DictionaryValue } from 'ton' +import util from 'util' export function bitLen(n: number) { return n.toString(2).length;; } @@ -1105,7 +1106,7 @@ export interface AccountBlock { export interface ShardAccountBlocks { readonly kind: 'ShardAccountBlocks'; - readonly anon0: HashmapAugE; + readonly anon0: Dictionary; } /* @@ -6963,18 +6964,37 @@ export function storeAccountBlock(accountBlock: AccountBlock): (builder: Builder // _ (HashmapAugE 256 AccountBlock CurrencyCollection) = ShardAccountBlocks; +const dictValueShardAccountBlocks: DictionaryValue<{accountBlock: AccountBlock, currencyCollection: CurrencyCollection}> = { + serialize: (arg, builder) => { + console.log('serializing now') + builder.store(storeCurrencyCollection(arg.currencyCollection)); + builder.store(storeAccountBlock(arg.accountBlock)); + }, + parse: (slice: Slice) => { + console.log('parsing now') + let currencyCollection = loadCurrencyCollection(slice); + let accountBlock = loadAccountBlock(slice); + return { + accountBlock, + currencyCollection + } + } +} + export function loadShardAccountBlocks(slice: Slice): ShardAccountBlocks { - let anon0: HashmapAugE = loadHashmapAugE(slice, 256, loadAccountBlock, loadCurrencyCollection); + let anon0: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), dictValueShardAccountBlocks, slice) + // console.log(util.inspect(anon0, false, null, true)) + // let anon0: HashmapAugE = loadHashmapAugE(slice, 256, loadAccountBlock, loadCurrencyCollection); return { kind: 'ShardAccountBlocks', anon0: anon0, } - } export function storeShardAccountBlocks(shardAccountBlocks: ShardAccountBlocks): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapAugE(shardAccountBlocks.anon0, storeAccountBlock, storeCurrencyCollection)(builder); + builder.storeDict(shardAccountBlocks.anon0, Dictionary.Keys.BigUint(256), dictValueShardAccountBlocks) + // storeHashmapAugE(shardAccountBlocks.anon0, storeAccountBlock, storeCurrencyCollection)(builder); }) }