import { common , ContractParameterTypeModel , ECPoint , UInt160 , WildcardContainer } from '@neo-one/client-common' ; import { constants } from '@neo-one/utils' ; import { ContractABIModel , ContractEventDescriptorModel , ContractGroupModel , ContractManifestModel , ContractMethodDescriptorModel , ContractParameterDefinitionModel , ContractPermissionDescriptorModel , ContractPermissionModel , ContractStateModel , } from '../models' ; export const contractParamDefinitionModel = { any : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Any , name : 'param' } ) , boolean : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Boolean , name : 'param' } ) , byteArray : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . ByteArray , name : 'param' } ) , hash160 : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Hash160 , name : 'param' } ) , hash256 : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Hash256 , name : 'param' } ) , array : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Array , name : 'param' } ) , integer : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Integer , name : 'param' } ) , interopInterface : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . InteropInterface , name : 'param' } ) , map : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Map , name : 'param' } ) , publicKey : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . PublicKey , name : 'param' } ) , signature : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Signature , name : 'param' } ) , string : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . String , name : 'param' } ) , void : new ContractParameterDefinitionModel ( { type : ContractParameterTypeModel . Void , name : 'param' } ) } ; export const contractMethodDescriptorModel = ( parameters = [ contractParamDefinitionModel . boolean ] , returnType = ContractParameterTypeModel . Void , name = 'function' , offset = 0 ) => new ContractMethodDescriptorModel ( { name , parameters , returnType , offset , safe : true } ) ; export const contractEventDescriptorModel = ( parameters = [ contractParamDefinitionModel . boolean ] , name = 'event' ) => new ContractEventDescriptorModel ( { name , parameters } ) ; export const contractAbiModel = ( methods = [ contractMethodDescriptorModel ( ) ] , events = [ contractEventDescriptorModel ( ) ] , hash = common . bufferToUInt160 ( Buffer . alloc ( 20 , 1 ) ) ) => new ContractABIModel ( { hash , methods , events } ) ; export const contractGroupModel = ( publicKey = common . stringToECPoint ( constants . PRIVATE_NET_PUBLIC_KEY ) , signature = Buffer . from ( 'ccaab040cc25021c91567b75db4778853441869157b8f6aad960cdcf1069812480027a528ca9b98e2205027de20696f848cf81824eeb7af1d5110870870ceb67' , 'hex' ) ) => new ContractGroupModel ( { publicKey , signature } ) ; export const contractPermissionDescriptorModel = ( hashOrGroupType ) => { let hashOrGroup ; if ( hashOrGroupType === 'uint160' ) { hashOrGroup = common . bufferToUInt160 ( Buffer . alloc ( 20 , 1 ) ) ; } else if ( hashOrGroupType === 'ecpoint' ) { hashOrGroup = common . stringToECPoint ( constants . PRIVATE_NET_PUBLIC_KEY ) ; } return new ContractPermissionDescriptorModel ( { hashOrGroup } ) ; } ; export const contractPermissionModel = ( hashOrGroupType , methods = [ ] ) => new ContractPermissionModel ( { contract : contractPermissionDescriptorModel ( hashOrGroupType ) , methods } ) ; export const contractManifestModel = ( name = 'name1' , groups = [ contractGroupModel ( ) ] , abi = contractAbiModel ( ) , permissions = [ contractPermissionModel ( 'uint160' , [ 'method1' ] ) ] , trusts = [ contractPermissionDescriptorModel ( 'uint160' ) ] , supportedStandards = [ ] ) => new ContractManifestModel ( { name , groups , supportedStandards , abi , permissions , trusts } ) ; export const contractModel = ( id = 1 , script = Buffer . alloc ( 25 ) , manifest = contractManifestModel ( ) ) => new ContractStateModel ( { id , script , manifest } ) ;