UNPKG

@ton/core

Version:

Core TypeScript library that implements low level primitives for TON blockchain.

29 lines (26 loc) 951 B
import { beginCell } from '../boc/Builder'; import { Cell } from '../boc/Cell'; import { DictionaryKeyTypes, Dictionary, DictionaryKey } from './Dictionary'; import { generateMerkleProof } from './generateMerkleProof'; function convertToMerkleUpdate(c1: Cell, c2: Cell): Cell { 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({ exotic: true }); } export function generateMerkleUpdate<K extends DictionaryKeyTypes, V>( dict: Dictionary<K, V>, key: K, keyObject: DictionaryKey<K>, newValue: V ): Cell { const oldProof = generateMerkleProof(dict, [key], keyObject).refs[0]; dict.set(key, newValue); const newProof = generateMerkleProof(dict, [key], keyObject).refs[0]; return convertToMerkleUpdate(oldProof, newProof); }