UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 2.47 kB
import{ObjectType,ValueType,OperatorType,WitnessType,ContextType,PackageAddress,GasTokenType,GasCoinType,RegistrarAddress,EntityAddress}from'../common.js';import{query_permissions}from'../call/permission.js';import{filterGuardInstruct}from'../call/guard-ins.js';import{Config}from'../local/config.js';const CONSTANTS=[{'name':'Protocol\x20Package\x20ID','value':PackageAddress,'description':'Protocol\x20package\x20ID'},{'name':'Gas\x20Token\x20Type','value':GasTokenType,'description':'Gas\x20token\x20type'},{'name':'Gas\x20Coin\x20Type','value':GasCoinType,'description':'Gas\x20coin\x20type'},{'name':'Entity\x20Linker\x20ID','value':RegistrarAddress,'description':'Entity\x20Linker\x20ID'},{'name':'Entity\x20Registrar\x20ID','value':EntityAddress,'description':'Entity\x20registrar\x20ID'}],VALUE_TYPES=Object['entries'](ValueType)['filter'](([a,b])=>isNaN(Number(a))&&a!=='Value')['map'](([a,b])=>({'name':a,'value':a,'description':'Value\x20type\x20'+a+'\x20=\x20'+b})),OBJECT_TYPES=Object['values'](ObjectType)['map'](a=>({'name':a,'value':a,'description':'Object\x20type\x20'+a}));export const INFO_CONSTANT={'type':'constants','constants':CONSTANTS,'value_types':VALUE_TYPES,'object_types':OBJECT_TYPES,'guard_instructions':Object['values'](OperatorType)['map'](a=>({'name':a,'value':a,'description':'Guard\x20instruction\x20'+a})),'guard_contexts':Object['values'](ContextType)['map'](a=>({'name':a,'value':a,'description':'Guard\x20context\x20'+a})),'guard_witnesses':Object['values'](WitnessType)['map'](a=>({'name':a,'value':a,'description':'Guard\x20witness\x20'+a}))};export async function queryProtocolInfo(a){switch(a['info']){case'constants':return{'info':'constants','result':INFO_CONSTANT['constants']};case'built-in\x20permissions':return{'info':'built-in\x20permissions','result':queryPermissions(a['filter']||{})};case'guard\x20instructions':return{'info':'guard\x20instructions','result':filterGuardInstruct(a['filter']||{})};case'current\x20network':return{'info':'current\x20network','result':await Config['Instance']()['network_get']()};case'value\x20types':return{'info':'value\x20types','result':INFO_CONSTANT['value_types']};default:throw new Error('Unsupported\x20info\x20type:\x20\x22'+a['info']+'\x22.\x20Valid\x20are:\x20\x22constants\x22,\x20\x22built-in\x20permissions\x22,\x20\x22guard\x20instructions\x22,\x20\x22current\x20network\x22,\x20\x22value\x20types\x22');}}export function queryPermissions(a){return query_permissions(a);}