import { DoubleMerkleInclusionProof , GenericMerkleIntervalTree , GenericMerkleIntervalTreeNode , MerkleIntervalTreeNode , } from '@pigi/core-db' ; import { DoubleMerkleIntervalTree , SubtreeContents } from '../../types' ; import { MerkleStateIntervalTree } from './state-interval-tree' ; import { AbiStateUpdate } from '../serialization' ; export class PlasmaBlock extends GenericMerkleIntervalTree implements DoubleMerkleIntervalTree { public subtrees : MerkleStateIntervalTree [ ] ; public generateLeafNodes ( ) { this . subtrees = [ ] ; super . generateLeafNodes ( ) ; } public generateLeafNode ( subtree ) { const merkleStateIntervalTree = new MerkleStateIntervalTree ( subtree . stateUpdates ) ; this . subtrees . push ( merkleStateIntervalTree ) ; return new GenericMerkleIntervalTreeNode ( merkleStateIntervalTree . root ( ) . hash , subtree . assetId ) ; } param stateUpdatePosition param assetIdPosition public getStateUpdateInclusionProof ( stateUpdatePosition , assetIdPosition ) { return { stateTreeInclusionProof : this . subtrees [ assetIdPosition ] . getInclusionProof ( stateUpdatePosition ) , assetTreeInclusionProof : this . getInclusionProof ( assetIdPosition ) , } ; } param stateUpdate param stateUpdateInclusionProof param blockRootHash public static verifyStateUpdateInclusionProof ( stateUpdate , stateUpdateInclusionProof , blockRootHash ) { const expectedRoot = MerkleStateIntervalTree . verifyExectedRoot ( stateUpdate , stateUpdateInclusionProof . stateTreeInclusionProof ) ; const addressLeafStart = Buffer . from ( stateUpdate . depositAddress . slice ( 2 ) , 'hex' ) ; const addressLeafNode = new GenericMerkleIntervalTreeNode ( expectedRoot . hash , addressLeafStart ) ; return GenericMerkleIntervalTree . verify ( addressLeafNode , stateUpdateInclusionProof . assetTreeInclusionProof , blockRootHash ) ; } }