Comparing version 0.14.1 to 0.14.2
@@ -121,2 +121,8 @@ "use strict"; | ||
this._hashes = hashes; | ||
Object.freeze(this); | ||
Object.freeze(this.refs); | ||
Object.freeze(this.bits); | ||
Object.freeze(this.mask); | ||
Object.freeze(this._depths); | ||
Object.freeze(this._hashes); | ||
} | ||
@@ -123,0 +129,0 @@ /** |
@@ -18,4 +18,4 @@ "use strict"; | ||
this[_a] = () => this.toString(); | ||
this._reader = reader; | ||
this._refs = refs; | ||
this._reader = reader.clone(); | ||
this._refs = [...refs]; | ||
} | ||
@@ -383,3 +383,3 @@ /** | ||
clone() { | ||
return new Slice(this._reader.clone(), [...this._refs]); | ||
return new Slice(this._reader, this._refs); | ||
} | ||
@@ -386,0 +386,0 @@ /** |
@@ -34,2 +34,8 @@ /// <reference types="node" /> | ||
Uint: (bits?: number | null | undefined) => DictionaryKey<bigint>; | ||
/** | ||
* Create standard buffer key | ||
* @param bytes number of bytes of a buffer | ||
* @returns DictionaryKey<Buffer> | ||
*/ | ||
Buffer: (bytes: number) => DictionaryKey<Buffer>; | ||
}; | ||
@@ -102,5 +108,5 @@ static Values: { | ||
static loadDirect<K, V>(key: DictionaryKey<K>, value: DictionaryValue<V>, sc: Slice): Dictionary<K, V>; | ||
private readonly key; | ||
private readonly value; | ||
private readonly values; | ||
private readonly _key; | ||
private readonly _value; | ||
private readonly _map; | ||
private constructor(); | ||
@@ -114,4 +120,6 @@ get size(): number; | ||
[Symbol.iterator](): IterableIterator<[K, V]>; | ||
keys(): K[]; | ||
values(): V[]; | ||
store(builder: Builder): void; | ||
storeDirect(builder: Builder): void; | ||
} |
@@ -47,35 +47,40 @@ "use strict"; | ||
constructor(key, value, values) { | ||
this.key = key; | ||
this.value = value; | ||
this.values = values; | ||
this._key = key; | ||
this._value = value; | ||
this._map = values; | ||
} | ||
get size() { | ||
return this.values.size; | ||
return this._map.size; | ||
} | ||
get(key) { | ||
return this.values.get(this.key.serialize(key)); | ||
; | ||
return this._map.get(this._key.serialize(key)); | ||
} | ||
has(key) { | ||
return this.values.has(this.key.serialize(key)); | ||
return this._map.has(this._key.serialize(key)); | ||
} | ||
set(key, value) { | ||
this.values.set(this.key.serialize(key), value); | ||
this._map.set(this._key.serialize(key), value); | ||
return this; | ||
} | ||
delete(key) { | ||
const k = this.key.serialize(key); | ||
return this.values.delete(k); | ||
const k = this._key.serialize(key); | ||
return this._map.delete(k); | ||
} | ||
clear() { | ||
this.values.clear(); | ||
this._map.clear(); | ||
} | ||
*[Symbol.iterator]() { | ||
for (const [k, v] of this.values) { | ||
const key = this.key.parse(k); | ||
for (const [k, v] of this._map) { | ||
const key = this._key.parse(k); | ||
yield [key, v]; | ||
} | ||
} | ||
keys() { | ||
return Array.from(this._map.keys()).map((v) => this._key.parse(v)); | ||
} | ||
values() { | ||
return Array.from(this._map.values()); | ||
} | ||
store(builder) { | ||
if (this.values.size === 0) { | ||
if (this._map.size === 0) { | ||
builder.storeBit(0); | ||
@@ -86,3 +91,3 @@ } | ||
let dd = (0, Builder_1.beginCell)(); | ||
(0, serializeDict_1.serializeDict)(this.values, this.key.bits, this.value.serialize, dd); | ||
(0, serializeDict_1.serializeDict)(this._map, this._key.bits, this._value.serialize, dd); | ||
builder.storeRef(dd.endCell()); | ||
@@ -92,6 +97,6 @@ } | ||
storeDirect(builder) { | ||
if (this.values.size === 0) { | ||
if (this._map.size === 0) { | ||
throw Error('Cannot store empty dictionary directly'); | ||
} | ||
(0, serializeDict_1.serializeDict)(this.values, this.key.bits, this.value.serialize, builder); | ||
(0, serializeDict_1.serializeDict)(this._map, this._key.bits, this._value.serialize, builder); | ||
} | ||
@@ -123,2 +128,10 @@ } | ||
return createUintKey(bits); | ||
}, | ||
/** | ||
* Create standard buffer key | ||
* @param bytes number of bytes of a buffer | ||
* @returns DictionaryKey<Buffer> | ||
*/ | ||
Buffer: (bytes) => { | ||
return createBufferKey(bytes); | ||
} | ||
@@ -219,2 +232,13 @@ }; | ||
} | ||
function createBufferKey(bytes) { | ||
return { | ||
bits: bytes * 8, | ||
serialize: (src) => { | ||
return (0, Builder_1.beginCell)().storeBuffer(src).endCell().beginParse().loadUintBig(bytes * 8); | ||
}, | ||
parse: (src) => { | ||
return (0, Builder_1.beginCell)().storeUint(src, bytes * 8).endCell().beginParse().loadBuffer(bytes); | ||
} | ||
}; | ||
} | ||
function createIntValue(bits) { | ||
@@ -221,0 +245,0 @@ const bt = (bits === null || bits === undefined) ? 257 : bits; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Builder_1 = require("../boc/Builder"); | ||
const Cell_1 = require("../boc/Cell"); | ||
const Dictionary_1 = require("./Dictionary"); | ||
const fs_1 = __importDefault(require("fs")); | ||
function storeBits(builder, src) { | ||
@@ -36,2 +41,26 @@ for (let s of src) { | ||
}); | ||
it('should parse config', () => { | ||
let cell = Cell_1.Cell.fromBoc(Buffer.from(fs_1.default.readFileSync(__dirname + '/__testdata__/config.txt', 'utf-8'), 'base64'))[0]; | ||
let configs = cell.beginParse().loadDictDirect(Dictionary_1.Dictionary.Keys.Int(32), Dictionary_1.Dictionary.Values.Cell()); | ||
let ids = [0, 1, 2, 4, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 28, 29, 31, 32, 34, 71, 72, -999, -71]; | ||
let keys = configs.keys(); | ||
for (let i of ids) { | ||
expect(keys).toContain(BigInt(i)); | ||
expect(configs.get(BigInt(i))).not.toBeUndefined(); | ||
expect(configs.has(BigInt(i))).toBe(true); | ||
} | ||
}); | ||
it('should parse bridge config', () => { | ||
let cell = Cell_1.Cell.fromBoc(Buffer.from(fs_1.default.readFileSync(__dirname + '/__testdata__/config.txt', 'utf-8'), 'base64'))[0]; | ||
let configs = cell.beginParse().loadDictDirect(Dictionary_1.Dictionary.Keys.Int(32), Dictionary_1.Dictionary.Values.Cell()); | ||
for (let i of [71n, 72n]) { | ||
let r = configs.get(i); | ||
let config = r.beginParse(); | ||
let bridgeAddress = config.loadBuffer(32); | ||
let oracleMultisigAddress = config.loadBuffer(32); | ||
let oracles = config.loadDict(Dictionary_1.Dictionary.Keys.Uint(256), Dictionary_1.Dictionary.Values.Buffer(32)); | ||
let externalChainAddress = config.loadBuffer(32); | ||
// console.warn(oracles); | ||
} | ||
}); | ||
}); |
{ | ||
"name": "ton-core", | ||
"version": "0.14.1", | ||
"version": "0.14.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/ton-community/ton-core.git", |
@@ -96,2 +96,9 @@ import inspectSymbol from 'symbol.inspect'; | ||
this._hashes = hashes; | ||
Object.freeze(this); | ||
Object.freeze(this.refs); | ||
Object.freeze(this.bits); | ||
Object.freeze(this.mask); | ||
Object.freeze(this._depths); | ||
Object.freeze(this._hashes); | ||
} | ||
@@ -98,0 +105,0 @@ |
@@ -16,4 +16,4 @@ import inspectSymbol from 'symbol.inspect'; | ||
constructor(reader: BitReader, refs: Cell[]) { | ||
this._reader = reader; | ||
this._refs = refs; | ||
this._reader = reader.clone(); | ||
this._refs = [...refs]; | ||
} | ||
@@ -423,3 +423,3 @@ | ||
clone() { | ||
return new Slice(this._reader.clone(), [...this._refs]); | ||
return new Slice(this._reader, this._refs); | ||
} | ||
@@ -426,0 +426,0 @@ |
import { beginCell, Builder } from "../boc/Builder"; | ||
import { Cell } from "../boc/Cell"; | ||
import { Dictionary } from "./Dictionary"; | ||
import fs from 'fs'; | ||
@@ -39,2 +41,29 @@ function storeBits(builder: Builder, src: string) { | ||
}); | ||
it('should parse config', () => { | ||
let cell = Cell.fromBoc(Buffer.from(fs.readFileSync(__dirname + '/__testdata__/config.txt', 'utf-8'), 'base64'))[0]; | ||
let configs = cell.beginParse().loadDictDirect(Dictionary.Keys.Int(32), Dictionary.Values.Cell()); | ||
let ids: number[] = [0, 1, 2, 4, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 28, 29, 31, 32, 34, 71, 72, -999, -71]; | ||
let keys = configs.keys(); | ||
for (let i of ids) { | ||
expect(keys).toContain(BigInt(i)); | ||
expect(configs.get(BigInt(i))).not.toBeUndefined(); | ||
expect(configs.has(BigInt(i))).toBe(true); | ||
} | ||
}); | ||
it('should parse bridge config', () => { | ||
let cell = Cell.fromBoc(Buffer.from(fs.readFileSync(__dirname + '/__testdata__/config.txt', 'utf-8'), 'base64'))[0]; | ||
let configs = cell.beginParse().loadDictDirect(Dictionary.Keys.Int(32), Dictionary.Values.Cell()); | ||
for (let i of [71n, 72n]) { | ||
let r = configs.get(i)!; | ||
let config = r.beginParse(); | ||
let bridgeAddress = config.loadBuffer(32); | ||
let oracleMultisigAddress = config.loadBuffer(32); | ||
let oracles = config.loadDict(Dictionary.Keys.Uint(256), Dictionary.Values.Buffer(32)); | ||
let externalChainAddress = config.loadBuffer(32); | ||
// console.warn(oracles); | ||
} | ||
}); | ||
}); |
@@ -47,2 +47,11 @@ import { Address } from "../address/Address"; | ||
return createUintKey(bits); | ||
}, | ||
/** | ||
* Create standard buffer key | ||
* @param bytes number of bytes of a buffer | ||
* @returns DictionaryKey<Buffer> | ||
*/ | ||
Buffer: (bytes: number) => { | ||
return createBufferKey(bytes); | ||
} | ||
@@ -153,26 +162,26 @@ } | ||
private readonly key: DictionaryKey<K>; | ||
private readonly value: DictionaryValue<V>; | ||
private readonly values: Map<bigint, V>; | ||
private readonly _key: DictionaryKey<K>; | ||
private readonly _value: DictionaryValue<V>; | ||
private readonly _map: Map<bigint, V>; | ||
private constructor(key: DictionaryKey<K>, value: DictionaryValue<V>, values: Map<bigint, V>) { | ||
this.key = key; | ||
this.value = value; | ||
this.values = values; | ||
this._key = key; | ||
this._value = value; | ||
this._map = values; | ||
} | ||
get size() { | ||
return this.values.size; | ||
return this._map.size; | ||
} | ||
get(key: K): V | undefined { | ||
return this.values.get(this.key.serialize(key));; | ||
return this._map.get(this._key.serialize(key)); | ||
} | ||
has(key: K): boolean { | ||
return this.values.has(this.key.serialize(key)); | ||
return this._map.has(this._key.serialize(key)); | ||
} | ||
set(key: K, value: V): this { | ||
this.values.set(this.key.serialize(key), value) | ||
this._map.set(this._key.serialize(key), value) | ||
return this; | ||
@@ -182,13 +191,13 @@ } | ||
delete(key: K) { | ||
const k = this.key.serialize(key); | ||
return this.values.delete(k) | ||
const k = this._key.serialize(key); | ||
return this._map.delete(k) | ||
} | ||
clear() { | ||
this.values.clear(); | ||
this._map.clear(); | ||
} | ||
*[Symbol.iterator](): IterableIterator<[K, V]> { | ||
for (const [k, v] of this.values) { | ||
const key = this.key.parse(k); | ||
for (const [k, v] of this._map) { | ||
const key = this._key.parse(k); | ||
yield [key, v] | ||
@@ -198,4 +207,12 @@ } | ||
keys() { | ||
return Array.from(this._map.keys()).map((v) => this._key.parse(v)); | ||
} | ||
values() { | ||
return Array.from(this._map.values()); | ||
} | ||
store(builder: Builder) { | ||
if (this.values.size === 0) { | ||
if (this._map.size === 0) { | ||
builder.storeBit(0); | ||
@@ -205,3 +222,3 @@ } else { | ||
let dd = beginCell(); | ||
serializeDict(this.values, this.key.bits, this.value.serialize, dd); | ||
serializeDict(this._map, this._key.bits, this._value.serialize, dd); | ||
builder.storeRef(dd.endCell()); | ||
@@ -212,6 +229,6 @@ } | ||
storeDirect(builder: Builder) { | ||
if (this.values.size === 0) { | ||
if (this._map.size === 0) { | ||
throw Error('Cannot store empty dictionary directly'); | ||
} | ||
serializeDict(this.values, this.key.bits, this.value.serialize, builder); | ||
serializeDict(this._map, this._key.bits, this._value.serialize, builder); | ||
} | ||
@@ -262,2 +279,14 @@ } | ||
function createBufferKey(bytes: number): DictionaryKey<Buffer> { | ||
return { | ||
bits: bytes * 8, | ||
serialize: (src) => { | ||
return beginCell().storeBuffer(src).endCell().beginParse().loadUintBig(bytes * 8); | ||
}, | ||
parse: (src) => { | ||
return beginCell().storeUint(src, bytes * 8).endCell().beginParse().loadBuffer(bytes); | ||
} | ||
} | ||
} | ||
function createIntValue(bits: number | null | undefined): DictionaryValue<bigint> { | ||
@@ -264,0 +293,0 @@ const bt = (bits === null || bits === undefined) ? 257 : bits; |
781822
221
12514
4