UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 1.34 kB
import{W_ERROR,WErrors}from'../exception.js';import{parseObjectType}from'../util.js';import{query_objects}from'./object.js';export async function queryObjectWithType(a,b,c,d){const e=await query_objects({'objects':[b],'no_cache':a['no_cache'],'network':a['network']});(!e['objects']||e['objects']['length']!==0x1)&&W_ERROR(WErrors['IsValidArgType'],'object\x20'+b+'\x20not\x20found');(!e['objects'][0x0]['type']||e['objects'][0x0]['type']!==c)&&W_ERROR(WErrors['IsValidArgType'],'object\x20'+b+'\x20type\x20'+e['objects'][0x0]['type']+'\x20is\x20not\x20'+c);const f=parseObjectType(e['objects'][0x0]['type_raw'],d);return!f&&W_ERROR(WErrors['IsValidArgType'],'object\x20'+b+'\x20type_raw\x20'+e['objects'][0x0]['type_raw']+'\x20is\x20not\x20'+d),{'object':e['objects'][0x0]['object'],'type':f};}export async function queryObjectsWithType(a,b,c,d,e){const f=await query_objects({'objects':b,'no_cache':a['no_cache'],'network':a['network']}),g=[];return f['objects']&&f['objects']['forEach'](h=>{if(h['type']===c){const i=parseObjectType(h['type_raw'],''+d);i&&g['push']({'object':h['object'],'type':i});}}),e&&g['length']!==b['length']&&W_ERROR(WErrors['InvalidParam'],'founded\x20'+g['length']+'\x20objects\x20'+g['map'](h=>h['object'])+'\x20,\x20expect\x20'+b['length']+':\x20'+b['filter'](h=>!g['map'](i=>i['object'])['includes'](h))),g;}