From 323f0de01b698e9197412a0fc3dd5c9dca8720cb Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 26 Jan 2024 00:03:38 +0300 Subject: [PATCH 1/2] add `exotic` flag to .endCell params --- src/boc/Builder.ts | 6 ++++-- src/dict/generateMerkleProof.ts | 34 +++++++++++--------------------- src/dict/generateMerkleUpdate.ts | 22 +++++++++------------ 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/boc/Builder.ts b/src/boc/Builder.ts index 81b5cb4..38370c9 100644 --- a/src/boc/Builder.ts +++ b/src/boc/Builder.ts @@ -468,12 +468,14 @@ export class Builder { /** * Complete cell + * @param exotic exotic flag * @returns cell */ - endCell() { + endCell(exotic?: boolean) { return new Cell({ bits: this._bits.build(), - refs: this._refs + refs: this._refs, + exotic }); } diff --git a/src/dict/generateMerkleProof.ts b/src/dict/generateMerkleProof.ts index 32d7b89..ebfb0fb 100644 --- a/src/dict/generateMerkleProof.ts +++ b/src/dict/generateMerkleProof.ts @@ -5,31 +5,21 @@ import { DictionaryKeyTypes, Dictionary, DictionaryKey } from './Dictionary'; import { readUnaryLength } from './utils/readUnaryLength'; function convertToPrunedBranch(c: Cell): Cell { - return new Cell({ - exotic: true, - bits: beginCell() - .storeUint(1, 8) - .storeUint(1, 8) - .storeBuffer(c.hash(0)) - .storeUint(c.depth(0), 16) - .endCell() - .beginParse() - .loadBits(288), - }); + return beginCell() + .storeUint(1, 8) + .storeUint(1, 8) + .storeBuffer(c.hash(0)) + .storeUint(c.depth(0), 16) + .endCell(true); } function convertToMerkleProof(c: Cell): Cell { - return new Cell({ - exotic: true, - bits: beginCell() - .storeUint(3, 8) - .storeBuffer(c.hash(0)) - .storeUint(c.depth(0), 16) - .endCell() - .beginParse() - .loadBits(280), - refs: [c], - }); + return beginCell() + .storeUint(3, 8) + .storeBuffer(c.hash(0)) + .storeUint(c.depth(0), 16) + .storeRef(c) + .endCell(true); } function doGenerateMerkleProof( diff --git a/src/dict/generateMerkleUpdate.ts b/src/dict/generateMerkleUpdate.ts index 0e5c997..2b70668 100644 --- a/src/dict/generateMerkleUpdate.ts +++ b/src/dict/generateMerkleUpdate.ts @@ -4,19 +4,15 @@ import { DictionaryKeyTypes, Dictionary, DictionaryKey } from './Dictionary'; import { generateMerkleProof } from './generateMerkleProof'; function convertToMerkleUpdate(c1: Cell, c2: Cell): Cell { - return new Cell({ - exotic: true, - bits: beginCell() - .storeUint(4, 8) - .storeBuffer(c1.hash(0)) - .storeBuffer(c2.hash(0)) - .storeUint(c1.depth(0), 16) - .storeUint(c2.depth(0), 16) - .endCell() - .beginParse() - .loadBits(552), - refs: [c1, c2], - }); + return beginCell() + .storeUint(4, 8) + .storeBuffer(c1.hash(0)) + .storeBuffer(c2.hash(0)) + .storeUint(c1.depth(0), 16) + .storeUint(c2.depth(0), 16) + .storeRef(c1) + .storeRef(c2) + .endCell(true); } export function generateMerkleUpdate( From a8867353237e9ca93886d4507751b4bb4cd8b1a0 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 26 Jan 2024 00:11:24 +0300 Subject: [PATCH 2/2] change param from bool to object --- src/boc/Builder.ts | 6 +++--- src/dict/generateMerkleProof.ts | 4 ++-- src/dict/generateMerkleUpdate.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/boc/Builder.ts b/src/boc/Builder.ts index 38370c9..57b622e 100644 --- a/src/boc/Builder.ts +++ b/src/boc/Builder.ts @@ -468,14 +468,14 @@ export class Builder { /** * Complete cell - * @param exotic exotic flag + * @param opts options * @returns cell */ - endCell(exotic?: boolean) { + endCell(opts?: { exotic?: boolean }) { return new Cell({ bits: this._bits.build(), refs: this._refs, - exotic + exotic: opts?.exotic }); } diff --git a/src/dict/generateMerkleProof.ts b/src/dict/generateMerkleProof.ts index ebfb0fb..623d73f 100644 --- a/src/dict/generateMerkleProof.ts +++ b/src/dict/generateMerkleProof.ts @@ -10,7 +10,7 @@ function convertToPrunedBranch(c: Cell): Cell { .storeUint(1, 8) .storeBuffer(c.hash(0)) .storeUint(c.depth(0), 16) - .endCell(true); + .endCell({ exotic: true }); } function convertToMerkleProof(c: Cell): Cell { @@ -19,7 +19,7 @@ function convertToMerkleProof(c: Cell): Cell { .storeBuffer(c.hash(0)) .storeUint(c.depth(0), 16) .storeRef(c) - .endCell(true); + .endCell({ exotic: true }); } function doGenerateMerkleProof( diff --git a/src/dict/generateMerkleUpdate.ts b/src/dict/generateMerkleUpdate.ts index 2b70668..bf63b8c 100644 --- a/src/dict/generateMerkleUpdate.ts +++ b/src/dict/generateMerkleUpdate.ts @@ -12,7 +12,7 @@ function convertToMerkleUpdate(c1: Cell, c2: Cell): Cell { .storeUint(c2.depth(0), 16) .storeRef(c1) .storeRef(c2) - .endCell(true); + .endCell({ exotic: true }); } export function generateMerkleUpdate(