UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 26.3 kB
import{bcs}from'../../bcs/index.js';import{isValueTypeNumber,OperatorType,ValueType,parseValueType}from'../common.js';import{ContextType,MAX_ENV_PERMISSION_GUARD_COUNT}from'../common.js';import{W_ERROR,WErrors}from'../exception.js';import{Config,GetAccountOrMark_Address}from'../local/index.js';import{LocalMark}from'../local/local.js';import{GUARDQUERY,getGuardQueryInfo}from'./guard-ins.js';const ProgressHistoryFindConditionsBCS=bcs['struct']('ProgressHistoryFindConditions',{'node':bcs['option'](bcs['String']),'next_node':bcs['option'](bcs['String']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'find':bcs['U8']}),ProgressSessionFindConditionsBCS=bcs['struct']('ProgressSessionFindConditions',{'next_node':bcs['option'](bcs['String']),'find':bcs['U8']}),ProgressForwardFindConditionsBCS=bcs['struct']('ProgressForwardFindConditions',{'who':bcs['option'](bcs['Address']),'operation':bcs['option'](bcs['String']),'accomplished':bcs['option'](bcs['Bool']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'find':bcs['U8']}),StoreFromIdFilterBCS=bcs['struct']('StoreFromIdFilter',{'mode':bcs['U8'],'value':bcs['option'](bcs['Address'])}),RecordQueryConditionsBCS=bcs['struct']('RecordQueryConditions',{'recipient':bcs['Address'],'guard':bcs['option'](bcs['Address']),'time_min':bcs['option'](bcs['U64']),'time_max':bcs['option'](bcs['U64']),'amount_min':bcs['option'](bcs['U64']),'amount_max':bcs['option'](bcs['U64']),'store_from_id':bcs['option'](StoreFromIdFilterBCS)});export const getCallEnvAccount=async a=>{const b=await GetAccountOrMark_Address({'name_or_address':a['account']||''});return!b&&W_ERROR(WErrors['InvalidParam'],'account\x20'+a['account']+'\x20not\x20found'),a['account']=b,b;};function createSingleOperandNode(a,b){const c={'type':a,'node':b};return c;}export const resolveCallEnv=async a=>{a['network']=await Config['Instance']()['network_get'](a?.['network']);const b=await getCallEnvAccount(a);if(a?.['permission_guard']&&a['permission_guard']?.['length']>0x0){const c=await LocalMark['Instance']()['get_many_address_availables'](a['permission_guard']);if(c['length']!==a['permission_guard']['length']){const d=new Set(c),e=a['permission_guard']['filter'](f=>!d['has'](f));W_ERROR(WErrors['InvalidParam'],'permission_guard\x20not\x20found:\x20'+e['join'](',\x20'));}a['permission_guard']=[...c],a['permission_guard']['length']>MAX_ENV_PERMISSION_GUARD_COUNT&&W_ERROR(WErrors['InvalidParam'],'permission_guard\x20length\x20'+a['permission_guard']['length']+'\x20exceeds\x20'+MAX_ENV_PERMISSION_GUARD_COUNT);}if(a?.['referrer']){const f=await GetAccountOrMark_Address({'name_or_address':a['referrer']||''});f?a['referrer']=f:W_ERROR(WErrors['InvalidParam'],'referrer\x20'+a['referrer']+'\x20not\x20found');}return b;};export const checkType=(a,b,c)=>{if(b==='variable')return;else{if(b==='number'){if(isValueTypeNumber(a)||a===ContextType['TypeClock']||a===ValueType['Value'])return;}else{if(b===ValueType['Address']){if(a===ContextType['TypeSigner']||a===ContextType['TypeGuard']||a===ValueType['Value'])return;}else{if(a===ValueType['Value'])return;else{if(b===ValueType['Value'])return;else{if(b==='vec_number'){if(a===ValueType['VecU8']||a===ValueType['VecU16']||a===ValueType['VecU32']||a===ValueType['VecU64']||a===ValueType['VecU128']||a===ValueType['VecU256'])return;}else{if(b==='vec'){if(a===ValueType['VecBool']||a===ValueType['VecAddress']||a===ValueType['VecString']||a===ValueType['VecU8']||a===ValueType['VecU16']||a===ValueType['VecU32']||a===ValueType['VecU64']||a===ValueType['VecU128']||a===ValueType['VecU256'])return;}}}}}}}a!==b&&W_ERROR(WErrors['InvalidParam'],'checkType:\x20'+a+'\x20require\x20type:\x20'+b+'\x20with\x20node:\x20'+JSON['stringify'](c));};const parseNode=a=>{a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseNode:\x20Unexpected\x20end\x20of\x20output\x20while\x20parsing\x20node');const b=a['output'][a['currentPosition']];a['currentPosition']++;switch(b){case ContextType['TypeConstant']:a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseNode:\x20Missing\x20identifier\x20after\x20TypeConstant\x20opcode');const c=a['output'][a['currentPosition']];a['currentPosition']++;return{'type':'identifier','identifier':c};case OperatorType['TypeQuery']:return parseQueryNode(a);case OperatorType['TypeLogicAsU256GreaterEqual']:return parseMultiOperandNode(a,'logic_as_u256_greater_or_equal');case OperatorType['TypeLogicAsU256LesserEqual']:return parseMultiOperandNode(a,'logic_as_u256_lesser_or_equal');case OperatorType['TypeLogicAsU256Equal']:return parseMultiOperandNode(a,'logic_as_u256_equal');case OperatorType['TypeLogicAsU256Greater']:return parseMultiOperandNode(a,'logic_as_u256_greater');case OperatorType['TypeLogicAsU256Lesser']:return parseMultiOperandNode(a,'logic_as_u256_lesser');case OperatorType['TypeLogicEqual']:return parseMultiOperandNode(a,'logic_equal');case OperatorType['TypeLogicAnd']:return parseMultiOperandNode(a,'logic_and');case OperatorType['TypeLogicOr']:return parseMultiOperandNode(a,'logic_or');case OperatorType['TypeStringContains']:return parseMultiOperandNode(a,'logic_string_contains');case OperatorType['TypeStringNocaseContains']:return parseMultiOperandNode(a,'logic_string_nocase_contains');case OperatorType['TypeStringNocaseEqual']:return parseMultiOperandNode(a,'logic_string_nocase_equal');case OperatorType['TypeNumberAdd']:return parseMultiOperandNode(a,'calc_number_add');case OperatorType['TypeNumberSubtract']:return parseMultiOperandNode(a,'calc_number_subtract');case OperatorType['TypeNumberMultiply']:return parseMultiOperandNode(a,'calc_number_multiply');case OperatorType['TypeNumberDivide']:return parseMultiOperandNode(a,'calc_number_divide');case OperatorType['TypeNumberMod']:return parseMultiOperandNode(a,'calc_number_mod');case OperatorType['TypeLogicNot']:return parseSingleOperandNode(a,'logic_not');case OperatorType['TypeStringLength']:return parseSingleOperandNode(a,'calc_string_length');case OperatorType['TypeNumberAddress']:return parseSingleOperandNode(a,'convert_number_address');case OperatorType['TypeAddressNumber']:return parseSingleOperandNode(a,'convert_address_number');case OperatorType['TypeNumberString']:return parseSingleOperandNode(a,'convert_number_string');case OperatorType['TypeStringNumber']:return parseSingleOperandNode(a,'convert_string_number');case OperatorType['TypeSafeU8']:return parseSingleOperandNode(a,'convert_safe_u8');case OperatorType['TypeSafeU16']:return parseSingleOperandNode(a,'convert_safe_u16');case OperatorType['TypeSafeU32']:return parseSingleOperandNode(a,'convert_safe_u32');case OperatorType['TypeSafeU64']:return parseSingleOperandNode(a,'convert_safe_u64');case OperatorType['TypeSafeU128']:return parseSingleOperandNode(a,'convert_safe_u128');case OperatorType['TypeSafeU256']:return parseSingleOperandNode(a,'convert_safe_u256');case OperatorType['TypeStringIndexof']:return parseTwoOperandNode(a,'calc_string_indexof');case OperatorType['TypeStringNocaseIndexof']:return parseTwoOperandNode(a,'calc_string_nocase_indexof');case OperatorType['TypedValueType']:return parseSingleOperandNode(a,'value_type');case OperatorType['TypedValueVecLength']:return parseSingleOperandNode(a,'vec_length');case OperatorType['TypedValueVecContains_Bool']:return parseMultiOperandNode(a,'vec_contains_bool');case OperatorType['TypedValueVecContains_Address']:return parseMultiOperandNode(a,'vec_contains_address');case OperatorType['TypedValueVecContains_String']:return parseMultiOperandNode(a,'vec_contains_string');case OperatorType['TypedValueVecContains_StringNoCase']:return parseMultiOperandNode(a,'vec_contains_string_nocase');case OperatorType['TypedValueVecContains_Number']:return parseMultiOperandNode(a,'vec_contains_number');case OperatorType['TypedValueVecIndexOf_Bool']:return parseTwoOperandNode(a,'vec_indexof_bool');case OperatorType['TypedValueVecIndexOf_Address']:return parseTwoOperandNode(a,'vec_indexof_address');case OperatorType['TypedValueVecIndexOf_String']:return parseTwoOperandNode(a,'vec_indexof_string');case OperatorType['TypedValueVecIndexOf_StringNoCase']:return parseTwoOperandNode(a,'vec_indexof_string_nocase');case OperatorType['TypedValueVecIndexOf_Number']:return parseTwoOperandNode(a,'vec_indexof_number');case ContextType['TypeSigner']:return{'type':'context','context':'Signer'};case ContextType['TypeGuard']:return{'type':'context','context':'Guard'};case ContextType['TypeClock']:return{'type':'context','context':'Clock'};default:throw new Error('ParseGuardNode:\x20Unknown\x20opcode:\x20'+b);}},parseMultiOperandNode=(a,b)=>{a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseMultiOperandNode:\x20Insufficient\x20data\x20for\x20multi-operand\x20operation');const c=a['output'][a['currentPosition']];a['currentPosition']++;const d=[];for(let f=0x0;f<c;f++){d['unshift'](parseNode(a));}const e={'type':b,'nodes':d};return e;},parseSingleOperandNode=(a,b)=>{const c=parseNode(a);return createSingleOperandNode(b,c);},parseTwoOperandNode=(a,b)=>{a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseTwoOperandNode:\x20Missing\x20order\x20byte');const c=a['output'][a['currentPosition']];a['currentPosition']++;const d=c===0x0?'forward':'backward',e=parseNode(a),f=parseNode(a),g={'type':b,'nodeLeft':f,'nodeRight':e,'order':d};return g;},parseQueryNode=a=>{a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseQueryNode:\x20Missing\x20witness\x20byte\x20after\x20TypeQuery\x20opcode');const b=a['output'][a['currentPosition']];a['currentPosition']++;a['currentPosition']>=a['output']['length']&&W_ERROR(WErrors['InvalidParam'],'parseQueryNode:\x20Missing\x20object\x20identifier\x20after\x20witness\x20byte');const c=a['output'][a['currentPosition']];a['currentPosition']++;const d=a['output']['subarray'](a['currentPosition']);d['length']<0x2&&W_ERROR(WErrors['InvalidParam'],'parseQueryNode:\x20Not\x20enough\x20bytes\x20for\x20query\x20ID\x20after\x20object\x20identifier');const e=bcs['U16']['parse'](d);a['currentPosition']+=0x2;const f=GUARDQUERY['find'](m=>m['id']===e);!f&&W_ERROR(WErrors['InvalidParam'],'parseQueryNode:\x20Query\x20with\x20ID\x20'+e+'\x20not\x20found');const g=getGuardQueryInfo(e);!g&&W_ERROR(WErrors['InvalidParam'],'parseQueryNode:\x20Query\x20name\x20not\x20found\x20for\x20ID\x20'+e);const h=[],j=g['parameters'];for(let m=j['length']-0x1;m>=0x0;m--){h['unshift'](parseNode(a));}const k=parseSpecializedQueryNode(e,c,h,a['table']);if(k)return k;const l={'type':'query','query':g['name'],'object':{'identifier':c,...b!==ContextType['TypeConstant']?{'convert_witness':b}:{}},'parameters':h};return l;},parseSpecializedQueryNode=(a,b,c,d)=>{if(a>=0x65a&&a<=0x65d)return parseRewardRecordQueryNode(a,b,c,d);if(a>=0x4fa&&a<=0x4ff)return parseProgressQueryNode(a,b,c,d);return null;},parseRewardRecordQueryNode=(a,b,c,d)=>{if(c['length']!==0x1||c[0x0]['type']!=='identifier')return null;const f=c[0x0]['identifier'];let g,h;switch(a){case 0x65a:g='query_reward_record_find',h='first';break;case 0x65b:g='query_reward_record_find',h='last';break;case 0x65c:g='query_reward_record_count';break;case 0x65d:g='query_reward_record_exists';break;default:return null;}const i=getConditionsFromTable(d,f);let j={};if(i)try{const m=RecordQueryConditionsBCS['parse'](i);j={'recipient':m['recipient'],'guard':m['guard'],'time_min':m['time_min'],'time_max':m['time_max'],'amount_min':m['amount_min'],'amount_max':m['amount_max']};}catch(n){}const k={};if(j['recipient'])k['recipient']=j['recipient'];if(j['guard'])k['guard']=j['guard'];if(j['time_min']!==null&&j['time_min']!==undefined)k['timeMin']=j['time_min']['toString']();if(j['time_max']!==null&&j['time_max']!==undefined)k['timeMax']=j['time_max']['toString']();if(j['amount_min']!==null&&j['amount_min']!==undefined)k['amountMin']=j['amount_min']['toString']();if(j['amount_max']!==null&&j['amount_max']!==undefined)k['amountMax']=j['amount_max']['toString']();const l={'object':{'identifier':b},'recipient':{'type':'identifier','identifier':f},'where':k};if(g==='query_reward_record_find')return{'type':g,...l,'find':h,'conditionsIdentifier':f};return{'type':g,...l,'conditionsIdentifier':f};},parseProgressQueryNode=(a,b,c,d)=>{switch(a){case 0x4fa:return parseProgressHistoryFindNode(b,c,d);case 0x4fb:return parseProgressSessionFindNode(b,c,d);case 0x4fc:return parseProgressForwardFindNode(b,c,d);case 0x4fd:return parseProgressSessionCountNode(b,c,d);case 0x4fe:return parseProgressForwardCountNode(b,c,d);case 0x4ff:return parseProgressRetainedCountNode(b,c,d);default:return null;}},parseProgressHistoryFindNode=(a,b,c)=>{if(b['length']!==0x1||b[0x0]['type']!=='identifier')return null;const d=b[0x0]['identifier'],f=getConditionsFromTable(c,d),g={};let h='first';if(f)try{const i=ProgressHistoryFindConditionsBCS['parse'](f);if(i['node'])g['node']=i['node'];if(i['next_node'])g['nextNode']=i['next_node'];if(i['time_min'])g['timeMin']=i['time_min']['toString']();if(i['time_max'])g['timeMax']=i['time_max']['toString']();h=i['find']===0x1?'last':'first';}catch(j){}return{'type':'query_progress_history_find','object':{'identifier':a},'where':g,'find':h,'conditionsIdentifier':d};},parseProgressSessionFindNode=(a,b,c)=>{if(b['length']!==0x2)return null;const d=b[0x0],f=b[0x1];if(d['type']!=='identifier')return null;if(f['type']!=='identifier'&&!f['type']['startsWith']('query_progress'))return null;const g=d['identifier'],h=getConditionsFromTable(c,g),i={};let j='first';if(h)try{const k=ProgressSessionFindConditionsBCS['parse'](h);if(k['next_node'])i['nextNode']=k['next_node'];j=k['find']===0x1?'last':'first';}catch(l){}return{'type':'query_progress_history_session_find','object':{'identifier':a},'historyIdx':f,'where':i,'find':j};},parseProgressForwardFindNode=(a,b,c)=>{if(b['length']!==0x3)return null;const d=b[0x0],f=b[0x1],g=b[0x2];if(d['type']!=='identifier')return null;const h=m=>m['type']==='identifier'||m['type']['startsWith']('query_progress');if(!h(f)||!h(g))return null;const i=d['identifier'],j=getConditionsFromTable(c,i),k={};let l='first';if(j)try{const m=ProgressForwardFindConditionsBCS['parse'](j);if(m['who'])k['who']=m['who'];if(m['operation'])k['operation']=m['operation'];if(m['accomplished']!==undefined)k['accomplished']=m['accomplished'];if(m['time_min'])k['timeMin']=m['time_min']['toString']();if(m['time_max'])k['timeMax']=m['time_max']['toString']();l=m['find']===0x1?'last':'first';}catch(n){}return{'type':'query_progress_history_session_forward_find','object':{'identifier':a},'historyIdx':g,'sessionIdx':f,'where':k,'find':l};},parseProgressSessionCountNode=(a,b,c)=>{if(b['length']!==0x1)return null;const d=b[0x0];if(d['type']!=='identifier'&&!d['type']['startsWith']('query_progress'))return null;return{'type':'query_progress_history_session_count','object':{'identifier':a},'historyIdx':d};},parseProgressForwardCountNode=(a,b,c)=>{if(b['length']!==0x2)return null;const d=b[0x0],e=b[0x1],f=g=>g['type']==='identifier'||g['type']['startsWith']('query_progress');if(!f(d)||!f(e))return null;return{'type':'query_progress_history_session_forward_count','object':{'identifier':a},'historyIdx':d,'sessionIdx':e};},parseProgressRetainedCountNode=(a,b,c)=>{if(b['length']!==0x3)return null;const d=b[0x0],e=b[0x1],f=b[0x2],g=h=>h['type']==='identifier'||h['type']['startsWith']('query_progress');if(!g(d)||!g(e)||!g(f))return null;return{'type':'query_progress_history_session_forward_retained_submission_count','object':{'identifier':a},'historyIdx':d,'sessionIdx':e,'forwardIdx':f};},getConditionsFromTable=(a,b)=>{const c=a['find'](d=>d['identifier']===b);if(!c||!c['value'])return null;if(Array['isArray'](c['value'])&&c['value']['length']>0x0&&typeof c['value'][0x0]==='number')return new Uint8Array(c['value']);return null;},createQueryNode=(a,b,c,d,e,f)=>{switch(a){case 0x4fa:{const g=parseProgressHistoryFindNode(c,e,f);if(g)return g;break;}case 0x4fb:{const h=parseProgressSessionFindNode(c,e,f);if(h)return h;break;}case 0x4fc:{const i=parseProgressForwardFindNode(c,e,f);if(i)return i;break;}case 0x4fd:{const j=parseProgressSessionCountNode(c,e,f);if(j)return j;break;}case 0x4fe:{const k=parseProgressForwardCountNode(c,e,f);if(k)return k;break;}case 0x4ff:{const l=parseProgressRetainedCountNode(c,e,f);if(l)return l;break;}}return{'type':'query','query':b,'object':{'identifier':c,...d!==ContextType['TypeConstant']?{'convert_witness':d}:{}},'parameters':e};};export const restoreNodeFromOutput=(a,b)=>{try{(!a||a['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20output\x20is\x20empty');const c=[],d=new Map();let e=0x0;const f=()=>{return e>=a['length']&&W_ERROR(WErrors['InvalidParam'],'readByte:\x20Unexpected\x20end\x20of\x20output'),a[e++];},g=()=>{e+0x2>a['length']&&W_ERROR(WErrors['InvalidParam'],'readU16:\x20Insufficient\x20bytes\x20for\x20u16');const j=a[e]+a[e+0x1]*0x100;return e+=0x2,j;};while(e<a['length']){const j=f();switch(j){case ContextType['TypeConstant']:{const k=f();c['push']({'type':'identifier','identifier':k});break;}case ContextType['TypeSigner']:c['push']({'type':'context','context':'Signer'});break;case ContextType['TypeClock']:c['push']({'type':'context','context':'Clock'});break;case ContextType['TypeGuard']:c['push']({'type':'context','context':'Guard'});break;case OperatorType['TypeQuery']:{const l=f(),m=f(),n=g(),o=getGuardQueryInfo(n);!o&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Query\x20with\x20ID\x20'+n+'\x20not\x20found');const p=[];for(let r=0x0;r<o['parameters']['length'];r++){c['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Insufficient\x20parameters\x20for\x20query\x20'+o['name']),p['unshift'](c['pop']());}if(o['id']===0x48f&&p[0x0]['type']==='identifier'&&p[0x0]?.['identifier']!=null){const s=b['find'](w=>w['identifier']===m&&!w['b_submission']),t=b['find'](w=>w['identifier']===p[0x0]['identifier']&&!w['b_submission']),u=s?parseValueType(s['value_type']):undefined,v=t?parseValueType(t['value_type']):undefined;s&&t&&u===ValueType['Address']&&v===ValueType['String']&&(d['has'](s['value'])?!d['get'](s['value'])['includes'](t['value'])&&d['get'](s['value'])['push'](t['value']):d['set'](s['value'],[t['value']]));}const q=createQueryNode(o['id'],o['name'],m,l,p,b);c['push'](q);break;}case OperatorType['TypeLogicEqual']:case OperatorType['TypeLogicAnd']:case OperatorType['TypeLogicOr']:case OperatorType['TypeLogicAsU256GreaterEqual']:case OperatorType['TypeLogicAsU256LesserEqual']:case OperatorType['TypeLogicAsU256Equal']:case OperatorType['TypeLogicAsU256Greater']:case OperatorType['TypeLogicAsU256Lesser']:case OperatorType['TypeStringContains']:case OperatorType['TypeStringNocaseContains']:case OperatorType['TypeStringNocaseEqual']:case OperatorType['TypeNumberAdd']:case OperatorType['TypeNumberSubtract']:case OperatorType['TypeNumberMultiply']:case OperatorType['TypeNumberDivide']:case OperatorType['TypeNumberMod']:{const w=f(),x=[];for(let z=0x0;z<w;z++){c['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Insufficient\x20operands\x20for\x20multi-operand\x20operation'),x['push'](c['pop']());}const y=getNodePropertyFromOpCode(j);c['push']({'type':y,'nodes':x});break;}case OperatorType['TypeLogicNot']:case OperatorType['TypeStringLength']:case OperatorType['TypeNumberAddress']:case OperatorType['TypeAddressNumber']:case OperatorType['TypeNumberString']:case OperatorType['TypeStringNumber']:case OperatorType['TypeSafeU8']:case OperatorType['TypeSafeU16']:case OperatorType['TypeSafeU32']:case OperatorType['TypeSafeU64']:case OperatorType['TypeSafeU128']:case OperatorType['TypeSafeU256']:case OperatorType['TypedValueType']:case OperatorType['TypedValueVecLength']:{c['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Insufficient\x20operand\x20for\x20single-operand\x20operation');const A=c['pop'](),B=getNodePropertyFromOpCode(j);c['push']({'type':B,'node':A});break;}case OperatorType['TypeStringIndexof']:case OperatorType['TypeStringNocaseIndexof']:case OperatorType['TypedValueVecIndexOf_Bool']:case OperatorType['TypedValueVecIndexOf_Address']:case OperatorType['TypedValueVecIndexOf_String']:case OperatorType['TypedValueVecIndexOf_StringNoCase']:case OperatorType['TypedValueVecIndexOf_Number']:{const C=f(),D=C===0x0?'forward':'backward';c['length']<0x2&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Insufficient\x20operands\x20for\x20two-operand\x20operation');const E=c['pop'](),F=c['pop'](),G=getNodePropertyFromOpCode(j);c['push']({'type':G,'nodeLeft':E,'nodeRight':F,'order':D});break;}default:W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Unknown\x20opcode\x20'+j);}}c['length']!==0x1&&W_ERROR(WErrors['InvalidParam'],'restoreNodeFromOutput:\x20Expected\x201\x20node\x20in\x20stack,\x20found\x20'+c['length']);const h=collectAutoGeneratedIdentifiers(c[0x0]);return{'root':c[0x0],'rep_quote':d,'autoGeneratedIdentifiers':h};}catch(H){throw new Error('restoreNodeFromOutput:\x20Failed\x20to\x20restore\x20GuardNode\x20from\x20output:\x20'+H['message']);}};const collectAutoGeneratedIdentifiers=a=>{const b=[];switch(a['type']){case'query_progress_history_find':break;case'query_progress_history_session_find':b['push'](...collectAutoGeneratedIdentifiers(a['historyIdx']));break;case'query_progress_history_session_forward_find':b['push'](...collectAutoGeneratedIdentifiers(a['historyIdx'])),b['push'](...collectAutoGeneratedIdentifiers(a['sessionIdx']));break;case'query_progress_history_session_count':b['push'](...collectAutoGeneratedIdentifiers(a['historyIdx']));break;case'query_progress_history_session_forward_count':b['push'](...collectAutoGeneratedIdentifiers(a['historyIdx'])),b['push'](...collectAutoGeneratedIdentifiers(a['sessionIdx']));break;case'query_progress_history_session_forward_retained_submission_count':b['push'](...collectAutoGeneratedIdentifiers(a['historyIdx'])),b['push'](...collectAutoGeneratedIdentifiers(a['sessionIdx'])),b['push'](...collectAutoGeneratedIdentifiers(a['forwardIdx']));break;case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':a['recipient']['type']==='identifier'&&b['push'](a['recipient']['identifier']);break;case'logic_equal':case'logic_and':case'logic_or':case'logic_as_u256_greater_or_equal':case'logic_as_u256_lesser_or_equal':case'logic_as_u256_equal':case'logic_as_u256_greater':case'logic_as_u256_lesser':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_multiply':case'calc_number_subtract':case'calc_number_divide':case'calc_number_mod':for(const c of a['nodes']){b['push'](...collectAutoGeneratedIdentifiers(c));}break;case'logic_not':case'calc_string_length':case'convert_number_address':case'convert_address_number':case'convert_number_string':case'convert_string_number':case'convert_safe_u8':case'convert_safe_u16':case'convert_safe_u32':case'convert_safe_u64':case'convert_safe_u128':case'convert_safe_u256':case'value_type':case'vec_length':b['push'](...collectAutoGeneratedIdentifiers(a['node']));break;case'calc_string_indexof':case'calc_string_nocase_indexof':case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':b['push'](...collectAutoGeneratedIdentifiers(a['nodeLeft'])),b['push'](...collectAutoGeneratedIdentifiers(a['nodeRight']));break;case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':for(const d of a['nodes']){b['push'](...collectAutoGeneratedIdentifiers(d));}break;}return b;},getNodePropertyFromOpCode=a=>{switch(a){case OperatorType['TypeLogicEqual']:return'logic_equal';case OperatorType['TypeLogicAnd']:return'logic_and';case OperatorType['TypeLogicOr']:return'logic_or';case OperatorType['TypeLogicAsU256GreaterEqual']:return'logic_as_u256_greater_or_equal';case OperatorType['TypeLogicAsU256LesserEqual']:return'logic_as_u256_lesser_or_equal';case OperatorType['TypeLogicAsU256Equal']:return'logic_as_u256_equal';case OperatorType['TypeLogicAsU256Greater']:return'logic_as_u256_greater';case OperatorType['TypeLogicAsU256Lesser']:return'logic_as_u256_lesser';case OperatorType['TypeStringContains']:return'logic_string_contains';case OperatorType['TypeStringNocaseContains']:return'logic_string_nocase_contains';case OperatorType['TypeStringNocaseEqual']:return'logic_string_nocase_equal';case OperatorType['TypeNumberAdd']:return'calc_number_add';case OperatorType['TypeNumberSubtract']:return'calc_number_subtract';case OperatorType['TypeNumberMultiply']:return'calc_number_multiply';case OperatorType['TypeNumberDivide']:return'calc_number_divide';case OperatorType['TypeNumberMod']:return'calc_number_mod';case OperatorType['TypeLogicNot']:return'logic_not';case OperatorType['TypeStringLength']:return'calc_string_length';case OperatorType['TypeNumberAddress']:return'convert_number_address';case OperatorType['TypeAddressNumber']:return'convert_address_number';case OperatorType['TypeNumberString']:return'convert_number_string';case OperatorType['TypeStringNumber']:return'convert_string_number';case OperatorType['TypeSafeU8']:return'convert_safe_u8';case OperatorType['TypeSafeU16']:return'convert_safe_u16';case OperatorType['TypeSafeU32']:return'convert_safe_u32';case OperatorType['TypeSafeU64']:return'convert_safe_u64';case OperatorType['TypeSafeU128']:return'convert_safe_u128';case OperatorType['TypeSafeU256']:return'convert_safe_u256';case OperatorType['TypedValueType']:return'value_type';case OperatorType['TypedValueVecLength']:return'vec_length';case OperatorType['TypeStringIndexof']:return'calc_string_indexof';case OperatorType['TypeStringNocaseIndexof']:return'calc_string_nocase_indexof';case OperatorType['TypedValueVecIndexOf_Bool']:return'vec_indexof_bool';case OperatorType['TypedValueVecIndexOf_Address']:return'vec_indexof_address';case OperatorType['TypedValueVecIndexOf_String']:return'vec_indexof_string';case OperatorType['TypedValueVecIndexOf_StringNoCase']:return'vec_indexof_string_nocase';case OperatorType['TypedValueVecIndexOf_Number']:return'vec_indexof_number';default:return'unknown';}};