import { hash } from '@liskhq/lisk-cryptography' ; import { branchData } from './utils' ; import { NodeSide } from './constants' ; export class Branch { private _leftHash : Buffer ; private _rightHash : Buffer ; private _hash : Buffer ; private _data : Buffer ; public constructor ( leftHash , rightHash ) { this . _leftHash = leftHash ; this . _rightHash = rightHash ; this . _data = branchData ( this . _leftHash , this . _rightHash ) ; this . _hash = hash ( this . _data ) ; } public get hash ( ) { return this . _hash ; } public get data ( ) { return this . _data ; } public get leftHash ( ) { return this . _leftHash ; } public get rightHash ( ) { return this . _rightHash ; } public update ( newChild , nodeSide ) { if ( nodeSide === NodeSide . LEFT ) { this . _leftHash = newChild ; } else { this . _rightHash = newChild ; } this . _data = branchData ( this . leftHash , this . rightHash ) ; this . _hash = hash ( this . data ) ; } }