Comparing version 12.3.2 to 12.3.3
@@ -12,3 +12,4 @@ /// <reference types="node" /> | ||
export declare function parseCurrencyCollection(slice: Slice): RawCurrencyCollection; | ||
export declare type RawCommonMessageInfo = { | ||
export declare type RawCommonMessageInfo = InternalCommonMessageInfo | ExternalOutCommonMessageInfo | ExternalInCommonMessageInfo; | ||
export declare type InternalCommonMessageInfo = { | ||
type: 'internal'; | ||
@@ -25,3 +26,4 @@ ihrDisabled: boolean; | ||
createdAt: number; | ||
} | { | ||
}; | ||
export declare type ExternalOutCommonMessageInfo = { | ||
type: 'external-out'; | ||
@@ -32,3 +34,4 @@ src: Address; | ||
createdAt: number; | ||
} | { | ||
}; | ||
export declare type ExternalInCommonMessageInfo = { | ||
type: 'external-in'; | ||
@@ -40,3 +43,4 @@ src: AddressExternal | null; | ||
export declare function parseCommonMsgInfo(slice: Slice): RawCommonMessageInfo; | ||
export declare type RawCommonMessageInfoRelaxed = { | ||
export declare type RawCommonMessageInfoRelaxed = InternalCommonMessageInfoRelaxed | ExternalOutCommonMessageInfoRelaxed; | ||
export declare type InternalCommonMessageInfoRelaxed = { | ||
type: 'internal'; | ||
@@ -53,3 +57,4 @@ ihrDisabled: boolean; | ||
createdAt: number; | ||
} | { | ||
}; | ||
export declare type ExternalOutCommonMessageInfoRelaxed = { | ||
type: 'external-out'; | ||
@@ -112,6 +117,8 @@ src: Address | null; | ||
export declare function parseCreditPhase(slice: Slice): RawCreditPhase; | ||
export declare type RawComputePhase = { | ||
export declare type RawComputePhase = SkippedComputePhase | ComputedComputePhase; | ||
export declare type SkippedComputePhase = { | ||
type: 'skipped'; | ||
reason: 'no-state' | 'bad-state' | 'no-gas'; | ||
} | { | ||
}; | ||
export declare type ComputedComputePhase = { | ||
type: 'computed'; | ||
@@ -150,3 +157,4 @@ success: boolean; | ||
export declare function parseActionPhase(slice: Slice): RawActionPhase; | ||
export declare type RawBouncePhase = { | ||
export declare type RawBouncePhase = OkBouncePhase | NoFundsBouncePhase | NegativeFundsBouncePhase; | ||
export declare type OkBouncePhase = { | ||
type: 'ok'; | ||
@@ -156,12 +164,15 @@ msgSize: RawStorageUsedShort; | ||
fwdFees: BN; | ||
} | { | ||
}; | ||
export declare type NoFundsBouncePhase = { | ||
type: 'no-funds'; | ||
msgSize: RawStorageUsedShort; | ||
fwdFees: BN; | ||
} | { | ||
}; | ||
export declare type NegativeFundsBouncePhase = { | ||
type: 'negative-funds'; | ||
}; | ||
export declare function parseBouncePhase(slice: Slice): RawBouncePhase; | ||
export declare type RawTransactionDescription = { | ||
type: 'generic'; | ||
export declare type RawTransactionDescription = GenericTransactionDescription | StorageTransactionDescription | TickTockTransactionDescription; | ||
export declare type GenericTransactionDescription = { | ||
type: "generic"; | ||
creditFirst: boolean; | ||
@@ -175,7 +186,9 @@ storagePhase: RawStoragePhase | null; | ||
destroyed: boolean; | ||
} | { | ||
type: 'storage'; | ||
}; | ||
export declare type StorageTransactionDescription = { | ||
type: "storage"; | ||
storagePhase: RawStoragePhase; | ||
} | { | ||
type: 'tick-tock'; | ||
}; | ||
export declare type TickTockTransactionDescription = { | ||
type: "tick-tock"; | ||
isTock: boolean; | ||
@@ -219,8 +232,11 @@ storagePhase: RawStoragePhase; | ||
export declare function parseStorageInfo(cs: Slice): RawStorageInfo; | ||
export declare type RawAccountState = { | ||
export declare type RawAccountState = UninitAccountState | ActiveAccountState | FrozenAccountState; | ||
export declare type UninitAccountState = { | ||
type: 'uninit'; | ||
} | { | ||
}; | ||
export declare type ActiveAccountState = { | ||
type: 'active'; | ||
state: RawStateInit; | ||
} | { | ||
}; | ||
export declare type FrozenAccountState = { | ||
type: 'frozen'; | ||
@@ -227,0 +243,0 @@ stateHash: Buffer; |
@@ -33,4 +33,6 @@ /// <reference types="node" /> | ||
setTopUppedArray(array: Buffer, fullfilledBytes?: boolean): void; | ||
getTopUppedLength(): number; | ||
writeTopUppedArray(b: Buffer, start?: number): void; | ||
getTopUppedArray(): Buffer; | ||
equals(src: BitString): boolean; | ||
} |
@@ -249,16 +249,19 @@ "use strict"; | ||
} | ||
getTopUppedArray() { | ||
const ret = this.clone(); | ||
let tu = Math.ceil(ret.cursor / 8) * 8 - ret.cursor; | ||
getTopUppedLength() { | ||
return Math.ceil(this.cursor / 8); | ||
} | ||
writeTopUppedArray(b, start = 0) { | ||
__classPrivateFieldGet(this, _BitString_buffer, "f").copy(b, start); | ||
const len = this.getTopUppedLength(); | ||
const tu = len * 8 - this.cursor; | ||
if (tu > 0) { | ||
tu = tu - 1; | ||
ret.writeBit(true); | ||
while (tu > 0) { | ||
tu = tu - 1; | ||
ret.writeBit(false); | ||
} | ||
const bit = 1 << (tu - 1); | ||
b[start + len - 1] = (b[start + len - 1] | bit) & (~(bit - 1)); | ||
} | ||
__classPrivateFieldSet(ret, _BitString_buffer, __classPrivateFieldGet(ret, _BitString_buffer, "f").slice(0, Math.ceil(ret.cursor / 8)), "f"); | ||
return __classPrivateFieldGet(ret, _BitString_buffer, "f"); | ||
} | ||
getTopUppedArray() { | ||
const ret = Buffer.alloc(this.getTopUppedLength()); | ||
this.writeTopUppedArray(ret); | ||
return ret; | ||
} | ||
equals(src) { | ||
@@ -265,0 +268,0 @@ if (src.cursor !== this.cursor) { |
@@ -62,9 +62,2 @@ "use strict"; | ||
exports.getMaxDepth = getMaxDepth; | ||
function getMaxDepthAsArray(cell) { | ||
const maxDepth = getMaxDepth(cell); | ||
const d = Uint8Array.from({ length: 2 }, () => 0); | ||
d[1] = maxDepth % 256; | ||
d[0] = Math.floor(maxDepth / 256); | ||
return Buffer.from(d); | ||
} | ||
function getMaxLevel(cell) { | ||
@@ -84,8 +77,5 @@ //TODO level calculation differ for exotic cells | ||
function getRefsDescriptor(cell) { | ||
const d1 = Uint8Array.from({ length: 1 }, () => 0); | ||
d1[0] = cell.refs.length + (cell.isExotic ? 1 : 0) * 8 + getMaxLevel(cell) * 32; | ||
return Buffer.from(d1); | ||
return cell.refs.length + (cell.isExotic ? 1 : 0) * 8 + getMaxLevel(cell) * 32; | ||
} | ||
function getBitsDescriptor(cell) { | ||
const d2 = Uint8Array.from({ length: 1 }, () => 0); | ||
let len = cell.bits.cursor; | ||
@@ -95,28 +85,22 @@ if (cell.isExotic) { | ||
} | ||
d2[0] = Math.ceil(len / 8) + Math.floor(len / 8); | ||
return Buffer.from(d2); | ||
return Math.ceil(len / 8) + Math.floor(len / 8); | ||
} | ||
function getDataWithDescriptors(cell) { | ||
const d1 = getRefsDescriptor(cell); | ||
const d2 = getBitsDescriptor(cell); | ||
const tuBits = cell.bits.getTopUppedArray(); | ||
return Buffer.concat([d1, d2, tuBits]); | ||
} | ||
function getRepr(cell) { | ||
const reprArray = []; | ||
reprArray.push(getDataWithDescriptors(cell)); | ||
for (let k in cell.refs) { | ||
const i = cell.refs[k]; | ||
reprArray.push(getMaxDepthAsArray(i)); | ||
const tuLen = cell.bits.getTopUppedLength(); | ||
const repr = Buffer.alloc(2 + tuLen + (2 + 32) * cell.refs.length); | ||
let reprCursor = 0; | ||
repr[reprCursor++] = getRefsDescriptor(cell); | ||
repr[reprCursor++] = getBitsDescriptor(cell); | ||
cell.bits.writeTopUppedArray(repr, reprCursor); | ||
reprCursor += tuLen; | ||
for (const c of cell.refs) { | ||
const md = getMaxDepth(c); | ||
repr[reprCursor++] = Math.floor(md / 256); | ||
repr[reprCursor++] = md % 256; | ||
} | ||
for (let k in cell.refs) { | ||
const i = cell.refs[k]; | ||
reprArray.push(i.hash()); | ||
for (const c of cell.refs) { | ||
c.hash().copy(repr, reprCursor); | ||
reprCursor += 32; | ||
} | ||
let x = Buffer.alloc(0); | ||
for (let k in reprArray) { | ||
const i = reprArray[k]; | ||
x = Buffer.concat([x, i]); | ||
} | ||
return x; | ||
return repr; | ||
} | ||
@@ -340,18 +324,23 @@ function hashCell(cell) { | ||
// | ||
function serializeForBoc(cell, refs, sSize) { | ||
const reprArray = []; | ||
reprArray.push(getRefsDescriptor(cell)); | ||
reprArray.push(getBitsDescriptor(cell)); | ||
function calcCellSerializedSize(cell, sSize) { | ||
return (2 + // descriptors | ||
(cell.isExotic ? 1 : 0) + | ||
cell.bits.getTopUppedLength() + | ||
cell.refs.length * sSize); | ||
} | ||
function serializeForBoc(cell, refs, sSize, repr, reprCursor) { | ||
repr[reprCursor++] = getRefsDescriptor(cell); | ||
repr[reprCursor++] = getBitsDescriptor(cell); | ||
if (cell.isExotic) { | ||
if (cell.kind === 'pruned') { | ||
reprArray.push(Buffer.from([1])); | ||
repr[reprCursor++] = 1; | ||
} | ||
else if (cell.kind === 'library_reference') { | ||
reprArray.push(Buffer.from([2])); | ||
repr[reprCursor++] = 2; | ||
} | ||
else if (cell.kind === 'merkle_proof') { | ||
reprArray.push(Buffer.from([3])); | ||
repr[reprCursor++] = 3; | ||
} | ||
else if (cell.kind === 'merkle_update') { | ||
reprArray.push(Buffer.from([4])); | ||
repr[reprCursor++] = 4; | ||
} | ||
@@ -362,22 +351,13 @@ else { | ||
} | ||
reprArray.push(cell.bits.getTopUppedArray()); | ||
cell.bits.writeTopUppedArray(repr, reprCursor); | ||
reprCursor += cell.bits.getTopUppedLength(); | ||
for (let refIndexInt of refs) { | ||
// const i = cell.refs[k]; | ||
// const refHash = (await i.hash()).toString('hex'); | ||
// const refIndexInt = cellsIndex[refHash]; | ||
// refIndexInt | ||
let refIndexHex = refIndexInt.toString(16); | ||
while (refIndexHex.length < sSize * 2) { | ||
// Add leading zeros | ||
refIndexHex = '0' + refIndexHex; | ||
} | ||
const reference = Buffer.from(refIndexHex, 'hex'); | ||
reprArray.push(reference); | ||
writeNumber(repr, reprCursor, refIndexInt, sSize); | ||
reprCursor += sSize; | ||
} | ||
let x = Buffer.alloc(0); | ||
for (let k in reprArray) { | ||
const i = reprArray[k]; | ||
x = Buffer.concat([x, i]); | ||
} | ||
function writeNumber(b, start, n, bytes) { | ||
for (let i = bytes - 1; i >= 0; i--) { | ||
b[start++] = (n >> (i * 8)) & 0xff; | ||
} | ||
return x; | ||
} | ||
@@ -391,6 +371,7 @@ function serializeToBoc(cell, has_idx = true, hash_crc32 = true, has_cache_bits = false, flags = 0) { | ||
const s_bytes = Math.max(Math.ceil(s / 8), 1); | ||
const sizes = allCells.map((c, i) => calcCellSerializedSize(c.cell, s_bytes)); | ||
let full_size = 0; | ||
let sizeIndex = []; | ||
for (let cell_info of allCells) { | ||
full_size = full_size + (serializeForBoc(cell_info.cell, cell_info.refs, s_bytes)).length; | ||
for (let i = 0; i < sizes.length; i++) { | ||
full_size += sizes[i]; | ||
sizeIndex.push(full_size); | ||
@@ -400,28 +381,47 @@ } | ||
const offset_bytes = Math.max(Math.ceil(offset_bits / 8), 1); | ||
const serialization = __1.BitString.alloc((1023 + 32 * 4 + 32 * 3) * allCells.length); | ||
serialization.writeBuffer(reachBocMagicPrefix); | ||
serialization.writeBitArray([has_idx, hash_crc32, has_cache_bits]); | ||
serialization.writeUint(flags, 2); | ||
serialization.writeUint(s_bytes, 3); | ||
serialization.writeUint8(offset_bytes); | ||
serialization.writeUint(cells_num, s_bytes * 8); | ||
serialization.writeUint(1, s_bytes * 8); // One root for now | ||
serialization.writeUint(0, s_bytes * 8); // Complete BOCs only | ||
serialization.writeUint(full_size, offset_bytes * 8); | ||
serialization.writeUint(0, s_bytes * 8); // Root shoulh have index 0 | ||
const serialization = Buffer.alloc(4 + // magic | ||
1 + // flags and s_bytes | ||
1 + // offset_bytes | ||
3 * s_bytes + // cells_num, roots, complete | ||
offset_bytes + // full_size | ||
s_bytes + // root_idx | ||
(has_idx ? cells_num * offset_bytes : 0) + | ||
full_size + | ||
(hash_crc32 ? 4 : 0)); | ||
let serCursor = 0; | ||
reachBocMagicPrefix.copy(serialization); | ||
serCursor = 4; | ||
serialization[serCursor++] = ((has_idx ? 1 : 0) << 7) | | ||
((hash_crc32 ? 1 : 0) << 6) | | ||
((has_cache_bits ? 1 : 0) << 5) | | ||
flags << 3 | | ||
s_bytes; | ||
serialization[serCursor++] = offset_bytes; | ||
writeNumber(serialization, serCursor, cells_num, s_bytes); | ||
serCursor += s_bytes; | ||
writeNumber(serialization, serCursor, 1, s_bytes); | ||
serCursor += s_bytes; | ||
writeNumber(serialization, serCursor, 0, s_bytes); | ||
serCursor += s_bytes; | ||
writeNumber(serialization, serCursor, full_size, offset_bytes); | ||
serCursor += offset_bytes; | ||
writeNumber(serialization, serCursor, 0, s_bytes); | ||
serCursor += s_bytes; | ||
if (has_idx) { | ||
allCells.forEach((cell_data, index) => serialization.writeUint(sizeIndex[index], offset_bytes * 8)); | ||
allCells.forEach((_, index) => { | ||
writeNumber(serialization, serCursor, sizeIndex[index], offset_bytes); | ||
serCursor += offset_bytes; | ||
}); | ||
} | ||
for (let cell_info of allCells) { | ||
for (let i = 0; i < cells_num; i++) { | ||
//TODO it should be async map or async for | ||
const refcell_ser = serializeForBoc(cell_info.cell, cell_info.refs, s_bytes); | ||
serialization.writeBuffer(refcell_ser); | ||
serializeForBoc(allCells[i].cell, allCells[i].refs, s_bytes, serialization, serCursor); | ||
serCursor += sizes[i]; | ||
} | ||
let ser_arr = serialization.getTopUppedArray(); | ||
if (hash_crc32) { | ||
ser_arr = Buffer.concat([ser_arr, (0, crc32c_1.crc32c)(ser_arr)]); | ||
(0, crc32c_1.crc32c)(serialization.subarray(0, serialization.length - 4)).copy(serialization, serialization.length - 4); | ||
} | ||
return ser_arr; | ||
return serialization; | ||
}); | ||
} | ||
exports.serializeToBoc = serializeToBoc; |
@@ -21,3 +21,3 @@ "use strict"; | ||
nativeCell.bits.writeBit(1); | ||
expect(await cell.hash()).toEqual(Buffer.from(await nativeCell.hash())); | ||
expect(cell.hash()).toEqual(Buffer.from(await nativeCell.hash())); | ||
}); | ||
@@ -24,0 +24,0 @@ it('should correctly load cell', async () => { |
@@ -53,3 +53,3 @@ export { BitString } from './boc/BitString'; | ||
export { safeSign, safeSignVerify } from './client/safeSign'; | ||
export { parseTransaction, parseAccountStatus, parseCurrencyCollection, parseCommonMsgInfo, parseStateInit, parseMessage, parseMessageRelaxed, parseHashUpdate, parseAccountChange, parseStorageUsedShort, parseStoragePhase, parseCreditPhase, parseComputePhase, parseActionPhase, parseBouncePhase, parseTransactionDescription, parseRawTickTock, parseStorageUsed, parseStorageInfo, parseAccountState, parseAccountStorage, parseAccount, parseShardIdent, parseShardAccount, parseDepthBalanceInfo, parseShardAccounts, parseShardStateUnsplit, parseMasterchainStateExtra, RawAccountStatus, RawCurrencyCollection, RawCommonMessageInfo, RawStateInit, RawMessage, RawHashUpdate, RawAccountStatusChange, RawStorageUsedShort, RawStoragePhase, RawComputePhase, RawActionPhase, RawBouncePhase, RawTransactionDescription, RawTransaction, RawTickTock, RawStorageUsed, RawStorageInfo, RawAccountState, RawAccountStorage, RawAccount, RawShardIdent, RawShardAccount, RawDepthBalanceInfo, RawShardAccountRef, RawShardStateUnsplit, RawCreditPhase, RawMasterChainStateExtra } from './block/parse'; | ||
export { parseTransaction, parseAccountStatus, parseCurrencyCollection, parseCommonMsgInfo, parseStateInit, parseMessage, parseMessageRelaxed, parseHashUpdate, parseAccountChange, parseStorageUsedShort, parseStoragePhase, parseCreditPhase, parseComputePhase, parseActionPhase, parseBouncePhase, parseTransactionDescription, parseRawTickTock, parseStorageUsed, parseStorageInfo, parseAccountState, parseAccountStorage, parseAccount, parseShardIdent, parseShardAccount, parseDepthBalanceInfo, parseShardAccounts, parseShardStateUnsplit, parseMasterchainStateExtra, RawAccountStatus, RawCurrencyCollection, RawCommonMessageInfo, InternalCommonMessageInfo, ExternalOutCommonMessageInfo, ExternalInCommonMessageInfo, InternalCommonMessageInfoRelaxed, ExternalOutCommonMessageInfoRelaxed, RawStateInit, RawMessage, RawHashUpdate, RawAccountStatusChange, RawStorageUsedShort, RawStoragePhase, RawComputePhase, SkippedComputePhase, ComputedComputePhase, RawActionPhase, RawBouncePhase, OkBouncePhase, NoFundsBouncePhase, NegativeFundsBouncePhase, RawTransactionDescription, GenericTransactionDescription, StorageTransactionDescription, TickTockTransactionDescription, RawTransaction, RawTickTock, RawStorageUsed, RawStorageInfo, RawAccountState, ActiveAccountState, UninitAccountState, FrozenAccountState, RawAccountStorage, RawAccount, RawShardIdent, RawShardAccount, RawDepthBalanceInfo, RawShardAccountRef, RawShardStateUnsplit, RawCreditPhase, RawMasterChainStateExtra, } from './block/parse'; | ||
export { StackNull, StackInt, StackNaN, StackCell, StackSlice, StackBuilder, StackTuple, StackItem, serializeStack, parseStack } from './block/stack'; | ||
@@ -56,0 +56,0 @@ export { TonClient4, TonClient4Parameters } from './client/TonClient4'; |
{ | ||
"name": "ton", | ||
"version": "12.3.2", | ||
"version": "12.3.3", | ||
"repository": "https://github.com/tonwhales/ton.git", | ||
@@ -14,5 +14,6 @@ "author": "Steve Korshakov <steve@korshakov.com>", | ||
"test": "jest --verbose --runInBand", | ||
"release": "yarn build && yarn test && yarn publish" | ||
"release": "yarn build && yarn release-it --npm.yarn1" | ||
}, | ||
"devDependencies": { | ||
"@release-it/keep-a-changelog": "^3.1.0", | ||
"@types/bn.js": "^5.1.0", | ||
@@ -30,2 +31,3 @@ "@types/jest": "^27.0.1", | ||
"karma-webpack": "^5.0.0", | ||
"release-it": "^15.5.1", | ||
"tonweb": "0.0.18", | ||
@@ -50,3 +52,17 @@ "ts-jest": "^27.0.5", | ||
"tweetnacl": "1.0.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"release-it": { | ||
"github": { | ||
"release": true | ||
}, | ||
"plugins": { | ||
"@release-it/keep-a-changelog": { | ||
"filename": "CHANGELOG.md" | ||
} | ||
} | ||
} | ||
} |
461786
11944
20
239