wowok 2.2.9 → 2.2.10
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.
- package/dist/cjs/w/call/guard-ins.js +1 -1
- package/dist/cjs/w/call/guard.d.ts +1 -1
- package/dist/cjs/w/call/guard.js +1 -1
- package/dist/cjs/w/call/permission.js +1 -1
- package/dist/cjs/w/call/service.d.ts +3 -3
- package/dist/cjs/w/call/service.js +1 -1
- package/dist/cjs/w/exception.js +1 -1
- package/dist/cjs/w/query/object.d.ts +1 -1
- package/dist/cjs/w/query/object.js +1 -1
- package/dist/esm/w/call/guard-ins.js +1 -1
- package/dist/esm/w/call/guard.d.ts +1 -1
- package/dist/esm/w/call/guard.js +1 -1
- package/dist/esm/w/call/permission.js +1 -1
- package/dist/esm/w/call/service.d.ts +3 -3
- package/dist/esm/w/call/service.js +1 -1
- package/dist/esm/w/exception.js +1 -1
- package/dist/esm/w/query/object.d.ts +1 -1
- package/dist/esm/w/query/object.js +1 -1
- package/package.json +1 -1
|
@@ -327,7 +327,7 @@ export declare const generateNodeComments: (node: GuardNode, comments?: Array<{
|
|
|
327
327
|
type: string;
|
|
328
328
|
description: string;
|
|
329
329
|
}>;
|
|
330
|
-
export declare const gen_passport: (env: CallEnv, guard: string, info?: SubmissionCall) => Promise<CallResult>;
|
|
330
|
+
export declare const gen_passport: (env: CallEnv, guard: string | string[], info?: SubmissionCall) => Promise<CallResult>;
|
|
331
331
|
export interface GuardParseError {
|
|
332
332
|
message: string;
|
|
333
333
|
path: string;
|
package/dist/esm/w/call/guard.js
CHANGED
|
@@ -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 a152a 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/wow-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=a152a['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=a152a['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=a152a['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
|
+
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 a152a 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{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=a152a['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=a152a['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=a152a['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)=>{const d=Array['isArray'](b)?b:[b];d['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guards\x20empty');const e=await LocalMark['Instance']()['get_many_address'](d),f=e['findIndex'](i=>i===undefined);f!==-0x1&&W_ERROR(WErrors['InvalidParam'],'guard\x20invalid:\x20guard\x20\x22'+d[f]+'\x22\x20not\x20found\x20in\x20LocalMark');const g=e['filter'](i=>i!==undefined);await resolveCallEnv(a);const h=await get_guardSubmissions(a,g);return h['submission']['length']>0x0?!c?{'type':'submission','guard':h['guard'],'submission':h['submission']}:await verify_guard(a,c):await verify_guard(a,{'type':'submission','guard':g['map'](i=>({'object':i,'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{toTxObject,toTxU16,toTxAddress,toTxAddressVec,toTxU16Vec,MAX_DESCRIPTION_LENGTH,isValidLongName,MAX_LONG_NAME_LENGTH,GetObject,GetObjectExisted,PackageAddress,serviceFn,IsValidArgType,contactFn}from'../common.js';import{W_ERROR,WErrors}from'../exception.js';import{isValidDescription,toTxString}from'../common.js';import{CallBase}from'./base.js';import{ObjectType,query_objects}from'../query/object.js';import{GetAccountOrMark_Address,GetManyAccountOrMark_Address,LocalMark}from'../local/index.js';import{parseObjectType,permission_set}from'../util.js';import{demandFn,machineFn,treasuryFn,arbitrationFn,repositoryFn,rewardFn}from'../common.js';import{query_received}from'../query/received.js';export var BuiltinPermissionIndex;(function(a){a[a['REPOSITORY_NEW']=0x64]='REPOSITORY_NEW',a[a['REPOSITORY_DESCRIPTION']=0x65]='REPOSITORY_DESCRIPTION',a[a['REPOSITORY_POLICY']=0x66]='REPOSITORY_POLICY',a[a['REPOSITORY_REWARD']=0x67]='REPOSITORY_REWARD',a[a['REPOSITORY_OWNER_RECEIVE']=0x68]='REPOSITORY_OWNER_RECEIVE',a[a['REPOSITORY_UM']=0x69]='REPOSITORY_UM',a[a['REWARD_NEW']=0x96]='REWARD_NEW',a[a['REWARD_DESCRIPTION']=0x97]='REWARD_DESCRIPTION',a[a['REWARD_GUARD']=0x98]='REWARD_GUARD',a[a['REWARD_COIN_ADD']=0x99]='REWARD_COIN_ADD',a[a['REWARD_RECEIVE']=0x9a]='REWARD_RECEIVE',a[a['REWARD_GUARD_EXPIRATION_TIME_ADD']=0x9b]='REWARD_GUARD_EXPIRATION_TIME_ADD',a[a['REWARD_OWNER_RECEIVE']=0x9c]='REWARD_OWNER_RECEIVE',a[a['REWARD_UM']=0x9d]='REWARD_UM',a[a['MACHINE_NEW']=0xc8]='MACHINE_NEW',a[a['MACHINE_DESCRIPTION']=0xc9]='MACHINE_DESCRIPTION',a[a['MACHINE_CONSENSUS_REPOSITORIES']=0xcb]='MACHINE_CONSENSUS_REPOSITORIES',a[a['MACHINE_PAUSE']=0xcc]='MACHINE_PAUSE',a[a['MACHINE_PUBLISH']=0xcd]='MACHINE_PUBLISH',a[a['MACHINE_NODE']=0xce]='MACHINE_NODE',a[a['MACHINE_OWNER_RECEIVE']=0xcf]='MACHINE_OWNER_RECEIVE',a[a['MACHINE_UM']=0xd0]='MACHINE_UM',a[a['PROGRESS_NEW']=0xdc]='PROGRESS_NEW',a[a['PROGRESS_NAMED_OPERATOR']=0xdd]='PROGRESS_NAMED_OPERATOR',a[a['PROGRESS_TASK']=0xde]='PROGRESS_TASK',a[a['PROGRESS_CONTEXT_REPOSITORY']=0xdf]='PROGRESS_CONTEXT_REPOSITORY',a[a['PROGRESS_UNHOLD']=0xe0]='PROGRESS_UNHOLD',a[a['PROGRESS_OWNER_RECEIVE']=0xe1]='PROGRESS_OWNER_RECEIVE',a[a['TREASURY_NEW']=0xfa]='TREASURY_NEW',a[a['TREASURY_DESCRIPTION']=0xfb]='TREASURY_DESCRIPTION',a[a['TREASURY_DEPOSIT']=0xfc]='TREASURY_DEPOSIT',a[a['TREASURY_RECEIVE']=0xfd]='TREASURY_RECEIVE',a[a['TREASURY_WITHDRAW']=0xfe]='TREASURY_WITHDRAW',a[a['TREASURY_EXTERNAL_DEPOSIT']=0xff]='TREASURY_EXTERNAL_DEPOSIT',a[a['TREASURY_EXTERNAL_WITHDRAW']=0x100]='TREASURY_EXTERNAL_WITHDRAW',a[a['TREASURY_EXTERNAL_DEPOSIT_GUARD']=0x101]='TREASURY_EXTERNAL_DEPOSIT_GUARD',a[a['TREASURY_EXTERNAL_WITHDRAW_GUARD']=0x102]='TREASURY_EXTERNAL_WITHDRAW_GUARD',a[a['TREASURY_OWNER_RECEIVE']=0x103]='TREASURY_OWNER_RECEIVE',a[a['TREASURY_UM']=0x104]='TREASURY_UM',a[a['SERVICE_NEW']=0x12c]='SERVICE_NEW',a[a['SERVICE_DESCRIPTION']=0x12d]='SERVICE_DESCRIPTION',a[a['SERVICE_LOCATION']=0x12f]='SERVICE_LOCATION',a[a['SERVICE_REPOSITORY']=0x130]='SERVICE_REPOSITORY',a[a['SERVICE_SALES']=0x131]='SERVICE_SALES',a[a['SERVICE_MACHINE']=0x132]='SERVICE_MACHINE',a[a['SERVICE_BUY_GUARD']=0x133]='SERVICE_BUY_GUARD',a[a['SERVICE_ARBITRATION']=0x134]='SERVICE_ARBITRATION',a[a['SERVICE_CUSTOMER_INFO_REQUIRED']=0x135]='SERVICE_CUSTOMER_INFO_REQUIRED',a[a['SERVICE_PAUSE']=0x136]='SERVICE_PAUSE',a[a['SERVICE_PUBLISH']=0x137]='SERVICE_PUBLISH',a[a['SERVICE_DISCOUNT']=0x138]='SERVICE_DISCOUNT',a[a['SERVICE_ORDER_ALLOCATOR']=0x139]='SERVICE_ORDER_ALLOCATOR',a[a['SERVICE_COMPENSATION_FUND_WITHDRAW']=0x13a]='SERVICE_COMPENSATION_FUND_WITHDRAW',a[a['SERVICE_COMPENSATION_FUND_DEPOSIT']=0x13b]='SERVICE_COMPENSATION_FUND_DEPOSIT',a[a['SERVICE_COMPENSATION_FUND_RECEIVE']=0x13c]='SERVICE_COMPENSATION_FUND_RECEIVE',a[a['SERVICE_COMPENSATION_LOCKED_TIME_ADD']=0x13d]='SERVICE_COMPENSATION_LOCKED_TIME_ADD',a[a['SERVICE_REWARD']=0x13e]='SERVICE_REWARD',a[a['SERVICE_OWNER_RECEIVE']=0x13f]='SERVICE_OWNER_RECEIVE',a[a['SERVICE_UM']=0x140]='SERVICE_UM',a[a['ARBITRATION_NEW']=0x15e]='ARBITRATION_NEW',a[a['ARBITRATION_DESCRIPTION']=0x15f]='ARBITRATION_DESCRIPTION',a[a['ARBITRATION_LOCATION']=0x161]='ARBITRATION_LOCATION',a[a['ARBITRATION_VOTING_GUARD']=0x162]='ARBITRATION_VOTING_GUARD',a[a['ARBITRATION_USAGE_GUARD']=0x163]='ARBITRATION_USAGE_GUARD',a[a['ARBITRATION_PAUSE']=0x164]='ARBITRATION_PAUSE',a[a['ARBITRATION_FEE']=0x165]='ARBITRATION_FEE',a[a['ARBITRATION_VOTE']=0x166]='ARBITRATION_VOTE',a[a['ARBITRATION_ARBITRATION']=0x167]='ARBITRATION_ARBITRATION',a[a['ARBITRATION_FEEDBACK']=0x168]='ARBITRATION_FEEDBACK',a[a['ARBITRATION_CONFIRM']=0x169]='ARBITRATION_CONFIRM',a[a['ARBITRATION_VOTING_DEADLINE_CHANGE']=0x16a]='ARBITRATION_VOTING_DEADLINE_CHANGE',a[a['ARBITRATION_RESET']=0x16b]='ARBITRATION_RESET',a[a['ARBITRATION_ARB_WITHDRAW']=0x16c]='ARBITRATION_ARB_WITHDRAW',a[a['ARBITRATION_FEES_ALLOC']=0x16d]='ARBITRATION_FEES_ALLOC',a[a['ARBITRATION_FEES_TRANSFER']=0x16e]='ARBITRATION_FEES_TRANSFER',a[a['ARBITRATION_OWNER_RECEIVE']=0x16f]='ARBITRATION_OWNER_RECEIVE',a[a['ARBITRATION_UM']=0x170]='ARBITRATION_UM',a[a['DEMAND_NEW']=0x190]='DEMAND_NEW',a[a['DEMAND_DESCRIPTION']=0x191]='DEMAND_DESCRIPTION',a[a['DEMAND_LOCATION']=0x192]='DEMAND_LOCATION',a[a['DEMAND_GUARD']=0x194]='DEMAND_GUARD',a[a['DEMAND_REWARD']=0x195]='DEMAND_REWARD',a[a['DEMAND_FEEDBACK']=0x196]='DEMAND_FEEDBACK',a[a['DEMAND_OWNER_RECEIVE']=0x197]='DEMAND_OWNER_RECEIVE',a[a['DEMAND_UM']=0x198]='DEMAND_UM',a[a['MESSNGER_NEW']=0x1c2]='MESSNGER_NEW',a[a['MESSNGER_DESCRIPTION']=0x1c3]='MESSNGER_DESCRIPTION',a[a['MESSNGER_LOCATION']=0x1c4]='MESSNGER_LOCATION',a[a['MESSNGER_IM']=0x1c5]='MESSNGER_IM',a[a['MESSNGER_OWNER_RECEIVE']=0x1c6]='MESSNGER_OWNER_RECEIVE';}(BuiltinPermissionIndex||(BuiltinPermissionIndex={})));export const PermissionInfo=[{'index':BuiltinPermissionIndex['REPOSITORY_NEW'],'name':'repository.new','description':'Create\x20new\x20repository','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_DESCRIPTION'],'name':'repository.description','description':'Set\x20repository\x20description','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_POLICY'],'name':'repository.policy','description':'Manage\x20repository\x20policies','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_REWARD'],'name':'repository.reward','description':'Manage\x20repository\x20rewards','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_OWNER_RECEIVE'],'name':'repository.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20repository','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_UM'],'name':'repository.um','description':'Manage\x20repository\x20UM\x20(User\x20Manager)','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REWARD_NEW'],'name':'reward.new','description':'Create\x20new\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_DESCRIPTION'],'name':'reward.description','description':'Set\x20reward\x20description','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_GUARD'],'name':'reward.guard','description':'Manage\x20reward\x20guards','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_COIN_ADD'],'name':'reward.coin_add','description':'Add\x20coin\x20to\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_RECEIVE'],'name':'reward.receive','description':'Receive\x20payment\x20for\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_GUARD_EXPIRATION_TIME_ADD'],'name':'reward.guard_expiration_time_add','description':'Add\x20guard\x20expiration\x20time','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_OWNER_RECEIVE'],'name':'reward.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_UM'],'name':'reward.um','description':'Manage\x20reward\x20UM\x20(User\x20Manager)','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['MACHINE_NEW'],'name':'machine.new','description':'Create\x20new\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_DESCRIPTION'],'name':'machine.description','description':'Set\x20machine\x20description','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_CONSENSUS_REPOSITORIES'],'name':'machine.consensus_repositories','description':'Manage\x20machine\x20consensus\x20repositories','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_PAUSE'],'name':'machine.pause','description':'Pause\x20or\x20resume\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_PUBLISH'],'name':'machine.publish','description':'Publish\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_NODE'],'name':'machine.node','description':'Manage\x20machine\x20nodes','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_OWNER_RECEIVE'],'name':'machine.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_UM'],'name':'machine.um','description':'Manage\x20machine\x20UM\x20(User\x20Manager)','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['PROGRESS_NEW'],'name':'progress.new','description':'Create\x20new\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_NAMED_OPERATOR'],'name':'progress.namedOperator','description':'Manage\x20progress\x20named\x20operators\x20(add,\x20remove,\x20set)','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_TASK'],'name':'progress.task','description':'Set\x20progress\x20task','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_CONTEXT_REPOSITORY'],'name':'progress.context_repository','description':'Manage\x20progress\x20context\x20repositories\x20(add,\x20remove,\x20clear)','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_UNHOLD'],'name':'progress.unhold','description':'Unhold\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_OWNER_RECEIVE'],'name':'progress.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['TREASURY_NEW'],'name':'treasury.new','description':'Create\x20new\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_DESCRIPTION'],'name':'treasury.description','description':'Set\x20treasury\x20description','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_DEPOSIT'],'name':'treasury.deposit','description':'Deposit\x20coins\x20to\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_RECEIVE'],'name':'treasury.receive','description':'Receive\x20payment\x20for\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_WITHDRAW'],'name':'treasury.withdraw','description':'Withdraw\x20coins\x20from\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_DEPOSIT'],'name':'treasury.external_deposit','description':'External\x20deposit\x20to\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_WITHDRAW'],'name':'treasury.external_withdraw','description':'External\x20withdraw\x20from\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_DEPOSIT_GUARD'],'name':'treasury.external_deposit_guard','description':'Manage\x20treasury\x20external\x20deposit\x20guards','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_WITHDRAW_GUARD'],'name':'treasury.external_withdraw_guard','description':'Manage\x20treasury\x20external\x20withdraw\x20guards','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_OWNER_RECEIVE'],'name':'treasury.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_UM'],'name':'treasury.um','description':'Manage\x20treasury\x20UM\x20(User\x20Manager)','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['SERVICE_NEW'],'name':'service.new','description':'Create\x20new\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_DESCRIPTION'],'name':'service.description','description':'Set\x20service\x20description','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_LOCATION'],'name':'service.location','description':'Set\x20service\x20location','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_REPOSITORY'],'name':'service.repository','description':'Manage\x20service\x20repositories','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_SALES'],'name':'service.sales','description':'Manage\x20service\x20sales','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_MACHINE'],'name':'service.machine','description':'Manage\x20service\x20machines','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_BUY_GUARD'],'name':'service.buy_guard','description':'Manage\x20service\x20buy\x20guards','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_ARBITRATION'],'name':'service.arbitration','description':'Manage\x20service\x20arbitrations','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_CUSTOMER_INFO_REQUIRED'],'name':'service.customer_info_required','description':'Manage\x20service\x20customer\x20info\x20requirements','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_PAUSE'],'name':'service.pause','description':'Pause\x20or\x20resume\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_PUBLISH'],'name':'service.publish','description':'Publish\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_DISCOUNT'],'name':'service.discount','description':'Manage\x20service\x20discounts','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_ORDER_ALLOCATOR'],'name':'service.order_allocator','description':'Manage\x20service\x20order\x20allocators','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_WITHDRAW'],'name':'service.compensation_fund_withdraw','description':'Withdraw\x20from\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_DEPOSIT'],'name':'service.compensation_fund_deposit','description':'Deposit\x20to\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_RECEIVE'],'name':'service.compensation_fund_receive','description':'Receive\x20payments\x20for\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_LOCKED_TIME_ADD'],'name':'service.compensation_locked_time_add','description':'Add\x20locked\x20time\x20to\x20service\x20compensation','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_REWARD'],'name':'service.reward','description':'Manage\x20service\x20rewards','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_OWNER_RECEIVE'],'name':'service.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_UM'],'name':'service.um','description':'Manage\x20service\x20UM\x20(User\x20Manager)','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['ARBITRATION_NEW'],'name':'arbitration.new','description':'Create\x20new\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_DESCRIPTION'],'name':'arbitration.description','description':'Set\x20arbitration\x20description','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_LOCATION'],'name':'arbitration.location','description':'Set\x20arbitration\x20location','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTING_GUARD'],'name':'arbitration.voting_guard','description':'Manage\x20arbitration\x20voting\x20guards','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_USAGE_GUARD'],'name':'arbitration.usage_guard','description':'Set\x20arbitration\x20usage\x20guard','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_PAUSE'],'name':'arbitration.pause','description':'Pause\x20or\x20resume\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEE'],'name':'arbitration.fee','description':'Set\x20arbitration\x20fee','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTE'],'name':'arbitration.vote','description':'Vote\x20on\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_ARBITRATION'],'name':'arbitration.arbitration','description':'Perform\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEEDBACK'],'name':'arbitration.feedback','description':'Provide\x20arbitration\x20feedback','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_CONFIRM'],'name':'arbitration.confirm','description':'Confirm\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTING_DEADLINE_CHANGE'],'name':'arbitration.voting_deadline_change','description':'Change\x20voting\x20deadline','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_RESET'],'name':'arbitration.reset','description':'Reset\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_ARB_WITHDRAW'],'name':'arbitration.arb_withdraw','description':'Withdraw\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEES_ALLOC'],'name':'arbitration.fees_alloc','description':'Allocate\x20arbitration\x20fees','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEES_TRANSFER'],'name':'arbitration.fees_transfer','description':'Transfer\x20arbitration\x20fees','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_OWNER_RECEIVE'],'name':'arbitration.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_UM'],'name':'arbitration.um','description':'Manage\x20arbitration\x20UM\x20(User\x20Manager)','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['DEMAND_NEW'],'name':'demand.new','description':'Create\x20new\x20demand','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_DESCRIPTION'],'name':'demand.description','description':'Set\x20demand\x20description','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_LOCATION'],'name':'demand.location','description':'Set\x20demand\x20location','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_GUARD'],'name':'demand.guard','description':'Manage\x20demand\x20guards','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_REWARD'],'name':'demand.reward','description':'Manage\x20demand\x20rewards','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_FEEDBACK'],'name':'demand.feedback','description':'Provide\x20demand\x20feedback','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_OWNER_RECEIVE'],'name':'demand.owner_receive','description':'Receive\x20objects\x20for\x20demand','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_UM'],'name':'demand.um','description':'Manage\x20demand\x20UM\x20(User\x20Manager)','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['MESSNGER_NEW'],'name':'messenger.new','description':'Create\x20new\x20messenger','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_DESCRIPTION'],'name':'messenger.description','description':'Set\x20messenger\x20description','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_LOCATION'],'name':'messenger.location','description':'Set\x20messenger\x20location','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_IM'],'name':'messenger.im','description':'Manager\x20im\x20address','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_OWNER_RECEIVE'],'name':'messenger.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20messenger','object_type':ObjectType['Contact']}];export class CallPermission extends CallBase{['data'];['object_address']=undefined;['object_data']=undefined;constructor(a){super(),this['data']=a;}async['prepare'](a){await super['prepare'](a),!this['object_address']&&(this['object_address']=await GetObjectExisted(this['data']?.['object']));}async['call'](a){await this['prepare'](a);let b=![],c=![];if(this['object_address'])return(this['data']?.['builder']!=null||this['data']?.['admin']!=null||this['data']?.['um']!==undefined)&&(b=!![]),(this['data']?.['table']!=null||this['data']?.['entity']!=null||this['data']?.['remark']!=null||this['data']?.['description']!=null)&&(c=!![]),await this['check_permission_and_call'](a,this['object_address'],[],[],b,c);return await this['exec'](a);}async['operate'](a,c,d,e){let f;this['object_address']?f=toTxObject(c,this['object_address']):f=newPermission(c,this['data']?.['description']??'');!f&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.object');this['data']?.['description']!=null&&this['object_address']&&descriptionSet(c,f,this['data']['description']);if(this['data']?.['remark']!=null)switch(this['data']['remark']['op']){case'set':{const g=this['data']['remark']['index'],h=this['data']['remark']['remark'];remarkSet(c,f,g,h);break;}case'remove':{const i=this['data']['remark']['index'];remarkRemove(c,f,i);break;}case'clear':{remarkClear(c,f);break;}}if(this['data']?.['table']!=null)switch(this['data']['table']['op']){case'add\x20perm\x20by\x20index':{const j=this['data']['table']['index'],k=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permAdd(c,f,j,k);break;}case'remove\x20perm\x20by\x20index':{const l=this['data']['table']['index'],m=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permRemove(c,f,l,m);break;}case'set\x20perm\x20by\x20index':{const n=this['data']['table']['index'],o=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permSet(c,f,n,o);break;}case'add\x20perm\x20by\x20entity':{const q=await GetAccountOrMark_Address(this['data']['table']['entity']);q&&entityAdd(c,f,q,this['data']['table']['index']);break;}case'remove\x20perm\x20by\x20entity':{const s=await GetAccountOrMark_Address(this['data']['table']['entity']);s&&entityRemove(c,f,s,this['data']['table']['index']);break;}case'set\x20perm\x20by\x20entity':{const t=await GetAccountOrMark_Address(this['data']['table']['entity']);t&&entitySet(c,f,t,this['data']['table']['index']);break;}}if(this['data']?.['entity']!=null)switch(this['data']['entity']['op']){case'swap':{const u=await GetAccountOrMark_Address(this['data']['entity']['entity1']),v=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(u&&v)entitySwap(c,f,u,v);break;}case'replace':{const w=await GetAccountOrMark_Address(this['data']['entity']['entity1']),x=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(w&&x)entityReplace(c,f,w,x);break;}case'copy':{const y=await GetAccountOrMark_Address(this['data']['entity']['entity1']),z=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(y&&z)entityCopy(c,f,y,z);break;}case'del':{const A=await GetAccountOrMark_Address(this['data']['entity']['entity']);if(A)entityDel(c,f,A);break;}}if(this['data']?.['admin']!=null){const B=await GetManyAccountOrMark_Address(this['data']['admin']['addresses']);switch(this['data']['admin']?.['op']){case'add':{adminAdd(c,f,B);break;}case'set':{adminSet(c,f,B);break;}case'remove':{adminRemove(c,f,B);break;}}}if(this['data']?.['apply']!=null&&this['data']['apply']['length']>0x0){const C=await query_objects({'objects':this['data']['apply'],'no_cache':a['no_cache'],'network':a['network']});(!C['objects']||C['objects']['length']!==this['data']['apply']['length'])&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.apply\x20some\x20objects\x20not\x20found\x20'+this['data']['apply']),C['objects']?.['forEach'](D=>{switch(D['type']){case'Demand':const E=D;permission_set(c,E['object'],E['permission'],f,parseObjectType(E['type_raw'],'demand::Demand'),L=>demandFn(L));break;case'Machine':const F=D;permission_set(c,F['object'],F['permission'],f,undefined,L=>machineFn(L));break;case'Service':const G=D;permission_set(c,G['object'],G['permission'],f,parseObjectType(G['type_raw'],'service::Service'),L=>serviceFn(L));break;case'Treasury':const H=D;permission_set(c,H['object'],H['permission'],f,parseObjectType(H['type_raw'],'treasury::Treasury'),L=>treasuryFn(L));break;case'Arbitration':const I=D;permission_set(c,I['object'],I['permission'],f,parseObjectType(I['type_raw'],'arbitration::Arbitration'),L=>arbitrationFn(L));break;case'Repository':const J=D;permission_set(c,J['object'],J['permission'],f,undefined,L=>repositoryFn(L));break;case'Reward':const K=D;permission_set(c,K['object'],K['permission'],f,parseObjectType(K['type_raw'],'reward::Reward'),L=>rewardFn(L));break;}});}if(this['data']?.['builder']!=null){const D=await GetAccountOrMark_Address(this['data']['builder']);if(D)transferPermission(c,f,D);}if(this['data']['owner_receive']!=null&&this['object_address']){this['data']['owner_receive']==='recently'&&(this['data']['owner_receive']=await query_received({'name_or_address':{'name_or_address':this['object_address'],'local_mark_first':!![]},'all_type':!![],'no_cache':a['no_cache'],'network':a['network']}));if(Array['isArray'](this['data']['owner_receive']))for(const E of this['data']['owner_receive']){!IsValidArgType(E['type'])&&W_ERROR(WErrors['IsValidArgType'],'Invalid\x20type:\x20'+E['type']);const F=await LocalMark['Instance']()['get_address'](E['id']);!F&&W_ERROR(WErrors['IsValidArgType'],'Received\x20'+E['id']+'\x20is\x20invalid'),ownerReceiveObject(c,f,F,E['type']);}else for(const G of this['data']['owner_receive']['received']){const [H,I]=await Promise['all']([LocalMark['Instance']()['get_address'](G['id']),LocalMark['Instance']()['get_address'](G['payment'])]);(!H||!I)&&W_ERROR(WErrors['IsValidArgType'],'Received\x20'+G['id']+'\x20or\x20Payment\x20'+G['payment']+'\x20is\x20invalid'),ownerReceive(c,f,H,I,this['data']['owner_receive']['token_type']);}}if(this['data']['um']!==undefined){let J=null;this['data']['um']&&(J=await LocalMark['Instance']()['get_address'](this['data']['um'])||null,!J&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.um:'+this['data']['um'])),um_set(c,f,J);}!this['object_address']&&await this['new_with_mark'](a,c,ObjectType['Permission'],create(c,f),GetObject(this['data']?.['object']));}}export function permissionFn(a){return PackageAddress+'::permission::'+a;}export const MAX_ENTITY_COUNT=0x3e8;export const MAX_PERM_FOR_ENTITY=0x3e8;export const MAX_ADMIN_COUNT=0x1f4;export const USER_DEFINED_PERM_INDEX_START=0x3e8;export function isBizPermIndex(a){return a>=USER_DEFINED_PERM_INDEX_START;}export function newPermission(a,b){return typeof b==='string'&&!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH),a['moveCall']({'target':permissionFn('new'),'arguments':[toTxString(a,b)]});}export function create(a,b){return a['moveCall']({'target':permissionFn('create'),'arguments':[toTxObject(a,b)]});}export function descriptionSet(a,b,c){typeof c==='string'&&!isValidDescription(c)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH),a['moveCall']({'target':permissionFn('description_set'),'arguments':[toTxObject(a,b),toTxString(a,c)]});}export function remarkSet(a,b,c,d){typeof d==='string'&&!isValidLongName(d)&&W_ERROR(WErrors['IsValidDescription'],'Remark\x20exceeds\x20maximum\x20length\x20'+MAX_LONG_NAME_LENGTH),a['moveCall']({'target':permissionFn('remark_set'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxString(a,d)]});}export function remarkRemove(a,b,c){a['moveCall']({'target':permissionFn('remark_remove'),'arguments':[toTxObject(a,b),toTxU16(a,c)]});}export function remarkClear(a,b){a['moveCall']({'target':permissionFn('remark_clear'),'arguments':[toTxObject(a,b)]});}export function permAdd(a,b,c,d){a['moveCall']({'target':permissionFn('perm_add'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function permRemove(a,b,c,d){a['moveCall']({'target':permissionFn('perm_remove'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT)]});}export function permSet(a,b,c,d){a['moveCall']({'target':permissionFn('perm_set'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityAdd(a,b,c,d){a['moveCall']({'target':permissionFn('entity_add'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityRemove(a,b,c,d){a['moveCall']({'target':permissionFn('entity_remove'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY)]});}export function entitySet(a,b,c,d){a['moveCall']({'target':permissionFn('entity_set'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entitySwap(a,b,c,d){a['moveCall']({'target':permissionFn('entity_swap'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityReplace(a,b,c,d){a['moveCall']({'target':permissionFn('entity_replace'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityDel(a,b,c){a['moveCall']({'target':permissionFn('entity_del'),'arguments':[toTxObject(a,b),toTxAddress(a,c),a['object']['mutRegistrar']()]});}export function entityCopy(a,b,c,d){a['moveCall']({'target':permissionFn('entity_copy'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function adminAdd(a,b,c){a['moveCall']({'target':permissionFn('admin_add'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function adminRemove(a,b,c){a['moveCall']({'target':permissionFn('admin_remove'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function adminSet(a,b,c){a['moveCall']({'target':permissionFn('admin_set'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function transferPermission(a,b,c){a['moveCall']({'target':permissionFn('transfer'),'arguments':[toTxObject(a,b),toTxAddress(a,c)]});}export function um_set(a,b,c){c?a['moveCall']({'target':contactFn('permission_um_set'),'arguments':[toTxObject(a,c),toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]}):a['moveCall']({'target':permissionFn('um_none'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function ownerReceiveObject(a,b,c,d){a['moveCall']({'target':permissionFn('owner_receive_object'),'arguments':[toTxObject(a,b),toTxObject(a,c)],'typeArguments':[d]});}export function ownerReceive(a,b,c,d,e){a['moveCall']({'target':permissionFn('owner_receive'),'arguments':[toTxObject(a,b),toTxObject(a,c),toTxObject(a,d)],'typeArguments':[e]});}export function query_permissions(a){if(!a)return PermissionInfo;return PermissionInfo['filter'](b=>{if(a['objectType']&&b['object_type']!==a['objectType'])return![];if(a['name']&&!b['name']['includes'](a['name']))return![];if(a['index']!==undefined&&b['index']!==a['index'])return![];if(a['description']&&!b['description']['includes'](a['description']))return![];return!![];});}
|
|
1
|
+
import{toTxObject,toTxU16,toTxAddress,toTxAddressVec,toTxU16Vec,MAX_DESCRIPTION_LENGTH,isValidLongName,MAX_LONG_NAME_LENGTH,GetObject,GetObjectExisted,PackageAddress,serviceFn,IsValidArgType,contactFn}from'../common.js';import{W_ERROR,WErrors}from'../exception.js';import{isValidDescription,toTxString}from'../common.js';import{CallBase}from'./base.js';import{ObjectType,query_objects}from'../query/object.js';import{GetAccountOrMark_Address,GetManyAccountOrMark_Address,LocalMark}from'../local/index.js';import{parseObjectType,permission_set}from'../util.js';import{demandFn,machineFn,treasuryFn,arbitrationFn,repositoryFn,rewardFn}from'../common.js';import{query_received}from'../query/received.js';export var BuiltinPermissionIndex;(function(a){a[a['REPOSITORY_NEW']=0x64]='REPOSITORY_NEW',a[a['REPOSITORY_DESCRIPTION']=0x65]='REPOSITORY_DESCRIPTION',a[a['REPOSITORY_POLICY']=0x66]='REPOSITORY_POLICY',a[a['REPOSITORY_REWARD']=0x67]='REPOSITORY_REWARD',a[a['REPOSITORY_OWNER_RECEIVE']=0x68]='REPOSITORY_OWNER_RECEIVE',a[a['REPOSITORY_UM']=0x69]='REPOSITORY_UM',a[a['REWARD_NEW']=0x96]='REWARD_NEW',a[a['REWARD_DESCRIPTION']=0x97]='REWARD_DESCRIPTION',a[a['REWARD_GUARD']=0x98]='REWARD_GUARD',a[a['REWARD_COIN_ADD']=0x99]='REWARD_COIN_ADD',a[a['REWARD_RECEIVE']=0x9a]='REWARD_RECEIVE',a[a['REWARD_GUARD_EXPIRATION_TIME_ADD']=0x9b]='REWARD_GUARD_EXPIRATION_TIME_ADD',a[a['REWARD_OWNER_RECEIVE']=0x9c]='REWARD_OWNER_RECEIVE',a[a['REWARD_UM']=0x9d]='REWARD_UM',a[a['MACHINE_NEW']=0xc8]='MACHINE_NEW',a[a['MACHINE_DESCRIPTION']=0xc9]='MACHINE_DESCRIPTION',a[a['MACHINE_CONSENSUS_REPOSITORIES']=0xcb]='MACHINE_CONSENSUS_REPOSITORIES',a[a['MACHINE_PAUSE']=0xcc]='MACHINE_PAUSE',a[a['MACHINE_PUBLISH']=0xcd]='MACHINE_PUBLISH',a[a['MACHINE_NODE']=0xce]='MACHINE_NODE',a[a['MACHINE_OWNER_RECEIVE']=0xcf]='MACHINE_OWNER_RECEIVE',a[a['MACHINE_UM']=0xd0]='MACHINE_UM',a[a['PROGRESS_NEW']=0xdc]='PROGRESS_NEW',a[a['PROGRESS_NAMED_OPERATOR']=0xdd]='PROGRESS_NAMED_OPERATOR',a[a['PROGRESS_TASK']=0xde]='PROGRESS_TASK',a[a['PROGRESS_CONTEXT_REPOSITORY']=0xdf]='PROGRESS_CONTEXT_REPOSITORY',a[a['PROGRESS_UNHOLD']=0xe0]='PROGRESS_UNHOLD',a[a['PROGRESS_OWNER_RECEIVE']=0xe1]='PROGRESS_OWNER_RECEIVE',a[a['TREASURY_NEW']=0xfa]='TREASURY_NEW',a[a['TREASURY_DESCRIPTION']=0xfb]='TREASURY_DESCRIPTION',a[a['TREASURY_DEPOSIT']=0xfc]='TREASURY_DEPOSIT',a[a['TREASURY_RECEIVE']=0xfd]='TREASURY_RECEIVE',a[a['TREASURY_WITHDRAW']=0xfe]='TREASURY_WITHDRAW',a[a['TREASURY_EXTERNAL_DEPOSIT']=0xff]='TREASURY_EXTERNAL_DEPOSIT',a[a['TREASURY_EXTERNAL_WITHDRAW']=0x100]='TREASURY_EXTERNAL_WITHDRAW',a[a['TREASURY_EXTERNAL_DEPOSIT_GUARD']=0x101]='TREASURY_EXTERNAL_DEPOSIT_GUARD',a[a['TREASURY_EXTERNAL_WITHDRAW_GUARD']=0x102]='TREASURY_EXTERNAL_WITHDRAW_GUARD',a[a['TREASURY_OWNER_RECEIVE']=0x103]='TREASURY_OWNER_RECEIVE',a[a['TREASURY_UM']=0x104]='TREASURY_UM',a[a['SERVICE_NEW']=0x12c]='SERVICE_NEW',a[a['SERVICE_DESCRIPTION']=0x12d]='SERVICE_DESCRIPTION',a[a['SERVICE_LOCATION']=0x12f]='SERVICE_LOCATION',a[a['SERVICE_REPOSITORY']=0x130]='SERVICE_REPOSITORY',a[a['SERVICE_SALES']=0x131]='SERVICE_SALES',a[a['SERVICE_MACHINE']=0x132]='SERVICE_MACHINE',a[a['SERVICE_BUY_GUARD']=0x133]='SERVICE_BUY_GUARD',a[a['SERVICE_ARBITRATION']=0x134]='SERVICE_ARBITRATION',a[a['SERVICE_CUSTOMER_INFO_REQUIRED']=0x135]='SERVICE_CUSTOMER_INFO_REQUIRED',a[a['SERVICE_PAUSE']=0x136]='SERVICE_PAUSE',a[a['SERVICE_PUBLISH']=0x137]='SERVICE_PUBLISH',a[a['SERVICE_DISCOUNT']=0x138]='SERVICE_DISCOUNT',a[a['SERVICE_ORDER_ALLOCATOR']=0x139]='SERVICE_ORDER_ALLOCATOR',a[a['SERVICE_COMPENSATION_FUND_WITHDRAW']=0x13a]='SERVICE_COMPENSATION_FUND_WITHDRAW',a[a['SERVICE_COMPENSATION_FUND_DEPOSIT']=0x13b]='SERVICE_COMPENSATION_FUND_DEPOSIT',a[a['SERVICE_COMPENSATION_FUND_RECEIVE']=0x13c]='SERVICE_COMPENSATION_FUND_RECEIVE',a[a['SERVICE_COMPENSATION_LOCKED_TIME_ADD']=0x13d]='SERVICE_COMPENSATION_LOCKED_TIME_ADD',a[a['SERVICE_REWARD']=0x13e]='SERVICE_REWARD',a[a['SERVICE_OWNER_RECEIVE']=0x13f]='SERVICE_OWNER_RECEIVE',a[a['SERVICE_UM']=0x140]='SERVICE_UM',a[a['ARBITRATION_NEW']=0x15e]='ARBITRATION_NEW',a[a['ARBITRATION_DESCRIPTION']=0x15f]='ARBITRATION_DESCRIPTION',a[a['ARBITRATION_LOCATION']=0x161]='ARBITRATION_LOCATION',a[a['ARBITRATION_VOTING_GUARD']=0x162]='ARBITRATION_VOTING_GUARD',a[a['ARBITRATION_USAGE_GUARD']=0x163]='ARBITRATION_USAGE_GUARD',a[a['ARBITRATION_PAUSE']=0x164]='ARBITRATION_PAUSE',a[a['ARBITRATION_FEE']=0x165]='ARBITRATION_FEE',a[a['ARBITRATION_VOTE']=0x166]='ARBITRATION_VOTE',a[a['ARBITRATION_ARBITRATION']=0x167]='ARBITRATION_ARBITRATION',a[a['ARBITRATION_FEEDBACK']=0x168]='ARBITRATION_FEEDBACK',a[a['ARBITRATION_CONFIRM']=0x169]='ARBITRATION_CONFIRM',a[a['ARBITRATION_VOTING_DEADLINE_CHANGE']=0x16a]='ARBITRATION_VOTING_DEADLINE_CHANGE',a[a['ARBITRATION_RESET']=0x16b]='ARBITRATION_RESET',a[a['ARBITRATION_ARB_WITHDRAW']=0x16c]='ARBITRATION_ARB_WITHDRAW',a[a['ARBITRATION_FEES_ALLOC']=0x16d]='ARBITRATION_FEES_ALLOC',a[a['ARBITRATION_FEES_TRANSFER']=0x16e]='ARBITRATION_FEES_TRANSFER',a[a['ARBITRATION_OWNER_RECEIVE']=0x16f]='ARBITRATION_OWNER_RECEIVE',a[a['ARBITRATION_UM']=0x170]='ARBITRATION_UM',a[a['DEMAND_NEW']=0x190]='DEMAND_NEW',a[a['DEMAND_DESCRIPTION']=0x191]='DEMAND_DESCRIPTION',a[a['DEMAND_LOCATION']=0x192]='DEMAND_LOCATION',a[a['DEMAND_GUARD']=0x194]='DEMAND_GUARD',a[a['DEMAND_REWARD']=0x195]='DEMAND_REWARD',a[a['DEMAND_FEEDBACK']=0x196]='DEMAND_FEEDBACK',a[a['DEMAND_OWNER_RECEIVE']=0x197]='DEMAND_OWNER_RECEIVE',a[a['DEMAND_UM']=0x198]='DEMAND_UM',a[a['MESSNGER_NEW']=0x1c2]='MESSNGER_NEW',a[a['MESSNGER_DESCRIPTION']=0x1c3]='MESSNGER_DESCRIPTION',a[a['MESSNGER_LOCATION']=0x1c4]='MESSNGER_LOCATION',a[a['MESSNGER_IM']=0x1c5]='MESSNGER_IM',a[a['MESSNGER_OWNER_RECEIVE']=0x1c6]='MESSNGER_OWNER_RECEIVE';}(BuiltinPermissionIndex||(BuiltinPermissionIndex={})));export const PermissionInfo=[{'index':BuiltinPermissionIndex['REPOSITORY_NEW'],'name':'repository.new','description':'Create\x20new\x20repository','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_DESCRIPTION'],'name':'repository.description','description':'Set\x20repository\x20description','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_POLICY'],'name':'repository.policy','description':'Manage\x20repository\x20policies','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_REWARD'],'name':'repository.reward','description':'Manage\x20repository\x20rewards','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_OWNER_RECEIVE'],'name':'repository.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20repository','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REPOSITORY_UM'],'name':'repository.um','description':'Manage\x20repository\x20UM\x20(User\x20Manager)','object_type':ObjectType['Repository']},{'index':BuiltinPermissionIndex['REWARD_NEW'],'name':'reward.new','description':'Create\x20new\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_DESCRIPTION'],'name':'reward.description','description':'Set\x20reward\x20description','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_GUARD'],'name':'reward.guard','description':'Manage\x20reward\x20guards','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_COIN_ADD'],'name':'reward.coin_add','description':'Add\x20coin\x20to\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_RECEIVE'],'name':'reward.receive','description':'Receive\x20payment\x20for\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_GUARD_EXPIRATION_TIME_ADD'],'name':'reward.guard_expiration_time_add','description':'Add\x20guard\x20expiration\x20time','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_OWNER_RECEIVE'],'name':'reward.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20reward','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['REWARD_UM'],'name':'reward.um','description':'Manage\x20reward\x20UM\x20(User\x20Manager)','object_type':ObjectType['Reward']},{'index':BuiltinPermissionIndex['MACHINE_NEW'],'name':'machine.new','description':'Create\x20new\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_DESCRIPTION'],'name':'machine.description','description':'Set\x20machine\x20description','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_CONSENSUS_REPOSITORIES'],'name':'machine.consensus_repositories','description':'Manage\x20machine\x20consensus\x20repositories','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_PAUSE'],'name':'machine.pause','description':'Pause\x20or\x20resume\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_PUBLISH'],'name':'machine.publish','description':'Publish\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_NODE'],'name':'machine.node','description':'Manage\x20machine\x20nodes','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_OWNER_RECEIVE'],'name':'machine.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20machine','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['MACHINE_UM'],'name':'machine.um','description':'Manage\x20machine\x20UM\x20(User\x20Manager)','object_type':ObjectType['Machine']},{'index':BuiltinPermissionIndex['PROGRESS_NEW'],'name':'progress.new','description':'Create\x20new\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_NAMED_OPERATOR'],'name':'progress.namedOperator','description':'Manage\x20progress\x20named\x20operators\x20(add,\x20remove,\x20set)','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_TASK'],'name':'progress.task','description':'Set\x20progress\x20task','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_CONTEXT_REPOSITORY'],'name':'progress.context_repository','description':'Manage\x20progress\x20context\x20repositories\x20(add,\x20remove,\x20clear)','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_UNHOLD'],'name':'progress.unhold','description':'Unhold\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['PROGRESS_OWNER_RECEIVE'],'name':'progress.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20progress','object_type':ObjectType['Progress']},{'index':BuiltinPermissionIndex['TREASURY_NEW'],'name':'treasury.new','description':'Create\x20new\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_DESCRIPTION'],'name':'treasury.description','description':'Set\x20treasury\x20description','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_DEPOSIT'],'name':'treasury.deposit','description':'Deposit\x20coins\x20to\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_RECEIVE'],'name':'treasury.receive','description':'Receive\x20payment\x20for\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_WITHDRAW'],'name':'treasury.withdraw','description':'Withdraw\x20coins\x20from\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_DEPOSIT'],'name':'treasury.external_deposit','description':'External\x20deposit\x20to\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_WITHDRAW'],'name':'treasury.external_withdraw','description':'External\x20withdraw\x20from\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_DEPOSIT_GUARD'],'name':'treasury.external_deposit_guard','description':'Manage\x20treasury\x20external\x20deposit\x20guards','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_EXTERNAL_WITHDRAW_GUARD'],'name':'treasury.external_withdraw_guard','description':'Manage\x20treasury\x20external\x20withdraw\x20guards','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_OWNER_RECEIVE'],'name':'treasury.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20treasury','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['TREASURY_UM'],'name':'treasury.um','description':'Manage\x20treasury\x20UM\x20(User\x20Manager)','object_type':ObjectType['Treasury']},{'index':BuiltinPermissionIndex['SERVICE_NEW'],'name':'service.new','description':'Create\x20new\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_DESCRIPTION'],'name':'service.description','description':'Set\x20service\x20description','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_LOCATION'],'name':'service.location','description':'Set\x20service\x20location','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_REPOSITORY'],'name':'service.repository','description':'Manage\x20service\x20repositories','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_SALES'],'name':'service.sales','description':'Manage\x20service\x20sales','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_MACHINE'],'name':'service.machine','description':'Manage\x20service\x20machines','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_BUY_GUARD'],'name':'service.buy_guard','description':'Manage\x20service\x20buy\x20guards','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_ARBITRATION'],'name':'service.arbitration','description':'Manage\x20service\x20arbitrations','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_CUSTOMER_INFO_REQUIRED'],'name':'service.customer_info_required','description':'Manage\x20service\x20customer\x20info\x20requirements','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_PAUSE'],'name':'service.pause','description':'Pause\x20or\x20resume\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_PUBLISH'],'name':'service.publish','description':'Publish\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_DISCOUNT'],'name':'service.discount','description':'Manage\x20service\x20discounts','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_ORDER_ALLOCATOR'],'name':'service.order_allocator','description':'Manage\x20service\x20order\x20allocators','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_WITHDRAW'],'name':'service.compensation_fund_withdraw','description':'Withdraw\x20from\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_DEPOSIT'],'name':'service.compensation_fund_deposit','description':'Deposit\x20to\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_FUND_RECEIVE'],'name':'service.compensation_fund_receive','description':'Receive\x20payments\x20for\x20service\x20compensation\x20fund','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_COMPENSATION_LOCKED_TIME_ADD'],'name':'service.setting_locked_time_add','description':'Add\x20locked\x20time\x20to\x20service\x20compensation','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_REWARD'],'name':'service.reward','description':'Manage\x20service\x20rewards','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_OWNER_RECEIVE'],'name':'service.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20service','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['SERVICE_UM'],'name':'service.um','description':'Manage\x20service\x20UM\x20(User\x20Manager)','object_type':ObjectType['Service']},{'index':BuiltinPermissionIndex['ARBITRATION_NEW'],'name':'arbitration.new','description':'Create\x20new\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_DESCRIPTION'],'name':'arbitration.description','description':'Set\x20arbitration\x20description','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_LOCATION'],'name':'arbitration.location','description':'Set\x20arbitration\x20location','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTING_GUARD'],'name':'arbitration.voting_guard','description':'Manage\x20arbitration\x20voting\x20guards','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_USAGE_GUARD'],'name':'arbitration.usage_guard','description':'Set\x20arbitration\x20usage\x20guard','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_PAUSE'],'name':'arbitration.pause','description':'Pause\x20or\x20resume\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEE'],'name':'arbitration.fee','description':'Set\x20arbitration\x20fee','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTE'],'name':'arbitration.vote','description':'Vote\x20on\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_ARBITRATION'],'name':'arbitration.arbitration','description':'Perform\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEEDBACK'],'name':'arbitration.feedback','description':'Provide\x20arbitration\x20feedback','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_CONFIRM'],'name':'arbitration.confirm','description':'Confirm\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_VOTING_DEADLINE_CHANGE'],'name':'arbitration.voting_deadline_change','description':'Change\x20voting\x20deadline','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_RESET'],'name':'arbitration.reset','description':'Reset\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_ARB_WITHDRAW'],'name':'arbitration.arb_withdraw','description':'Withdraw\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEES_ALLOC'],'name':'arbitration.fees_alloc','description':'Allocate\x20arbitration\x20fees','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_FEES_TRANSFER'],'name':'arbitration.fees_transfer','description':'Transfer\x20arbitration\x20fees','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_OWNER_RECEIVE'],'name':'arbitration.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20arbitration','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['ARBITRATION_UM'],'name':'arbitration.um','description':'Manage\x20arbitration\x20UM\x20(User\x20Manager)','object_type':ObjectType['Arbitration']},{'index':BuiltinPermissionIndex['DEMAND_NEW'],'name':'demand.new','description':'Create\x20new\x20demand','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_DESCRIPTION'],'name':'demand.description','description':'Set\x20demand\x20description','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_LOCATION'],'name':'demand.location','description':'Set\x20demand\x20location','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_GUARD'],'name':'demand.guard','description':'Manage\x20demand\x20guards','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_REWARD'],'name':'demand.reward','description':'Manage\x20demand\x20rewards','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_FEEDBACK'],'name':'demand.feedback','description':'Provide\x20demand\x20feedback','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_OWNER_RECEIVE'],'name':'demand.owner_receive','description':'Receive\x20objects\x20for\x20demand','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['DEMAND_UM'],'name':'demand.um','description':'Manage\x20demand\x20UM\x20(User\x20Manager)','object_type':ObjectType['Demand']},{'index':BuiltinPermissionIndex['MESSNGER_NEW'],'name':'messenger.new','description':'Create\x20new\x20messenger','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_DESCRIPTION'],'name':'messenger.description','description':'Set\x20messenger\x20description','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_LOCATION'],'name':'messenger.location','description':'Set\x20messenger\x20location','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_IM'],'name':'messenger.im','description':'Manager\x20im\x20address','object_type':ObjectType['Contact']},{'index':BuiltinPermissionIndex['MESSNGER_OWNER_RECEIVE'],'name':'messenger.owner_receive','description':'Receive\x20objects\x20or\x20payments\x20for\x20messenger','object_type':ObjectType['Contact']}];export class CallPermission extends CallBase{['data'];['object_address']=undefined;['object_data']=undefined;constructor(a){super(),this['data']=a;}async['prepare'](a){await super['prepare'](a),!this['object_address']&&(this['object_address']=await GetObjectExisted(this['data']?.['object']));}async['call'](a){await this['prepare'](a);let b=![],c=![];if(this['object_address'])return(this['data']?.['builder']!=null||this['data']?.['admin']!=null||this['data']?.['um']!==undefined)&&(b=!![]),(this['data']?.['table']!=null||this['data']?.['entity']!=null||this['data']?.['remark']!=null||this['data']?.['description']!=null)&&(c=!![]),await this['check_permission_and_call'](a,this['object_address'],[],[],b,c);return await this['exec'](a);}async['operate'](a,c,d,e){let f;this['object_address']?f=toTxObject(c,this['object_address']):f=newPermission(c,this['data']?.['description']??'');!f&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.object');this['data']?.['description']!=null&&this['object_address']&&descriptionSet(c,f,this['data']['description']);if(this['data']?.['remark']!=null)switch(this['data']['remark']['op']){case'set':{const g=this['data']['remark']['index'],h=this['data']['remark']['remark'];remarkSet(c,f,g,h);break;}case'remove':{const i=this['data']['remark']['index'];remarkRemove(c,f,i);break;}case'clear':{remarkClear(c,f);break;}}if(this['data']?.['table']!=null)switch(this['data']['table']['op']){case'add\x20perm\x20by\x20index':{const j=this['data']['table']['index'],k=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permAdd(c,f,j,k);break;}case'remove\x20perm\x20by\x20index':{const l=this['data']['table']['index'],m=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permRemove(c,f,l,m);break;}case'set\x20perm\x20by\x20index':{const n=this['data']['table']['index'],o=await GetManyAccountOrMark_Address(this['data']['table']['entity']);permSet(c,f,n,o);break;}case'add\x20perm\x20by\x20entity':{const q=await GetAccountOrMark_Address(this['data']['table']['entity']);q&&entityAdd(c,f,q,this['data']['table']['index']);break;}case'remove\x20perm\x20by\x20entity':{const s=await GetAccountOrMark_Address(this['data']['table']['entity']);s&&entityRemove(c,f,s,this['data']['table']['index']);break;}case'set\x20perm\x20by\x20entity':{const t=await GetAccountOrMark_Address(this['data']['table']['entity']);t&&entitySet(c,f,t,this['data']['table']['index']);break;}}if(this['data']?.['entity']!=null)switch(this['data']['entity']['op']){case'swap':{const u=await GetAccountOrMark_Address(this['data']['entity']['entity1']),v=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(u&&v)entitySwap(c,f,u,v);break;}case'replace':{const w=await GetAccountOrMark_Address(this['data']['entity']['entity1']),x=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(w&&x)entityReplace(c,f,w,x);break;}case'copy':{const y=await GetAccountOrMark_Address(this['data']['entity']['entity1']),z=await GetAccountOrMark_Address(this['data']['entity']['entity2']);if(y&&z)entityCopy(c,f,y,z);break;}case'del':{const A=await GetAccountOrMark_Address(this['data']['entity']['entity']);if(A)entityDel(c,f,A);break;}}if(this['data']?.['admin']!=null){const B=await GetManyAccountOrMark_Address(this['data']['admin']['addresses']);switch(this['data']['admin']?.['op']){case'add':{adminAdd(c,f,B);break;}case'set':{adminSet(c,f,B);break;}case'remove':{adminRemove(c,f,B);break;}}}if(this['data']?.['apply']!=null&&this['data']['apply']['length']>0x0){const C=await query_objects({'objects':this['data']['apply'],'no_cache':a['no_cache'],'network':a['network']});(!C['objects']||C['objects']['length']!==this['data']['apply']['length'])&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.apply\x20some\x20objects\x20not\x20found\x20'+this['data']['apply']),C['objects']?.['forEach'](D=>{switch(D['type']){case'Demand':const E=D;permission_set(c,E['object'],E['permission'],f,parseObjectType(E['type_raw'],'demand::Demand'),L=>demandFn(L));break;case'Machine':const F=D;permission_set(c,F['object'],F['permission'],f,undefined,L=>machineFn(L));break;case'Service':const G=D;permission_set(c,G['object'],G['permission'],f,parseObjectType(G['type_raw'],'service::Service'),L=>serviceFn(L));break;case'Treasury':const H=D;permission_set(c,H['object'],H['permission'],f,parseObjectType(H['type_raw'],'treasury::Treasury'),L=>treasuryFn(L));break;case'Arbitration':const I=D;permission_set(c,I['object'],I['permission'],f,parseObjectType(I['type_raw'],'arbitration::Arbitration'),L=>arbitrationFn(L));break;case'Repository':const J=D;permission_set(c,J['object'],J['permission'],f,undefined,L=>repositoryFn(L));break;case'Reward':const K=D;permission_set(c,K['object'],K['permission'],f,parseObjectType(K['type_raw'],'reward::Reward'),L=>rewardFn(L));break;}});}if(this['data']?.['builder']!=null){const D=await GetAccountOrMark_Address(this['data']['builder']);if(D)transferPermission(c,f,D);}if(this['data']['owner_receive']!=null&&this['object_address']){this['data']['owner_receive']==='recently'&&(this['data']['owner_receive']=await query_received({'name_or_address':{'name_or_address':this['object_address'],'local_mark_first':!![]},'all_type':!![],'no_cache':a['no_cache'],'network':a['network']}));if(Array['isArray'](this['data']['owner_receive']))for(const E of this['data']['owner_receive']){!IsValidArgType(E['type'])&&W_ERROR(WErrors['IsValidArgType'],'Invalid\x20type:\x20'+E['type']);const F=await LocalMark['Instance']()['get_address'](E['id']);!F&&W_ERROR(WErrors['IsValidArgType'],'Received\x20'+E['id']+'\x20is\x20invalid'),ownerReceiveObject(c,f,F,E['type']);}else for(const G of this['data']['owner_receive']['received']){const [H,I]=await Promise['all']([LocalMark['Instance']()['get_address'](G['id']),LocalMark['Instance']()['get_address'](G['payment'])]);(!H||!I)&&W_ERROR(WErrors['IsValidArgType'],'Received\x20'+G['id']+'\x20or\x20Payment\x20'+G['payment']+'\x20is\x20invalid'),ownerReceive(c,f,H,I,this['data']['owner_receive']['token_type']);}}if(this['data']['um']!==undefined){let J=null;this['data']['um']&&(J=await LocalMark['Instance']()['get_address'](this['data']['um'])||null,!J&&W_ERROR(WErrors['InvalidParam'],'CallPermission_Data.data.um:'+this['data']['um'])),um_set(c,f,J);}!this['object_address']&&await this['new_with_mark'](a,c,ObjectType['Permission'],create(c,f),GetObject(this['data']?.['object']));}}export function permissionFn(a){return PackageAddress+'::permission::'+a;}export const MAX_ENTITY_COUNT=0x3e8;export const MAX_PERM_FOR_ENTITY=0x3e8;export const MAX_ADMIN_COUNT=0x1f4;export const USER_DEFINED_PERM_INDEX_START=0x3e8;export function isBizPermIndex(a){return a>=USER_DEFINED_PERM_INDEX_START;}export function newPermission(a,b){return typeof b==='string'&&!isValidDescription(b)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH),a['moveCall']({'target':permissionFn('new'),'arguments':[toTxString(a,b)]});}export function create(a,b){return a['moveCall']({'target':permissionFn('create'),'arguments':[toTxObject(a,b)]});}export function descriptionSet(a,b,c){typeof c==='string'&&!isValidDescription(c)&&W_ERROR(WErrors['IsValidDescription'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH),a['moveCall']({'target':permissionFn('description_set'),'arguments':[toTxObject(a,b),toTxString(a,c)]});}export function remarkSet(a,b,c,d){typeof d==='string'&&!isValidLongName(d)&&W_ERROR(WErrors['IsValidDescription'],'Remark\x20exceeds\x20maximum\x20length\x20'+MAX_LONG_NAME_LENGTH),a['moveCall']({'target':permissionFn('remark_set'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxString(a,d)]});}export function remarkRemove(a,b,c){a['moveCall']({'target':permissionFn('remark_remove'),'arguments':[toTxObject(a,b),toTxU16(a,c)]});}export function remarkClear(a,b){a['moveCall']({'target':permissionFn('remark_clear'),'arguments':[toTxObject(a,b)]});}export function permAdd(a,b,c,d){a['moveCall']({'target':permissionFn('perm_add'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function permRemove(a,b,c,d){a['moveCall']({'target':permissionFn('perm_remove'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT)]});}export function permSet(a,b,c,d){a['moveCall']({'target':permissionFn('perm_set'),'arguments':[toTxObject(a,b),toTxU16(a,c),toTxAddressVec(a,d,MAX_ENTITY_COUNT),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityAdd(a,b,c,d){a['moveCall']({'target':permissionFn('entity_add'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityRemove(a,b,c,d){a['moveCall']({'target':permissionFn('entity_remove'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY)]});}export function entitySet(a,b,c,d){a['moveCall']({'target':permissionFn('entity_set'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxU16Vec(a,d,MAX_PERM_FOR_ENTITY),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entitySwap(a,b,c,d){a['moveCall']({'target':permissionFn('entity_swap'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityReplace(a,b,c,d){a['moveCall']({'target':permissionFn('entity_replace'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function entityDel(a,b,c){a['moveCall']({'target':permissionFn('entity_del'),'arguments':[toTxObject(a,b),toTxAddress(a,c),a['object']['mutRegistrar']()]});}export function entityCopy(a,b,c,d){a['moveCall']({'target':permissionFn('entity_copy'),'arguments':[toTxObject(a,b),toTxAddress(a,c),toTxAddress(a,d),a['object']['mutRegistrar'](),a['object']['clock']()]});}export function adminAdd(a,b,c){a['moveCall']({'target':permissionFn('admin_add'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function adminRemove(a,b,c){a['moveCall']({'target':permissionFn('admin_remove'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function adminSet(a,b,c){a['moveCall']({'target':permissionFn('admin_set'),'arguments':[toTxObject(a,b),toTxAddressVec(a,c,MAX_ADMIN_COUNT)]});}export function transferPermission(a,b,c){a['moveCall']({'target':permissionFn('transfer'),'arguments':[toTxObject(a,b),toTxAddress(a,c)]});}export function um_set(a,b,c){c?a['moveCall']({'target':contactFn('permission_um_set'),'arguments':[toTxObject(a,c),toTxObject(a,b),a['object']['mutRegistrar'](),a['object']['clock']()]}):a['moveCall']({'target':permissionFn('um_none'),'arguments':[toTxObject(a,b),a['object']['mutRegistrar']()]});}export function ownerReceiveObject(a,b,c,d){a['moveCall']({'target':permissionFn('owner_receive_object'),'arguments':[toTxObject(a,b),toTxObject(a,c)],'typeArguments':[d]});}export function ownerReceive(a,b,c,d,e){a['moveCall']({'target':permissionFn('owner_receive'),'arguments':[toTxObject(a,b),toTxObject(a,c),toTxObject(a,d)],'typeArguments':[e]});}export function query_permissions(a){if(!a)return PermissionInfo;return PermissionInfo['filter'](b=>{if(a['objectType']&&b['object_type']!==a['objectType'])return![];if(a['name']&&!b['name']['includes'](a['name']))return![];if(a['index']!==undefined&&b['index']!==a['index'])return![];if(a['description']&&!b['description']['includes'](a['description']))return![];return!![];});}
|
|
@@ -64,7 +64,7 @@ export interface CallService_Data {
|
|
|
64
64
|
order_allocators?: Allocators | null;
|
|
65
65
|
buy_guard?: string | null;
|
|
66
66
|
compensation_fund_add?: CoinParam;
|
|
67
|
-
|
|
67
|
+
setting_locked_time_add?: number;
|
|
68
68
|
compensation_fund_receive?: ReceivedBalanceOrRecently;
|
|
69
69
|
owner_receive?: ReceivedObjectsOrRecently;
|
|
70
70
|
pause?: boolean;
|
|
@@ -96,7 +96,7 @@ export declare const MAX_DISCOUNT_COUNT_ONCE = 1000;
|
|
|
96
96
|
export declare const MAX_DISCOUNT_RECEIVER_ONCE = 1000;
|
|
97
97
|
export declare const MAX_DISCOUNT_TOTAL_COUNT = 20000;
|
|
98
98
|
export declare const MAX_REQUIRED_INFO_SIZE = 20;
|
|
99
|
-
export declare const
|
|
99
|
+
export declare const DEFAULT_SETTING_LOCK_DURATION = 2592000000;
|
|
100
100
|
export declare const DISCOUNT_TYPE_RATES = 0;
|
|
101
101
|
export declare const DISCOUNT_TYPE_MINUS = 1;
|
|
102
102
|
export interface ServiceSale {
|
|
@@ -175,7 +175,7 @@ export declare function arbitrations_add(tx: Transaction, service: ServiceObject
|
|
|
175
175
|
export declare function arbitrations_remove(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, arbitrations: string[], passport?: PassportObject): void;
|
|
176
176
|
export declare function arbitration_clear(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, passport?: PassportObject): void;
|
|
177
177
|
export declare function compensation_fund_add(env: CallEnv, tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, coin: CoinParam, passport?: PassportObject): Promise<void>;
|
|
178
|
-
export declare function
|
|
178
|
+
export declare function setting_lock_duration_set(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, duration_ms: number | string | bigint, passport?: PassportObject): void;
|
|
179
179
|
export declare function order_allocators_set(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, allocators: AllocatorsType | null, passport?: PassportObject): void;
|
|
180
180
|
export declare function reward_add(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, reward: RewardObject, reward_type: string, passport?: PassportObject): void;
|
|
181
181
|
export declare function reward_remove(tx: Transaction, service: ServiceObject, service_type: string, permission: PermissionObject, rewards: string[], passport?: PassportObject): void;
|