import { assertContractParameterType , BinaryReader } from '@neo-one/client-common' ; import { utils } from '@neo-one/utils' ; import { DeserializeWire , DeserializeWireBase , DeserializeWireBaseOptions } from '../Serializable' ; import { AnyContractParameter } from './AnyContractParameter' ; import { ArrayContractParameter } from './ArrayContractParameter' ; import { BooleanContractParameter } from './BooleanContractParameter' ; import { ByteArrayContractParameter } from './ByteArrayContractParameter' ; import { ContractParameterBase } from './ContractParameterBase' ; import { ContractParameterType } from './ContractParameterType' ; import { Hash160ContractParameter } from './Hash160ContractParameter' ; import { Hash256ContractParameter } from './Hash256ContractParameter' ; import { IntegerContractParameter } from './IntegerContractParameter' ; import { InteropInterfaceContractParameter } from './InteropInterfaceContractParameter' ; import { MapContractParameter } from './MapContractParameter' ; import { PublicKeyContractParameter } from './PublicKeyContractParameter' ; import { SignatureContractParameter } from './SignatureContractParameter' ; import { StringContractParameter } from './StringContractParameter' ; import { VoidContractParameter } from './VoidContractParameter' ; export type ContractParameter = SignatureContractParameter | BooleanContractParameter | IntegerContractParameter | Hash160ContractParameter | Hash256ContractParameter | ByteArrayContractParameter | SignatureContractParameter | PublicKeyContractParameter | StringContractParameter | ArrayContractParameter | MapContractParameter | InteropInterfaceContractParameter | VoidContractParameter | AnyContractParameter ; export const deserializeContractParameterWireBase = ( options ) : ContractParameter => { const { reader } = options ; const type = assertContractParameterType ( reader . clone ( ) . readUInt8 ( ) ) ; switch ( type ) { case ContractParameterType . Signature : return SignatureContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Boolean : return BooleanContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Integer : return IntegerContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Hash160 : return Hash160ContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Hash256 : return Hash256ContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . ByteArray : return ByteArrayContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . PublicKey : return PublicKeyContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . String : return StringContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Array : return ( ArrayContractParameter as any ) . deserializeWireBase ( options ) ; case ContractParameterType . Map : return ( MapContractParameter as any ) . deserializeWireBase ( options ) ; case ContractParameterType . InteropInterface : return InteropInterfaceContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Void : return VoidContractParameter . deserializeWireBase ( options ) ; case ContractParameterType . Any : return AnyContractParameter . deserializeWireBase ( options ) ; default : utils . assertNever ( type ) ; throw new Error ( 'For TS' ) ; } } ; function createDeserializeWire < T > ( deserializeWireBase ) { return ( options ) => deserializeWireBase ( { context : options . context , reader : new BinaryReader ( options . buffer ) } ) ; } export const deserializeWire = createDeserializeWire ( deserializeContractParameterWireBase ) ; ( ArrayContractParameter as { deserializeWireBase ? : DeserializeWireBase < ContractParameterBase > ; } ) . deserializeWireBase = ( options ) : ArrayContractParameter => { const { reader } = options ; reader . readUInt8 ( ) ; const value = reader . readArray ( ( ) => deserializeContractParameterWireBase ( options ) ) ; return new ArrayContractParameter ( value ) ; } ; ( ArrayContractParameter as { deserializeWire ? : DeserializeWire < ContractParameterBase > ; } ) . deserializeWire = createDeserializeWire ( ( ArrayContractParameter as any ) . deserializeWireBase . bind ( ArrayContractParameter ) ) ; ( MapContractParameter as { deserializeWireBase ? : DeserializeWireBase < ContractParameterBase > ; } ) . deserializeWireBase = ( options ) : MapContractParameter => { const { reader } = options ; reader . readUInt8 ( ) ; const value = reader . readArray ( ( ) => reader . readArray ( ( ) => deserializeContractParameterWireBase ( options ) ) ) ; return new MapContractParameter ( value as any ) ; } ; ( MapContractParameter as { deserializeWire ? : DeserializeWire < ContractParameterBase > ; } ) . deserializeWire = createDeserializeWire ( ( MapContractParameter as any ) . deserializeWireBase . bind ( MapContractParameter ) ) ;