wowok 2.1.41 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -231,6 +231,8 @@ export type GuardNode = {
231
231
  nextNode?: string;
232
232
  timeMin?: string;
233
233
  timeMax?: string;
234
+ indexMin?: string;
235
+ indexMax?: string;
234
236
  };
235
237
  find: "first" | "last";
236
238
  conditionsIdentifier?: number;
@@ -1 +1 @@
1
- import{toTxObject,toTxString,isValidDescription,MAX_DESCRIPTION_LENGTH,isValidU8,isValidU64,isValidName,ValueType,parseValueType,OperatorType,ContextType,isWitnessType,PackageAddress,ObjectType,MAX_INPUT_SIZE,MAX_DEPENDED_COUNT,MAX_MULTI_OPERANDS}from'../common.js';import a151a from'lodash';import{W_ERROR,WErrors}from'../exception.js';import{CallBase}from'./base.js';import{isValidAddress,LocalMark}from'../local/local.js';import{GetAccountOrMark_Address}from'../local/index.js';import{WitnessSourceType,WitnessTargetType,query_objects}from'../query/object.js';import{bcs}from'../../bcs/index.js';import{valueToBcsBytes}from'../util.js';import{getGuardQueryInfo,GUARDQUERY}from'./guard-ins.js';import{checkType,resolveCallEnv}from'./util.js';import{isValidWowAddress}from'../../utils/sui-types.js';import{get_guardSubmissions,verify_guard}from'./passport.js';import{writeFileSync}from'fs';import{resolve}from'path';export function guardFn(a){return PackageAddress+'::guard::'+a;}export class CallGuard extends CallBase{['data'];constructor(a){super(),this['data']=a;}async['call'](a){return await this['prepare'](a),await this['exec'](a);}async['operate'](a,b,c,d){(!this['data']['table']||this['data']['table']['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'table\x20is\x20empty');!this['data']['root']&&W_ERROR(WErrors['InvalidParam'],'root\x20is\x20empty');const e=await newGuard(b,this['data']?.['description']||'',this['data']?.['table'],this['data']?.['root']);if(this['data']?.['rely']!=null){const f=await LocalMark['Instance']()['get_many_address'](this['data']['rely']['guards']),g=f['findIndex'](h=>h===undefined);g!==-0x1&&W_ERROR(WErrors['InvalidParam'],'rely.guards\x20invalid:\x20guard\x20at\x20index\x20'+g+'\x20not\x20found'),reliesAdd(b,e,f['filter'](h=>h!==undefined));}await this['new_with_mark'](a,b,ObjectType['Guard'],create(b,e),this['data']?.['namedNew']);}}export const newGuard=async(a,b,c,d)=>{!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);for(let m=0x0;m<c['length'];m++){const n=c[m];if(!isValidU8(n['identifier']))W_ERROR(WErrors['InvalidParam'],'table.identifier\x20'+n['identifier']+'\x20invalid');if(!n['b_submission']&&(n['value']===undefined||n['value']===null))W_ERROR(WErrors['InvalidParam'],'table.value\x20'+n['value']+'\x20with\x20identifier\x20'+n['identifier']+'\x20invalid');if(!isValidName(n['name']))W_ERROR(WErrors['InvalidParam'],'table.name');}const e=a151a['groupBy'](c,'identifier'),f=Object['keys'](e)['filter'](o=>e[o]['length']>0x1);f['length']>0x0&&W_ERROR(WErrors['InvalidParam'],'table.identifier\x20duplicates:\x20'+f['join'](',\x20'));var g=[];await buildNode(d,ValueType['Bool'],c,g);const h=g['reduce']((o,p)=>o+p['length'],0x0),j=new Uint8Array(h);let k=0x0;for(const o of g){j['set'](o,k),k+=o['length'];}j['length']>MAX_INPUT_SIZE&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20size\x20exceeds\x20maximum\x20limit\x20'+MAX_INPUT_SIZE);j['length']===0x0&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20cannot\x20be\x20empty');const l=[];for(let p=0x0;p<c['length'];p++){const q=c[p],r=parseValueType(q['value_type']);let s;q['b_submission']?(s=new Uint8Array(0x1),s[0x0]=r):((q['value']===undefined||q['value']===null)&&W_ERROR(WErrors['NewGuardCheckFailed'],'Table\x20item\x20value\x20is\x20required\x20when\x20b_submission\x20is\x20false'),s=await valueToBcsBytes(r,q['value'])),l['push'](a['moveCall']({'target':guardFn('table_item'),'arguments':[a['pure']['u8'](q['identifier']),a['pure']['bool'](q['b_submission']),a['pure']['vector']('u8',Array['from'](s)),toTxString(a,q['name'])]}));}return a['moveCall']({'target':guardFn('new'),'arguments':[toTxString(a,b),a['makeMoveVec']({'elements':l,'type':PackageAddress+'::guard::TableItem'}),a['pure']['vector']('u8',Array['from'](j))]});};export function create(a,b){return a['moveCall']({'target':guardFn('create'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function reliesAdd(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{e===b&&W_ERROR(WErrors['NewGuardCheckFailed'],'Guard\x20cannot\x20rely\x20on\x20itself'),a['moveCall']({'target':guardFn('relies_add'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()]});});}export function reliesRemove(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{a['moveCall']({'target':guardFn('relies_remove'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar']()]});});}export function reliesClear(a,b){a['moveCall']({'target':guardFn('relies_clear'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function reliesLogic(a,b,c){a['moveCall']({'target':guardFn('relies_logic_and'),'arguments':[toTxObject(a,b),a['pure']['bool'](c)]});}const buildNode=async(a,b,c,d)=>{const e=a;switch(e['type']){case'identifier':{const g=c['find'](h=>h['identifier']===e['identifier']);if(g){const h=parseValueType(g['value_type']);checkType(h,b,e),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](e['identifier'])['toBytes']());}else W_ERROR(WErrors['InvalidParam'],'node\x20identifier\x20-\x20'+JSON['stringify'](e));break;}case'query':{const j=getGuardQueryInfo(e['query']);!j&&W_ERROR(WErrors['InvalidParam'],'query\x20not\x20found:\x20'+e['query']);checkType(j['return'],b,e);if(j['parameters']['length']===e['parameters']['length'])for(let m=e['parameters']['length']-0x1;m>=0x0;--m){await buildNode(e['parameters'][m],j['parameters'][m],c,d);}else W_ERROR(WErrors['InvalidParam'],'node\x20query\x20parameters\x20length\x20not\x20match\x20-\x20'+JSON['stringify'](e));const k=c['find'](n=>n['identifier']===e['object']['identifier']);!k&&W_ERROR(WErrors['InvalidParam'],'node\x20object\x20from\x20identifier\x20-\x20'+JSON['stringify'](e));const l=parseValueType(k['value_type']);l!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],'object\x20to\x20query\x20must\x20be\x20address\x20in\x20table\x20'+k+'.\x20'+e['object']);d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']());if(isWitnessType(e['object']['convert_witness'])){const n=WitnessTargetType(e['object']['convert_witness']);n!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+n+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+j['objectType']+')');const o=WitnessSourceType(e['object']['convert_witness']);k['object_type']?k['object_type']!==o&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+o+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=o,d['push'](bcs['U8']['serialize'](e['object']['convert_witness'])['toBytes']());}else k?.['object_type']?k['object_type']!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+j['objectType']+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=j['objectType'],d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']());d['push'](bcs['U8']['serialize'](e['object']['identifier'])['toBytes']()),d['push'](bcs['U16']['serialize'](j['id'])['toBytes']());break;}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_equal':case'logic_and':case'logic_or':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_subtract':case'calc_number_multiply':case'calc_number_divide':case'calc_number_mod':case'calc_string_nocase_contains':case'calc_string_nocase_equal':case'calc_string_contains':{const p={'logic_as_u256_greater_or_equal':OperatorType['TypeLogicAsU256GreaterEqual'],'logic_as_u256_lesser_or_equal':OperatorType['TypeLogicAsU256LesserEqual'],'logic_as_u256_equal':OperatorType['TypeLogicAsU256Equal'],'logic_as_u256_greater':OperatorType['TypeLogicAsU256Greater'],'logic_as_u256_lesser':OperatorType['TypeLogicAsU256Lesser'],'logic_equal':OperatorType['TypeLogicEqual'],'logic_and':OperatorType['TypeLogicAnd'],'logic_or':OperatorType['TypeLogicOr'],'logic_string_contains':OperatorType['TypeStringContains'],'logic_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'logic_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_number_add':OperatorType['TypeNumberAdd'],'calc_number_subtract':OperatorType['TypeNumberSubtract'],'calc_number_multiply':OperatorType['TypeNumberMultiply'],'calc_number_divide':OperatorType['TypeNumberDivide'],'calc_number_mod':OperatorType['TypeNumberMod'],'calc_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'calc_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_string_contains':OperatorType['TypeStringContains']},r={'logic_as_u256_greater_or_equal':'number','logic_as_u256_lesser_or_equal':'number','logic_as_u256_equal':'number','logic_as_u256_greater':'number','logic_as_u256_lesser':'number','logic_equal':'variable','logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['String'],'logic_string_nocase_contains':ValueType['String'],'logic_string_nocase_equal':ValueType['String'],'calc_number_add':'number','calc_number_subtract':'number','calc_number_multiply':'number','calc_number_divide':'number','calc_number_mod':'number','calc_string_nocase_contains':ValueType['String'],'calc_string_nocase_equal':ValueType['String'],'calc_string_contains':ValueType['String']},s={'logic_as_u256_greater_or_equal':ValueType['Bool'],'logic_as_u256_lesser_or_equal':ValueType['Bool'],'logic_as_u256_equal':ValueType['Bool'],'logic_as_u256_greater':ValueType['Bool'],'logic_as_u256_lesser':ValueType['Bool'],'logic_equal':ValueType['Bool'],'logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['Bool'],'logic_string_nocase_contains':ValueType['Bool'],'logic_string_nocase_equal':ValueType['Bool'],'calc_number_add':ValueType['U256'],'calc_number_subtract':ValueType['U256'],'calc_number_multiply':ValueType['U256'],'calc_number_divide':ValueType['U256'],'calc_number_mod':ValueType['U256'],'calc_string_nocase_contains':ValueType['Bool'],'calc_string_nocase_equal':ValueType['Bool'],'calc_string_contains':ValueType['Bool']};checkType(s[e['type']],b,e),await multi_operand_op(p[e['type']],e['nodes'],r[e['type']],c,d);break;}case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':{const t={'vec_contains_bool':OperatorType['TypedValueVecContains_Bool'],'vec_contains_address':OperatorType['TypedValueVecContains_Address'],'vec_contains_string':OperatorType['TypedValueVecContains_String'],'vec_contains_string_nocase':OperatorType['TypedValueVecContains_StringNoCase'],'vec_contains_number':OperatorType['TypedValueVecContains_Number']},u={'vec_contains_bool':ValueType['VecBool'],'vec_contains_address':ValueType['VecAddress'],'vec_contains_string':ValueType['VecString'],'vec_contains_string_nocase':ValueType['VecString'],'vec_contains_number':'vec_number'},v={'vec_contains_bool':ValueType['Bool'],'vec_contains_address':ValueType['Address'],'vec_contains_string':ValueType['String'],'vec_contains_string_nocase':ValueType['String'],'vec_contains_number':'number'};checkType(ValueType['Bool'],b,e);for(let w=e['nodes']['length']-0x1;w>=0x0;--w){const x=w===0x0?u[e['type']]:v[e['type']];await buildNode(e['nodes'][w],x,c,d);}d['push'](bcs['U8']['serialize'](t[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['nodes']['length'])['toBytes']());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':{const y={'logic_not':OperatorType['TypeLogicNot'],'calc_string_length':OperatorType['TypeStringLength'],'convert_number_address':OperatorType['TypeNumberAddress'],'convert_address_number':OperatorType['TypeAddressNumber'],'convert_number_string':OperatorType['TypeNumberString'],'convert_string_number':OperatorType['TypeStringNumber'],'convert_safe_u8':OperatorType['TypeSafeU8'],'convert_safe_u16':OperatorType['TypeSafeU16'],'convert_safe_u32':OperatorType['TypeSafeU32'],'convert_safe_u64':OperatorType['TypeSafeU64'],'convert_safe_u128':OperatorType['TypeSafeU128'],'convert_safe_u256':OperatorType['TypeSafeU256'],'value_type':OperatorType['TypedValueType'],'vec_length':OperatorType['TypedValueVecLength']},z={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['String'],'convert_number_address':'number','convert_address_number':ValueType['Address'],'convert_number_string':'number','convert_string_number':ValueType['String'],'convert_safe_u8':'number','convert_safe_u16':'number','convert_safe_u32':'number','convert_safe_u64':'number','convert_safe_u128':'number','convert_safe_u256':'number','value_type':'variable','vec_length':'vec'},A={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['U64'],'convert_number_address':ValueType['Address'],'convert_address_number':ValueType['U256'],'convert_number_string':ValueType['String'],'convert_string_number':ValueType['U256'],'convert_safe_u8':ValueType['U8'],'convert_safe_u16':ValueType['U16'],'convert_safe_u32':ValueType['U32'],'convert_safe_u64':ValueType['U64'],'convert_safe_u128':ValueType['U128'],'convert_safe_u256':ValueType['U256'],'value_type':ValueType['U8'],'vec_length':ValueType['U64']};checkType(A[e['type']],b,e),await single_operand_op(y[e['type']],e['node'],z[e['type']],c,d);break;}case'calc_string_indexof':case'calc_string_nocase_indexof':{const B={'calc_string_indexof':OperatorType['TypeStringIndexof'],'calc_string_nocase_indexof':OperatorType['TypeStringNocaseIndexof']};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],ValueType['String'],c,d),await buildNode(e['nodeLeft'],ValueType['String'],c,d),d['push'](bcs['U8']['serialize'](B[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':{const C={'vec_indexof_bool':OperatorType['TypedValueVecIndexOf_Bool'],'vec_indexof_address':OperatorType['TypedValueVecIndexOf_Address'],'vec_indexof_string':OperatorType['TypedValueVecIndexOf_String'],'vec_indexof_string_nocase':OperatorType['TypedValueVecIndexOf_StringNoCase'],'vec_indexof_number':OperatorType['TypedValueVecIndexOf_Number']},D={'vec_indexof_bool':ValueType['Bool'],'vec_indexof_address':ValueType['Address'],'vec_indexof_string':ValueType['String'],'vec_indexof_string_nocase':ValueType['String'],'vec_indexof_number':'number'},E={'vec_indexof_bool':ValueType['VecBool'],'vec_indexof_address':ValueType['VecAddress'],'vec_indexof_string':ValueType['VecString'],'vec_indexof_string_nocase':ValueType['VecString'],'vec_indexof_number':'vec_number'};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],D[e['type']],c,d),await buildNode(e['nodeLeft'],E[e['type']],c,d),d['push'](bcs['U8']['serialize'](C[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const F=c['find'](H=>H['identifier']===e['object']['identifier']);!F&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const G=await buildRewardRecordQuery(e,c,b);d['push'](...G['output']);break;}case'query_progress_history_find':case'query_progress_history_session_find':case'query_progress_history_session_forward_find':case'query_progress_history_session_count':case'query_progress_history_session_forward_count':case'query_progress_history_session_forward_retained_submission_count':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const H=c['find'](J=>J['identifier']===e['object']['identifier']);!H&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const I=await buildProgressQuery(e,c,b);d['push'](...I['output']);break;}case'context':{let J;switch(e['context']){case'Signer':J=ContextType['TypeSigner'];break;case'Clock':J=ContextType['TypeClock'];break;case'Guard':J=ContextType['TypeGuard'];break;default:W_ERROR(WErrors['InvalidParam'],'Invalid\x20context\x20type:\x20'+e['context']);}d['push'](bcs['U8']['serialize'](J)['toBytes']());e['context']==='Clock'?checkType(ContextType['TypeClock'],b,e):checkType(ValueType['Address'],b,e);break;}default:W_ERROR(WErrors['InvalidParam'],'node:'+JSON['stringify'](e));}},multi_operand_op=async(a,b,c,d,e)=>{(b['length']<0x2||b['length']>MAX_MULTI_OPERANDS)&&W_ERROR(WErrors['InvalidParam'],'op\x20'+a+'\x20parameters\x20length\x20must\x20>=\x202\x20and\x20<=\x20\x20\x0a\x09\x09\x09\x09'+MAX_MULTI_OPERANDS+'.\x20\x09parameters:\x0a\x09\x09\x09\x09'+JSON['stringify'](b));for(let f=b['length']-0x1;f>=0x0;--f){await buildNode(b[f],c,d,e);}e['push'](bcs['U8']['serialize'](a)['toBytes']()),e['push'](bcs['U8']['serialize'](b['length'])['toBytes']());},getNewIdentifier=(a,b)=>{let c=0x0;while(c<0x100&&a['find'](d=>d['identifier']===c)){c++;}return c>=0x100&&W_ERROR(WErrors['InvalidParam'],b+'\x20cannot\x20find\x20available\x20identifier\x20in\x20table\x20(all\x20256\x20identifiers\x20are\x20used)'),c;},StoreFromIdFilter=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'](StoreFromIdFilter)}),buildRecordQueryConditionsFromConst=a=>{const b={'recipient':a['recipient'],'guard':a['guard']??null,'time_min':a['timeMin']??null,'time_max':a['timeMax']??null,'amount_min':a['amountMin']??null,'amount_max':a['amountMax']??null,'store_from_id':a['storeFromId']?{'mode':a['storeFromId']==='not_exists'?0x0:a['storeFromId']==='exists'?0x1:0x2,'value':typeof a['storeFromId']==='object'?a['storeFromId']['eq']:null}:null};return RecordQueryConditionsBCS['serialize'](b)['toBytes']();},buildRewardRecordQuery=async(a,b,c)=>{const d=a['recipient'];d['type']!=='identifier'&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20an\x20identifier');const e=d,f=b[e['identifier']];!f&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20identifier\x20'+e['identifier']+'\x20not\x20found\x20in\x20table');f['value_type']!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20Address\x20type,\x20got\x20'+f['value_type']);a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMin']!==undefined&&!isValidU64(a['where']['amountMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMin\x20\x22'+a['where']['amountMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMax']!==undefined&&!isValidU64(a['where']['amountMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMax\x20\x22'+a['where']['amountMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const g={'recipient':f['value']};if(a['where']['guard']){const o=await LocalMark['Instance']()['get_address'](a['where']['guard']);!o&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20guard\x20\x22'+a['where']['guard']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['guard']=o;}if(a['where']['timeMin']!==undefined)g['timeMin']=a['where']['timeMin'];if(a['where']['timeMax']!==undefined)g['timeMax']=a['where']['timeMax'];if(a['where']['amountMin']!==undefined)g['amountMin']=a['where']['amountMin'];if(a['where']['amountMax']!==undefined)g['amountMax']=a['where']['amountMax'];if(a['where']['storeFromId']!==undefined){if(typeof a['where']['storeFromId']==='object'&&'eq'in a['where']['storeFromId']){const p=await LocalMark['Instance']()['get_address'](a['where']['storeFromId']['eq']);!p&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20storeFromId\x20\x22'+a['where']['storeFromId']['eq']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['storeFromId']={'eq':p};}else g['storeFromId']=a['where']['storeFromId'];}const h=buildRecordQueryConditionsFromConst(g);let i,j;switch(a['type']){case'query_reward_record_find':i=a['find']==='first'?0x65a:0x65b,j=ValueType['U64'];break;case'query_reward_record_count':i=0x65c,j=ValueType['U64'];break;case'query_reward_record_exists':i=0x65d,j=ValueType['Bool'];break;}const k=a['object']['identifier'],l=getNewIdentifier(b,a['type']);b['push']({'identifier':l,'value_type':ValueType['VecU8'],'value':Array['from'](h),'b_submission':![],'name':'query_conditions_'+l});const m=b['find'](q=>q['identifier']===k);m&&(m['object_type']=ObjectType['Reward']);const n=[];return n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](l)['toBytes']()),n['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](k)['toBytes']()),n['push'](bcs['U16']['serialize'](i)['toBytes']()),checkType(j,c,a),{'output':n,'returnType':j};},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']}),buildProgressHistoryFindConditions=a=>{a['where']['node']!==undefined&&!isValidName(a['where']['node'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20node\x20\x22'+a['where']['node']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMin']!==undefined&&!isValidU64(a['where']['indexMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMin\x20\x22'+a['where']['indexMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMax']!==undefined&&!isValidU64(a['where']['indexMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMax\x20\x22'+a['where']['indexMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const b={'node':a['where']['node']??null,'next_node':a['where']['nextNode']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'index_min':a['where']['indexMin']??null,'index_max':a['where']['indexMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressHistoryFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressSessionFindConditions=a=>{a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20session\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');const b={'next_node':a['where']['nextNode']??null,'find':a['find']==='first'?0x0:0x1};return ProgressSessionFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressForwardFindConditions=async a=>{a['where']['operation']!==undefined&&!isValidName(a['where']['operation'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20forward\x20find\x20operation\x20\x22'+a['where']['operation']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');let b=null;if(a['where']['who']!==undefined){const d=await GetAccountOrMark_Address({'name_or_address':a['where']['who']});!d&&W_ERROR(WErrors['AddressNotFound'],'Progress\x20forward\x20find\x20who\x20\x22'+a['where']['who']+'\x22\x20not\x20found\x20in\x20LocalMark\x20or\x20accounts'),b=d;}const c={'who':b,'operation':a['where']['operation']??null,'accomplished':a['where']['accomplished']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressForwardFindConditionsBCS['serialize'](c)['toBytes']();},buildProgressQuery=async(a,b,c)=>{const d=[];let e;const f=ValueType['U64'];let g;switch(a['type']){case'query_progress_history_find':{e=0x4fa,g=buildProgressHistoryFindConditions(a);break;}case'query_progress_history_session_find':{e=0x4fb,g=buildProgressSessionFindConditions(a);break;}case'query_progress_history_session_forward_find':{e=0x4fc,g=await buildProgressForwardFindConditions(a);break;}case'query_progress_history_session_count':{e=0x4fd,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_count':{e=0x4fe,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_retained_submission_count':{e=0x4ff,g=new Uint8Array(0x0);break;}}const h=a['object']['identifier'],i=getNewIdentifier(b,a['type']);b['push']({'identifier':i,'value_type':ValueType['VecU8'],'value':Array['from'](g),'b_submission':![],'name':'query_conditions_'+i});if(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find'||a['type']==='query_progress_history_session_count'||a['type']==='query_progress_history_session_forward_count'||a['type']==='query_progress_history_session_forward_retained_submission_count'){const j=b['find'](k=>k['identifier']===h);j&&(j['object_type']=ObjectType['Progress']);}(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find')&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));switch(a['type']){case'query_progress_history_session_forward_retained_submission_count':{await buildNode(a['forwardIdx'],ValueType['U64'],b,d),await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_find':case'query_progress_history_session_forward_count':{await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_find':case'query_progress_history_session_count':{await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_find':{break;}}return d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](h)['toBytes']()),d['push'](bcs['U16']['serialize'](e)['toBytes']()),checkType(f,c,a),{'output':d,'returnType':f};},single_operand_op=async(a,b,c,d,e)=>{await buildNode(b,c,d,e),e['push'](bcs['U8']['serialize'](a)['toBytes']());};export const guard2file=async(a,b,c='json',d)=>{const f=await query_objects({'objects':[a],'network':d}),g=f['objects'];if(!g||g['length']===0x0||g[0x0]['type']!=='Guard'){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Guard\x20object\x20not\x20found:\x20'+a);return;}const h=g[0x0];if(!h){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20get\x20Guard\x20object\x20data:\x20'+a);return;}let i;c==='json'?i=generateGuardJson(h):i=generateGuardMarkdown(h);try{const j=resolve(b);writeFileSync(j,i,'utf-8');}catch(k){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20write\x20file\x20\x27'+b+'\x27:\x20'+k['message']);}};const generateGuardJson=a=>{const b={};return a['description']&&(b['description']=a['description']),a['table']&&a['table']['length']>0x0&&(b['table']=a['table']['map'](c=>({'identifier':c['identifier'],'b_submission':c['b_submission'],'value_type':c['value_type'],'value':c['value'],'name':c['name']}))),a['root']&&(b['root']=a['root']),a['relies']&&a['relies']['length']>0x0&&(b['rely']={'guards':a['relies'],'logic_or':!a['relies_logic_and']}),JSON['stringify'](b,null,0x2);},generateGuardMarkdown=a=>{const b=[];b['push']('#\x20Guard\x20Definition'),b['push'](''),b['push']('**Object\x20ID:**\x20'+a['object']),b['push'](''),b['push']('##\x20Summary'),b['push']('');const c=a['description']||'',d=a['table']?a['table']['length']:0x0;let e=''+(c['length']>0x64?c['substring'](0x0,0x61)+'...':c);e+='\x20['+d+'\x20tables]',b['push'](e),b['push'](''),b['push']('##\x20Description'),b['push'](''),b['push'](a['description']||''),b['push'](''),b['push']('##\x20Table\x20(Data\x20Definitions)'),b['push'](''),b['push']('|\x20Identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),b['push']('|------------|--------------|------------|-------|------|');if(a['table']&&a['table']['length']>0x0)for(const f of a['table']){const g=parseValueType(f['value_type']),h=valueTypeToString(g),i=formatValueForMarkdown(f['value']);b['push']('|\x20'+f['identifier']+'\x20|\x20'+f['b_submission']+'\x20|\x20'+h+'\x20('+f['value_type']+')\x20|\x20'+i+'\x20|\x20'+f['name']+'\x20|');}else b['push']('|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|');b['push'](''),b['push']('##\x20Root\x20(Computational\x20Tree)'),b['push'](''),b['push']('The\x20root\x20node\x20MUST\x20return\x20a\x20Bool\x20value\x20(pass/fail).'),b['push']('');if(a['root']){b['push']('```json'),b['push'](JSON['stringify'](a['root'],null,0x2)),b['push']('```'),b['push']('');const j=generateNodeComments(a['root']);if(j['length']>0x0){b['push']('###\x20Node\x20Comments'),b['push']('');for(const k of j){b['push']('-\x20**'+k['type']+'**:\x20'+k['description']);}b['push']('');}}else b['push']('*No\x20root\x20node\x20data\x20available*'),b['push']('');if(a['relies']&&a['relies']['length']>0x0){b['push']('##\x20Rely\x20(Dependencies)'),b['push'](''),b['push']('**Logic:**\x20'+(a['relies_logic_and']?'AND':'OR')),b['push'](''),b['push']('**Dependent\x20Guards:**');for(const l of a['relies']){b['push']('-\x20'+l);}b['push']('');}return b['join']('\x0a');},formatValueForMarkdown=a=>{if(a===undefined||a===null)return'-';if(typeof a==='boolean')return a?'true':'false';if(typeof a==='string')return a['startsWith']('0x')&&a['length']===0x42&&(!isValidAddress(a)&&W_ERROR(WErrors['IsValidAddress'],'Invalid\x20address:\x20'+a)),a;if(typeof a==='number')return a['toString']();if(Array['isArray'](a)){if(a['length']===0x0)return'[]';if(a['length']>0x3)return'['+a['slice'](0x0,0x3)['join'](',\x20')+',\x20...\x20('+a['length']+'\x20items)]';return'['+a['join'](',\x20')+']';}if(typeof a==='object')return'{...}';return String(a);};export const generateNodeComments=(a,b=[])=>{if(!a)return b;if(a['type']==='query'){const c=typeof a['query']==='number'?a['query']:undefined;if(c!==undefined){const d=GUARDQUERY['find'](e=>e['id']===c);d&&b['push']({'type':'query('+a['query']+')','description':d['name']+':\x20'+d['description']});}}else{if(a['type']['startsWith']('query_reward_record_')){const e=a['type']['replace']('query_','')['replace'](/_/g,'.'),f=GUARDQUERY['find'](g=>g['name']===e);f?b['push']({'type':a['type'],'description':f['name']+':\x20'+f['description']}):b['push']({'type':a['type'],'description':'Reward\x20Record\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('query_progress_history_')){const g=a['type']['replace']('query_','')['replace'](/_/g,'.'),h=GUARDQUERY['find'](i=>i['name']===g);h?b['push']({'type':a['type'],'description':h['name']+':\x20'+h['description']}):b['push']({'type':a['type'],'description':'Progress\x20History\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('logic_'))b['push']({'type':a['type'],'description':'Logic\x20operation:\x20'+a['type']['replace'](/_/g,'\x20')});else{if(a['type']['startsWith']('calc_'))b['push']({'type':a['type'],'description':'Calculation:\x20'+a['type']['replace'](/_/g,'\x20')});else a['type']['startsWith']('convert_')&&b['push']({'type':a['type'],'description':'Type\x20conversion:\x20'+a['type']['replace'](/_/g,'\x20')});}}}}if('nodes'in a&&Array['isArray'](a['nodes']))for(const i of a['nodes']){generateNodeComments(i,b);}'node'in a&&a['node']&&generateNodeComments(a['node'],b);if('parameters'in a&&Array['isArray'](a['parameters']))for(const j of a['parameters']){generateNodeComments(j,b);}return'nodeLeft'in a&&a['nodeLeft']&&generateNodeComments(a['nodeLeft'],b),'nodeRight'in a&&a['nodeRight']&&generateNodeComments(a['nodeRight'],b),'recipient'in a&&a['recipient']&&generateNodeComments(a['recipient'],b),'historyIdx'in a&&a['historyIdx']&&generateNodeComments(a['historyIdx'],b),'sessionIdx'in a&&a['sessionIdx']&&generateNodeComments(a['sessionIdx'],b),'forwardIdx'in a&&a['forwardIdx']&&generateNodeComments(a['forwardIdx'],b),b;};const valueTypeToString=a=>{const b={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8',[ValueType['Value']]:'Value'};return b[a]||'Unknown('+a+')';};export const gen_passport=async(a,b,c)=>{!isValidWowAddress(b)&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20empty');await resolveCallEnv(a);const d=await get_guardSubmissions(a,[b]);return d['submission']['length']>0x0?!c?{'type':'submission','guard':d['guard'],'submission':d['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':[{'object':b,'impack':!![]}],'submission':[]});};function detectFileFormatFromContent(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')||e['startsWith']('[')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseTableFromMarkdown(a){const b=a['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(b)try{const d=JSON['parse'](b[0x1]);if(Array['isArray'](d))return d;}catch{}const c=a['match'](/\|[^\n]+\|/g);if(c&&c['length']>0x2)return c['slice'](0x2)['map'](e=>{const f=e['split']('|')['filter'](j=>j['trim']())['map'](j=>j['trim']()),g=f[0x2];let h;const i=g['match'](/\((\d+)\)/);if(i)h=parseInt(i[0x1],0xa);else{const j=g['match'](/^\s*(\d+)\s*$/);if(j)h=parseInt(j[0x1],0xa);else{const k=g['match'](/^([A-Za-z]+)/);if(k)h=k[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+g+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}}return{'identifier':parseInt(f[0x0],0xa),'b_submission':f[0x1]['toLowerCase']()==='true','value_type':h,'value':f[0x3]==='-'?undefined:f[0x3],'name':f[0x4]==='-'?undefined:f[0x4]};});return undefined;}function parseRelyFromMarkdown(a){const b=a['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),c=a['match'](/^\s*[-*]\s*(\S+)$/gm);if(b||c)return{'logic_or':b?b[0x1]['toUpperCase']()==='OR':![],'guards':c?c['map'](d=>d['replace'](/^\s*[-*]\s*/,'')['trim']()):[]};return undefined;}export function parseGuardFromMarkdown(a){const b=[],c={},d=extractJsonFromMarkdown(a);if(d)try{const f=JSON['parse'](d['json']);Object['assign'](c,f);}catch(g){b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20code\x20block:\x20'+g['message'],'path':'/','line':d['lineOffset']});}if(!c['description']){const h=a['match'](/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);h&&(c['description']=h[0x1]['trim']());}if(!c['table']){const i=a['match'](/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const j=parseTableFromMarkdown(i[0x1]);j&&(c['table']=j);}}if(!c['root']){const k=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(k){const l=k[0x1],m=l['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(m)try{c['root']=JSON['parse'](m[0x1]);}catch(n){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+n['message'],'path':'/root'});}}}if(!c['rely']){const o=a['match'](/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(o){const p=parseRelyFromMarkdown(o[0x1]);p&&(c['rely']=p);}}if(!c['root'])return b['push']({'message':'Guard\x20root\x20node\x20not\x20found\x20in\x20markdown\x20file','path':'/root'}),{'success':![],'errors':b};return{'success':!![],'data':c,'errors':b};}export function parseGuardFile(a,b){const c=b??detectFileFormatFromContent(a);if(c==='json')try{const d=JSON['parse'](a);if(!d['root'])return{'success':![],'errors':[{'message':'Missing\x20required\x20field:\x20root','path':'/root'}]};return{'success':!![],'data':d,'errors':[]};}catch(f){return{'success':![],'errors':[{'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/'}]};}return parseGuardFromMarkdown(a);}export function validateGuardNode(a){const b=[];if(!a||typeof a!=='object')return b['push']({'message':'GuardNode\x20must\x20be\x20an\x20object','path':'/'}),{'success':![],'errors':b};const c=a;if(!c['type']||typeof c['type']!=='string')return b['push']({'message':'GuardNode\x20must\x20have\x20a\x20\x27type\x27\x20property','path':'/type'}),{'success':![],'errors':b};const d=['identifier','query','context','logic_not','logic_and','logic_or','logic_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','calc_string_length','calc_string_nocase_contains','calc_string_nocase_equal','calc_string_contains','calc_string_indexof','calc_string_nocase_indexof','convert_number_address','convert_address_number','convert_number_string','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','value_type','vec_length','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_find','query_reward_record_count','query_reward_record_exists','query_progress_history_find','query_progress_history_session_find','query_progress_history_session_forward_find','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];return!d['includes'](c['type'])&&b['push']({'message':'Invalid\x20GuardNode\x20type:\x20'+c['type'],'path':'/type'}),{'success':b['length']===0x0,'errors':b};}export function formatGuardParseErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}
1
+ import{toTxObject,toTxString,isValidDescription,MAX_DESCRIPTION_LENGTH,isValidU8,isValidU64,isValidName,ValueType,parseValueType,OperatorType,ContextType,isWitnessType,PackageAddress,ObjectType,MAX_INPUT_SIZE,MAX_DEPENDED_COUNT,MAX_MULTI_OPERANDS}from'../common.js';import a151a from'lodash';import{W_ERROR,WErrors}from'../exception.js';import{CallBase}from'./base.js';import{isValidAddress,LocalMark}from'../local/local.js';import{GetAccountOrMark_Address}from'../local/index.js';import{WitnessSourceType,WitnessTargetType,query_objects}from'../query/object.js';import{bcs}from'../../bcs/index.js';import{valueToBcsBytes}from'../util.js';import{getGuardQueryInfo,GUARDQUERY}from'./guard-ins.js';import{checkType,resolveCallEnv}from'./util.js';import{isValidWowAddress}from'../../utils/sui-types.js';import{get_guardSubmissions,verify_guard}from'./passport.js';import{writeFileSync}from'fs';import{resolve}from'path';export function guardFn(a){return PackageAddress+'::guard::'+a;}export class CallGuard extends CallBase{['data'];constructor(a){super(),this['data']=a;}async['call'](a){return await this['prepare'](a),await this['exec'](a);}async['operate'](a,b,c,d){(!this['data']['table']||this['data']['table']['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'table\x20is\x20empty');!this['data']['root']&&W_ERROR(WErrors['InvalidParam'],'root\x20is\x20empty');const e=await newGuard(b,this['data']?.['description']||'',this['data']?.['table'],this['data']?.['root']);if(this['data']?.['rely']!=null){const f=await LocalMark['Instance']()['get_many_address'](this['data']['rely']['guards']),g=f['findIndex'](h=>h===undefined);g!==-0x1&&W_ERROR(WErrors['InvalidParam'],'rely.guards\x20invalid:\x20guard\x20at\x20index\x20'+g+'\x20not\x20found'),reliesAdd(b,e,f['filter'](h=>h!==undefined));}await this['new_with_mark'](a,b,ObjectType['Guard'],create(b,e),this['data']?.['namedNew']);}}export const newGuard=async(a,b,c,d)=>{!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);for(let m=0x0;m<c['length'];m++){const n=c[m];if(!isValidU8(n['identifier']))W_ERROR(WErrors['InvalidParam'],'table.identifier\x20'+n['identifier']+'\x20invalid');if(!n['b_submission']&&(n['value']===undefined||n['value']===null))W_ERROR(WErrors['InvalidParam'],'table.value\x20'+n['value']+'\x20with\x20identifier\x20'+n['identifier']+'\x20invalid');if(!isValidName(n['name']))W_ERROR(WErrors['InvalidParam'],'table.name');}const e=a151a['groupBy'](c,'identifier'),f=Object['keys'](e)['filter'](o=>e[o]['length']>0x1);f['length']>0x0&&W_ERROR(WErrors['InvalidParam'],'table.identifier\x20duplicates:\x20'+f['join'](',\x20'));var g=[];await buildNode(d,ValueType['Bool'],c,g);const h=g['reduce']((o,p)=>o+p['length'],0x0),j=new Uint8Array(h);let k=0x0;for(const o of g){j['set'](o,k),k+=o['length'];}j['length']>MAX_INPUT_SIZE&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20size\x20exceeds\x20maximum\x20limit\x20'+MAX_INPUT_SIZE);j['length']===0x0&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20cannot\x20be\x20empty');const l=[];for(let p=0x0;p<c['length'];p++){const q=c[p],r=parseValueType(q['value_type']);let s;q['b_submission']?(s=new Uint8Array(0x1),s[0x0]=r):((q['value']===undefined||q['value']===null)&&W_ERROR(WErrors['NewGuardCheckFailed'],'Table\x20item\x20value\x20is\x20required\x20when\x20b_submission\x20is\x20false'),s=await valueToBcsBytes(r,q['value'])),l['push'](a['moveCall']({'target':guardFn('table_item'),'arguments':[a['pure']['u8'](q['identifier']),a['pure']['bool'](q['b_submission']),a['pure']['vector']('u8',Array['from'](s)),toTxString(a,q['name'])]}));}return a['moveCall']({'target':guardFn('new'),'arguments':[toTxString(a,b),a['makeMoveVec']({'elements':l,'type':PackageAddress+'::guard::TableItem'}),a['pure']['vector']('u8',Array['from'](j))]});};export function create(a,b){return a['moveCall']({'target':guardFn('create'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function reliesAdd(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{e===b&&W_ERROR(WErrors['NewGuardCheckFailed'],'Guard\x20cannot\x20rely\x20on\x20itself'),a['moveCall']({'target':guardFn('relies_add'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()]});});}export function reliesRemove(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{a['moveCall']({'target':guardFn('relies_remove'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar']()]});});}export function reliesClear(a,b){a['moveCall']({'target':guardFn('relies_clear'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function reliesLogic(a,b,c){a['moveCall']({'target':guardFn('relies_logic_and'),'arguments':[toTxObject(a,b),a['pure']['bool'](c)]});}const buildNode=async(a,b,c,d)=>{const e=a;switch(e['type']){case'identifier':{const g=c['find'](h=>h['identifier']===e['identifier']);if(g){const h=parseValueType(g['value_type']);checkType(h,b,e),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](e['identifier'])['toBytes']());}else W_ERROR(WErrors['InvalidParam'],'node\x20identifier\x20-\x20'+JSON['stringify'](e));break;}case'query':{const j=getGuardQueryInfo(e['query']);!j&&W_ERROR(WErrors['InvalidParam'],'query\x20not\x20found:\x20'+e['query']);checkType(j['return'],b,e);if(j['parameters']['length']===e['parameters']['length'])for(let m=e['parameters']['length']-0x1;m>=0x0;--m){await buildNode(e['parameters'][m],j['parameters'][m],c,d);}else W_ERROR(WErrors['InvalidParam'],'node\x20query\x20parameters\x20length\x20not\x20match\x20-\x20'+JSON['stringify'](e));const k=c['find'](n=>n['identifier']===e['object']['identifier']);!k&&W_ERROR(WErrors['InvalidParam'],'node\x20object\x20from\x20identifier\x20-\x20'+JSON['stringify'](e));const l=parseValueType(k['value_type']);l!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],'object\x20to\x20query\x20must\x20be\x20address\x20in\x20table\x20'+k+'.\x20'+e['object']);d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']());if(isWitnessType(e['object']['convert_witness'])){const n=WitnessTargetType(e['object']['convert_witness']);n!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+n+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+j['objectType']+')');const o=WitnessSourceType(e['object']['convert_witness']);k['object_type']?k['object_type']!==o&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+o+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=o,d['push'](bcs['U8']['serialize'](e['object']['convert_witness'])['toBytes']());}else k?.['object_type']?k['object_type']!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+j['objectType']+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=j['objectType'],d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']());d['push'](bcs['U8']['serialize'](e['object']['identifier'])['toBytes']()),d['push'](bcs['U16']['serialize'](j['id'])['toBytes']());break;}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_equal':case'logic_and':case'logic_or':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_subtract':case'calc_number_multiply':case'calc_number_divide':case'calc_number_mod':case'calc_string_nocase_contains':case'calc_string_nocase_equal':case'calc_string_contains':{const p={'logic_as_u256_greater_or_equal':OperatorType['TypeLogicAsU256GreaterEqual'],'logic_as_u256_lesser_or_equal':OperatorType['TypeLogicAsU256LesserEqual'],'logic_as_u256_equal':OperatorType['TypeLogicAsU256Equal'],'logic_as_u256_greater':OperatorType['TypeLogicAsU256Greater'],'logic_as_u256_lesser':OperatorType['TypeLogicAsU256Lesser'],'logic_equal':OperatorType['TypeLogicEqual'],'logic_and':OperatorType['TypeLogicAnd'],'logic_or':OperatorType['TypeLogicOr'],'logic_string_contains':OperatorType['TypeStringContains'],'logic_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'logic_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_number_add':OperatorType['TypeNumberAdd'],'calc_number_subtract':OperatorType['TypeNumberSubtract'],'calc_number_multiply':OperatorType['TypeNumberMultiply'],'calc_number_divide':OperatorType['TypeNumberDivide'],'calc_number_mod':OperatorType['TypeNumberMod'],'calc_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'calc_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_string_contains':OperatorType['TypeStringContains']},r={'logic_as_u256_greater_or_equal':'number','logic_as_u256_lesser_or_equal':'number','logic_as_u256_equal':'number','logic_as_u256_greater':'number','logic_as_u256_lesser':'number','logic_equal':'variable','logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['String'],'logic_string_nocase_contains':ValueType['String'],'logic_string_nocase_equal':ValueType['String'],'calc_number_add':'number','calc_number_subtract':'number','calc_number_multiply':'number','calc_number_divide':'number','calc_number_mod':'number','calc_string_nocase_contains':ValueType['String'],'calc_string_nocase_equal':ValueType['String'],'calc_string_contains':ValueType['String']},s={'logic_as_u256_greater_or_equal':ValueType['Bool'],'logic_as_u256_lesser_or_equal':ValueType['Bool'],'logic_as_u256_equal':ValueType['Bool'],'logic_as_u256_greater':ValueType['Bool'],'logic_as_u256_lesser':ValueType['Bool'],'logic_equal':ValueType['Bool'],'logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['Bool'],'logic_string_nocase_contains':ValueType['Bool'],'logic_string_nocase_equal':ValueType['Bool'],'calc_number_add':ValueType['U256'],'calc_number_subtract':ValueType['U256'],'calc_number_multiply':ValueType['U256'],'calc_number_divide':ValueType['U256'],'calc_number_mod':ValueType['U256'],'calc_string_nocase_contains':ValueType['Bool'],'calc_string_nocase_equal':ValueType['Bool'],'calc_string_contains':ValueType['Bool']};checkType(s[e['type']],b,e),await multi_operand_op(p[e['type']],e['nodes'],r[e['type']],c,d);break;}case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':{const t={'vec_contains_bool':OperatorType['TypedValueVecContains_Bool'],'vec_contains_address':OperatorType['TypedValueVecContains_Address'],'vec_contains_string':OperatorType['TypedValueVecContains_String'],'vec_contains_string_nocase':OperatorType['TypedValueVecContains_StringNoCase'],'vec_contains_number':OperatorType['TypedValueVecContains_Number']},u={'vec_contains_bool':ValueType['VecBool'],'vec_contains_address':ValueType['VecAddress'],'vec_contains_string':ValueType['VecString'],'vec_contains_string_nocase':ValueType['VecString'],'vec_contains_number':'vec_number'},v={'vec_contains_bool':ValueType['Bool'],'vec_contains_address':ValueType['Address'],'vec_contains_string':ValueType['String'],'vec_contains_string_nocase':ValueType['String'],'vec_contains_number':'number'};checkType(ValueType['Bool'],b,e);for(let w=e['nodes']['length']-0x1;w>=0x0;--w){const x=w===0x0?u[e['type']]:v[e['type']];await buildNode(e['nodes'][w],x,c,d);}d['push'](bcs['U8']['serialize'](t[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['nodes']['length'])['toBytes']());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':{const y={'logic_not':OperatorType['TypeLogicNot'],'calc_string_length':OperatorType['TypeStringLength'],'convert_number_address':OperatorType['TypeNumberAddress'],'convert_address_number':OperatorType['TypeAddressNumber'],'convert_number_string':OperatorType['TypeNumberString'],'convert_string_number':OperatorType['TypeStringNumber'],'convert_safe_u8':OperatorType['TypeSafeU8'],'convert_safe_u16':OperatorType['TypeSafeU16'],'convert_safe_u32':OperatorType['TypeSafeU32'],'convert_safe_u64':OperatorType['TypeSafeU64'],'convert_safe_u128':OperatorType['TypeSafeU128'],'convert_safe_u256':OperatorType['TypeSafeU256'],'value_type':OperatorType['TypedValueType'],'vec_length':OperatorType['TypedValueVecLength']},z={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['String'],'convert_number_address':'number','convert_address_number':ValueType['Address'],'convert_number_string':'number','convert_string_number':ValueType['String'],'convert_safe_u8':'number','convert_safe_u16':'number','convert_safe_u32':'number','convert_safe_u64':'number','convert_safe_u128':'number','convert_safe_u256':'number','value_type':'variable','vec_length':'vec'},A={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['U64'],'convert_number_address':ValueType['Address'],'convert_address_number':ValueType['U256'],'convert_number_string':ValueType['String'],'convert_string_number':ValueType['U256'],'convert_safe_u8':ValueType['U8'],'convert_safe_u16':ValueType['U16'],'convert_safe_u32':ValueType['U32'],'convert_safe_u64':ValueType['U64'],'convert_safe_u128':ValueType['U128'],'convert_safe_u256':ValueType['U256'],'value_type':ValueType['U8'],'vec_length':ValueType['U64']};checkType(A[e['type']],b,e),await single_operand_op(y[e['type']],e['node'],z[e['type']],c,d);break;}case'calc_string_indexof':case'calc_string_nocase_indexof':{const B={'calc_string_indexof':OperatorType['TypeStringIndexof'],'calc_string_nocase_indexof':OperatorType['TypeStringNocaseIndexof']};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],ValueType['String'],c,d),await buildNode(e['nodeLeft'],ValueType['String'],c,d),d['push'](bcs['U8']['serialize'](B[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':{const C={'vec_indexof_bool':OperatorType['TypedValueVecIndexOf_Bool'],'vec_indexof_address':OperatorType['TypedValueVecIndexOf_Address'],'vec_indexof_string':OperatorType['TypedValueVecIndexOf_String'],'vec_indexof_string_nocase':OperatorType['TypedValueVecIndexOf_StringNoCase'],'vec_indexof_number':OperatorType['TypedValueVecIndexOf_Number']},D={'vec_indexof_bool':ValueType['Bool'],'vec_indexof_address':ValueType['Address'],'vec_indexof_string':ValueType['String'],'vec_indexof_string_nocase':ValueType['String'],'vec_indexof_number':'number'},E={'vec_indexof_bool':ValueType['VecBool'],'vec_indexof_address':ValueType['VecAddress'],'vec_indexof_string':ValueType['VecString'],'vec_indexof_string_nocase':ValueType['VecString'],'vec_indexof_number':'vec_number'};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],D[e['type']],c,d),await buildNode(e['nodeLeft'],E[e['type']],c,d),d['push'](bcs['U8']['serialize'](C[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const F=c['find'](H=>H['identifier']===e['object']['identifier']);!F&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const G=await buildRewardRecordQuery(e,c,b);d['push'](...G['output']);break;}case'query_progress_history_find':case'query_progress_history_session_find':case'query_progress_history_session_forward_find':case'query_progress_history_session_count':case'query_progress_history_session_forward_count':case'query_progress_history_session_forward_retained_submission_count':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const H=c['find'](J=>J['identifier']===e['object']['identifier']);!H&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const I=await buildProgressQuery(e,c,b);d['push'](...I['output']);break;}case'context':{let J;switch(e['context']){case'Signer':J=ContextType['TypeSigner'];break;case'Clock':J=ContextType['TypeClock'];break;case'Guard':J=ContextType['TypeGuard'];break;default:W_ERROR(WErrors['InvalidParam'],'Invalid\x20context\x20type:\x20'+e['context']);}d['push'](bcs['U8']['serialize'](J)['toBytes']());e['context']==='Clock'?checkType(ContextType['TypeClock'],b,e):checkType(ValueType['Address'],b,e);break;}default:W_ERROR(WErrors['InvalidParam'],'node:'+JSON['stringify'](e));}},multi_operand_op=async(a,b,c,d,e)=>{(b['length']<0x2||b['length']>MAX_MULTI_OPERANDS)&&W_ERROR(WErrors['InvalidParam'],'op\x20'+a+'\x20parameters\x20length\x20must\x20>=\x202\x20and\x20<=\x20\x20\x0a\x09\x09\x09\x09'+MAX_MULTI_OPERANDS+'.\x20\x09parameters:\x0a\x09\x09\x09\x09'+JSON['stringify'](b));for(let f=b['length']-0x1;f>=0x0;--f){await buildNode(b[f],c,d,e);}e['push'](bcs['U8']['serialize'](a)['toBytes']()),e['push'](bcs['U8']['serialize'](b['length'])['toBytes']());},getNewIdentifier=(a,b)=>{for(let c=0x0;c<0x100;c++){if(!a['find'](d=>d['identifier']===c))return c;}return W_ERROR(WErrors['InvalidParam'],b+'\x20cannot\x20find\x20available\x20identifier\x20in\x20table\x20(all\x20256\x20identifiers\x20are\x20used)'),-0x1;},StoreFromIdFilter=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'](StoreFromIdFilter)}),buildRecordQueryConditionsFromConst=a=>{const b={'recipient':a['recipient'],'guard':a['guard']??null,'time_min':a['timeMin']??null,'time_max':a['timeMax']??null,'amount_min':a['amountMin']??null,'amount_max':a['amountMax']??null,'store_from_id':a['storeFromId']?{'mode':a['storeFromId']==='not_exists'?0x0:a['storeFromId']==='exists'?0x1:0x2,'value':typeof a['storeFromId']==='object'?a['storeFromId']['eq']:null}:null};return RecordQueryConditionsBCS['serialize'](b)['toBytes']();},buildRewardRecordQuery=async(a,b,c)=>{const d=a['recipient'];d['type']!=='identifier'&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20an\x20identifier');const e=d,f=b[e['identifier']];!f&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20identifier\x20'+e['identifier']+'\x20not\x20found\x20in\x20table');f['value_type']!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20Address\x20type,\x20got\x20'+f['value_type']);a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMin']!==undefined&&!isValidU64(a['where']['amountMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMin\x20\x22'+a['where']['amountMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMax']!==undefined&&!isValidU64(a['where']['amountMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMax\x20\x22'+a['where']['amountMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const g={'recipient':f['value']};if(a['where']['guard']){const o=await LocalMark['Instance']()['get_address'](a['where']['guard']);!o&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20guard\x20\x22'+a['where']['guard']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['guard']=o;}if(a['where']['timeMin']!==undefined)g['timeMin']=a['where']['timeMin'];if(a['where']['timeMax']!==undefined)g['timeMax']=a['where']['timeMax'];if(a['where']['amountMin']!==undefined)g['amountMin']=a['where']['amountMin'];if(a['where']['amountMax']!==undefined)g['amountMax']=a['where']['amountMax'];if(a['where']['storeFromId']!==undefined){if(typeof a['where']['storeFromId']==='object'&&'eq'in a['where']['storeFromId']){const p=await LocalMark['Instance']()['get_address'](a['where']['storeFromId']['eq']);!p&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20storeFromId\x20\x22'+a['where']['storeFromId']['eq']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['storeFromId']={'eq':p};}else g['storeFromId']=a['where']['storeFromId'];}const h=buildRecordQueryConditionsFromConst(g);let i,j;switch(a['type']){case'query_reward_record_find':i=a['find']==='first'?0x65a:0x65b,j=ValueType['U64'];break;case'query_reward_record_count':i=0x65c,j=ValueType['U64'];break;case'query_reward_record_exists':i=0x65d,j=ValueType['Bool'];break;}const k=a['object']['identifier'],l=getNewIdentifier(b,a['type']);b['push']({'identifier':l,'value_type':ValueType['VecU8'],'value':Array['from'](h),'b_submission':![],'name':'query_conditions_'+l});const m=b['find'](q=>q['identifier']===k);m&&(m['object_type']=ObjectType['Reward']);const n=[];return n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](l)['toBytes']()),n['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](k)['toBytes']()),n['push'](bcs['U16']['serialize'](i)['toBytes']()),checkType(j,c,a),{'output':n,'returnType':j};},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']),'index_min':bcs['option'](bcs['U64']),'index_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']}),buildProgressHistoryFindConditions=a=>{a['where']['node']!==undefined&&!isValidName(a['where']['node'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20node\x20\x22'+a['where']['node']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMin']!==undefined&&!isValidU64(a['where']['indexMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMin\x20\x22'+a['where']['indexMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMax']!==undefined&&!isValidU64(a['where']['indexMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMax\x20\x22'+a['where']['indexMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const b={'node':a['where']['node']??null,'next_node':a['where']['nextNode']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'index_min':a['where']['indexMin']??null,'index_max':a['where']['indexMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressHistoryFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressSessionFindConditions=a=>{a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20session\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');const b={'next_node':a['where']['nextNode']??null,'find':a['find']==='first'?0x0:0x1},c=ProgressSessionFindConditionsBCS['serialize'](b)['toBytes']();return c;},buildProgressForwardFindConditions=async a=>{a['where']['operation']!==undefined&&!isValidName(a['where']['operation'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20forward\x20find\x20operation\x20\x22'+a['where']['operation']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');let b=null;if(a['where']['who']!==undefined){const d=await GetAccountOrMark_Address({'name_or_address':a['where']['who']});!d&&W_ERROR(WErrors['AddressNotFound'],'Progress\x20forward\x20find\x20who\x20\x22'+a['where']['who']+'\x22\x20not\x20found\x20in\x20LocalMark\x20or\x20accounts'),b=d;}const c={'who':b,'operation':a['where']['operation']??null,'accomplished':a['where']['accomplished']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressForwardFindConditionsBCS['serialize'](c)['toBytes']();},buildProgressQuery=async(a,b,c)=>{const d=[];let e;const f=ValueType['U64'];let g;switch(a['type']){case'query_progress_history_find':{e=0x4fa,g=buildProgressHistoryFindConditions(a);break;}case'query_progress_history_session_find':{e=0x4fb,g=buildProgressSessionFindConditions(a);break;}case'query_progress_history_session_forward_find':{e=0x4fc,g=await buildProgressForwardFindConditions(a);break;}case'query_progress_history_session_count':{e=0x4fd,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_count':{e=0x4fe,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_retained_submission_count':{e=0x4ff,g=new Uint8Array(0x0);break;}}const h=a['object']['identifier'];let i=null;if('conditionsIdentifier'in a&&a['conditionsIdentifier']!==undefined&&a['conditionsIdentifier']!==null)i=a['conditionsIdentifier'];else(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find')&&(i=getNewIdentifier(b,a['type']),b['push']({'identifier':i,'value_type':ValueType['VecU8'],'value':Array['from'](g),'b_submission':![],'name':'query_conditions_'+i}),a['conditionsIdentifier']=i);if(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find'||a['type']==='query_progress_history_session_count'||a['type']==='query_progress_history_session_forward_count'||a['type']==='query_progress_history_session_forward_retained_submission_count'){const j=b['find'](k=>k['identifier']===h);j&&(j['object_type']=ObjectType['Progress']);}switch(a['type']){case'query_progress_history_session_forward_retained_submission_count':{await buildNode(a['forwardIdx'],ValueType['U64'],b,d),await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_count':{await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_count':{await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));break;}}return d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](h)['toBytes']()),d['push'](bcs['U16']['serialize'](e)['toBytes']()),checkType(f,c,a),{'output':d,'returnType':f};},single_operand_op=async(a,b,c,d,e)=>{await buildNode(b,c,d,e),e['push'](bcs['U8']['serialize'](a)['toBytes']());};export const guard2file=async(a,b,c='json',d)=>{const f=await query_objects({'objects':[a],'network':d}),g=f['objects'];if(!g||g['length']===0x0||g[0x0]['type']!=='Guard'){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Guard\x20object\x20not\x20found:\x20'+a);return;}const h=g[0x0];if(!h){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20get\x20Guard\x20object\x20data:\x20'+a);return;}let i;c==='json'?i=generateGuardJson(h):i=generateGuardMarkdown(h);try{const j=resolve(b);writeFileSync(j,i,'utf-8');}catch(k){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20write\x20file\x20\x27'+b+'\x27:\x20'+k['message']);}};const generateGuardJson=a=>{const b={};return a['description']&&(b['description']=a['description']),a['table']&&a['table']['length']>0x0&&(b['table']=a['table']['map'](c=>({'identifier':c['identifier'],'b_submission':c['b_submission'],'value_type':c['value_type'],'value':c['value'],'name':c['name']}))),a['root']&&(b['root']=a['root']),a['relies']&&a['relies']['length']>0x0&&(b['rely']={'guards':a['relies'],'logic_or':!a['relies_logic_and']}),JSON['stringify'](b,null,0x2);},generateGuardMarkdown=a=>{const b=[];b['push']('#\x20Guard\x20Definition'),b['push'](''),b['push']('**Object\x20ID:**\x20'+a['object']),b['push'](''),b['push']('##\x20Summary'),b['push']('');const c=a['description']||'',d=a['table']?a['table']['length']:0x0;let e=''+(c['length']>0x64?c['substring'](0x0,0x61)+'...':c);e+='\x20['+d+'\x20tables]',b['push'](e),b['push'](''),b['push']('##\x20Description'),b['push'](''),b['push'](a['description']||''),b['push'](''),b['push']('##\x20Table\x20(Data\x20Definitions)'),b['push'](''),b['push']('|\x20Identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),b['push']('|------------|--------------|------------|-------|------|');if(a['table']&&a['table']['length']>0x0)for(const f of a['table']){const g=parseValueType(f['value_type']),h=valueTypeToString(g),i=formatValueForMarkdown(f['value']);b['push']('|\x20'+f['identifier']+'\x20|\x20'+f['b_submission']+'\x20|\x20'+h+'\x20('+f['value_type']+')\x20|\x20'+i+'\x20|\x20'+f['name']+'\x20|');}else b['push']('|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|');b['push'](''),b['push']('##\x20Root\x20(Computational\x20Tree)'),b['push'](''),b['push']('The\x20root\x20node\x20MUST\x20return\x20a\x20Bool\x20value\x20(pass/fail).'),b['push']('');if(a['root']){b['push']('```json'),b['push'](JSON['stringify'](a['root'],null,0x2)),b['push']('```'),b['push']('');const j=generateNodeComments(a['root']);if(j['length']>0x0){b['push']('###\x20Node\x20Comments'),b['push']('');for(const k of j){b['push']('-\x20**'+k['type']+'**:\x20'+k['description']);}b['push']('');}}else b['push']('*No\x20root\x20node\x20data\x20available*'),b['push']('');if(a['relies']&&a['relies']['length']>0x0){b['push']('##\x20Rely\x20(Dependencies)'),b['push'](''),b['push']('**Logic:**\x20'+(a['relies_logic_and']?'AND':'OR')),b['push'](''),b['push']('**Dependent\x20Guards:**');for(const l of a['relies']){b['push']('-\x20'+l);}b['push']('');}return b['join']('\x0a');},formatValueForMarkdown=a=>{if(a===undefined||a===null)return'-';if(typeof a==='boolean')return a?'true':'false';if(typeof a==='string')return a['startsWith']('0x')&&a['length']===0x42&&(!isValidAddress(a)&&W_ERROR(WErrors['IsValidAddress'],'Invalid\x20address:\x20'+a)),a;if(typeof a==='number')return a['toString']();if(Array['isArray'](a)){if(a['length']===0x0)return'[]';if(a['length']>0x3)return'['+a['slice'](0x0,0x3)['join'](',\x20')+',\x20...\x20('+a['length']+'\x20items)]';return'['+a['join'](',\x20')+']';}if(typeof a==='object')return'{...}';return String(a);};export const generateNodeComments=(a,b=[])=>{if(!a)return b;if(a['type']==='query'){const c=typeof a['query']==='number'?a['query']:undefined;if(c!==undefined){const d=GUARDQUERY['find'](e=>e['id']===c);d&&b['push']({'type':'query('+a['query']+')','description':d['name']+':\x20'+d['description']});}}else{if(a['type']['startsWith']('query_reward_record_')){const e=a['type']['replace']('query_','')['replace'](/_/g,'.'),f=GUARDQUERY['find'](g=>g['name']===e);f?b['push']({'type':a['type'],'description':f['name']+':\x20'+f['description']}):b['push']({'type':a['type'],'description':'Reward\x20Record\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('query_progress_history_')){const g=a['type']['replace']('query_','')['replace'](/_/g,'.'),h=GUARDQUERY['find'](i=>i['name']===g);h?b['push']({'type':a['type'],'description':h['name']+':\x20'+h['description']}):b['push']({'type':a['type'],'description':'Progress\x20History\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('logic_'))b['push']({'type':a['type'],'description':'Logic\x20operation:\x20'+a['type']['replace'](/_/g,'\x20')});else{if(a['type']['startsWith']('calc_'))b['push']({'type':a['type'],'description':'Calculation:\x20'+a['type']['replace'](/_/g,'\x20')});else a['type']['startsWith']('convert_')&&b['push']({'type':a['type'],'description':'Type\x20conversion:\x20'+a['type']['replace'](/_/g,'\x20')});}}}}if('nodes'in a&&Array['isArray'](a['nodes']))for(const i of a['nodes']){generateNodeComments(i,b);}'node'in a&&a['node']&&generateNodeComments(a['node'],b);if('parameters'in a&&Array['isArray'](a['parameters']))for(const j of a['parameters']){generateNodeComments(j,b);}return'nodeLeft'in a&&a['nodeLeft']&&generateNodeComments(a['nodeLeft'],b),'nodeRight'in a&&a['nodeRight']&&generateNodeComments(a['nodeRight'],b),'recipient'in a&&a['recipient']&&generateNodeComments(a['recipient'],b),'historyIdx'in a&&a['historyIdx']&&generateNodeComments(a['historyIdx'],b),'sessionIdx'in a&&a['sessionIdx']&&generateNodeComments(a['sessionIdx'],b),'forwardIdx'in a&&a['forwardIdx']&&generateNodeComments(a['forwardIdx'],b),b;};const valueTypeToString=a=>{const b={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8',[ValueType['Value']]:'Value'};return b[a]||'Unknown('+a+')';};export const gen_passport=async(a,b,c)=>{!isValidWowAddress(b)&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20empty');await resolveCallEnv(a);const d=await get_guardSubmissions(a,[b]);return d['submission']['length']>0x0?!c?{'type':'submission','guard':d['guard'],'submission':d['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':[{'object':b,'impack':!![]}],'submission':[]});};function detectFileFormatFromContent(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')||e['startsWith']('[')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseTableFromMarkdown(a){const b=a['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(b)try{const d=JSON['parse'](b[0x1]);if(Array['isArray'](d))return d;}catch{}const c=a['match'](/\|[^\n]+\|/g);if(c&&c['length']>0x2)return c['slice'](0x2)['map'](e=>{const f=e['split']('|')['filter'](j=>j['trim']())['map'](j=>j['trim']()),g=f[0x2];let h;const i=g['match'](/\((\d+)\)/);if(i)h=parseInt(i[0x1],0xa);else{const j=g['match'](/^\s*(\d+)\s*$/);if(j)h=parseInt(j[0x1],0xa);else{const k=g['match'](/^([A-Za-z]+)/);if(k)h=k[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+g+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}}return{'identifier':parseInt(f[0x0],0xa),'b_submission':f[0x1]['toLowerCase']()==='true','value_type':h,'value':f[0x3]==='-'?undefined:f[0x3],'name':f[0x4]==='-'?undefined:f[0x4]};});return undefined;}function parseRelyFromMarkdown(a){const b=a['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),c=a['match'](/^\s*[-*]\s*(\S+)$/gm);if(b||c)return{'logic_or':b?b[0x1]['toUpperCase']()==='OR':![],'guards':c?c['map'](d=>d['replace'](/^\s*[-*]\s*/,'')['trim']()):[]};return undefined;}export function parseGuardFromMarkdown(a){const b=[],c={},d=extractJsonFromMarkdown(a);if(d)try{const f=JSON['parse'](d['json']);Object['assign'](c,f);}catch(g){b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20code\x20block:\x20'+g['message'],'path':'/','line':d['lineOffset']});}if(!c['description']){const h=a['match'](/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);h&&(c['description']=h[0x1]['trim']());}if(!c['table']){const i=a['match'](/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const j=parseTableFromMarkdown(i[0x1]);j&&(c['table']=j);}}if(!c['root']){const k=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(k){const l=k[0x1],m=l['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(m)try{c['root']=JSON['parse'](m[0x1]);}catch(n){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+n['message'],'path':'/root'});}}}if(!c['rely']){const o=a['match'](/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(o){const p=parseRelyFromMarkdown(o[0x1]);p&&(c['rely']=p);}}if(!c['root'])return b['push']({'message':'Guard\x20root\x20node\x20not\x20found\x20in\x20markdown\x20file','path':'/root'}),{'success':![],'errors':b};return{'success':!![],'data':c,'errors':b};}export function parseGuardFile(a,b){const c=b??detectFileFormatFromContent(a);if(c==='json')try{const d=JSON['parse'](a);if(!d['root'])return{'success':![],'errors':[{'message':'Missing\x20required\x20field:\x20root','path':'/root'}]};return{'success':!![],'data':d,'errors':[]};}catch(f){return{'success':![],'errors':[{'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/'}]};}return parseGuardFromMarkdown(a);}export function validateGuardNode(a){const b=[];if(!a||typeof a!=='object')return b['push']({'message':'GuardNode\x20must\x20be\x20an\x20object','path':'/'}),{'success':![],'errors':b};const c=a;if(!c['type']||typeof c['type']!=='string')return b['push']({'message':'GuardNode\x20must\x20have\x20a\x20\x27type\x27\x20property','path':'/type'}),{'success':![],'errors':b};const d=['identifier','query','context','logic_not','logic_and','logic_or','logic_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','calc_string_length','calc_string_nocase_contains','calc_string_nocase_equal','calc_string_contains','calc_string_indexof','calc_string_nocase_indexof','convert_number_address','convert_address_number','convert_number_string','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','value_type','vec_length','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_find','query_reward_record_count','query_reward_record_exists','query_progress_history_find','query_progress_history_session_find','query_progress_history_session_forward_find','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];return!d['includes'](c['type'])&&b['push']({'message':'Invalid\x20GuardNode\x20type:\x20'+c['type'],'path':'/type'}),{'success':b['length']===0x0,'errors':b};}export function formatGuardParseErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}
@@ -1 +1 @@
1
- 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'||f['type']!=='identifier')return null;const g=f['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':d,'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'||f['type']!=='identifier'||g['type']!=='identifier')return null;const h=g['identifier'],i=getConditionsFromTable(c,h),j={};let k='first';if(i)try{const l=ProgressForwardFindConditionsBCS['parse'](i);if(l['who'])j['who']=l['who'];if(l['operation'])j['operation']=l['operation'];if(l['accomplished']!==undefined)j['accomplished']=l['accomplished'];if(l['time_min'])j['timeMin']=l['time_min']['toString']();if(l['time_max'])j['timeMax']=l['time_max']['toString']();k=l['find']===0x1?'last':'first';}catch(m){}return{'type':'query_progress_history_session_forward_find','object':{'identifier':a},'historyIdx':d,'sessionIdx':f,'where':j,'find':k};},parseProgressSessionCountNode=(a,b,c)=>{if(b['length']!==0x1||b[0x0]['type']!=='identifier')return null;return{'type':'query_progress_history_session_count','object':{'identifier':a},'historyIdx':b[0x0]};},parseProgressForwardCountNode=(a,b,c)=>{if(b['length']!==0x2)return null;const d=b[0x0],e=b[0x1];if(d['type']!=='identifier'||e['type']!=='identifier')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];if(d['type']!=='identifier'||e['type']!=='identifier'||f['type']!=='identifier')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':a['conditionsIdentifier']!==undefined&&b['push'](a['conditionsIdentifier']);break;case'query_progress_history_session_find':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);break;case'query_progress_history_session_forward_find':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);break;case'query_progress_history_session_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);break;case'query_progress_history_session_forward_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);break;case'query_progress_history_session_forward_retained_submission_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);a['forwardIdx']['type']==='identifier'&&b['push'](a['forwardIdx']['identifier']);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';}};
1
+ 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';}};
@@ -231,6 +231,8 @@ export type GuardNode = {
231
231
  nextNode?: string;
232
232
  timeMin?: string;
233
233
  timeMax?: string;
234
+ indexMin?: string;
235
+ indexMax?: string;
234
236
  };
235
237
  find: "first" | "last";
236
238
  conditionsIdentifier?: number;
@@ -1 +1 @@
1
- import{toTxObject,toTxString,isValidDescription,MAX_DESCRIPTION_LENGTH,isValidU8,isValidU64,isValidName,ValueType,parseValueType,OperatorType,ContextType,isWitnessType,PackageAddress,ObjectType,MAX_INPUT_SIZE,MAX_DEPENDED_COUNT,MAX_MULTI_OPERANDS}from'../common.js';import a151a from'lodash';import{W_ERROR,WErrors}from'../exception.js';import{CallBase}from'./base.js';import{isValidAddress,LocalMark}from'../local/local.js';import{GetAccountOrMark_Address}from'../local/index.js';import{WitnessSourceType,WitnessTargetType,query_objects}from'../query/object.js';import{bcs}from'../../bcs/index.js';import{valueToBcsBytes}from'../util.js';import{getGuardQueryInfo,GUARDQUERY}from'./guard-ins.js';import{checkType,resolveCallEnv}from'./util.js';import{isValidWowAddress}from'../../utils/sui-types.js';import{get_guardSubmissions,verify_guard}from'./passport.js';import{writeFileSync}from'fs';import{resolve}from'path';export function guardFn(a){return PackageAddress+'::guard::'+a;}export class CallGuard extends CallBase{['data'];constructor(a){super(),this['data']=a;}async['call'](a){return await this['prepare'](a),await this['exec'](a);}async['operate'](a,b,c,d){(!this['data']['table']||this['data']['table']['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'table\x20is\x20empty');!this['data']['root']&&W_ERROR(WErrors['InvalidParam'],'root\x20is\x20empty');const e=await newGuard(b,this['data']?.['description']||'',this['data']?.['table'],this['data']?.['root']);if(this['data']?.['rely']!=null){const f=await LocalMark['Instance']()['get_many_address'](this['data']['rely']['guards']),g=f['findIndex'](h=>h===undefined);g!==-0x1&&W_ERROR(WErrors['InvalidParam'],'rely.guards\x20invalid:\x20guard\x20at\x20index\x20'+g+'\x20not\x20found'),reliesAdd(b,e,f['filter'](h=>h!==undefined));}await this['new_with_mark'](a,b,ObjectType['Guard'],create(b,e),this['data']?.['namedNew']);}}export const newGuard=async(a,b,c,d)=>{!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);for(let m=0x0;m<c['length'];m++){const n=c[m];if(!isValidU8(n['identifier']))W_ERROR(WErrors['InvalidParam'],'table.identifier\x20'+n['identifier']+'\x20invalid');if(!n['b_submission']&&(n['value']===undefined||n['value']===null))W_ERROR(WErrors['InvalidParam'],'table.value\x20'+n['value']+'\x20with\x20identifier\x20'+n['identifier']+'\x20invalid');if(!isValidName(n['name']))W_ERROR(WErrors['InvalidParam'],'table.name');}const e=a151a['groupBy'](c,'identifier'),f=Object['keys'](e)['filter'](o=>e[o]['length']>0x1);f['length']>0x0&&W_ERROR(WErrors['InvalidParam'],'table.identifier\x20duplicates:\x20'+f['join'](',\x20'));var g=[];await buildNode(d,ValueType['Bool'],c,g);const h=g['reduce']((o,p)=>o+p['length'],0x0),j=new Uint8Array(h);let k=0x0;for(const o of g){j['set'](o,k),k+=o['length'];}j['length']>MAX_INPUT_SIZE&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20size\x20exceeds\x20maximum\x20limit\x20'+MAX_INPUT_SIZE);j['length']===0x0&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20cannot\x20be\x20empty');const l=[];for(let p=0x0;p<c['length'];p++){const q=c[p],r=parseValueType(q['value_type']);let s;q['b_submission']?(s=new Uint8Array(0x1),s[0x0]=r):((q['value']===undefined||q['value']===null)&&W_ERROR(WErrors['NewGuardCheckFailed'],'Table\x20item\x20value\x20is\x20required\x20when\x20b_submission\x20is\x20false'),s=await valueToBcsBytes(r,q['value'])),l['push'](a['moveCall']({'target':guardFn('table_item'),'arguments':[a['pure']['u8'](q['identifier']),a['pure']['bool'](q['b_submission']),a['pure']['vector']('u8',Array['from'](s)),toTxString(a,q['name'])]}));}return a['moveCall']({'target':guardFn('new'),'arguments':[toTxString(a,b),a['makeMoveVec']({'elements':l,'type':PackageAddress+'::guard::TableItem'}),a['pure']['vector']('u8',Array['from'](j))]});};export function create(a,b){return a['moveCall']({'target':guardFn('create'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function reliesAdd(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{e===b&&W_ERROR(WErrors['NewGuardCheckFailed'],'Guard\x20cannot\x20rely\x20on\x20itself'),a['moveCall']({'target':guardFn('relies_add'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()]});});}export function reliesRemove(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{a['moveCall']({'target':guardFn('relies_remove'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar']()]});});}export function reliesClear(a,b){a['moveCall']({'target':guardFn('relies_clear'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function reliesLogic(a,b,c){a['moveCall']({'target':guardFn('relies_logic_and'),'arguments':[toTxObject(a,b),a['pure']['bool'](c)]});}const buildNode=async(a,b,c,d)=>{const e=a;switch(e['type']){case'identifier':{const g=c['find'](h=>h['identifier']===e['identifier']);if(g){const h=parseValueType(g['value_type']);checkType(h,b,e),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](e['identifier'])['toBytes']());}else W_ERROR(WErrors['InvalidParam'],'node\x20identifier\x20-\x20'+JSON['stringify'](e));break;}case'query':{const j=getGuardQueryInfo(e['query']);!j&&W_ERROR(WErrors['InvalidParam'],'query\x20not\x20found:\x20'+e['query']);checkType(j['return'],b,e);if(j['parameters']['length']===e['parameters']['length'])for(let m=e['parameters']['length']-0x1;m>=0x0;--m){await buildNode(e['parameters'][m],j['parameters'][m],c,d);}else W_ERROR(WErrors['InvalidParam'],'node\x20query\x20parameters\x20length\x20not\x20match\x20-\x20'+JSON['stringify'](e));const k=c['find'](n=>n['identifier']===e['object']['identifier']);!k&&W_ERROR(WErrors['InvalidParam'],'node\x20object\x20from\x20identifier\x20-\x20'+JSON['stringify'](e));const l=parseValueType(k['value_type']);l!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],'object\x20to\x20query\x20must\x20be\x20address\x20in\x20table\x20'+k+'.\x20'+e['object']);d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']());if(isWitnessType(e['object']['convert_witness'])){const n=WitnessTargetType(e['object']['convert_witness']);n!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+n+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+j['objectType']+')');const o=WitnessSourceType(e['object']['convert_witness']);k['object_type']?k['object_type']!==o&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+o+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=o,d['push'](bcs['U8']['serialize'](e['object']['convert_witness'])['toBytes']());}else k?.['object_type']?k['object_type']!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+j['objectType']+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=j['objectType'],d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']());d['push'](bcs['U8']['serialize'](e['object']['identifier'])['toBytes']()),d['push'](bcs['U16']['serialize'](j['id'])['toBytes']());break;}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_equal':case'logic_and':case'logic_or':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_subtract':case'calc_number_multiply':case'calc_number_divide':case'calc_number_mod':case'calc_string_nocase_contains':case'calc_string_nocase_equal':case'calc_string_contains':{const p={'logic_as_u256_greater_or_equal':OperatorType['TypeLogicAsU256GreaterEqual'],'logic_as_u256_lesser_or_equal':OperatorType['TypeLogicAsU256LesserEqual'],'logic_as_u256_equal':OperatorType['TypeLogicAsU256Equal'],'logic_as_u256_greater':OperatorType['TypeLogicAsU256Greater'],'logic_as_u256_lesser':OperatorType['TypeLogicAsU256Lesser'],'logic_equal':OperatorType['TypeLogicEqual'],'logic_and':OperatorType['TypeLogicAnd'],'logic_or':OperatorType['TypeLogicOr'],'logic_string_contains':OperatorType['TypeStringContains'],'logic_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'logic_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_number_add':OperatorType['TypeNumberAdd'],'calc_number_subtract':OperatorType['TypeNumberSubtract'],'calc_number_multiply':OperatorType['TypeNumberMultiply'],'calc_number_divide':OperatorType['TypeNumberDivide'],'calc_number_mod':OperatorType['TypeNumberMod'],'calc_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'calc_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_string_contains':OperatorType['TypeStringContains']},r={'logic_as_u256_greater_or_equal':'number','logic_as_u256_lesser_or_equal':'number','logic_as_u256_equal':'number','logic_as_u256_greater':'number','logic_as_u256_lesser':'number','logic_equal':'variable','logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['String'],'logic_string_nocase_contains':ValueType['String'],'logic_string_nocase_equal':ValueType['String'],'calc_number_add':'number','calc_number_subtract':'number','calc_number_multiply':'number','calc_number_divide':'number','calc_number_mod':'number','calc_string_nocase_contains':ValueType['String'],'calc_string_nocase_equal':ValueType['String'],'calc_string_contains':ValueType['String']},s={'logic_as_u256_greater_or_equal':ValueType['Bool'],'logic_as_u256_lesser_or_equal':ValueType['Bool'],'logic_as_u256_equal':ValueType['Bool'],'logic_as_u256_greater':ValueType['Bool'],'logic_as_u256_lesser':ValueType['Bool'],'logic_equal':ValueType['Bool'],'logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['Bool'],'logic_string_nocase_contains':ValueType['Bool'],'logic_string_nocase_equal':ValueType['Bool'],'calc_number_add':ValueType['U256'],'calc_number_subtract':ValueType['U256'],'calc_number_multiply':ValueType['U256'],'calc_number_divide':ValueType['U256'],'calc_number_mod':ValueType['U256'],'calc_string_nocase_contains':ValueType['Bool'],'calc_string_nocase_equal':ValueType['Bool'],'calc_string_contains':ValueType['Bool']};checkType(s[e['type']],b,e),await multi_operand_op(p[e['type']],e['nodes'],r[e['type']],c,d);break;}case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':{const t={'vec_contains_bool':OperatorType['TypedValueVecContains_Bool'],'vec_contains_address':OperatorType['TypedValueVecContains_Address'],'vec_contains_string':OperatorType['TypedValueVecContains_String'],'vec_contains_string_nocase':OperatorType['TypedValueVecContains_StringNoCase'],'vec_contains_number':OperatorType['TypedValueVecContains_Number']},u={'vec_contains_bool':ValueType['VecBool'],'vec_contains_address':ValueType['VecAddress'],'vec_contains_string':ValueType['VecString'],'vec_contains_string_nocase':ValueType['VecString'],'vec_contains_number':'vec_number'},v={'vec_contains_bool':ValueType['Bool'],'vec_contains_address':ValueType['Address'],'vec_contains_string':ValueType['String'],'vec_contains_string_nocase':ValueType['String'],'vec_contains_number':'number'};checkType(ValueType['Bool'],b,e);for(let w=e['nodes']['length']-0x1;w>=0x0;--w){const x=w===0x0?u[e['type']]:v[e['type']];await buildNode(e['nodes'][w],x,c,d);}d['push'](bcs['U8']['serialize'](t[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['nodes']['length'])['toBytes']());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':{const y={'logic_not':OperatorType['TypeLogicNot'],'calc_string_length':OperatorType['TypeStringLength'],'convert_number_address':OperatorType['TypeNumberAddress'],'convert_address_number':OperatorType['TypeAddressNumber'],'convert_number_string':OperatorType['TypeNumberString'],'convert_string_number':OperatorType['TypeStringNumber'],'convert_safe_u8':OperatorType['TypeSafeU8'],'convert_safe_u16':OperatorType['TypeSafeU16'],'convert_safe_u32':OperatorType['TypeSafeU32'],'convert_safe_u64':OperatorType['TypeSafeU64'],'convert_safe_u128':OperatorType['TypeSafeU128'],'convert_safe_u256':OperatorType['TypeSafeU256'],'value_type':OperatorType['TypedValueType'],'vec_length':OperatorType['TypedValueVecLength']},z={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['String'],'convert_number_address':'number','convert_address_number':ValueType['Address'],'convert_number_string':'number','convert_string_number':ValueType['String'],'convert_safe_u8':'number','convert_safe_u16':'number','convert_safe_u32':'number','convert_safe_u64':'number','convert_safe_u128':'number','convert_safe_u256':'number','value_type':'variable','vec_length':'vec'},A={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['U64'],'convert_number_address':ValueType['Address'],'convert_address_number':ValueType['U256'],'convert_number_string':ValueType['String'],'convert_string_number':ValueType['U256'],'convert_safe_u8':ValueType['U8'],'convert_safe_u16':ValueType['U16'],'convert_safe_u32':ValueType['U32'],'convert_safe_u64':ValueType['U64'],'convert_safe_u128':ValueType['U128'],'convert_safe_u256':ValueType['U256'],'value_type':ValueType['U8'],'vec_length':ValueType['U64']};checkType(A[e['type']],b,e),await single_operand_op(y[e['type']],e['node'],z[e['type']],c,d);break;}case'calc_string_indexof':case'calc_string_nocase_indexof':{const B={'calc_string_indexof':OperatorType['TypeStringIndexof'],'calc_string_nocase_indexof':OperatorType['TypeStringNocaseIndexof']};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],ValueType['String'],c,d),await buildNode(e['nodeLeft'],ValueType['String'],c,d),d['push'](bcs['U8']['serialize'](B[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':{const C={'vec_indexof_bool':OperatorType['TypedValueVecIndexOf_Bool'],'vec_indexof_address':OperatorType['TypedValueVecIndexOf_Address'],'vec_indexof_string':OperatorType['TypedValueVecIndexOf_String'],'vec_indexof_string_nocase':OperatorType['TypedValueVecIndexOf_StringNoCase'],'vec_indexof_number':OperatorType['TypedValueVecIndexOf_Number']},D={'vec_indexof_bool':ValueType['Bool'],'vec_indexof_address':ValueType['Address'],'vec_indexof_string':ValueType['String'],'vec_indexof_string_nocase':ValueType['String'],'vec_indexof_number':'number'},E={'vec_indexof_bool':ValueType['VecBool'],'vec_indexof_address':ValueType['VecAddress'],'vec_indexof_string':ValueType['VecString'],'vec_indexof_string_nocase':ValueType['VecString'],'vec_indexof_number':'vec_number'};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],D[e['type']],c,d),await buildNode(e['nodeLeft'],E[e['type']],c,d),d['push'](bcs['U8']['serialize'](C[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const F=c['find'](H=>H['identifier']===e['object']['identifier']);!F&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const G=await buildRewardRecordQuery(e,c,b);d['push'](...G['output']);break;}case'query_progress_history_find':case'query_progress_history_session_find':case'query_progress_history_session_forward_find':case'query_progress_history_session_count':case'query_progress_history_session_forward_count':case'query_progress_history_session_forward_retained_submission_count':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const H=c['find'](J=>J['identifier']===e['object']['identifier']);!H&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const I=await buildProgressQuery(e,c,b);d['push'](...I['output']);break;}case'context':{let J;switch(e['context']){case'Signer':J=ContextType['TypeSigner'];break;case'Clock':J=ContextType['TypeClock'];break;case'Guard':J=ContextType['TypeGuard'];break;default:W_ERROR(WErrors['InvalidParam'],'Invalid\x20context\x20type:\x20'+e['context']);}d['push'](bcs['U8']['serialize'](J)['toBytes']());e['context']==='Clock'?checkType(ContextType['TypeClock'],b,e):checkType(ValueType['Address'],b,e);break;}default:W_ERROR(WErrors['InvalidParam'],'node:'+JSON['stringify'](e));}},multi_operand_op=async(a,b,c,d,e)=>{(b['length']<0x2||b['length']>MAX_MULTI_OPERANDS)&&W_ERROR(WErrors['InvalidParam'],'op\x20'+a+'\x20parameters\x20length\x20must\x20>=\x202\x20and\x20<=\x20\x20\x0a\x09\x09\x09\x09'+MAX_MULTI_OPERANDS+'.\x20\x09parameters:\x0a\x09\x09\x09\x09'+JSON['stringify'](b));for(let f=b['length']-0x1;f>=0x0;--f){await buildNode(b[f],c,d,e);}e['push'](bcs['U8']['serialize'](a)['toBytes']()),e['push'](bcs['U8']['serialize'](b['length'])['toBytes']());},getNewIdentifier=(a,b)=>{let c=0x0;while(c<0x100&&a['find'](d=>d['identifier']===c)){c++;}return c>=0x100&&W_ERROR(WErrors['InvalidParam'],b+'\x20cannot\x20find\x20available\x20identifier\x20in\x20table\x20(all\x20256\x20identifiers\x20are\x20used)'),c;},StoreFromIdFilter=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'](StoreFromIdFilter)}),buildRecordQueryConditionsFromConst=a=>{const b={'recipient':a['recipient'],'guard':a['guard']??null,'time_min':a['timeMin']??null,'time_max':a['timeMax']??null,'amount_min':a['amountMin']??null,'amount_max':a['amountMax']??null,'store_from_id':a['storeFromId']?{'mode':a['storeFromId']==='not_exists'?0x0:a['storeFromId']==='exists'?0x1:0x2,'value':typeof a['storeFromId']==='object'?a['storeFromId']['eq']:null}:null};return RecordQueryConditionsBCS['serialize'](b)['toBytes']();},buildRewardRecordQuery=async(a,b,c)=>{const d=a['recipient'];d['type']!=='identifier'&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20an\x20identifier');const e=d,f=b[e['identifier']];!f&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20identifier\x20'+e['identifier']+'\x20not\x20found\x20in\x20table');f['value_type']!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20Address\x20type,\x20got\x20'+f['value_type']);a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMin']!==undefined&&!isValidU64(a['where']['amountMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMin\x20\x22'+a['where']['amountMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMax']!==undefined&&!isValidU64(a['where']['amountMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMax\x20\x22'+a['where']['amountMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const g={'recipient':f['value']};if(a['where']['guard']){const o=await LocalMark['Instance']()['get_address'](a['where']['guard']);!o&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20guard\x20\x22'+a['where']['guard']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['guard']=o;}if(a['where']['timeMin']!==undefined)g['timeMin']=a['where']['timeMin'];if(a['where']['timeMax']!==undefined)g['timeMax']=a['where']['timeMax'];if(a['where']['amountMin']!==undefined)g['amountMin']=a['where']['amountMin'];if(a['where']['amountMax']!==undefined)g['amountMax']=a['where']['amountMax'];if(a['where']['storeFromId']!==undefined){if(typeof a['where']['storeFromId']==='object'&&'eq'in a['where']['storeFromId']){const p=await LocalMark['Instance']()['get_address'](a['where']['storeFromId']['eq']);!p&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20storeFromId\x20\x22'+a['where']['storeFromId']['eq']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['storeFromId']={'eq':p};}else g['storeFromId']=a['where']['storeFromId'];}const h=buildRecordQueryConditionsFromConst(g);let i,j;switch(a['type']){case'query_reward_record_find':i=a['find']==='first'?0x65a:0x65b,j=ValueType['U64'];break;case'query_reward_record_count':i=0x65c,j=ValueType['U64'];break;case'query_reward_record_exists':i=0x65d,j=ValueType['Bool'];break;}const k=a['object']['identifier'],l=getNewIdentifier(b,a['type']);b['push']({'identifier':l,'value_type':ValueType['VecU8'],'value':Array['from'](h),'b_submission':![],'name':'query_conditions_'+l});const m=b['find'](q=>q['identifier']===k);m&&(m['object_type']=ObjectType['Reward']);const n=[];return n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](l)['toBytes']()),n['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](k)['toBytes']()),n['push'](bcs['U16']['serialize'](i)['toBytes']()),checkType(j,c,a),{'output':n,'returnType':j};},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']}),buildProgressHistoryFindConditions=a=>{a['where']['node']!==undefined&&!isValidName(a['where']['node'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20node\x20\x22'+a['where']['node']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMin']!==undefined&&!isValidU64(a['where']['indexMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMin\x20\x22'+a['where']['indexMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMax']!==undefined&&!isValidU64(a['where']['indexMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMax\x20\x22'+a['where']['indexMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const b={'node':a['where']['node']??null,'next_node':a['where']['nextNode']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'index_min':a['where']['indexMin']??null,'index_max':a['where']['indexMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressHistoryFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressSessionFindConditions=a=>{a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20session\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');const b={'next_node':a['where']['nextNode']??null,'find':a['find']==='first'?0x0:0x1};return ProgressSessionFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressForwardFindConditions=async a=>{a['where']['operation']!==undefined&&!isValidName(a['where']['operation'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20forward\x20find\x20operation\x20\x22'+a['where']['operation']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');let b=null;if(a['where']['who']!==undefined){const d=await GetAccountOrMark_Address({'name_or_address':a['where']['who']});!d&&W_ERROR(WErrors['AddressNotFound'],'Progress\x20forward\x20find\x20who\x20\x22'+a['where']['who']+'\x22\x20not\x20found\x20in\x20LocalMark\x20or\x20accounts'),b=d;}const c={'who':b,'operation':a['where']['operation']??null,'accomplished':a['where']['accomplished']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressForwardFindConditionsBCS['serialize'](c)['toBytes']();},buildProgressQuery=async(a,b,c)=>{const d=[];let e;const f=ValueType['U64'];let g;switch(a['type']){case'query_progress_history_find':{e=0x4fa,g=buildProgressHistoryFindConditions(a);break;}case'query_progress_history_session_find':{e=0x4fb,g=buildProgressSessionFindConditions(a);break;}case'query_progress_history_session_forward_find':{e=0x4fc,g=await buildProgressForwardFindConditions(a);break;}case'query_progress_history_session_count':{e=0x4fd,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_count':{e=0x4fe,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_retained_submission_count':{e=0x4ff,g=new Uint8Array(0x0);break;}}const h=a['object']['identifier'],i=getNewIdentifier(b,a['type']);b['push']({'identifier':i,'value_type':ValueType['VecU8'],'value':Array['from'](g),'b_submission':![],'name':'query_conditions_'+i});if(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find'||a['type']==='query_progress_history_session_count'||a['type']==='query_progress_history_session_forward_count'||a['type']==='query_progress_history_session_forward_retained_submission_count'){const j=b['find'](k=>k['identifier']===h);j&&(j['object_type']=ObjectType['Progress']);}(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find')&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));switch(a['type']){case'query_progress_history_session_forward_retained_submission_count':{await buildNode(a['forwardIdx'],ValueType['U64'],b,d),await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_find':case'query_progress_history_session_forward_count':{await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_find':case'query_progress_history_session_count':{await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_find':{break;}}return d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](h)['toBytes']()),d['push'](bcs['U16']['serialize'](e)['toBytes']()),checkType(f,c,a),{'output':d,'returnType':f};},single_operand_op=async(a,b,c,d,e)=>{await buildNode(b,c,d,e),e['push'](bcs['U8']['serialize'](a)['toBytes']());};export const guard2file=async(a,b,c='json',d)=>{const f=await query_objects({'objects':[a],'network':d}),g=f['objects'];if(!g||g['length']===0x0||g[0x0]['type']!=='Guard'){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Guard\x20object\x20not\x20found:\x20'+a);return;}const h=g[0x0];if(!h){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20get\x20Guard\x20object\x20data:\x20'+a);return;}let i;c==='json'?i=generateGuardJson(h):i=generateGuardMarkdown(h);try{const j=resolve(b);writeFileSync(j,i,'utf-8');}catch(k){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20write\x20file\x20\x27'+b+'\x27:\x20'+k['message']);}};const generateGuardJson=a=>{const b={};return a['description']&&(b['description']=a['description']),a['table']&&a['table']['length']>0x0&&(b['table']=a['table']['map'](c=>({'identifier':c['identifier'],'b_submission':c['b_submission'],'value_type':c['value_type'],'value':c['value'],'name':c['name']}))),a['root']&&(b['root']=a['root']),a['relies']&&a['relies']['length']>0x0&&(b['rely']={'guards':a['relies'],'logic_or':!a['relies_logic_and']}),JSON['stringify'](b,null,0x2);},generateGuardMarkdown=a=>{const b=[];b['push']('#\x20Guard\x20Definition'),b['push'](''),b['push']('**Object\x20ID:**\x20'+a['object']),b['push'](''),b['push']('##\x20Summary'),b['push']('');const c=a['description']||'',d=a['table']?a['table']['length']:0x0;let e=''+(c['length']>0x64?c['substring'](0x0,0x61)+'...':c);e+='\x20['+d+'\x20tables]',b['push'](e),b['push'](''),b['push']('##\x20Description'),b['push'](''),b['push'](a['description']||''),b['push'](''),b['push']('##\x20Table\x20(Data\x20Definitions)'),b['push'](''),b['push']('|\x20Identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),b['push']('|------------|--------------|------------|-------|------|');if(a['table']&&a['table']['length']>0x0)for(const f of a['table']){const g=parseValueType(f['value_type']),h=valueTypeToString(g),i=formatValueForMarkdown(f['value']);b['push']('|\x20'+f['identifier']+'\x20|\x20'+f['b_submission']+'\x20|\x20'+h+'\x20('+f['value_type']+')\x20|\x20'+i+'\x20|\x20'+f['name']+'\x20|');}else b['push']('|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|');b['push'](''),b['push']('##\x20Root\x20(Computational\x20Tree)'),b['push'](''),b['push']('The\x20root\x20node\x20MUST\x20return\x20a\x20Bool\x20value\x20(pass/fail).'),b['push']('');if(a['root']){b['push']('```json'),b['push'](JSON['stringify'](a['root'],null,0x2)),b['push']('```'),b['push']('');const j=generateNodeComments(a['root']);if(j['length']>0x0){b['push']('###\x20Node\x20Comments'),b['push']('');for(const k of j){b['push']('-\x20**'+k['type']+'**:\x20'+k['description']);}b['push']('');}}else b['push']('*No\x20root\x20node\x20data\x20available*'),b['push']('');if(a['relies']&&a['relies']['length']>0x0){b['push']('##\x20Rely\x20(Dependencies)'),b['push'](''),b['push']('**Logic:**\x20'+(a['relies_logic_and']?'AND':'OR')),b['push'](''),b['push']('**Dependent\x20Guards:**');for(const l of a['relies']){b['push']('-\x20'+l);}b['push']('');}return b['join']('\x0a');},formatValueForMarkdown=a=>{if(a===undefined||a===null)return'-';if(typeof a==='boolean')return a?'true':'false';if(typeof a==='string')return a['startsWith']('0x')&&a['length']===0x42&&(!isValidAddress(a)&&W_ERROR(WErrors['IsValidAddress'],'Invalid\x20address:\x20'+a)),a;if(typeof a==='number')return a['toString']();if(Array['isArray'](a)){if(a['length']===0x0)return'[]';if(a['length']>0x3)return'['+a['slice'](0x0,0x3)['join'](',\x20')+',\x20...\x20('+a['length']+'\x20items)]';return'['+a['join'](',\x20')+']';}if(typeof a==='object')return'{...}';return String(a);};export const generateNodeComments=(a,b=[])=>{if(!a)return b;if(a['type']==='query'){const c=typeof a['query']==='number'?a['query']:undefined;if(c!==undefined){const d=GUARDQUERY['find'](e=>e['id']===c);d&&b['push']({'type':'query('+a['query']+')','description':d['name']+':\x20'+d['description']});}}else{if(a['type']['startsWith']('query_reward_record_')){const e=a['type']['replace']('query_','')['replace'](/_/g,'.'),f=GUARDQUERY['find'](g=>g['name']===e);f?b['push']({'type':a['type'],'description':f['name']+':\x20'+f['description']}):b['push']({'type':a['type'],'description':'Reward\x20Record\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('query_progress_history_')){const g=a['type']['replace']('query_','')['replace'](/_/g,'.'),h=GUARDQUERY['find'](i=>i['name']===g);h?b['push']({'type':a['type'],'description':h['name']+':\x20'+h['description']}):b['push']({'type':a['type'],'description':'Progress\x20History\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('logic_'))b['push']({'type':a['type'],'description':'Logic\x20operation:\x20'+a['type']['replace'](/_/g,'\x20')});else{if(a['type']['startsWith']('calc_'))b['push']({'type':a['type'],'description':'Calculation:\x20'+a['type']['replace'](/_/g,'\x20')});else a['type']['startsWith']('convert_')&&b['push']({'type':a['type'],'description':'Type\x20conversion:\x20'+a['type']['replace'](/_/g,'\x20')});}}}}if('nodes'in a&&Array['isArray'](a['nodes']))for(const i of a['nodes']){generateNodeComments(i,b);}'node'in a&&a['node']&&generateNodeComments(a['node'],b);if('parameters'in a&&Array['isArray'](a['parameters']))for(const j of a['parameters']){generateNodeComments(j,b);}return'nodeLeft'in a&&a['nodeLeft']&&generateNodeComments(a['nodeLeft'],b),'nodeRight'in a&&a['nodeRight']&&generateNodeComments(a['nodeRight'],b),'recipient'in a&&a['recipient']&&generateNodeComments(a['recipient'],b),'historyIdx'in a&&a['historyIdx']&&generateNodeComments(a['historyIdx'],b),'sessionIdx'in a&&a['sessionIdx']&&generateNodeComments(a['sessionIdx'],b),'forwardIdx'in a&&a['forwardIdx']&&generateNodeComments(a['forwardIdx'],b),b;};const valueTypeToString=a=>{const b={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8',[ValueType['Value']]:'Value'};return b[a]||'Unknown('+a+')';};export const gen_passport=async(a,b,c)=>{!isValidWowAddress(b)&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20empty');await resolveCallEnv(a);const d=await get_guardSubmissions(a,[b]);return d['submission']['length']>0x0?!c?{'type':'submission','guard':d['guard'],'submission':d['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':[{'object':b,'impack':!![]}],'submission':[]});};function detectFileFormatFromContent(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')||e['startsWith']('[')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseTableFromMarkdown(a){const b=a['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(b)try{const d=JSON['parse'](b[0x1]);if(Array['isArray'](d))return d;}catch{}const c=a['match'](/\|[^\n]+\|/g);if(c&&c['length']>0x2)return c['slice'](0x2)['map'](e=>{const f=e['split']('|')['filter'](j=>j['trim']())['map'](j=>j['trim']()),g=f[0x2];let h;const i=g['match'](/\((\d+)\)/);if(i)h=parseInt(i[0x1],0xa);else{const j=g['match'](/^\s*(\d+)\s*$/);if(j)h=parseInt(j[0x1],0xa);else{const k=g['match'](/^([A-Za-z]+)/);if(k)h=k[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+g+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}}return{'identifier':parseInt(f[0x0],0xa),'b_submission':f[0x1]['toLowerCase']()==='true','value_type':h,'value':f[0x3]==='-'?undefined:f[0x3],'name':f[0x4]==='-'?undefined:f[0x4]};});return undefined;}function parseRelyFromMarkdown(a){const b=a['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),c=a['match'](/^\s*[-*]\s*(\S+)$/gm);if(b||c)return{'logic_or':b?b[0x1]['toUpperCase']()==='OR':![],'guards':c?c['map'](d=>d['replace'](/^\s*[-*]\s*/,'')['trim']()):[]};return undefined;}export function parseGuardFromMarkdown(a){const b=[],c={},d=extractJsonFromMarkdown(a);if(d)try{const f=JSON['parse'](d['json']);Object['assign'](c,f);}catch(g){b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20code\x20block:\x20'+g['message'],'path':'/','line':d['lineOffset']});}if(!c['description']){const h=a['match'](/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);h&&(c['description']=h[0x1]['trim']());}if(!c['table']){const i=a['match'](/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const j=parseTableFromMarkdown(i[0x1]);j&&(c['table']=j);}}if(!c['root']){const k=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(k){const l=k[0x1],m=l['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(m)try{c['root']=JSON['parse'](m[0x1]);}catch(n){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+n['message'],'path':'/root'});}}}if(!c['rely']){const o=a['match'](/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(o){const p=parseRelyFromMarkdown(o[0x1]);p&&(c['rely']=p);}}if(!c['root'])return b['push']({'message':'Guard\x20root\x20node\x20not\x20found\x20in\x20markdown\x20file','path':'/root'}),{'success':![],'errors':b};return{'success':!![],'data':c,'errors':b};}export function parseGuardFile(a,b){const c=b??detectFileFormatFromContent(a);if(c==='json')try{const d=JSON['parse'](a);if(!d['root'])return{'success':![],'errors':[{'message':'Missing\x20required\x20field:\x20root','path':'/root'}]};return{'success':!![],'data':d,'errors':[]};}catch(f){return{'success':![],'errors':[{'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/'}]};}return parseGuardFromMarkdown(a);}export function validateGuardNode(a){const b=[];if(!a||typeof a!=='object')return b['push']({'message':'GuardNode\x20must\x20be\x20an\x20object','path':'/'}),{'success':![],'errors':b};const c=a;if(!c['type']||typeof c['type']!=='string')return b['push']({'message':'GuardNode\x20must\x20have\x20a\x20\x27type\x27\x20property','path':'/type'}),{'success':![],'errors':b};const d=['identifier','query','context','logic_not','logic_and','logic_or','logic_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','calc_string_length','calc_string_nocase_contains','calc_string_nocase_equal','calc_string_contains','calc_string_indexof','calc_string_nocase_indexof','convert_number_address','convert_address_number','convert_number_string','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','value_type','vec_length','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_find','query_reward_record_count','query_reward_record_exists','query_progress_history_find','query_progress_history_session_find','query_progress_history_session_forward_find','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];return!d['includes'](c['type'])&&b['push']({'message':'Invalid\x20GuardNode\x20type:\x20'+c['type'],'path':'/type'}),{'success':b['length']===0x0,'errors':b};}export function formatGuardParseErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}
1
+ import{toTxObject,toTxString,isValidDescription,MAX_DESCRIPTION_LENGTH,isValidU8,isValidU64,isValidName,ValueType,parseValueType,OperatorType,ContextType,isWitnessType,PackageAddress,ObjectType,MAX_INPUT_SIZE,MAX_DEPENDED_COUNT,MAX_MULTI_OPERANDS}from'../common.js';import a151a from'lodash';import{W_ERROR,WErrors}from'../exception.js';import{CallBase}from'./base.js';import{isValidAddress,LocalMark}from'../local/local.js';import{GetAccountOrMark_Address}from'../local/index.js';import{WitnessSourceType,WitnessTargetType,query_objects}from'../query/object.js';import{bcs}from'../../bcs/index.js';import{valueToBcsBytes}from'../util.js';import{getGuardQueryInfo,GUARDQUERY}from'./guard-ins.js';import{checkType,resolveCallEnv}from'./util.js';import{isValidWowAddress}from'../../utils/sui-types.js';import{get_guardSubmissions,verify_guard}from'./passport.js';import{writeFileSync}from'fs';import{resolve}from'path';export function guardFn(a){return PackageAddress+'::guard::'+a;}export class CallGuard extends CallBase{['data'];constructor(a){super(),this['data']=a;}async['call'](a){return await this['prepare'](a),await this['exec'](a);}async['operate'](a,b,c,d){(!this['data']['table']||this['data']['table']['length']===0x0)&&W_ERROR(WErrors['InvalidParam'],'table\x20is\x20empty');!this['data']['root']&&W_ERROR(WErrors['InvalidParam'],'root\x20is\x20empty');const e=await newGuard(b,this['data']?.['description']||'',this['data']?.['table'],this['data']?.['root']);if(this['data']?.['rely']!=null){const f=await LocalMark['Instance']()['get_many_address'](this['data']['rely']['guards']),g=f['findIndex'](h=>h===undefined);g!==-0x1&&W_ERROR(WErrors['InvalidParam'],'rely.guards\x20invalid:\x20guard\x20at\x20index\x20'+g+'\x20not\x20found'),reliesAdd(b,e,f['filter'](h=>h!==undefined));}await this['new_with_mark'](a,b,ObjectType['Guard'],create(b,e),this['data']?.['namedNew']);}}export const newGuard=async(a,b,c,d)=>{!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);for(let m=0x0;m<c['length'];m++){const n=c[m];if(!isValidU8(n['identifier']))W_ERROR(WErrors['InvalidParam'],'table.identifier\x20'+n['identifier']+'\x20invalid');if(!n['b_submission']&&(n['value']===undefined||n['value']===null))W_ERROR(WErrors['InvalidParam'],'table.value\x20'+n['value']+'\x20with\x20identifier\x20'+n['identifier']+'\x20invalid');if(!isValidName(n['name']))W_ERROR(WErrors['InvalidParam'],'table.name');}const e=a151a['groupBy'](c,'identifier'),f=Object['keys'](e)['filter'](o=>e[o]['length']>0x1);f['length']>0x0&&W_ERROR(WErrors['InvalidParam'],'table.identifier\x20duplicates:\x20'+f['join'](',\x20'));var g=[];await buildNode(d,ValueType['Bool'],c,g);const h=g['reduce']((o,p)=>o+p['length'],0x0),j=new Uint8Array(h);let k=0x0;for(const o of g){j['set'](o,k),k+=o['length'];}j['length']>MAX_INPUT_SIZE&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20size\x20exceeds\x20maximum\x20limit\x20'+MAX_INPUT_SIZE);j['length']===0x0&&W_ERROR(WErrors['NewGuardCheckFailed'],'Input\x20cannot\x20be\x20empty');const l=[];for(let p=0x0;p<c['length'];p++){const q=c[p],r=parseValueType(q['value_type']);let s;q['b_submission']?(s=new Uint8Array(0x1),s[0x0]=r):((q['value']===undefined||q['value']===null)&&W_ERROR(WErrors['NewGuardCheckFailed'],'Table\x20item\x20value\x20is\x20required\x20when\x20b_submission\x20is\x20false'),s=await valueToBcsBytes(r,q['value'])),l['push'](a['moveCall']({'target':guardFn('table_item'),'arguments':[a['pure']['u8'](q['identifier']),a['pure']['bool'](q['b_submission']),a['pure']['vector']('u8',Array['from'](s)),toTxString(a,q['name'])]}));}return a['moveCall']({'target':guardFn('new'),'arguments':[toTxString(a,b),a['makeMoveVec']({'elements':l,'type':PackageAddress+'::guard::TableItem'}),a['pure']['vector']('u8',Array['from'](j))]});};export function create(a,b){return a['moveCall']({'target':guardFn('create'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function reliesAdd(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{e===b&&W_ERROR(WErrors['NewGuardCheckFailed'],'Guard\x20cannot\x20rely\x20on\x20itself'),a['moveCall']({'target':guardFn('relies_add'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()]});});}export function reliesRemove(a,b,c){const d=a151a['uniq'](c);d['length']>MAX_DEPENDED_COUNT&&W_ERROR(WErrors['NewGuardCheckFailed'],'Relies\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_DEPENDED_COUNT),d['forEach'](e=>{a['moveCall']({'target':guardFn('relies_remove'),'arguments':[toTxObject(a,b),toTxObject(a,e),a['object']['mutRegistrar']()]});});}export function reliesClear(a,b){a['moveCall']({'target':guardFn('relies_clear'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function reliesLogic(a,b,c){a['moveCall']({'target':guardFn('relies_logic_and'),'arguments':[toTxObject(a,b),a['pure']['bool'](c)]});}const buildNode=async(a,b,c,d)=>{const e=a;switch(e['type']){case'identifier':{const g=c['find'](h=>h['identifier']===e['identifier']);if(g){const h=parseValueType(g['value_type']);checkType(h,b,e),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](e['identifier'])['toBytes']());}else W_ERROR(WErrors['InvalidParam'],'node\x20identifier\x20-\x20'+JSON['stringify'](e));break;}case'query':{const j=getGuardQueryInfo(e['query']);!j&&W_ERROR(WErrors['InvalidParam'],'query\x20not\x20found:\x20'+e['query']);checkType(j['return'],b,e);if(j['parameters']['length']===e['parameters']['length'])for(let m=e['parameters']['length']-0x1;m>=0x0;--m){await buildNode(e['parameters'][m],j['parameters'][m],c,d);}else W_ERROR(WErrors['InvalidParam'],'node\x20query\x20parameters\x20length\x20not\x20match\x20-\x20'+JSON['stringify'](e));const k=c['find'](n=>n['identifier']===e['object']['identifier']);!k&&W_ERROR(WErrors['InvalidParam'],'node\x20object\x20from\x20identifier\x20-\x20'+JSON['stringify'](e));const l=parseValueType(k['value_type']);l!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],'object\x20to\x20query\x20must\x20be\x20address\x20in\x20table\x20'+k+'.\x20'+e['object']);d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']());if(isWitnessType(e['object']['convert_witness'])){const n=WitnessTargetType(e['object']['convert_witness']);n!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+n+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+j['objectType']+')');const o=WitnessSourceType(e['object']['convert_witness']);k['object_type']?k['object_type']!==o&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+o+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=o,d['push'](bcs['U8']['serialize'](e['object']['convert_witness'])['toBytes']());}else k?.['object_type']?k['object_type']!==j['objectType']&&W_ERROR(WErrors['InvalidParam'],'witness\x20object\x20type('+j['objectType']+')\x20not\x20consistent\x20with\x20query\x20object\x20type('+k['object_type']+')'):k['object_type']=j['objectType'],d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']());d['push'](bcs['U8']['serialize'](e['object']['identifier'])['toBytes']()),d['push'](bcs['U16']['serialize'](j['id'])['toBytes']());break;}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_equal':case'logic_and':case'logic_or':case'logic_string_contains':case'logic_string_nocase_contains':case'logic_string_nocase_equal':case'calc_number_add':case'calc_number_subtract':case'calc_number_multiply':case'calc_number_divide':case'calc_number_mod':case'calc_string_nocase_contains':case'calc_string_nocase_equal':case'calc_string_contains':{const p={'logic_as_u256_greater_or_equal':OperatorType['TypeLogicAsU256GreaterEqual'],'logic_as_u256_lesser_or_equal':OperatorType['TypeLogicAsU256LesserEqual'],'logic_as_u256_equal':OperatorType['TypeLogicAsU256Equal'],'logic_as_u256_greater':OperatorType['TypeLogicAsU256Greater'],'logic_as_u256_lesser':OperatorType['TypeLogicAsU256Lesser'],'logic_equal':OperatorType['TypeLogicEqual'],'logic_and':OperatorType['TypeLogicAnd'],'logic_or':OperatorType['TypeLogicOr'],'logic_string_contains':OperatorType['TypeStringContains'],'logic_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'logic_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_number_add':OperatorType['TypeNumberAdd'],'calc_number_subtract':OperatorType['TypeNumberSubtract'],'calc_number_multiply':OperatorType['TypeNumberMultiply'],'calc_number_divide':OperatorType['TypeNumberDivide'],'calc_number_mod':OperatorType['TypeNumberMod'],'calc_string_nocase_contains':OperatorType['TypeStringNocaseContains'],'calc_string_nocase_equal':OperatorType['TypeStringNocaseEqual'],'calc_string_contains':OperatorType['TypeStringContains']},r={'logic_as_u256_greater_or_equal':'number','logic_as_u256_lesser_or_equal':'number','logic_as_u256_equal':'number','logic_as_u256_greater':'number','logic_as_u256_lesser':'number','logic_equal':'variable','logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['String'],'logic_string_nocase_contains':ValueType['String'],'logic_string_nocase_equal':ValueType['String'],'calc_number_add':'number','calc_number_subtract':'number','calc_number_multiply':'number','calc_number_divide':'number','calc_number_mod':'number','calc_string_nocase_contains':ValueType['String'],'calc_string_nocase_equal':ValueType['String'],'calc_string_contains':ValueType['String']},s={'logic_as_u256_greater_or_equal':ValueType['Bool'],'logic_as_u256_lesser_or_equal':ValueType['Bool'],'logic_as_u256_equal':ValueType['Bool'],'logic_as_u256_greater':ValueType['Bool'],'logic_as_u256_lesser':ValueType['Bool'],'logic_equal':ValueType['Bool'],'logic_and':ValueType['Bool'],'logic_or':ValueType['Bool'],'logic_string_contains':ValueType['Bool'],'logic_string_nocase_contains':ValueType['Bool'],'logic_string_nocase_equal':ValueType['Bool'],'calc_number_add':ValueType['U256'],'calc_number_subtract':ValueType['U256'],'calc_number_multiply':ValueType['U256'],'calc_number_divide':ValueType['U256'],'calc_number_mod':ValueType['U256'],'calc_string_nocase_contains':ValueType['Bool'],'calc_string_nocase_equal':ValueType['Bool'],'calc_string_contains':ValueType['Bool']};checkType(s[e['type']],b,e),await multi_operand_op(p[e['type']],e['nodes'],r[e['type']],c,d);break;}case'vec_contains_bool':case'vec_contains_address':case'vec_contains_string':case'vec_contains_string_nocase':case'vec_contains_number':{const t={'vec_contains_bool':OperatorType['TypedValueVecContains_Bool'],'vec_contains_address':OperatorType['TypedValueVecContains_Address'],'vec_contains_string':OperatorType['TypedValueVecContains_String'],'vec_contains_string_nocase':OperatorType['TypedValueVecContains_StringNoCase'],'vec_contains_number':OperatorType['TypedValueVecContains_Number']},u={'vec_contains_bool':ValueType['VecBool'],'vec_contains_address':ValueType['VecAddress'],'vec_contains_string':ValueType['VecString'],'vec_contains_string_nocase':ValueType['VecString'],'vec_contains_number':'vec_number'},v={'vec_contains_bool':ValueType['Bool'],'vec_contains_address':ValueType['Address'],'vec_contains_string':ValueType['String'],'vec_contains_string_nocase':ValueType['String'],'vec_contains_number':'number'};checkType(ValueType['Bool'],b,e);for(let w=e['nodes']['length']-0x1;w>=0x0;--w){const x=w===0x0?u[e['type']]:v[e['type']];await buildNode(e['nodes'][w],x,c,d);}d['push'](bcs['U8']['serialize'](t[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['nodes']['length'])['toBytes']());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':{const y={'logic_not':OperatorType['TypeLogicNot'],'calc_string_length':OperatorType['TypeStringLength'],'convert_number_address':OperatorType['TypeNumberAddress'],'convert_address_number':OperatorType['TypeAddressNumber'],'convert_number_string':OperatorType['TypeNumberString'],'convert_string_number':OperatorType['TypeStringNumber'],'convert_safe_u8':OperatorType['TypeSafeU8'],'convert_safe_u16':OperatorType['TypeSafeU16'],'convert_safe_u32':OperatorType['TypeSafeU32'],'convert_safe_u64':OperatorType['TypeSafeU64'],'convert_safe_u128':OperatorType['TypeSafeU128'],'convert_safe_u256':OperatorType['TypeSafeU256'],'value_type':OperatorType['TypedValueType'],'vec_length':OperatorType['TypedValueVecLength']},z={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['String'],'convert_number_address':'number','convert_address_number':ValueType['Address'],'convert_number_string':'number','convert_string_number':ValueType['String'],'convert_safe_u8':'number','convert_safe_u16':'number','convert_safe_u32':'number','convert_safe_u64':'number','convert_safe_u128':'number','convert_safe_u256':'number','value_type':'variable','vec_length':'vec'},A={'logic_not':ValueType['Bool'],'calc_string_length':ValueType['U64'],'convert_number_address':ValueType['Address'],'convert_address_number':ValueType['U256'],'convert_number_string':ValueType['String'],'convert_string_number':ValueType['U256'],'convert_safe_u8':ValueType['U8'],'convert_safe_u16':ValueType['U16'],'convert_safe_u32':ValueType['U32'],'convert_safe_u64':ValueType['U64'],'convert_safe_u128':ValueType['U128'],'convert_safe_u256':ValueType['U256'],'value_type':ValueType['U8'],'vec_length':ValueType['U64']};checkType(A[e['type']],b,e),await single_operand_op(y[e['type']],e['node'],z[e['type']],c,d);break;}case'calc_string_indexof':case'calc_string_nocase_indexof':{const B={'calc_string_indexof':OperatorType['TypeStringIndexof'],'calc_string_nocase_indexof':OperatorType['TypeStringNocaseIndexof']};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],ValueType['String'],c,d),await buildNode(e['nodeLeft'],ValueType['String'],c,d),d['push'](bcs['U8']['serialize'](B[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'vec_indexof_bool':case'vec_indexof_address':case'vec_indexof_string':case'vec_indexof_string_nocase':case'vec_indexof_number':{const C={'vec_indexof_bool':OperatorType['TypedValueVecIndexOf_Bool'],'vec_indexof_address':OperatorType['TypedValueVecIndexOf_Address'],'vec_indexof_string':OperatorType['TypedValueVecIndexOf_String'],'vec_indexof_string_nocase':OperatorType['TypedValueVecIndexOf_StringNoCase'],'vec_indexof_number':OperatorType['TypedValueVecIndexOf_Number']},D={'vec_indexof_bool':ValueType['Bool'],'vec_indexof_address':ValueType['Address'],'vec_indexof_string':ValueType['String'],'vec_indexof_string_nocase':ValueType['String'],'vec_indexof_number':'number'},E={'vec_indexof_bool':ValueType['VecBool'],'vec_indexof_address':ValueType['VecAddress'],'vec_indexof_string':ValueType['VecString'],'vec_indexof_string_nocase':ValueType['VecString'],'vec_indexof_number':'vec_number'};checkType(ValueType['U64'],b,e),await buildNode(e['nodeRight'],D[e['type']],c,d),await buildNode(e['nodeLeft'],E[e['type']],c,d),d['push'](bcs['U8']['serialize'](C[e['type']])['toBytes']()),d['push'](bcs['U8']['serialize'](e['order']==='forward'?0x0:0x1)['toBytes']());break;}case'query_reward_record_find':case'query_reward_record_count':case'query_reward_record_exists':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const F=c['find'](H=>H['identifier']===e['object']['identifier']);!F&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const G=await buildRewardRecordQuery(e,c,b);d['push'](...G['output']);break;}case'query_progress_history_find':case'query_progress_history_session_find':case'query_progress_history_session_forward_find':case'query_progress_history_session_count':case'query_progress_history_session_forward_count':case'query_progress_history_session_forward_retained_submission_count':{!isValidU8(e['object']['identifier'])&&W_ERROR(WErrors['IsValidU8'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20is\x20not\x20a\x20valid\x20U8\x20(0-255)');const H=c['find'](J=>J['identifier']===e['object']['identifier']);!H&&W_ERROR(WErrors['IsValidIdentifier'],e['type']+'\x20object\x20identifier\x20'+e['object']['identifier']+'\x20not\x20found\x20in\x20table');const I=await buildProgressQuery(e,c,b);d['push'](...I['output']);break;}case'context':{let J;switch(e['context']){case'Signer':J=ContextType['TypeSigner'];break;case'Clock':J=ContextType['TypeClock'];break;case'Guard':J=ContextType['TypeGuard'];break;default:W_ERROR(WErrors['InvalidParam'],'Invalid\x20context\x20type:\x20'+e['context']);}d['push'](bcs['U8']['serialize'](J)['toBytes']());e['context']==='Clock'?checkType(ContextType['TypeClock'],b,e):checkType(ValueType['Address'],b,e);break;}default:W_ERROR(WErrors['InvalidParam'],'node:'+JSON['stringify'](e));}},multi_operand_op=async(a,b,c,d,e)=>{(b['length']<0x2||b['length']>MAX_MULTI_OPERANDS)&&W_ERROR(WErrors['InvalidParam'],'op\x20'+a+'\x20parameters\x20length\x20must\x20>=\x202\x20and\x20<=\x20\x20\x0a\x09\x09\x09\x09'+MAX_MULTI_OPERANDS+'.\x20\x09parameters:\x0a\x09\x09\x09\x09'+JSON['stringify'](b));for(let f=b['length']-0x1;f>=0x0;--f){await buildNode(b[f],c,d,e);}e['push'](bcs['U8']['serialize'](a)['toBytes']()),e['push'](bcs['U8']['serialize'](b['length'])['toBytes']());},getNewIdentifier=(a,b)=>{for(let c=0x0;c<0x100;c++){if(!a['find'](d=>d['identifier']===c))return c;}return W_ERROR(WErrors['InvalidParam'],b+'\x20cannot\x20find\x20available\x20identifier\x20in\x20table\x20(all\x20256\x20identifiers\x20are\x20used)'),-0x1;},StoreFromIdFilter=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'](StoreFromIdFilter)}),buildRecordQueryConditionsFromConst=a=>{const b={'recipient':a['recipient'],'guard':a['guard']??null,'time_min':a['timeMin']??null,'time_max':a['timeMax']??null,'amount_min':a['amountMin']??null,'amount_max':a['amountMax']??null,'store_from_id':a['storeFromId']?{'mode':a['storeFromId']==='not_exists'?0x0:a['storeFromId']==='exists'?0x1:0x2,'value':typeof a['storeFromId']==='object'?a['storeFromId']['eq']:null}:null};return RecordQueryConditionsBCS['serialize'](b)['toBytes']();},buildRewardRecordQuery=async(a,b,c)=>{const d=a['recipient'];d['type']!=='identifier'&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20an\x20identifier');const e=d,f=b[e['identifier']];!f&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20identifier\x20'+e['identifier']+'\x20not\x20found\x20in\x20table');f['value_type']!==ValueType['Address']&&W_ERROR(WErrors['InvalidParam'],a['type']+'\x20recipient\x20must\x20be\x20Address\x20type,\x20got\x20'+f['value_type']);a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMin']!==undefined&&!isValidU64(a['where']['amountMin'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMin\x20\x22'+a['where']['amountMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['amountMax']!==undefined&&!isValidU64(a['where']['amountMax'])&&W_ERROR(WErrors['IsValidU64'],'Reward\x20record\x20query\x20amountMax\x20\x22'+a['where']['amountMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const g={'recipient':f['value']};if(a['where']['guard']){const o=await LocalMark['Instance']()['get_address'](a['where']['guard']);!o&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20guard\x20\x22'+a['where']['guard']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['guard']=o;}if(a['where']['timeMin']!==undefined)g['timeMin']=a['where']['timeMin'];if(a['where']['timeMax']!==undefined)g['timeMax']=a['where']['timeMax'];if(a['where']['amountMin']!==undefined)g['amountMin']=a['where']['amountMin'];if(a['where']['amountMax']!==undefined)g['amountMax']=a['where']['amountMax'];if(a['where']['storeFromId']!==undefined){if(typeof a['where']['storeFromId']==='object'&&'eq'in a['where']['storeFromId']){const p=await LocalMark['Instance']()['get_address'](a['where']['storeFromId']['eq']);!p&&W_ERROR(WErrors['AddressNotFound'],'Reward\x20record\x20query\x20storeFromId\x20\x22'+a['where']['storeFromId']['eq']+'\x22\x20not\x20found\x20in\x20LocalMark'),g['storeFromId']={'eq':p};}else g['storeFromId']=a['where']['storeFromId'];}const h=buildRecordQueryConditionsFromConst(g);let i,j;switch(a['type']){case'query_reward_record_find':i=a['find']==='first'?0x65a:0x65b,j=ValueType['U64'];break;case'query_reward_record_count':i=0x65c,j=ValueType['U64'];break;case'query_reward_record_exists':i=0x65d,j=ValueType['Bool'];break;}const k=a['object']['identifier'],l=getNewIdentifier(b,a['type']);b['push']({'identifier':l,'value_type':ValueType['VecU8'],'value':Array['from'](h),'b_submission':![],'name':'query_conditions_'+l});const m=b['find'](q=>q['identifier']===k);m&&(m['object_type']=ObjectType['Reward']);const n=[];return n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](l)['toBytes']()),n['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),n['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),n['push'](bcs['U8']['serialize'](k)['toBytes']()),n['push'](bcs['U16']['serialize'](i)['toBytes']()),checkType(j,c,a),{'output':n,'returnType':j};},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']),'index_min':bcs['option'](bcs['U64']),'index_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']}),buildProgressHistoryFindConditions=a=>{a['where']['node']!==undefined&&!isValidName(a['where']['node'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20node\x20\x22'+a['where']['node']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20history\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMin']!==undefined&&!isValidU64(a['where']['indexMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMin\x20\x22'+a['where']['indexMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['indexMax']!==undefined&&!isValidU64(a['where']['indexMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20history\x20find\x20indexMax\x20\x22'+a['where']['indexMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');const b={'node':a['where']['node']??null,'next_node':a['where']['nextNode']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'index_min':a['where']['indexMin']??null,'index_max':a['where']['indexMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressHistoryFindConditionsBCS['serialize'](b)['toBytes']();},buildProgressSessionFindConditions=a=>{a['where']['nextNode']!==undefined&&!isValidName(a['where']['nextNode'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20session\x20find\x20nextNode\x20\x22'+a['where']['nextNode']+'\x22\x20is\x20not\x20a\x20valid\x20name');const b={'next_node':a['where']['nextNode']??null,'find':a['find']==='first'?0x0:0x1},c=ProgressSessionFindConditionsBCS['serialize'](b)['toBytes']();return c;},buildProgressForwardFindConditions=async a=>{a['where']['operation']!==undefined&&!isValidName(a['where']['operation'])&&W_ERROR(WErrors['IsValidName'],'Progress\x20forward\x20find\x20operation\x20\x22'+a['where']['operation']+'\x22\x20is\x20not\x20a\x20valid\x20name');a['where']['timeMin']!==undefined&&!isValidU64(a['where']['timeMin'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMin\x20\x22'+a['where']['timeMin']+'\x22\x20is\x20not\x20a\x20valid\x20U64');a['where']['timeMax']!==undefined&&!isValidU64(a['where']['timeMax'])&&W_ERROR(WErrors['IsValidU64'],'Progress\x20forward\x20find\x20timeMax\x20\x22'+a['where']['timeMax']+'\x22\x20is\x20not\x20a\x20valid\x20U64');let b=null;if(a['where']['who']!==undefined){const d=await GetAccountOrMark_Address({'name_or_address':a['where']['who']});!d&&W_ERROR(WErrors['AddressNotFound'],'Progress\x20forward\x20find\x20who\x20\x22'+a['where']['who']+'\x22\x20not\x20found\x20in\x20LocalMark\x20or\x20accounts'),b=d;}const c={'who':b,'operation':a['where']['operation']??null,'accomplished':a['where']['accomplished']??null,'time_min':a['where']['timeMin']??null,'time_max':a['where']['timeMax']??null,'find':a['find']==='first'?0x0:0x1};return ProgressForwardFindConditionsBCS['serialize'](c)['toBytes']();},buildProgressQuery=async(a,b,c)=>{const d=[];let e;const f=ValueType['U64'];let g;switch(a['type']){case'query_progress_history_find':{e=0x4fa,g=buildProgressHistoryFindConditions(a);break;}case'query_progress_history_session_find':{e=0x4fb,g=buildProgressSessionFindConditions(a);break;}case'query_progress_history_session_forward_find':{e=0x4fc,g=await buildProgressForwardFindConditions(a);break;}case'query_progress_history_session_count':{e=0x4fd,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_count':{e=0x4fe,g=new Uint8Array(0x0);break;}case'query_progress_history_session_forward_retained_submission_count':{e=0x4ff,g=new Uint8Array(0x0);break;}}const h=a['object']['identifier'];let i=null;if('conditionsIdentifier'in a&&a['conditionsIdentifier']!==undefined&&a['conditionsIdentifier']!==null)i=a['conditionsIdentifier'];else(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find')&&(i=getNewIdentifier(b,a['type']),b['push']({'identifier':i,'value_type':ValueType['VecU8'],'value':Array['from'](g),'b_submission':![],'name':'query_conditions_'+i}),a['conditionsIdentifier']=i);if(a['type']==='query_progress_history_find'||a['type']==='query_progress_history_session_find'||a['type']==='query_progress_history_session_forward_find'||a['type']==='query_progress_history_session_count'||a['type']==='query_progress_history_session_forward_count'||a['type']==='query_progress_history_session_forward_retained_submission_count'){const j=b['find'](k=>k['identifier']===h);j&&(j['object_type']=ObjectType['Progress']);}switch(a['type']){case'query_progress_history_session_forward_retained_submission_count':{await buildNode(a['forwardIdx'],ValueType['U64'],b,d),await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_count':{await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_forward_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));await buildNode(a['sessionIdx'],ValueType['U64'],b,d),await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_count':{await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_session_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));await buildNode(a['historyIdx'],ValueType['U64'],b,d);break;}case'query_progress_history_find':{i!==null&&(d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](i)['toBytes']()));break;}}return d['push'](bcs['U8']['serialize'](OperatorType['TypeQuery'])['toBytes']()),d['push'](bcs['U8']['serialize'](ContextType['TypeConstant'])['toBytes']()),d['push'](bcs['U8']['serialize'](h)['toBytes']()),d['push'](bcs['U16']['serialize'](e)['toBytes']()),checkType(f,c,a),{'output':d,'returnType':f};},single_operand_op=async(a,b,c,d,e)=>{await buildNode(b,c,d,e),e['push'](bcs['U8']['serialize'](a)['toBytes']());};export const guard2file=async(a,b,c='json',d)=>{const f=await query_objects({'objects':[a],'network':d}),g=f['objects'];if(!g||g['length']===0x0||g[0x0]['type']!=='Guard'){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Guard\x20object\x20not\x20found:\x20'+a);return;}const h=g[0x0];if(!h){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20get\x20Guard\x20object\x20data:\x20'+a);return;}let i;c==='json'?i=generateGuardJson(h):i=generateGuardMarkdown(h);try{const j=resolve(b);writeFileSync(j,i,'utf-8');}catch(k){W_ERROR(WErrors['InvalidParam'],'guard2file:\x20Failed\x20to\x20write\x20file\x20\x27'+b+'\x27:\x20'+k['message']);}};const generateGuardJson=a=>{const b={};return a['description']&&(b['description']=a['description']),a['table']&&a['table']['length']>0x0&&(b['table']=a['table']['map'](c=>({'identifier':c['identifier'],'b_submission':c['b_submission'],'value_type':c['value_type'],'value':c['value'],'name':c['name']}))),a['root']&&(b['root']=a['root']),a['relies']&&a['relies']['length']>0x0&&(b['rely']={'guards':a['relies'],'logic_or':!a['relies_logic_and']}),JSON['stringify'](b,null,0x2);},generateGuardMarkdown=a=>{const b=[];b['push']('#\x20Guard\x20Definition'),b['push'](''),b['push']('**Object\x20ID:**\x20'+a['object']),b['push'](''),b['push']('##\x20Summary'),b['push']('');const c=a['description']||'',d=a['table']?a['table']['length']:0x0;let e=''+(c['length']>0x64?c['substring'](0x0,0x61)+'...':c);e+='\x20['+d+'\x20tables]',b['push'](e),b['push'](''),b['push']('##\x20Description'),b['push'](''),b['push'](a['description']||''),b['push'](''),b['push']('##\x20Table\x20(Data\x20Definitions)'),b['push'](''),b['push']('|\x20Identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),b['push']('|------------|--------------|------------|-------|------|');if(a['table']&&a['table']['length']>0x0)for(const f of a['table']){const g=parseValueType(f['value_type']),h=valueTypeToString(g),i=formatValueForMarkdown(f['value']);b['push']('|\x20'+f['identifier']+'\x20|\x20'+f['b_submission']+'\x20|\x20'+h+'\x20('+f['value_type']+')\x20|\x20'+i+'\x20|\x20'+f['name']+'\x20|');}else b['push']('|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|\x20-\x20|');b['push'](''),b['push']('##\x20Root\x20(Computational\x20Tree)'),b['push'](''),b['push']('The\x20root\x20node\x20MUST\x20return\x20a\x20Bool\x20value\x20(pass/fail).'),b['push']('');if(a['root']){b['push']('```json'),b['push'](JSON['stringify'](a['root'],null,0x2)),b['push']('```'),b['push']('');const j=generateNodeComments(a['root']);if(j['length']>0x0){b['push']('###\x20Node\x20Comments'),b['push']('');for(const k of j){b['push']('-\x20**'+k['type']+'**:\x20'+k['description']);}b['push']('');}}else b['push']('*No\x20root\x20node\x20data\x20available*'),b['push']('');if(a['relies']&&a['relies']['length']>0x0){b['push']('##\x20Rely\x20(Dependencies)'),b['push'](''),b['push']('**Logic:**\x20'+(a['relies_logic_and']?'AND':'OR')),b['push'](''),b['push']('**Dependent\x20Guards:**');for(const l of a['relies']){b['push']('-\x20'+l);}b['push']('');}return b['join']('\x0a');},formatValueForMarkdown=a=>{if(a===undefined||a===null)return'-';if(typeof a==='boolean')return a?'true':'false';if(typeof a==='string')return a['startsWith']('0x')&&a['length']===0x42&&(!isValidAddress(a)&&W_ERROR(WErrors['IsValidAddress'],'Invalid\x20address:\x20'+a)),a;if(typeof a==='number')return a['toString']();if(Array['isArray'](a)){if(a['length']===0x0)return'[]';if(a['length']>0x3)return'['+a['slice'](0x0,0x3)['join'](',\x20')+',\x20...\x20('+a['length']+'\x20items)]';return'['+a['join'](',\x20')+']';}if(typeof a==='object')return'{...}';return String(a);};export const generateNodeComments=(a,b=[])=>{if(!a)return b;if(a['type']==='query'){const c=typeof a['query']==='number'?a['query']:undefined;if(c!==undefined){const d=GUARDQUERY['find'](e=>e['id']===c);d&&b['push']({'type':'query('+a['query']+')','description':d['name']+':\x20'+d['description']});}}else{if(a['type']['startsWith']('query_reward_record_')){const e=a['type']['replace']('query_','')['replace'](/_/g,'.'),f=GUARDQUERY['find'](g=>g['name']===e);f?b['push']({'type':a['type'],'description':f['name']+':\x20'+f['description']}):b['push']({'type':a['type'],'description':'Reward\x20Record\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('query_progress_history_')){const g=a['type']['replace']('query_','')['replace'](/_/g,'.'),h=GUARDQUERY['find'](i=>i['name']===g);h?b['push']({'type':a['type'],'description':h['name']+':\x20'+h['description']}):b['push']({'type':a['type'],'description':'Progress\x20History\x20query:\x20'+a['type']['replace'](/_/g,'\x20')});}else{if(a['type']['startsWith']('logic_'))b['push']({'type':a['type'],'description':'Logic\x20operation:\x20'+a['type']['replace'](/_/g,'\x20')});else{if(a['type']['startsWith']('calc_'))b['push']({'type':a['type'],'description':'Calculation:\x20'+a['type']['replace'](/_/g,'\x20')});else a['type']['startsWith']('convert_')&&b['push']({'type':a['type'],'description':'Type\x20conversion:\x20'+a['type']['replace'](/_/g,'\x20')});}}}}if('nodes'in a&&Array['isArray'](a['nodes']))for(const i of a['nodes']){generateNodeComments(i,b);}'node'in a&&a['node']&&generateNodeComments(a['node'],b);if('parameters'in a&&Array['isArray'](a['parameters']))for(const j of a['parameters']){generateNodeComments(j,b);}return'nodeLeft'in a&&a['nodeLeft']&&generateNodeComments(a['nodeLeft'],b),'nodeRight'in a&&a['nodeRight']&&generateNodeComments(a['nodeRight'],b),'recipient'in a&&a['recipient']&&generateNodeComments(a['recipient'],b),'historyIdx'in a&&a['historyIdx']&&generateNodeComments(a['historyIdx'],b),'sessionIdx'in a&&a['sessionIdx']&&generateNodeComments(a['sessionIdx'],b),'forwardIdx'in a&&a['forwardIdx']&&generateNodeComments(a['forwardIdx'],b),b;};const valueTypeToString=a=>{const b={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8',[ValueType['Value']]:'Value'};return b[a]||'Unknown('+a+')';};export const gen_passport=async(a,b,c)=>{!isValidWowAddress(b)&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20empty');await resolveCallEnv(a);const d=await get_guardSubmissions(a,[b]);return d['submission']['length']>0x0?!c?{'type':'submission','guard':d['guard'],'submission':d['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':[{'object':b,'impack':!![]}],'submission':[]});};function detectFileFormatFromContent(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('{')||e['startsWith']('[')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseTableFromMarkdown(a){const b=a['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(b)try{const d=JSON['parse'](b[0x1]);if(Array['isArray'](d))return d;}catch{}const c=a['match'](/\|[^\n]+\|/g);if(c&&c['length']>0x2)return c['slice'](0x2)['map'](e=>{const f=e['split']('|')['filter'](j=>j['trim']())['map'](j=>j['trim']()),g=f[0x2];let h;const i=g['match'](/\((\d+)\)/);if(i)h=parseInt(i[0x1],0xa);else{const j=g['match'](/^\s*(\d+)\s*$/);if(j)h=parseInt(j[0x1],0xa);else{const k=g['match'](/^([A-Za-z]+)/);if(k)h=k[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+g+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}}return{'identifier':parseInt(f[0x0],0xa),'b_submission':f[0x1]['toLowerCase']()==='true','value_type':h,'value':f[0x3]==='-'?undefined:f[0x3],'name':f[0x4]==='-'?undefined:f[0x4]};});return undefined;}function parseRelyFromMarkdown(a){const b=a['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),c=a['match'](/^\s*[-*]\s*(\S+)$/gm);if(b||c)return{'logic_or':b?b[0x1]['toUpperCase']()==='OR':![],'guards':c?c['map'](d=>d['replace'](/^\s*[-*]\s*/,'')['trim']()):[]};return undefined;}export function parseGuardFromMarkdown(a){const b=[],c={},d=extractJsonFromMarkdown(a);if(d)try{const f=JSON['parse'](d['json']);Object['assign'](c,f);}catch(g){b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20code\x20block:\x20'+g['message'],'path':'/','line':d['lineOffset']});}if(!c['description']){const h=a['match'](/(?:^|\n)#+\s*(?:Description|Description|Description)[^\n]*\n+([^\n#]+)/i);h&&(c['description']=h[0x1]['trim']());}if(!c['table']){const i=a['match'](/(?:^|\n)#+\s*(?:Table|Data Table|数据表)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const j=parseTableFromMarkdown(i[0x1]);j&&(c['table']=j);}}if(!c['root']){const k=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(k){const l=k[0x1],m=l['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(m)try{c['root']=JSON['parse'](m[0x1]);}catch(n){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+n['message'],'path':'/root'});}}}if(!c['rely']){const o=a['match'](/(?:^|\n)#+\s*(?:Rely|Dependencies|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(o){const p=parseRelyFromMarkdown(o[0x1]);p&&(c['rely']=p);}}if(!c['root'])return b['push']({'message':'Guard\x20root\x20node\x20not\x20found\x20in\x20markdown\x20file','path':'/root'}),{'success':![],'errors':b};return{'success':!![],'data':c,'errors':b};}export function parseGuardFile(a,b){const c=b??detectFileFormatFromContent(a);if(c==='json')try{const d=JSON['parse'](a);if(!d['root'])return{'success':![],'errors':[{'message':'Missing\x20required\x20field:\x20root','path':'/root'}]};return{'success':!![],'data':d,'errors':[]};}catch(f){return{'success':![],'errors':[{'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/'}]};}return parseGuardFromMarkdown(a);}export function validateGuardNode(a){const b=[];if(!a||typeof a!=='object')return b['push']({'message':'GuardNode\x20must\x20be\x20an\x20object','path':'/'}),{'success':![],'errors':b};const c=a;if(!c['type']||typeof c['type']!=='string')return b['push']({'message':'GuardNode\x20must\x20have\x20a\x20\x27type\x27\x20property','path':'/type'}),{'success':![],'errors':b};const d=['identifier','query','context','logic_not','logic_and','logic_or','logic_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','calc_string_length','calc_string_nocase_contains','calc_string_nocase_equal','calc_string_contains','calc_string_indexof','calc_string_nocase_indexof','convert_number_address','convert_address_number','convert_number_string','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','value_type','vec_length','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_find','query_reward_record_count','query_reward_record_exists','query_progress_history_find','query_progress_history_session_find','query_progress_history_session_forward_find','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];return!d['includes'](c['type'])&&b['push']({'message':'Invalid\x20GuardNode\x20type:\x20'+c['type'],'path':'/type'}),{'success':b['length']===0x0,'errors':b};}export function formatGuardParseErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}
@@ -1 +1 @@
1
- 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'||f['type']!=='identifier')return null;const g=f['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':d,'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'||f['type']!=='identifier'||g['type']!=='identifier')return null;const h=g['identifier'],i=getConditionsFromTable(c,h),j={};let k='first';if(i)try{const l=ProgressForwardFindConditionsBCS['parse'](i);if(l['who'])j['who']=l['who'];if(l['operation'])j['operation']=l['operation'];if(l['accomplished']!==undefined)j['accomplished']=l['accomplished'];if(l['time_min'])j['timeMin']=l['time_min']['toString']();if(l['time_max'])j['timeMax']=l['time_max']['toString']();k=l['find']===0x1?'last':'first';}catch(m){}return{'type':'query_progress_history_session_forward_find','object':{'identifier':a},'historyIdx':d,'sessionIdx':f,'where':j,'find':k};},parseProgressSessionCountNode=(a,b,c)=>{if(b['length']!==0x1||b[0x0]['type']!=='identifier')return null;return{'type':'query_progress_history_session_count','object':{'identifier':a},'historyIdx':b[0x0]};},parseProgressForwardCountNode=(a,b,c)=>{if(b['length']!==0x2)return null;const d=b[0x0],e=b[0x1];if(d['type']!=='identifier'||e['type']!=='identifier')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];if(d['type']!=='identifier'||e['type']!=='identifier'||f['type']!=='identifier')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':a['conditionsIdentifier']!==undefined&&b['push'](a['conditionsIdentifier']);break;case'query_progress_history_session_find':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);break;case'query_progress_history_session_forward_find':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);break;case'query_progress_history_session_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);break;case'query_progress_history_session_forward_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);break;case'query_progress_history_session_forward_retained_submission_count':a['historyIdx']['type']==='identifier'&&b['push'](a['historyIdx']['identifier']);a['sessionIdx']['type']==='identifier'&&b['push'](a['sessionIdx']['identifier']);a['forwardIdx']['type']==='identifier'&&b['push'](a['forwardIdx']['identifier']);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';}};
1
+ 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';}};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "wowok <build@wowok.net>",
4
4
  "description": "Wowok Blockchain TypeScript API",
5
5
  "homepage": "https://wowok.net",
6
- "version": "2.1.41",
6
+ "version": "2.2.0",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [