import { abi , BigNumber , AbiEncodable , AbiRange , hexStringify , } from '@pigi/core-utils' ; import { AbiStateObject } from './state-object' ; import { StateUpdate } from '../../types' ; param encoded returns const fromEncoded = ( encoded ) : AbiStateUpdate => { const decoded = abi . decode ( AbiStateUpdate . abiTypes , encoded ) ; const stateObject = AbiStateObject . from ( decoded [ 0 ] ) ; const range = AbiRange . from ( decoded [ 1 ] ) ; return new AbiStateUpdate ( stateObject , range , new BigNumber ( decoded [ 2 ] . toString ( ) ) , decoded [ 3 ] ) ; } ; param stateUpdate returns export const serializeStateUpdate = ( stateUpdate ) : string => { return JSON . stringify ( { range : { start : stateUpdate . range . start . toString ( ) , end : stateUpdate . range . end . toString ( ) , } , stateObject : stateUpdate . stateObject , depositAddress : stateUpdate . depositAddress , plasmaBlockNumber : stateUpdate . plasmaBlockNumber . toString ( ) , } ) ; } ; param stateUpdate returns export const deserializeStateUpdate = ( stateUpdate ) : StateUpdate => { const obj = JSON . parse ( stateUpdate ) ; return { range : { start : new BigNumber ( obj [ 'range' ] [ 'start' ] , 'hex' ) , end : new BigNumber ( obj [ 'range' ] [ 'end' ] , 'hex' ) , } , stateObject : obj [ 'stateObject' ] , depositAddress : obj [ 'depositAddress' ] , plasmaBlockNumber : new BigNumber ( obj [ 'plasmaBlockNumber' ] , 'hex' ) , } ; } ; /**
 * Represents a basic abi encodable AbiStateUpdate
 */ export class AbiStateUpdate implements StateUpdate , AbiEncodable { public static abiTypes = [ 'bytes' , 'bytes' , 'uint256' , 'address' ] ; constructor ( readonly stateObject , readonly range , readonly plasmaBlockNumber , readonly depositAddress ) { } returns get encoded ( ) : string { return abi . encode ( AbiStateUpdate . abiTypes , [ this . stateObject . encoded , this . range . encoded , hexStringify ( this . plasmaBlockNumber ) , this . depositAddress , ] ) ; } returns get jsonified ( ) : any { return { stateObject : this . stateObject . jsonified , range : this . range . jsonified , plasmaBlockNumber : this . plasmaBlockNumber , depositAddress : this . depositAddress , } ; } param value returns public static from ( value ) { if ( typeof value === 'string' ) { return fromEncoded ( value ) ; } throw new Error ( 'Got invalid argument type when casting to AbiStateUpdate.' ) ; } param other returns public equals ( other ) { return this . encoded === other . encoded ; } }