import { BinaryWriter , IntegerContractParameterJSON , IOHelper , utils } from '@neo-one/client-common' ; import { BN } from 'bn.js' ; import { DeserializeWireBaseOptions } from '../Serializable' ; import { ContractParameterBase } from './ContractParameterBase' ; import { ContractParameterType } from './ContractParameterType' ; export class IntegerContractParameter extends ContractParameterBase < IntegerContractParameter , IntegerContractParameterJSON , ContractParameterType . Integer > { public static deserializeWireBase ( options ) { const { reader } = options ; super . deserializeContractParameterBaseWireBase ( options ) ; const value = utils . fromSignedBuffer ( reader . readVarBytesLE ( ) ) ; return new this ( value ) ; } public readonly type = ContractParameterType . Integer ; public readonly value : BN ; private readonly sizeInternal : ( ) => number ; public constructor ( value ) { super ( ) ; this . value = value ; this . sizeInternal = utils . lazy ( ( ) => IOHelper . sizeOfVarBytesLE ( utils . toSignedBuffer ( this . value ) ) ) ; } public get size ( ) : number { return this . sizeInternal ( ) ; } public asBoolean ( ) { return ! this . value . isZero ( ) ; } public asBuffer ( useGetBuffer ? ) { if ( useGetBuffer ) { return this . value . eqn ( 0 ) ? Buffer . from ( [ ] ) : this . value . toBuffer ( 'le' ) ; } return utils . toSignedBuffer ( this . value ) ; } public asInteger ( ) { return this . value ; } public serializeWireBase ( writer ) { super . serializeWireBase ( writer ) ; writer . writeVarBytesLE ( utils . toSignedBuffer ( this . value ) ) ; } public serializeJSON ( ) { return { type : 'Integer' , value : this . value . toString ( 10 ) } ; } }