diff --git a/package-lock.json b/package-lock.json index d6529d0..c8c495d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ton-community/tlb-codegen", - "version": "1.0.13", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ton-community/tlb-codegen", - "version": "1.0.13", + "version": "1.0.0", "license": "ISC", "dependencies": { "@ton-community/tlb-parser": "^0.1.3", diff --git a/src/generators/typescript/complex_expr.ts b/src/generators/typescript/complex_expr.ts index 353b21c..74a62f5 100644 --- a/src/generators/typescript/complex_expr.ts +++ b/src/generators/typescript/complex_expr.ts @@ -43,6 +43,7 @@ export function bitlenFunctionDecl(): GenDeclaration { export function typedSlice() { return [tTypedIdentifier(id("slice"), id("Slice"))]; } + export function sliceLoad(slicePrefix: number[], currentSlice: string) { return tExpressionStatement( tDeclareVariable( @@ -141,7 +142,7 @@ export function storeExprForParam(theCell: string, exprForParam: ExprForParam, i } export function returnSliceFunc(): Expression { return tArrowFunctionExpression(typedSlice(), [ - tReturnStatement(id("slice")), + tReturnStatement(tFunctionCall(tMemberExpression(id("slice"), id("asCell")), [])), ]); } export function loadExprForParam(currentSlice: string, exprForParam: ExprForParam): Expression { diff --git a/src/generators/typescript/generator.ts b/src/generators/typescript/generator.ts index 6b62f2f..6df1ddc 100644 --- a/src/generators/typescript/generator.ts +++ b/src/generators/typescript/generator.ts @@ -702,10 +702,18 @@ export class TypescriptGenerator implements CodeGenerator { exprForParam = { argLoadExpr: id(theSlice), argStoreExpr: id(theSlice), - paramType: "Slice", - fieldLoadSuffix: "Slice", + paramType: "Cell", + fieldLoadSuffix: "Ref", fieldStoreSuffix: "Slice", }; + storeParametersOutside[0] = tFunctionCall( + tMemberExpression(storeParametersOutside[0], id("beginParse")), + [id("true")] + ) + storeParametersInside[0] = tFunctionCall( + tMemberExpression(storeParametersInside[0], id("beginParse")), + [id("true")] + ) } else if (fieldType.kind == "TLBBoolType") { exprForParam = { argLoadExpr: undefined, @@ -994,7 +1002,7 @@ export class TypescriptGenerator implements CodeGenerator { if (exprForParam) { if ( exprForParam.paramType != "BitString" && - exprForParam.paramType != "Slice" + exprForParam.paramType != "Cell" ) { if (exprForParam.argStoreExpr) { storeParametersOutside.push(exprForParam.argStoreExpr); @@ -1002,8 +1010,8 @@ export class TypescriptGenerator implements CodeGenerator { } } result.loadExpr = loadExprForParam(currentSlice, exprForParam); - if (exprForParam.paramType == "Slice") { - result.loadExpr = id(currentSlice); + if (exprForParam.paramType == "Cell") { + result.loadExpr = tFunctionCall(tMemberExpression(id(currentSlice), id('asCell')), []); result.loadFunctionExpr = returnSliceFunc(); } result.typeParamExpr = id(exprForParam.paramType); diff --git a/test/generated_files/generated_block.ts b/test/generated_files/generated_block.ts index ec701d4..a665127 100644 --- a/test/generated_files/generated_block.ts +++ b/test/generated_files/generated_block.ts @@ -471,9 +471,9 @@ export interface StateInit { readonly kind: 'StateInit'; readonly split_depth: Maybe; readonly special: Maybe; - readonly code: Maybe; - readonly data: Maybe; - readonly library: Maybe; + readonly code: Maybe; + readonly data: Maybe; + readonly library: Maybe; } /* @@ -486,8 +486,8 @@ export interface StateInitWithLibs { readonly kind: 'StateInitWithLibs'; readonly split_depth: Maybe; readonly special: Maybe; - readonly code: Maybe; - readonly data: Maybe; + readonly code: Maybe; + readonly data: Maybe; readonly library: Dictionary; } @@ -496,7 +496,7 @@ export interface StateInitWithLibs { export interface SimpleLib { readonly kind: 'SimpleLib'; readonly public0: boolean; - readonly root: Slice; + readonly root: Cell; } /* @@ -529,7 +529,7 @@ export interface MessageRelaxed { export interface MessageAny { readonly kind: 'MessageAny'; - readonly anon0: Message; + readonly anon0: Message; } /* @@ -577,7 +577,7 @@ export interface MsgEnvelope { readonly cur_addr: IntermediateAddress; readonly next_addr: IntermediateAddress; readonly fwd_fee_remaining: bigint; - readonly msg: Message; + readonly msg: Message; } /* @@ -619,16 +619,16 @@ export type InMsg = InMsg_msg_import_ext | InMsg_msg_import_ihr | InMsg_msg_impo export interface InMsg_msg_import_ext { readonly kind: 'InMsg_msg_import_ext'; - readonly msg: Message; + readonly msg: Message; readonly transaction: Transaction; } export interface InMsg_msg_import_ihr { readonly kind: 'InMsg_msg_import_ihr'; - readonly msg: Message; + readonly msg: Message; readonly transaction: Transaction; readonly ihr_fee: bigint; - readonly proof_created: Slice; + readonly proof_created: Cell; } export interface InMsg_msg_import_imm { @@ -664,7 +664,7 @@ export interface InMsg_msg_discard_tr { readonly in_msg: MsgEnvelope; readonly transaction_id: number; readonly fwd_fee: bigint; - readonly proof_delivered: Slice; + readonly proof_delivered: Cell; } /* @@ -730,7 +730,7 @@ export type OutMsg = OutMsg_msg_export_ext | OutMsg_msg_export_imm | OutMsg_msg_ export interface OutMsg_msg_export_ext { readonly kind: 'OutMsg_msg_export_ext'; - readonly msg: Message; + readonly msg: Message; readonly transaction: Transaction; } @@ -1005,8 +1005,8 @@ export interface Transaction { readonly outmsg_cnt: number; readonly orig_status: AccountStatus; readonly end_status: AccountStatus; - readonly in_msg: Maybe>; - readonly out_msgs: Dictionary>; + readonly in_msg: Maybe>; + readonly out_msgs: Dictionary>; readonly total_fees: CurrencyCollection; readonly state_update: HASH_UPDATE; readonly description: TransactionDescr; @@ -1383,7 +1383,7 @@ export interface SmartContractInfo { readonly rand_seed: BitString; readonly balance_remaining: CurrencyCollection; readonly myself: Address; - readonly global_config: Maybe; + readonly global_config: Maybe; } // out_list_empty$_ = OutList 0; @@ -1428,12 +1428,12 @@ export type OutAction = OutAction_action_send_msg | OutAction_action_set_code | export interface OutAction_action_send_msg { readonly kind: 'OutAction_action_send_msg'; readonly mode: number; - readonly out_msg: MessageRelaxed; + readonly out_msg: MessageRelaxed; } export interface OutAction_action_set_code { readonly kind: 'OutAction_action_set_code'; - readonly new_code: Slice; + readonly new_code: Cell; } export interface OutAction_action_reserve_currency { @@ -1461,14 +1461,14 @@ export interface LibRef_libref_hash { export interface LibRef_libref_ref { readonly kind: 'LibRef_libref_ref'; - readonly library: Slice; + readonly library: Cell; } // out_list_node$_ prev:^Cell action:OutAction = OutListNode; export interface OutListNode { readonly kind: 'OutListNode'; - readonly prev: Slice; + readonly prev: Cell; readonly action: OutAction; } @@ -1581,7 +1581,7 @@ shared_lib_descr$00 lib:^Cell publishers:(Hashmap 256 True) export interface LibDescr { readonly kind: 'LibDescr'; - readonly lib: Slice; + readonly lib: Cell; readonly publishers: Hashmap; } @@ -1919,7 +1919,7 @@ _ config_addr:bits256 config:^(Hashmap 32 ^Cell) export interface ConfigParams { readonly kind: 'ConfigParams'; readonly config_addr: BitString; - readonly config: Hashmap; + readonly config: Hashmap; } /* @@ -2566,7 +2566,7 @@ cfg_proposal#f3 param_id:int32 param_value:(Maybe ^Cell) if_hash_equal:(Maybe ui export interface ConfigProposal { readonly kind: 'ConfigProposal'; readonly param_id: number; - readonly param_value: Maybe; + readonly param_value: Maybe; readonly if_hash_equal: Maybe; } @@ -3092,7 +3092,7 @@ export interface BlockSignatures { export interface BlockProof { readonly kind: 'BlockProof'; readonly proof_for: BlockIdExt; - readonly root: Slice; + readonly root: Cell; readonly signatures: Maybe; } @@ -3109,7 +3109,7 @@ export interface ProofChain_chain_empty { export interface ProofChain_chain_link { readonly kind: 'ProofChain_chain_link'; readonly n: number; - readonly root: Slice; + readonly root: Cell; readonly prev: ProofChain | undefined; } @@ -3228,7 +3228,7 @@ export interface VmStackValue_vm_stk_nan { export interface VmStackValue_vm_stk_cell { readonly kind: 'VmStackValue_vm_stk_cell'; - readonly _cell: Slice; + readonly _cell: Cell; } export interface VmStackValue_vm_stk_slice { @@ -3238,7 +3238,7 @@ export interface VmStackValue_vm_stk_slice { export interface VmStackValue_vm_stk_builder { readonly kind: 'VmStackValue_vm_stk_builder'; - readonly _cell: Slice; + readonly _cell: Cell; } export interface VmStackValue_vm_stk_cont { @@ -3259,7 +3259,7 @@ _ cell:^Cell st_bits:(## 10) end_bits:(## 10) { st_bits <= end_bits } export interface VmCellSlice { readonly kind: 'VmCellSlice'; - readonly _cell: Slice; + readonly _cell: Cell; readonly st_bits: number; readonly end_bits: number; readonly st_ref: number; @@ -3355,7 +3355,7 @@ export interface VmGasLimits { export interface VmLibraries { readonly kind: 'VmLibraries'; - readonly libraries: Dictionary; + readonly libraries: Dictionary; } /* @@ -5000,19 +5000,19 @@ export function loadStateInit(slice: Slice): StateInit { })); let special: Maybe = loadMaybe(slice, loadTickTock); - let code: Maybe = loadMaybe(slice, ((slice: Slice) => { + let code: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); - let data: Maybe = loadMaybe(slice, ((slice: Slice) => { + let data: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); - let library: Maybe = loadMaybe(slice, ((slice: Slice) => { + let library: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); return { @@ -5035,28 +5035,28 @@ export function storeStateInit(stateInit: StateInit): (builder: Builder) => void }))(builder); storeMaybe(stateInit.special, storeTickTock)(builder); - storeMaybe(stateInit.code, ((arg: Slice) => { + storeMaybe(stateInit.code, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) }))(builder); - storeMaybe(stateInit.data, ((arg: Slice) => { + storeMaybe(stateInit.data, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) }))(builder); - storeMaybe(stateInit.library, ((arg: Slice) => { + storeMaybe(stateInit.library, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) @@ -5078,14 +5078,14 @@ export function loadStateInitWithLibs(slice: Slice): StateInitWithLibs { })); let special: Maybe = loadMaybe(slice, loadTickTock); - let code: Maybe = loadMaybe(slice, ((slice: Slice) => { + let code: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); - let data: Maybe = loadMaybe(slice, ((slice: Slice) => { + let data: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); let library: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { @@ -5112,19 +5112,19 @@ export function storeStateInitWithLibs(stateInitWithLibs: StateInitWithLibs): (b }))(builder); storeMaybe(stateInitWithLibs.special, storeTickTock)(builder); - storeMaybe(stateInitWithLibs.code, ((arg: Slice) => { + storeMaybe(stateInitWithLibs.code, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) }))(builder); - storeMaybe(stateInitWithLibs.data, ((arg: Slice) => { + storeMaybe(stateInitWithLibs.data, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) @@ -5145,7 +5145,7 @@ export function storeStateInitWithLibs(stateInitWithLibs: StateInitWithLibs): (b export function loadSimpleLib(slice: Slice): SimpleLib { let public0: boolean = slice.loadBoolean(); let slice1 = slice.loadRef().beginParse(true); - let root: Slice = slice1; + let root: Cell = slice1.asCell(); return { kind: 'SimpleLib', public0: public0, @@ -5158,7 +5158,7 @@ export function storeSimpleLib(simpleLib: SimpleLib): (builder: Builder) => void return ((builder: Builder) => { builder.storeBit(simpleLib.public0); let cell1 = beginCell(); - cell1.storeSlice(simpleLib.root); + cell1.storeSlice(simpleLib.root.beginParse(true)); builder.storeRef(cell1); }) @@ -5287,8 +5287,8 @@ export function storeMessageRelaxed(messageRelaxed: MessageRelaxed, storeX // _ (Message Any) = MessageAny; export function loadMessageAny(slice: Slice): MessageAny { - let anon0: Message = loadMessage(slice, ((slice: Slice) => { - return slice + let anon0: Message = loadMessage(slice, ((slice: Slice) => { + return slice.asCell() })); return { @@ -5300,9 +5300,9 @@ export function loadMessageAny(slice: Slice): MessageAny { export function storeMessageAny(messageAny: MessageAny): (builder: Builder) => void { return ((builder: Builder) => { - storeMessage(messageAny.anon0, ((arg: Slice) => { + storeMessage(messageAny.anon0, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(builder); @@ -5400,8 +5400,8 @@ export function loadMsgEnvelope(slice: Slice): MsgEnvelope { let next_addr: IntermediateAddress = loadIntermediateAddress(slice); let fwd_fee_remaining: bigint = slice.loadCoins(); let slice1 = slice.loadRef().beginParse(true); - let msg: Message = loadMessage(slice1, ((slice: Slice) => { - return slice + let msg: Message = loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })); return { @@ -5423,9 +5423,9 @@ export function storeMsgEnvelope(msgEnvelope: MsgEnvelope): (builder: Builder) = storeIntermediateAddress(msgEnvelope.next_addr)(builder); builder.storeCoins(msgEnvelope.fwd_fee_remaining); let cell1 = beginCell(); - storeMessage(msgEnvelope.msg, ((arg: Slice) => { + storeMessage(msgEnvelope.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -5473,8 +5473,8 @@ export function loadInMsg(slice: Slice): InMsg { if (((slice.remainingBits >= 3) && (slice.preloadUint(3) == 0b000))) { slice.loadUint(3); let slice1 = slice.loadRef().beginParse(true); - let msg: Message = loadMessage(slice1, ((slice: Slice) => { - return slice + let msg: Message = loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })); let slice2 = slice.loadRef().beginParse(true); @@ -5489,15 +5489,15 @@ export function loadInMsg(slice: Slice): InMsg { if (((slice.remainingBits >= 3) && (slice.preloadUint(3) == 0b010))) { slice.loadUint(3); let slice1 = slice.loadRef().beginParse(true); - let msg: Message = loadMessage(slice1, ((slice: Slice) => { - return slice + let msg: Message = loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })); let slice2 = slice.loadRef().beginParse(true); let transaction: Transaction = loadTransaction(slice2); let ihr_fee: bigint = slice.loadCoins(); let slice3 = slice.loadRef().beginParse(true); - let proof_created: Slice = slice3; + let proof_created: Cell = slice3.asCell(); return { kind: 'InMsg_msg_import_ihr', msg: msg, @@ -5573,7 +5573,7 @@ export function loadInMsg(slice: Slice): InMsg { let transaction_id: number = slice.loadUint(64); let fwd_fee: bigint = slice.loadCoins(); let slice2 = slice.loadRef().beginParse(true); - let proof_delivered: Slice = slice2; + let proof_delivered: Cell = slice2.asCell(); return { kind: 'InMsg_msg_discard_tr', in_msg: in_msg, @@ -5591,9 +5591,9 @@ export function storeInMsg(inMsg: InMsg): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0b000, 3); let cell1 = beginCell(); - storeMessage(inMsg.msg, ((arg: Slice) => { + storeMessage(inMsg.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -5608,9 +5608,9 @@ export function storeInMsg(inMsg: InMsg): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0b010, 3); let cell1 = beginCell(); - storeMessage(inMsg.msg, ((arg: Slice) => { + storeMessage(inMsg.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -5620,7 +5620,7 @@ export function storeInMsg(inMsg: InMsg): (builder: Builder) => void { builder.storeRef(cell2); builder.storeCoins(inMsg.ihr_fee); let cell3 = beginCell(); - cell3.storeSlice(inMsg.proof_created); + cell3.storeSlice(inMsg.proof_created.beginParse(true)); builder.storeRef(cell3); }) @@ -5684,7 +5684,7 @@ export function storeInMsg(inMsg: InMsg): (builder: Builder) => void { builder.storeUint(inMsg.transaction_id, 64); builder.storeCoins(inMsg.fwd_fee); let cell2 = beginCell(); - cell2.storeSlice(inMsg.proof_delivered); + cell2.storeSlice(inMsg.proof_delivered.beginParse(true)); builder.storeRef(cell2); }) @@ -5804,8 +5804,8 @@ export function loadOutMsg(slice: Slice): OutMsg { if (((slice.remainingBits >= 3) && (slice.preloadUint(3) == 0b000))) { slice.loadUint(3); let slice1 = slice.loadRef().beginParse(true); - let msg: Message = loadMessage(slice1, ((slice: Slice) => { - return slice + let msg: Message = loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })); let slice2 = slice.loadRef().beginParse(true); @@ -5920,9 +5920,9 @@ export function storeOutMsg(outMsg: OutMsg): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0b000, 3); let cell1 = beginCell(); - storeMessage(outMsg.msg, ((arg: Slice) => { + storeMessage(outMsg.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -6654,20 +6654,20 @@ export function loadTransaction(slice: Slice): Transaction { let orig_status: AccountStatus = loadAccountStatus(slice); let end_status: AccountStatus = loadAccountStatus(slice); let slice1 = slice.loadRef().beginParse(true); - let in_msg: Maybe> = loadMaybe>(slice1, ((slice: Slice) => { + let in_msg: Maybe> = loadMaybe>(slice1, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return loadMessage(slice1, ((slice: Slice) => { - return slice + return loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })) })); - let out_msgs: Dictionary> = Dictionary.load(Dictionary.Keys.Uint(15), { + let out_msgs: Dictionary> = Dictionary.load(Dictionary.Keys.Uint(15), { serialize: () => { throw new Error('Not implemented') }, parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return loadMessage(slice1, ((slice: Slice) => { - return slice + return loadMessage(slice1, ((slice: Slice) => { + return slice.asCell() })) @@ -6711,12 +6711,12 @@ export function storeTransaction(transaction: Transaction): (builder: Builder) = storeAccountStatus(transaction.orig_status)(builder); storeAccountStatus(transaction.end_status)(builder); let cell1 = beginCell(); - storeMaybe>(transaction.in_msg, ((arg: Message) => { + storeMaybe>(transaction.in_msg, ((arg: Message) => { return ((builder: Builder) => { let cell1 = beginCell(); - storeMessage(arg, ((arg: Slice) => { + storeMessage(arg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -6726,13 +6726,13 @@ export function storeTransaction(transaction: Transaction): (builder: Builder) = }))(cell1); cell1.storeDict(transaction.out_msgs, Dictionary.Keys.Uint(15), { - serialize: ((arg: Message, builder: Builder) => { - ((arg: Message) => { + serialize: ((arg: Message, builder: Builder) => { + ((arg: Message) => { return ((builder: Builder) => { let cell1 = beginCell(); - storeMessage(arg, ((arg: Slice) => { + storeMessage(arg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -7772,8 +7772,8 @@ export function loadSmartContractInfo(slice: Slice): SmartContractInfo { let rand_seed: BitString = slice.loadBits(256); let balance_remaining: CurrencyCollection = loadCurrencyCollection(slice); let myself: Address = slice.loadAddress(); - let global_config: Maybe = loadMaybe(slice, ((slice: Slice) => { - return slice + let global_config: Maybe = loadMaybe(slice, ((slice: Slice) => { + return slice.asCell() })); return { @@ -7804,9 +7804,9 @@ export function storeSmartContractInfo(smartContractInfo: SmartContractInfo): (b builder.storeBits(smartContractInfo.rand_seed); storeCurrencyCollection(smartContractInfo.balance_remaining)(builder); builder.storeAddress(smartContractInfo.myself); - storeMaybe(smartContractInfo.global_config, ((arg: Slice) => { + storeMaybe(smartContractInfo.global_config, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(builder); @@ -7883,8 +7883,8 @@ export function loadOutAction(slice: Slice): OutAction { slice.loadUint(32); let mode: number = slice.loadUint(8); let slice1 = slice.loadRef().beginParse(true); - let out_msg: MessageRelaxed = loadMessageRelaxed(slice1, ((slice: Slice) => { - return slice + let out_msg: MessageRelaxed = loadMessageRelaxed(slice1, ((slice: Slice) => { + return slice.asCell() })); return { @@ -7897,7 +7897,7 @@ export function loadOutAction(slice: Slice): OutAction { if (((slice.remainingBits >= 32) && (slice.preloadUint(32) == 0xad4de08e))) { slice.loadUint(32); let slice1 = slice.loadRef().beginParse(true); - let new_code: Slice = slice1; + let new_code: Cell = slice1.asCell(); return { kind: 'OutAction_action_set_code', new_code: new_code, @@ -7935,9 +7935,9 @@ export function storeOutAction(outAction: OutAction): (builder: Builder) => void builder.storeUint(0x0ec3c86d, 32); builder.storeUint(outAction.mode, 8); let cell1 = beginCell(); - storeMessageRelaxed(outAction.out_msg, ((arg: Slice) => { + storeMessageRelaxed(outAction.out_msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -7949,7 +7949,7 @@ export function storeOutAction(outAction: OutAction): (builder: Builder) => void return ((builder: Builder) => { builder.storeUint(0xad4de08e, 32); let cell1 = beginCell(); - cell1.storeSlice(outAction.new_code); + cell1.storeSlice(outAction.new_code.beginParse(true)); builder.storeRef(cell1); }) @@ -7990,7 +7990,7 @@ export function loadLibRef(slice: Slice): LibRef { if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { slice.loadUint(1); let slice1 = slice.loadRef().beginParse(true); - let library: Slice = slice1; + let library: Cell = slice1.asCell(); return { kind: 'LibRef_libref_ref', library: library, @@ -8012,7 +8012,7 @@ export function storeLibRef(libRef: LibRef): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0b1, 1); let cell1 = beginCell(); - cell1.storeSlice(libRef.library); + cell1.storeSlice(libRef.library.beginParse(true)); builder.storeRef(cell1); }) @@ -8024,7 +8024,7 @@ export function storeLibRef(libRef: LibRef): (builder: Builder) => void { export function loadOutListNode(slice: Slice): OutListNode { let slice1 = slice.loadRef().beginParse(true); - let prev: Slice = slice1; + let prev: Cell = slice1.asCell(); let action: OutAction = loadOutAction(slice); return { kind: 'OutListNode', @@ -8037,7 +8037,7 @@ export function loadOutListNode(slice: Slice): OutListNode { export function storeOutListNode(outListNode: OutListNode): (builder: Builder) => void { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(outListNode.prev); + cell1.storeSlice(outListNode.prev.beginParse(true)); builder.storeRef(cell1); storeOutAction(outListNode.action)(builder); }) @@ -8331,7 +8331,7 @@ export function loadLibDescr(slice: Slice): LibDescr { if (((slice.remainingBits >= 2) && (slice.preloadUint(2) == 0b00))) { slice.loadUint(2); let slice1 = slice.loadRef().beginParse(true); - let lib: Slice = slice1; + let lib: Cell = slice1.asCell(); let publishers: Hashmap = loadHashmap(slice, 256, loadTrue); return { kind: 'LibDescr', @@ -8347,7 +8347,7 @@ export function storeLibDescr(libDescr: LibDescr): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0b00, 2); let cell1 = beginCell(); - cell1.storeSlice(libDescr.lib); + cell1.storeSlice(libDescr.lib.beginParse(true)); builder.storeRef(cell1); storeHashmap(libDescr.publishers, storeTrue)(builder); }) @@ -9284,9 +9284,9 @@ _ config_addr:bits256 config:^(Hashmap 32 ^Cell) export function loadConfigParams(slice: Slice): ConfigParams { let config_addr: BitString = slice.loadBits(256); let slice1 = slice.loadRef().beginParse(true); - let config: Hashmap = loadHashmap(slice1, 32, ((slice: Slice) => { + let config: Hashmap = loadHashmap(slice1, 32, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); return { @@ -9301,10 +9301,10 @@ export function storeConfigParams(configParams: ConfigParams): (builder: Builder return ((builder: Builder) => { builder.storeBits(configParams.config_addr); let cell1 = beginCell(); - storeHashmap(configParams.config, ((arg: Slice) => { + storeHashmap(configParams.config, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) @@ -11070,9 +11070,9 @@ export function loadConfigProposal(slice: Slice): ConfigProposal { if (((slice.remainingBits >= 8) && (slice.preloadUint(8) == 0xf3))) { slice.loadUint(8); let param_id: number = slice.loadInt(32); - let param_value: Maybe = loadMaybe(slice, ((slice: Slice) => { + let param_value: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() })); let if_hash_equal: Maybe = loadMaybe(slice, ((slice: Slice) => { @@ -11094,10 +11094,10 @@ export function storeConfigProposal(configProposal: ConfigProposal): (builder: B return ((builder: Builder) => { builder.storeUint(0xf3, 8); builder.storeInt(configProposal.param_id, 32); - storeMaybe(configProposal.param_value, ((arg: Slice) => { + storeMaybe(configProposal.param_value, ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) @@ -12622,7 +12622,7 @@ export function loadBlockProof(slice: Slice): BlockProof { slice.loadUint(8); let proof_for: BlockIdExt = loadBlockIdExt(slice); let slice1 = slice.loadRef().beginParse(true); - let root: Slice = slice1; + let root: Cell = slice1.asCell(); let signatures: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); return loadBlockSignatures(slice1) @@ -12644,7 +12644,7 @@ export function storeBlockProof(blockProof: BlockProof): (builder: Builder) => v builder.storeUint(0xc3, 8); storeBlockIdExt(blockProof.proof_for)(builder); let cell1 = beginCell(); - cell1.storeSlice(blockProof.root); + cell1.storeSlice(blockProof.root.beginParse(true)); builder.storeRef(cell1); storeMaybe(blockProof.signatures, ((arg: BlockSignatures) => { return ((builder: Builder) => { @@ -12672,7 +12672,7 @@ export function loadProofChain(slice: Slice, arg0: number): ProofChain { } if (true) { let slice1 = slice.loadRef().beginParse(true); - let root: Slice = slice1; + let root: Cell = slice1.asCell(); let prev: ProofChain | undefined = ((arg0 - 1) ? ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); return loadProofChain(slice1, (arg0 - 1)) @@ -12698,7 +12698,7 @@ export function storeProofChain(proofChain: ProofChain): (builder: Builder) => v if ((proofChain.kind == 'ProofChain_chain_link')) { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(proofChain.root); + cell1.storeSlice(proofChain.root.beginParse(true)); builder.storeRef(cell1); if ((proofChain.prev != undefined)) { let cell1 = beginCell(); @@ -13058,7 +13058,7 @@ export function loadVmStackValue(slice: Slice): VmStackValue { if (((slice.remainingBits >= 8) && (slice.preloadUint(8) == 0x03))) { slice.loadUint(8); let slice1 = slice.loadRef().beginParse(true); - let _cell: Slice = slice1; + let _cell: Cell = slice1.asCell(); return { kind: 'VmStackValue_vm_stk_cell', _cell: _cell, @@ -13077,7 +13077,7 @@ export function loadVmStackValue(slice: Slice): VmStackValue { if (((slice.remainingBits >= 8) && (slice.preloadUint(8) == 0x05))) { slice.loadUint(8); let slice1 = slice.loadRef().beginParse(true); - let _cell: Slice = slice1; + let _cell: Cell = slice1.asCell(); return { kind: 'VmStackValue_vm_stk_builder', _cell: _cell, @@ -13138,7 +13138,7 @@ export function storeVmStackValue(vmStackValue: VmStackValue): (builder: Builder return ((builder: Builder) => { builder.storeUint(0x03, 8); let cell1 = beginCell(); - cell1.storeSlice(vmStackValue._cell); + cell1.storeSlice(vmStackValue._cell.beginParse(true)); builder.storeRef(cell1); }) @@ -13154,7 +13154,7 @@ export function storeVmStackValue(vmStackValue: VmStackValue): (builder: Builder return ((builder: Builder) => { builder.storeUint(0x05, 8); let cell1 = beginCell(); - cell1.storeSlice(vmStackValue._cell); + cell1.storeSlice(vmStackValue._cell.beginParse(true)); builder.storeRef(cell1); }) @@ -13184,7 +13184,7 @@ _ cell:^Cell st_bits:(## 10) end_bits:(## 10) { st_bits <= end_bits } export function loadVmCellSlice(slice: Slice): VmCellSlice { let slice1 = slice.loadRef().beginParse(true); - let _cell: Slice = slice1; + let _cell: Cell = slice1.asCell(); let st_bits: number = slice.loadUint(10); let end_bits: number = slice.loadUint(10); let st_ref: number = slice.loadUint(bitLen(4)); @@ -13209,7 +13209,7 @@ export function loadVmCellSlice(slice: Slice): VmCellSlice { export function storeVmCellSlice(vmCellSlice: VmCellSlice): (builder: Builder) => void { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(vmCellSlice._cell); + cell1.storeSlice(vmCellSlice._cell.beginParse(true)); builder.storeRef(cell1); builder.storeUint(vmCellSlice.st_bits, 10); builder.storeUint(vmCellSlice.end_bits, 10); @@ -13456,11 +13456,11 @@ export function storeVmGasLimits(vmGasLimits: VmGasLimits): (builder: Builder) = // _ libraries:(HashmapE 256 ^Cell) = VmLibraries; export function loadVmLibraries(slice: Slice): VmLibraries { - let libraries: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + let libraries: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { serialize: () => { throw new Error('Not implemented') }, parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(true); - return slice1 + return slice1.asCell() }), }, slice); @@ -13474,11 +13474,11 @@ export function loadVmLibraries(slice: Slice): VmLibraries { export function storeVmLibraries(vmLibraries: VmLibraries): (builder: Builder) => void { return ((builder: Builder) => { builder.storeDict(vmLibraries.libraries, Dictionary.Keys.BigUint(256), { - serialize: ((arg: Slice, builder: Builder) => { - ((arg: Slice) => { + serialize: ((arg: Cell, builder: Builder) => { + ((arg: Cell) => { return ((builder: Builder) => { let cell1 = beginCell(); - cell1.storeSlice(arg); + cell1.storeSlice(arg.beginParse(true)); builder.storeRef(cell1); }) diff --git a/test/generated_files/generated_test.ts b/test/generated_files/generated_test.ts index 13d899e..93ea548 100644 --- a/test/generated_files/generated_test.ts +++ b/test/generated_files/generated_test.ts @@ -162,7 +162,7 @@ export interface IntBits { readonly d: number; readonly g: BitString; readonly arg: Arg; - readonly x: Slice; + readonly x: Cell; } // a$_ {x:#} a:(IntBits (int (1 + x))) = IntBitsInside (x * 2); @@ -190,7 +190,7 @@ export interface IntBitsParametrized { readonly i: BitString; readonly j: number; readonly k: bigint; - readonly tc: Slice; + readonly tc: Cell; } // a$_ {x:#} a:(IntBitsParametrized x) = IntBitsParametrizedInside x; @@ -541,7 +541,7 @@ export interface ParamNamedArgInSecondConstr_b { export interface RefCombinatorAny { readonly kind: 'RefCombinatorAny'; - readonly msg: Maybe; + readonly msg: Maybe; } // a$_ n:# { 5 + n = 7 } = EqualityExpression; @@ -634,7 +634,7 @@ export interface RefCombinatorInRefHelper { export interface RefCombinatorInRef { readonly kind: 'RefCombinatorInRef'; - readonly msg: RefCombinatorInRefHelper; + readonly msg: RefCombinatorInRefHelper; } // _ a:Bool = BoolUser; @@ -1211,7 +1211,7 @@ export function loadIntBits(slice: Slice, loadArg: (slice: Slice) => Arg): let d: number = slice.loadInt(11); let g: BitString = slice.loadBits(2); let arg: Arg = loadArg(slice); - let x: Slice = slice; + let x: Cell = slice.asCell(); return { kind: 'IntBits', d: d, @@ -1227,7 +1227,7 @@ export function storeIntBits(intBits: IntBits, storeArg: (arg: Arg) => builder.storeInt(intBits.d, 11); builder.storeBits(intBits.g); storeArg(intBits.arg)(builder); - builder.storeSlice(intBits.x); + builder.storeSlice(intBits.x.beginParse(true)); }) } @@ -1285,7 +1285,7 @@ export function loadIntBitsParametrized(slice: Slice, e: number): IntBitsParamet let i: BitString = slice.loadBits((5 + e)); let j: number = slice.loadInt(5); let k: bigint = slice.loadUintBig(e); - let tc: Slice = slice; + let tc: Cell = slice.asCell(); return { kind: 'IntBitsParametrized', e: e, @@ -1306,7 +1306,7 @@ export function storeIntBitsParametrized(intBitsParametrized: IntBitsParametrize builder.storeBits(intBitsParametrized.i); builder.storeInt(intBitsParametrized.j, 5); builder.storeUint(intBitsParametrized.k, intBitsParametrized.e); - builder.storeSlice(intBitsParametrized.tc); + builder.storeSlice(intBitsParametrized.tc.beginParse(true)); }) } @@ -2447,8 +2447,8 @@ export function storeParamNamedArgInSecondConstr(paramNamedArgInSecondConstr: Pa export function loadRefCombinatorAny(slice: Slice): RefCombinatorAny { let slice1 = slice.loadRef().beginParse(true); - let msg: Maybe = loadMaybe(slice1, ((slice: Slice) => { - return slice + let msg: Maybe = loadMaybe(slice1, ((slice: Slice) => { + return slice.asCell() })); return { @@ -2461,9 +2461,9 @@ export function loadRefCombinatorAny(slice: Slice): RefCombinatorAny { export function storeRefCombinatorAny(refCombinatorAny: RefCombinatorAny): (builder: Builder) => void { return ((builder: Builder) => { let cell1 = beginCell(); - storeMaybe(refCombinatorAny.msg, ((arg: Slice) => { + storeMaybe(refCombinatorAny.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); @@ -2740,8 +2740,8 @@ export function storeRefCombinatorInRefHelper(refCombinatorInRefHelper: RefCo export function loadRefCombinatorInRef(slice: Slice): RefCombinatorInRef { let slice1 = slice.loadRef().beginParse(true); - let msg: RefCombinatorInRefHelper = loadRefCombinatorInRefHelper(slice1, ((slice: Slice) => { - return slice + let msg: RefCombinatorInRefHelper = loadRefCombinatorInRefHelper(slice1, ((slice: Slice) => { + return slice.asCell() })); return { @@ -2754,9 +2754,9 @@ export function loadRefCombinatorInRef(slice: Slice): RefCombinatorInRef { export function storeRefCombinatorInRef(refCombinatorInRef: RefCombinatorInRef): (builder: Builder) => void { return ((builder: Builder) => { let cell1 = beginCell(); - storeRefCombinatorInRefHelper(refCombinatorInRef.msg, ((arg: Slice) => { + storeRefCombinatorInRefHelper(refCombinatorInRef.msg, ((arg: Cell) => { return ((builder: Builder) => { - builder.storeSlice(arg); + builder.storeSlice(arg.beginParse(true)); }) }))(cell1); diff --git a/test/tlbgen.spec.ts b/test/tlbgen.spec.ts index 83ba38b..7392545 100644 --- a/test/tlbgen.spec.ts +++ b/test/tlbgen.spec.ts @@ -22,6 +22,9 @@ function deepEqual(object1: any, object2: any): boolean { if (object1 instanceof Slice && object2 instanceof Slice) { return object1.toString() == object2.toString(); } + if (object1 instanceof Cell && object2 instanceof Cell) { + return deepEqual(object1.beginParse(true), object2.beginParse(true)); + } if (object1 instanceof Address && object2 instanceof Address) { return object1.equals(object2); } @@ -79,7 +82,8 @@ function checkSameOnStoreLoad(expected: any, load: any, store: any, expectCell?: expectCell(slice) } let actual = load(slice) - expect(deepEqual(expected, actual)).toBeTruthy() + let equal = deepEqual(expected, actual); + expect(equal).toBeTruthy() } function checkDifferOnStoreLoad(expected: any, load: any, store: any) { @@ -270,11 +274,11 @@ describe('Generating tlb code', () => { let refCombinatorAny: RefCombinatorAny = { kind: 'RefCombinatorAny', - msg: { kind: 'Maybe_just', value: beginCell().storeUint(676, 10).endCell().beginParse() } + msg: { kind: 'Maybe_just', value: beginCell().storeUint(676, 10).endCell() } } checkSameOnStoreLoad(refCombinatorAny, loadRefCombinatorAny, storeRefCombinatorAny); - let msgEnvelope: RefCombinatorInRef = { kind: 'RefCombinatorInRef', msg: { kind: 'RefCombinatorInRefHelper', t: 3, y: { kind: 'Maybe_just', value: beginCell().storeUint(3, 32).endCell().beginParse() } } } + let msgEnvelope: RefCombinatorInRef = { kind: 'RefCombinatorInRef', msg: { kind: 'RefCombinatorInRefHelper', t: 3, y: { kind: 'Maybe_just', value: beginCell().storeUint(3, 32).endCell() } } } checkSameOnStoreLoad(msgEnvelope, loadRefCombinatorInRef, storeRefCombinatorInRef); }); @@ -467,7 +471,7 @@ describe('Generating tlb code', () => { a: { 'kind': 'IntBits', arg: BigInt(3), d: 5, g: beginCell().storeUint(3, 2).endCell().beginParse().loadBits(2), - x: beginCell().storeUint(76, 10).endCell().beginParse() + x: beginCell().storeUint(76, 10).endCell() }, x: 3 } @@ -481,7 +485,7 @@ describe('Generating tlb code', () => { a: { kind: 'IntBitsParametrized', e: 5, f: BigInt(3), h: BigInt(7), j: 9, k: BigInt(10), i: beginCell().storeUint(676, 10).endCell().beginParse().loadBits(10), - tc: beginCell().storeUint(76, 10).endCell().beginParse() + tc: beginCell().storeUint(76, 10).endCell() }, x: 5 } @@ -495,7 +499,7 @@ describe('Generating tlb code', () => { a: { kind: 'IntBitsParametrized', e: 6, f: BigInt(3), h: BigInt(7), j: 9, k: BigInt(10), i: beginCell().storeUint(676, 10).endCell().beginParse().loadBits(10), - tc: beginCell().storeUint(76, 10).endCell().beginParse() + tc: beginCell().storeUint(76, 10).endCell() }, x: 5 }