wowok 2.2.5 → 2.2.6
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/bcs/bcs.d.ts +1 -1
- package/dist/cjs/bcs/bcs.js +1 -1
- package/dist/cjs/bcs/effects.d.ts +4 -4
- package/dist/cjs/bcs/effects.js +1 -1
- package/dist/cjs/bcs/index.d.ts +2 -2
- package/dist/cjs/bcs/index.js +1 -1
- package/dist/cjs/bcs/type-tag-serializer.js +1 -1
- package/dist/cjs/bcs/types.d.ts +4 -4
- package/dist/cjs/client/index.d.ts +4 -4
- package/dist/cjs/client/index.js +1 -1
- package/dist/cjs/cryptography/keypair.d.ts +2 -2
- package/dist/cjs/cryptography/publickey.js +1 -1
- package/dist/cjs/experimental/client.d.ts +4 -4
- package/dist/cjs/experimental/core.d.ts +17 -17
- package/dist/cjs/experimental/core.js +1 -1
- package/dist/cjs/experimental/errors.d.ts +2 -2
- package/dist/cjs/experimental/errors.js +1 -1
- package/dist/cjs/experimental/index.d.ts +2 -2
- package/dist/cjs/experimental/transports/utils.d.ts +3 -3
- package/dist/cjs/experimental/types.d.ts +3 -3
- package/dist/cjs/faucet/faucet.d.ts +3 -3
- package/dist/cjs/faucet/faucet.js +1 -1
- package/dist/cjs/faucet/index.d.ts +1 -1
- package/dist/cjs/faucet/index.js +1 -1
- package/dist/cjs/grpc/client.d.ts +7 -7
- package/dist/cjs/grpc/client.js +1 -1
- package/dist/cjs/grpc/core.d.ts +15 -15
- package/dist/cjs/grpc/core.js +1 -1
- package/dist/cjs/grpc/index.d.ts +2 -2
- package/dist/cjs/grpc/index.js +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/jsonRpc/client.d.ts +24 -24
- package/dist/cjs/jsonRpc/client.js +1 -1
- package/dist/cjs/jsonRpc/core.d.ts +20 -20
- package/dist/cjs/jsonRpc/core.js +1 -1
- package/dist/cjs/jsonRpc/errors.d.ts +3 -3
- package/dist/cjs/jsonRpc/errors.js +1 -1
- package/dist/cjs/jsonRpc/http-transport.js +1 -1
- package/dist/cjs/jsonRpc/index.d.ts +2 -2
- package/dist/cjs/jsonRpc/index.js +1 -1
- package/dist/cjs/jsonRpc/json-rpc-resolver.d.ts +2 -2
- package/dist/cjs/jsonRpc/types/chain.d.ts +4 -4
- package/dist/cjs/jsonRpc/types/changes.d.ts +7 -7
- package/dist/cjs/jsonRpc/types/generated.d.ts +63 -63
- package/dist/cjs/jsonRpc/types/params.d.ts +13 -13
- package/dist/cjs/multisig/publickey.js +1 -1
- package/dist/cjs/transactions/Commands.js +1 -1
- package/dist/cjs/transactions/Inputs.js +1 -1
- package/dist/cjs/transactions/ObjectCache.js +1 -1
- package/dist/cjs/transactions/Transaction.js +1 -1
- package/dist/cjs/transactions/TransactionData.js +1 -1
- package/dist/cjs/transactions/__tests__/bcs.test.js +1 -1
- package/dist/cjs/transactions/data/internal.d.ts +1 -1
- package/dist/cjs/transactions/data/internal.js +1 -1
- package/dist/cjs/transactions/data/v2.js +1 -1
- package/dist/cjs/transactions/executor/caching.d.ts +4 -4
- package/dist/cjs/transactions/executor/parallel.d.ts +4 -4
- package/dist/cjs/transactions/executor/parallel.js +1 -1
- package/dist/cjs/transactions/executor/serial.d.ts +4 -4
- package/dist/cjs/transactions/intents/CoinWithBalance.d.ts +2 -2
- package/dist/cjs/transactions/intents/CoinWithBalance.js +1 -1
- package/dist/cjs/transactions/serializer.d.ts +2 -2
- package/dist/cjs/transactions/serializer.js +1 -1
- package/dist/cjs/transactions/utils.d.ts +4 -4
- package/dist/cjs/transactions/utils.js +1 -1
- package/dist/cjs/utils/constants.d.ts +0 -6
- package/dist/cjs/utils/constants.js +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/verify/index.d.ts +1 -1
- package/dist/cjs/verify/index.js +1 -1
- package/dist/cjs/verify/verify.d.ts +1 -1
- package/dist/cjs/verify/verify.js +1 -1
- package/dist/cjs/w/call/allocation.js +1 -1
- package/dist/cjs/w/call/arbitration.js +1 -1
- package/dist/cjs/w/call/base.d.ts +6 -6
- package/dist/cjs/w/call/base.js +1 -1
- package/dist/cjs/w/call/contact.js +1 -1
- package/dist/cjs/w/call/demand.js +1 -1
- package/dist/cjs/w/call/entity.js +1 -1
- package/dist/cjs/w/call/guard.js +1 -1
- package/dist/cjs/w/call/passport.d.ts +2 -2
- package/dist/cjs/w/call/passport.js +1 -1
- package/dist/cjs/w/local/account.d.ts +3 -3
- package/dist/cjs/w/local/account.js +1 -1
- package/dist/cjs/w/local/index.d.ts +2 -2
- package/dist/cjs/w/local/index.js +1 -1
- package/dist/cjs/w/local/local.js +1 -1
- package/dist/cjs/w/local/token.js +1 -1
- package/dist/cjs/w/messenger/messenger.js +1 -1
- package/dist/cjs/w/query/event.js +1 -1
- package/dist/cjs/w/query/object.js +1 -1
- package/dist/cjs/w/query/received.js +1 -1
- package/dist/cjs/w/util.js +1 -1
- package/dist/esm/bcs/bcs.d.ts +1 -1
- package/dist/esm/bcs/bcs.js +1 -1
- package/dist/esm/bcs/effects.d.ts +4 -4
- package/dist/esm/bcs/effects.js +1 -1
- package/dist/esm/bcs/index.d.ts +2 -2
- package/dist/esm/bcs/index.js +1 -1
- package/dist/esm/bcs/type-tag-serializer.js +1 -1
- package/dist/esm/bcs/types.d.ts +4 -4
- package/dist/esm/client/index.d.ts +4 -4
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/cryptography/keypair.d.ts +2 -2
- package/dist/esm/cryptography/publickey.js +1 -1
- package/dist/esm/experimental/client.d.ts +4 -4
- package/dist/esm/experimental/core.d.ts +17 -17
- package/dist/esm/experimental/core.js +1 -1
- package/dist/esm/experimental/errors.d.ts +2 -2
- package/dist/esm/experimental/errors.js +1 -1
- package/dist/esm/experimental/index.d.ts +2 -2
- package/dist/esm/experimental/transports/utils.d.ts +3 -3
- package/dist/esm/experimental/types.d.ts +3 -3
- package/dist/esm/faucet/faucet.d.ts +3 -3
- package/dist/esm/faucet/faucet.js +1 -1
- package/dist/esm/faucet/index.d.ts +1 -1
- package/dist/esm/faucet/index.js +1 -1
- package/dist/esm/grpc/client.d.ts +7 -7
- package/dist/esm/grpc/client.js +1 -1
- package/dist/esm/grpc/core.d.ts +15 -15
- package/dist/esm/grpc/core.js +1 -1
- package/dist/esm/grpc/index.d.ts +2 -2
- package/dist/esm/grpc/index.js +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/jsonRpc/client.d.ts +24 -24
- package/dist/esm/jsonRpc/client.js +1 -1
- package/dist/esm/jsonRpc/core.d.ts +20 -20
- package/dist/esm/jsonRpc/core.js +1 -1
- package/dist/esm/jsonRpc/errors.d.ts +3 -3
- package/dist/esm/jsonRpc/errors.js +1 -1
- package/dist/esm/jsonRpc/http-transport.js +1 -1
- package/dist/esm/jsonRpc/index.d.ts +2 -2
- package/dist/esm/jsonRpc/index.js +1 -1
- package/dist/esm/jsonRpc/json-rpc-resolver.d.ts +2 -2
- package/dist/esm/jsonRpc/types/chain.d.ts +4 -4
- package/dist/esm/jsonRpc/types/changes.d.ts +7 -7
- package/dist/esm/jsonRpc/types/generated.d.ts +63 -63
- package/dist/esm/jsonRpc/types/params.d.ts +13 -13
- package/dist/esm/multisig/publickey.js +1 -1
- package/dist/esm/transactions/Commands.js +1 -1
- package/dist/esm/transactions/Inputs.js +1 -1
- package/dist/esm/transactions/ObjectCache.js +1 -1
- package/dist/esm/transactions/Transaction.js +1 -1
- package/dist/esm/transactions/TransactionData.js +1 -1
- package/dist/esm/transactions/__tests__/bcs.test.js +1 -1
- package/dist/esm/transactions/data/internal.d.ts +1 -1
- package/dist/esm/transactions/data/internal.js +1 -1
- package/dist/esm/transactions/data/v2.js +1 -1
- package/dist/esm/transactions/executor/caching.d.ts +4 -4
- package/dist/esm/transactions/executor/parallel.d.ts +4 -4
- package/dist/esm/transactions/executor/parallel.js +1 -1
- package/dist/esm/transactions/executor/serial.d.ts +4 -4
- package/dist/esm/transactions/intents/CoinWithBalance.d.ts +2 -2
- package/dist/esm/transactions/intents/CoinWithBalance.js +1 -1
- package/dist/esm/transactions/serializer.d.ts +2 -2
- package/dist/esm/transactions/serializer.js +1 -1
- package/dist/esm/transactions/utils.d.ts +4 -4
- package/dist/esm/transactions/utils.js +1 -1
- package/dist/esm/utils/constants.d.ts +0 -6
- package/dist/esm/utils/constants.js +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/verify/index.d.ts +1 -1
- package/dist/esm/verify/index.js +1 -1
- package/dist/esm/verify/verify.d.ts +1 -1
- package/dist/esm/verify/verify.js +1 -1
- package/dist/esm/w/call/allocation.js +1 -1
- package/dist/esm/w/call/arbitration.js +1 -1
- package/dist/esm/w/call/base.d.ts +6 -6
- package/dist/esm/w/call/base.js +1 -1
- package/dist/esm/w/call/contact.js +1 -1
- package/dist/esm/w/call/demand.js +1 -1
- package/dist/esm/w/call/entity.js +1 -1
- package/dist/esm/w/call/guard.js +1 -1
- package/dist/esm/w/call/passport.d.ts +2 -2
- package/dist/esm/w/call/passport.js +1 -1
- package/dist/esm/w/local/account.d.ts +3 -3
- package/dist/esm/w/local/account.js +1 -1
- package/dist/esm/w/local/index.d.ts +2 -2
- package/dist/esm/w/local/index.js +1 -1
- package/dist/esm/w/local/local.js +1 -1
- package/dist/esm/w/local/token.js +1 -1
- package/dist/esm/w/messenger/messenger.js +1 -1
- package/dist/esm/w/query/event.js +1 -1
- package/dist/esm/w/query/object.js +1 -1
- package/dist/esm/w/query/received.js +1 -1
- package/dist/esm/w/util.js +1 -1
- package/package.json +4 -3
- /package/dist/cjs/utils/{sui-types.d.ts → wow-types.d.ts} +0 -0
- /package/dist/cjs/utils/{sui-types.js → wow-types.js} +0 -0
- /package/dist/esm/utils/{sui-types.d.ts → wow-types.d.ts} +0 -0
- /package/dist/esm/utils/{sui-types.js → wow-types.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toBase58}from'../_deps/bcs/index.js';import{parse}from'valibot';import{bcs}from'../bcs/index.js';import{normalizeWowAddress}from'../utils/
|
|
1
|
+
import{toBase58}from'../_deps/bcs/index.js';import{parse}from'valibot';import{bcs}from'../bcs/index.js';import{normalizeWowAddress}from'../utils/wow-types.js';import{ArgumentSchema,TransactionDataSchema}from'./data/internal.js';import{transactionDataFromV1}from'./data/v1.js';import{hashTypedData}from'./hash.js';import{getIdFromCallArg,remapCommandArguments}from'./utils.js';function prepareWowAddress(a){return normalizeWowAddress(a)['replace']('0x','');}export class TransactionDataBuilder{static['fromKindBytes'](a){const b=bcs['TransactionKind']['parse'](a),c=b['ProgrammableTransaction'];if(!c)throw new Error('Unable\x20to\x20deserialize\x20from\x20bytes.');return TransactionDataBuilder['restore']({'version':0x2,'sender':null,'expiration':null,'gasData':{'budget':null,'owner':null,'payment':null,'price':null},'inputs':c['inputs'],'commands':c['commands']});}static['fromBytes'](a){const b=bcs['TransactionData']['parse'](a),c=b?.['V1'],d=c['kind']['ProgrammableTransaction'];if(!c||!d)throw new Error('Unable\x20to\x20deserialize\x20from\x20bytes.');return TransactionDataBuilder['restore']({'version':0x2,'sender':c['sender'],'expiration':c['expiration'],'gasData':c['gasData'],'inputs':d['inputs'],'commands':d['commands']});}static['restore'](a){return a['version']===0x2?new TransactionDataBuilder(parse(TransactionDataSchema,a)):new TransactionDataBuilder(parse(TransactionDataSchema,transactionDataFromV1(a)));}static['getDigestFromBytes'](a){const b=hashTypedData('TransactionData',a);return toBase58(b);}get['gasConfig'](){return this['gasData'];}set['gasConfig'](a){this['gasData']=a;}['version']=0x2;['sender'];['expiration'];['gasData'];['inputs'];['commands'];constructor(a){this['sender']=a?.['sender']??null,this['expiration']=a?.['expiration']??null,this['inputs']=a?.['inputs']??[],this['commands']=a?.['commands']??[],this['gasData']=a?.['gasData']??{'budget':null,'price':null,'owner':null,'payment':null};}['build']({maxSizeBytes:maxSizeBytes=Infinity,overrides:a,onlyTransactionKind:b}={}){const c=this['inputs'],d=this['commands'],e={'ProgrammableTransaction':{'inputs':c,'commands':d}};if(b)return bcs['TransactionKind']['serialize'](e,{'maxSize':maxSizeBytes})['toBytes']();const f=a?.['expiration']??this['expiration'],g=a?.['sender']??this['sender'],h={...this['gasData'],...a?.['gasConfig'],...a?.['gasData']};if(!g)throw new Error('Missing\x20transaction\x20sender');if(!h['budget'])throw new Error('Missing\x20gas\x20budget');if(!h['payment'])throw new Error('Missing\x20gas\x20payment');if(!h['price'])throw new Error('Missing\x20gas\x20price');const i={'sender':prepareWowAddress(g),'expiration':f?f:{'None':!![]},'gasData':{'payment':h['payment'],'owner':prepareWowAddress(this['gasData']['owner']??g),'price':BigInt(h['price']),'budget':BigInt(h['budget'])},'kind':{'ProgrammableTransaction':{'inputs':c,'commands':d}}};return bcs['TransactionData']['serialize']({'V1':i},{'maxSize':maxSizeBytes})['toBytes']();}['addInput'](a,b){const c=this['inputs']['length'];return this['inputs']['push'](b),{'Input':c,'type':a,'$kind':'Input'};}['getInputUses'](a,b){this['mapArguments']((c,d)=>{return c['$kind']==='Input'&&c['Input']===a&&b(c,d),c;});}['mapCommandArguments'](a,b){const c=this['commands'][a];switch(c['$kind']){case'MoveCall':c['MoveCall']['arguments']=c['MoveCall']['arguments']['map'](e=>b(e,c,a));break;case'TransferObjects':c['TransferObjects']['objects']=c['TransferObjects']['objects']['map'](e=>b(e,c,a)),c['TransferObjects']['address']=b(c['TransferObjects']['address'],c,a);break;case'SplitCoins':c['SplitCoins']['coin']=b(c['SplitCoins']['coin'],c,a),c['SplitCoins']['amounts']=c['SplitCoins']['amounts']['map'](e=>b(e,c,a));break;case'MergeCoins':c['MergeCoins']['destination']=b(c['MergeCoins']['destination'],c,a),c['MergeCoins']['sources']=c['MergeCoins']['sources']['map'](e=>b(e,c,a));break;case'MakeMoveVec':c['MakeMoveVec']['elements']=c['MakeMoveVec']['elements']['map'](e=>b(e,c,a));break;case'Upgrade':c['Upgrade']['ticket']=b(c['Upgrade']['ticket'],c,a);break;case'$Intent':const d=c['$Intent']['inputs'];c['$Intent']['inputs']={};for(const [e,f]of Object['entries'](d)){c['$Intent']['inputs'][e]=Array['isArray'](f)?f['map'](g=>b(g,c,a)):b(f,c,a);}break;case'Publish':break;default:throw new Error('Unexpected\x20transaction\x20kind:\x20'+c['$kind']);}}['mapArguments'](a){for(const b of this['commands']['keys']()){this['mapCommandArguments'](b,a);}}['replaceCommand'](a,b,c=a){if(!Array['isArray'](b)){this['commands'][a]=b;return;}const d=b['length']-0x1;this['commands']['splice'](a,0x1,...structuredClone(b)),this['mapArguments']((e,f,g)=>{if(g<a+b['length'])return e;if(typeof c!=='number'){if(e['$kind']==='Result'&&e['Result']===a||e['$kind']==='NestedResult'&&e['NestedResult'][0x0]===a){if(!('NestedResult'in e)||e['NestedResult'][0x1]===0x0)return parse(ArgumentSchema,structuredClone(c));else throw new Error('Cannot\x20replace\x20command\x20'+a+'\x20with\x20a\x20specific\x20result\x20type:\x20NestedResult['+a+',\x20'+e['NestedResult'][0x1]+']\x20references\x20a\x20nested\x20element\x20that\x20cannot\x20be\x20mapped\x20to\x20the\x20replacement\x20result');}}switch(e['$kind']){case'Result':e['Result']===a&&typeof c==='number'&&(e['Result']=c);e['Result']>a&&(e['Result']+=d);break;case'NestedResult':if(e['NestedResult'][0x0]===a&&typeof c==='number')return{'$kind':'NestedResult','NestedResult':[c,e['NestedResult'][0x1]]};e['NestedResult'][0x0]>a&&(e['NestedResult'][0x0]+=d);break;}return e;});}['replaceCommandWithTransaction'](a,b,c){if(c['$kind']!=='Result'&&c['$kind']!=='NestedResult')throw new Error('Result\x20must\x20be\x20of\x20kind\x20Result\x20or\x20NestedResult');this['insertTransaction'](a,b),this['replaceCommand'](a+b['commands']['length'],[],'Result'in c?{'NestedResult':[c['Result']+a,0x0]}:{'NestedResult':[c['NestedResult'][0x0]+a,c['NestedResult'][0x1]]});}['insertTransaction'](a,b){const c=new Map(),d=new Map();for(let g=0x0;g<b['inputs']['length'];g++){const h=b['inputs'][g],j=getIdFromCallArg(h);let k=-0x1;j!==undefined&&(k=this['inputs']['findIndex'](l=>getIdFromCallArg(l)===j),k!==-0x1&&this['inputs'][k]['Object']?.['SharedObject']&&h['Object']?.['SharedObject']&&(this['inputs'][k]['Object']['SharedObject']['mutable']=this['inputs'][k]['Object']['SharedObject']['mutable']||h['Object']['SharedObject']['mutable']));if(k!==-0x1)c['set'](g,k);else{const l=this['inputs']['length'];this['inputs']['push'](h),c['set'](g,l);}}for(let m=0x0;m<b['commands']['length'];m++){d['set'](m,a+m);}const e=[];for(let n=0x0;n<b['commands']['length'];n++){const o=structuredClone(b['commands'][n]);remapCommandArguments(o,c,d),e['push'](o);}this['commands']['splice'](a,0x0,...e);const f=e['length'];f>0x0&&this['mapArguments']((p,q,r)=>{if(r>=a&&r<a+e['length'])return p;switch(p['$kind']){case'Result':p['Result']>=a&&(p['Result']+=f);break;case'NestedResult':p['NestedResult'][0x0]>=a&&(p['NestedResult'][0x0]+=f);break;}return p;});}['getDigest'](){const a=this['build']({'onlyTransactionKind':![]});return TransactionDataBuilder['getDigestFromBytes'](a);}['snapshot'](){return parse(TransactionDataSchema,this);}['shallowClone'](){return new TransactionDataBuilder({'version':this['version'],'sender':this['sender'],'expiration':this['expiration'],'gasData':{...this['gasData']},'inputs':[...this['inputs']],'commands':[...this['commands']]});}['applyResolvedData'](a){!this['sender']&&(this['sender']=a['sender']??null);!this['expiration']&&(this['expiration']=a['expiration']??null);!this['gasData']['budget']&&(this['gasData']['budget']=a['gasData']['budget']);!this['gasData']['owner']&&(this['gasData']['owner']=a['gasData']['owner']??null);!this['gasData']['payment']&&(this['gasData']['payment']=a['gasData']['payment']);!this['gasData']['price']&&(this['gasData']['price']=a['gasData']['price']);for(let b=0x0;b<this['inputs']['length'];b++){const c=this['inputs'][b],d=a['inputs'][b];switch(c['$kind']){case'UnresolvedPure':if(d['$kind']!=='Pure')throw new Error('Expected\x20input\x20at\x20index\x20'+b+'\x20to\x20resolve\x20to\x20a\x20Pure\x20argument,\x20but\x20got\x20'+JSON['stringify'](d));this['inputs'][b]=d;break;case'UnresolvedObject':if(d['$kind']!=='Object')throw new Error('Expected\x20input\x20at\x20index\x20'+b+'\x20to\x20resolve\x20to\x20an\x20Object\x20argument,\x20but\x20got\x20'+JSON['stringify'](d));if(d['Object']['$kind']==='ImmOrOwnedObject'||d['Object']['$kind']==='Receiving'){const e=c['UnresolvedObject'],f=d['Object']['ImmOrOwnedObject']??d['Object']['Receiving'];if(normalizeWowAddress(e['objectId'])!==normalizeWowAddress(f['objectId'])||e['version']!=null&&e['version']!==f['version']||e['digest']!=null&&e['digest']!==f['digest']||e['mutable']!=null||e['initialSharedVersion']!=null)throw new Error('Input\x20at\x20index\x20'+b+'\x20did\x20not\x20match\x20unresolved\x20object.\x20'+JSON['stringify'](e)+'\x20is\x20not\x20compatible\x20with\x20'+JSON['stringify'](f));}else{if(d['Object']['$kind']==='SharedObject'){const g=c['UnresolvedObject'],h=d['Object']['SharedObject'];if(normalizeWowAddress(g['objectId'])!==normalizeWowAddress(h['objectId'])||g['initialSharedVersion']!=null&&g['initialSharedVersion']!==h['initialSharedVersion']||g['mutable']!=null&&g['mutable']!==h['mutable']||g['version']!=null||g['digest']!=null)throw new Error('Input\x20at\x20index\x20'+b+'\x20did\x20not\x20match\x20unresolved\x20object.\x20'+JSON['stringify'](g)+'\x20is\x20not\x20compatible\x20with\x20'+JSON['stringify'](h));}else throw new Error('Input\x20at\x20index\x20'+b+'\x20resolved\x20to\x20an\x20unexpected\x20Object\x20kind:\x20'+JSON['stringify'](d['Object']));}this['inputs'][b]=d;break;}}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toBase58}from'../../_deps/bcs/index.js';import{expect,it}from'vitest';import{bcs}from'../../bcs/index.js';import{normalizeStructTag,normalizeWowAddress}from'../../utils/
|
|
1
|
+
import{toBase58}from'../../_deps/bcs/index.js';import{expect,it}from'vitest';import{bcs}from'../../bcs/index.js';import{normalizeStructTag,normalizeWowAddress}from'../../utils/wow-types.js';it('can\x20serialize\x20simplified\x20programmable\x20call\x20struct',()=>{const a={'package':'0x2','module':'display','function':'new','typeArguments':[normalizeStructTag('0x6::capy::Capy')],'arguments':[{'$kind':'GasCoin','GasCoin':!![]},{'$kind':'NestedResult','NestedResult':[0x0,0x1]},{'$kind':'Input','Input':0x3},{'$kind':'Result','Result':0x1}]},b=bcs['ProgrammableMoveCall']['serialize'](a)['toBytes'](),c=bcs['ProgrammableMoveCall']['parse'](b);expect(c['arguments'])['toEqual'](a['arguments']),expect(c['function'])['toEqual'](a['function']),expect(c['module'])['toEqual'](a['module']),expect(normalizeWowAddress(c['package']))['toEqual'](normalizeWowAddress(a['package'])),expect(c['typeArguments'][0x0])['toEqual'](a['typeArguments'][0x0]);});function ref(){return{'objectId':normalizeWowAddress((Math['random']()*0x186a0)['toFixed'](0x0)['padEnd'](0x40,'0')),'version':String((Math['random']()*0x2710)['toFixed'](0x0)),'digest':toBase58(new Uint8Array([0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x1,0x2]))};}it('can\x20serialize\x20transaction\x20data\x20with\x20a\x20programmable\x20transaction',()=>{const a=normalizeWowAddress('0x2'),b={'$kind':'V1','V1':{'sender':normalizeWowAddress('0xBAD'),'expiration':{'$kind':'None','None':!![]},'gasData':{'payment':[ref()],'owner':a,'price':'1','budget':'1000000'},'kind':{'$kind':'ProgrammableTransaction','ProgrammableTransaction':{'inputs':[{'$kind':'Object','Object':{'$kind':'ImmOrOwnedObject','ImmOrOwnedObject':ref()}},{'$kind':'Pure','Pure':{'bytes':bcs['vector'](bcs['String'])['serialize'](['name','description','img_url'])['toBase64']()}},{'$kind':'Pure','Pure':{'bytes':bcs['vector'](bcs['String'])['serialize'](['Capy\x20{name}','A\x20cute\x20little\x20creature','https://api.capy.art/{id}/svg'])['toBase64']()}},{'$kind':'Pure','Pure':{'bytes':bcs['Address']['serialize'](ref()['objectId'])['toBase64']()}}],'commands':[{'$kind':'MoveCall','MoveCall':{'package':a,'module':'display','function':'new','typeArguments':[a+'::capy::Capy'],'arguments':[{'$kind':'Input','Input':0x0}]}},{'$kind':'MoveCall','MoveCall':{'package':a,'module':'display','function':'add_multiple','typeArguments':[a+'::capy::Capy'],'arguments':[{'$kind':'Result','Result':0x0},{'$kind':'Input','Input':0x1},{'$kind':'Input','Input':0x2}]}},{'$kind':'MoveCall','MoveCall':{'package':a,'module':'display','function':'update_version','typeArguments':[a+'::capy::Capy'],'arguments':[{'$kind':'Result','Result':0x0}]}},{'$kind':'TransferObjects','TransferObjects':{'objects':[{'$kind':'Result','Result':0x0}],'address':{'$kind':'Input','Input':0x3}}}]}}}},c=bcs['TransactionData']['serialize'](b)['toBytes'](),d=bcs['TransactionData']['parse'](c);expect(d)['toMatchObject'](b);});
|
|
@@ -9,7 +9,7 @@ type EnumSchemaOutput<T extends Record<string, GenericSchema<any>>> = EnumOutput
|
|
|
9
9
|
}>>;
|
|
10
10
|
type EnumSchema<T extends Record<string, GenericSchema<any>>> = GenericSchema<EnumSchemaInput<T>, EnumSchemaOutput<T>>;
|
|
11
11
|
export declare function safeEnum<T extends Record<string, GenericSchema<any>>>(options: T): EnumSchema<T>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const WowAddress: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").TransformAction<string, string>, import("valibot").CheckAction<string, undefined>]>;
|
|
13
13
|
export declare const ObjectID: import("valibot").SchemaWithPipe<readonly [import("valibot").StringSchema<undefined>, import("valibot").TransformAction<string, string>, import("valibot").CheckAction<string, undefined>]>;
|
|
14
14
|
export declare const BCSBytes: import("valibot").StringSchema<undefined>;
|
|
15
15
|
export declare const JsonU64: import("valibot").SchemaWithPipe<readonly [import("valibot").UnionSchema<[import("valibot").StringSchema<undefined>, import("valibot").SchemaWithPipe<readonly [import("valibot").NumberSchema<undefined>, import("valibot").IntegerAction<number, undefined>]>], undefined>, import("valibot").CheckAction<string | number, "Invalid u64">]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{array,boolean,check,integer,lazy,literal,nullable,nullish,number,object,optional,pipe,record,string,transform,tuple,union,unknown}from'valibot';import{isValidWowAddress,normalizeWowAddress}from'../../utils/
|
|
1
|
+
import{array,boolean,check,integer,lazy,literal,nullable,nullish,number,object,optional,pipe,record,string,transform,tuple,union,unknown}from'valibot';import{isValidWowAddress,normalizeWowAddress}from'../../utils/wow-types.js';export function safeEnum(a){const b=Object['entries'](a)['map'](([c,d])=>object({[c]:d}));return pipe(union(b),transform(c=>({...c,'$kind':Object['keys'](c)[0x0]})));}export const WowAddress=pipe(string(),transform(a=>normalizeWowAddress(a)),check(isValidWowAddress));export const ObjectID=WowAddress;export const BCSBytes=string();export const JsonU64=pipe(union([string(),pipe(number(),integer())]),check(a=>{try{return BigInt(a),BigInt(a)>=0x0&&BigInt(a)<=0xffffffffffffffffn;}catch{return![];}},'Invalid\x20u64'));export const ObjectRefSchema=object({'objectId':WowAddress,'version':JsonU64,'digest':string()});export const ArgumentSchema=pipe(union([object({'GasCoin':literal(!![])}),object({'Input':pipe(number(),integer()),'type':optional(literal('pure'))}),object({'Input':pipe(number(),integer()),'type':optional(literal('object'))}),object({'Result':pipe(number(),integer())}),object({'NestedResult':tuple([pipe(number(),integer()),pipe(number(),integer())])})]),transform(a=>({...a,'$kind':Object['keys'](a)[0x0]})));export const GasDataSchema=object({'budget':nullable(JsonU64),'price':nullable(JsonU64),'owner':nullable(WowAddress),'payment':nullable(array(ObjectRefSchema))});export const StructTagSchema=object({'address':string(),'module':string(),'name':string(),'typeParams':array(string())});export const OpenMoveTypeSignatureBodySchema=union([literal('address'),literal('bool'),literal('u8'),literal('u16'),literal('u32'),literal('u64'),literal('u128'),literal('u256'),object({'vector':lazy(()=>OpenMoveTypeSignatureBodySchema)}),object({'datatype':object({'package':string(),'module':string(),'type':string(),'typeParameters':array(lazy(()=>OpenMoveTypeSignatureBodySchema))})}),object({'typeParameter':pipe(number(),integer())})]);export const OpenMoveTypeSignatureSchema=object({'ref':nullable(union([literal('&'),literal('&mut')])),'body':OpenMoveTypeSignatureBodySchema});const ProgrammableMoveCallSchema=object({'package':ObjectID,'module':string(),'function':string(),'typeArguments':array(string()),'arguments':array(ArgumentSchema),'_argumentTypes':optional(nullable(array(OpenMoveTypeSignatureSchema)))});export const $Intent=object({'name':string(),'inputs':record(string(),union([ArgumentSchema,array(ArgumentSchema)])),'data':record(string(),unknown())});export const CommandSchema=safeEnum({'MoveCall':ProgrammableMoveCallSchema,'TransferObjects':object({'objects':array(ArgumentSchema),'address':ArgumentSchema}),'SplitCoins':object({'coin':ArgumentSchema,'amounts':array(ArgumentSchema)}),'MergeCoins':object({'destination':ArgumentSchema,'sources':array(ArgumentSchema)}),'Publish':object({'modules':array(BCSBytes),'dependencies':array(ObjectID)}),'MakeMoveVec':object({'type':nullable(string()),'elements':array(ArgumentSchema)}),'Upgrade':object({'modules':array(BCSBytes),'dependencies':array(ObjectID),'package':ObjectID,'ticket':ArgumentSchema}),'$Intent':$Intent});export const ObjectArgSchema=safeEnum({'ImmOrOwnedObject':ObjectRefSchema,'SharedObject':object({'objectId':ObjectID,'initialSharedVersion':JsonU64,'mutable':boolean()}),'Receiving':ObjectRefSchema});const CallArgSchema=safeEnum({'Object':ObjectArgSchema,'Pure':object({'bytes':BCSBytes}),'UnresolvedPure':object({'value':unknown()}),'UnresolvedObject':object({'objectId':ObjectID,'version':optional(nullable(JsonU64)),'digest':optional(nullable(string())),'initialSharedVersion':optional(nullable(JsonU64)),'mutable':optional(nullable(boolean()))})});export const NormalizedCallArg=safeEnum({'Object':ObjectArgSchema,'Pure':object({'bytes':BCSBytes})});export const TransactionExpiration=safeEnum({'None':literal(!![]),'Epoch':JsonU64});export const TransactionDataSchema=object({'version':literal(0x2),'sender':nullish(WowAddress),'expiration':nullish(TransactionExpiration),'gasData':GasDataSchema,'inputs':array(CallArgSchema),'commands':array(CommandSchema)});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{array,boolean,integer,literal,nullable,nullish,number,object,optional,pipe,record,string,tuple,union,unknown}from'valibot';import{BCSBytes,JsonU64,ObjectID,ObjectRefSchema,
|
|
1
|
+
import{array,boolean,integer,literal,nullable,nullish,number,object,optional,pipe,record,string,tuple,union,unknown}from'valibot';import{BCSBytes,JsonU64,ObjectID,ObjectRefSchema,WowAddress}from'./internal.js';function enumUnion(a){return union(Object['entries'](a)['map'](([b,c])=>object({[b]:c})));}const Argument=enumUnion({'GasCoin':literal(!![]),'Input':pipe(number(),integer()),'Result':pipe(number(),integer()),'NestedResult':tuple([pipe(number(),integer()),pipe(number(),integer())])}),GasData=object({'budget':nullable(JsonU64),'price':nullable(JsonU64),'owner':nullable(WowAddress),'payment':nullable(array(ObjectRefSchema))}),ProgrammableMoveCall=object({'package':ObjectID,'module':string(),'function':string(),'typeArguments':array(string()),'arguments':array(Argument)}),$Intent=object({'name':string(),'inputs':record(string(),union([Argument,array(Argument)])),'data':record(string(),unknown())}),Command=enumUnion({'MoveCall':ProgrammableMoveCall,'TransferObjects':object({'objects':array(Argument),'address':Argument}),'SplitCoins':object({'coin':Argument,'amounts':array(Argument)}),'MergeCoins':object({'destination':Argument,'sources':array(Argument)}),'Publish':object({'modules':array(BCSBytes),'dependencies':array(ObjectID)}),'MakeMoveVec':object({'type':nullable(string()),'elements':array(Argument)}),'Upgrade':object({'modules':array(BCSBytes),'dependencies':array(ObjectID),'package':ObjectID,'ticket':Argument}),'$Intent':$Intent}),ObjectArg=enumUnion({'ImmOrOwnedObject':ObjectRefSchema,'SharedObject':object({'objectId':ObjectID,'initialSharedVersion':JsonU64,'mutable':boolean()}),'Receiving':ObjectRefSchema}),CallArg=enumUnion({'Object':ObjectArg,'Pure':object({'bytes':BCSBytes}),'UnresolvedPure':object({'value':unknown()}),'UnresolvedObject':object({'objectId':ObjectID,'version':optional(nullable(JsonU64)),'digest':optional(nullable(string())),'initialSharedVersion':optional(nullable(JsonU64)),'mutable':optional(nullable(boolean()))})}),TransactionExpiration=enumUnion({'None':literal(!![]),'Epoch':JsonU64});export const SerializedTransactionDataV2Schema=object({'version':literal(0x2),'sender':nullish(WowAddress),'expiration':nullish(TransactionExpiration),'gasData':GasData,'inputs':array(CallArg),'commands':array(Command),'digest':optional(nullable(string()))});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs } from "../../bcs/index.js";
|
|
2
|
-
import type { ExecuteTransactionBlockParams,
|
|
2
|
+
import type { ExecuteTransactionBlockParams, WowClient } from "../../client/index.js";
|
|
3
3
|
import type { Signer } from "../../cryptography/keypair.js";
|
|
4
4
|
import type { BuildTransactionOptions } from "../resolve.js";
|
|
5
5
|
import type { ObjectCacheOptions } from "../ObjectCache.js";
|
|
@@ -9,7 +9,7 @@ export declare class CachingTransactionExecutor {
|
|
|
9
9
|
#private;
|
|
10
10
|
cache: ObjectCache;
|
|
11
11
|
constructor({ client, ...options }: ObjectCacheOptions & {
|
|
12
|
-
client:
|
|
12
|
+
client: WowClient;
|
|
13
13
|
});
|
|
14
14
|
reset(): Promise<void>;
|
|
15
15
|
buildTransaction({ transaction, ...options }: {
|
|
@@ -17,11 +17,11 @@ export declare class CachingTransactionExecutor {
|
|
|
17
17
|
} & BuildTransactionOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
18
18
|
executeTransaction({ transaction, options, ...input }: {
|
|
19
19
|
transaction: Transaction | Uint8Array;
|
|
20
|
-
} & Omit<ExecuteTransactionBlockParams, "transactionBlock">): Promise<import("../../index.js").
|
|
20
|
+
} & Omit<ExecuteTransactionBlockParams, "transactionBlock">): Promise<import("../../index.js").WowTransactionBlockResponse>;
|
|
21
21
|
signAndExecuteTransaction({ options, transaction, ...input }: {
|
|
22
22
|
transaction: Transaction;
|
|
23
23
|
signer: Signer;
|
|
24
|
-
} & Omit<ExecuteTransactionBlockParams, "transactionBlock" | "signature">): Promise<import("../../index.js").
|
|
24
|
+
} & Omit<ExecuteTransactionBlockParams, "transactionBlock" | "signature">): Promise<import("../../index.js").WowTransactionBlockResponse>;
|
|
25
25
|
applyEffects(effects: typeof bcs.TransactionEffects.$inferType): Promise<void>;
|
|
26
26
|
waitForLastTransaction(): Promise<void>;
|
|
27
27
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WowClient, WowTransactionBlockResponse, WowTransactionBlockResponseOptions } from "../../client/index.js";
|
|
2
2
|
import type { Signer } from "../../cryptography/index.js";
|
|
3
3
|
import type { ObjectCacheOptions } from "../ObjectCache.js";
|
|
4
4
|
import { Transaction } from "../Transaction.js";
|
|
5
5
|
export interface ParallelTransactionExecutorOptions extends Omit<ObjectCacheOptions, "address"> {
|
|
6
|
-
client:
|
|
6
|
+
client: WowClient;
|
|
7
7
|
signer: Signer;
|
|
8
8
|
coinBatchSize?: number;
|
|
9
9
|
initialCoinBalance?: bigint;
|
|
@@ -18,9 +18,9 @@ export declare class ParallelTransactionExecutor {
|
|
|
18
18
|
constructor(options: ParallelTransactionExecutorOptions);
|
|
19
19
|
resetCache(): Promise<void>;
|
|
20
20
|
waitForLastTransaction(): Promise<void>;
|
|
21
|
-
executeTransaction(transaction: Transaction, options?:
|
|
21
|
+
executeTransaction(transaction: Transaction, options?: WowTransactionBlockResponseOptions, additionalSignatures?: string[]): Promise<{
|
|
22
22
|
digest: string;
|
|
23
23
|
effects: string;
|
|
24
|
-
data:
|
|
24
|
+
data: WowTransactionBlockResponse;
|
|
25
25
|
}>;
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toBase64}from'../../_deps/bcs/index.js';import{promiseWithResolvers}from'../../_deps/utils/index.js';import{bcs}from'../../bcs/index.js';import{Transaction}from'../Transaction.js';import{TransactionDataBuilder}from'../TransactionData.js';import{CachingTransactionExecutor}from'./caching.js';import{ParallelQueue,SerialQueue}from'./queue.js';import{getGasCoinFromEffects}from'./serial.js';const PARALLEL_EXECUTOR_DEFAULTS={'coinBatchSize':0x14,'initialCoinBalance':0xbebc200n,'minimumCoinBalance':0x2faf080n,'maxPoolSize':0x32,'epochBoundaryWindow':0x3e8};export class ParallelTransactionExecutor{#signer;#client;#coinBatchSize;#initialCoinBalance;#minimumCoinBalance;#epochBoundaryWindow;#defaultGasBudget;#maxPoolSize;#sourceCoins;#coinPool=[];#cache;#objectIdQueues=new Map();#buildQueue=new SerialQueue();#executeQueue;#lastDigest=null;#cacheLock=null;#pendingTransactions=0x0;#gasPrice=null;constructor(a){this.#signer=a['signer'],this.#client=a['client'],this.#coinBatchSize=a['coinBatchSize']??PARALLEL_EXECUTOR_DEFAULTS['coinBatchSize'],this.#initialCoinBalance=a['initialCoinBalance']??PARALLEL_EXECUTOR_DEFAULTS['initialCoinBalance'],this.#minimumCoinBalance=a['minimumCoinBalance']??PARALLEL_EXECUTOR_DEFAULTS['minimumCoinBalance'],this.#defaultGasBudget=a['defaultGasBudget']??this.#minimumCoinBalance,this.#epochBoundaryWindow=a['epochBoundaryWindow']??PARALLEL_EXECUTOR_DEFAULTS['epochBoundaryWindow'],this.#maxPoolSize=a['maxPoolSize']??PARALLEL_EXECUTOR_DEFAULTS['maxPoolSize'],this.#cache=new CachingTransactionExecutor({'client':a['client'],'cache':a['cache']}),this.#executeQueue=new ParallelQueue(this.#maxPoolSize),this.#sourceCoins=a['sourceCoins']?new Map(a['sourceCoins']['map'](b=>[b,null])):null;}['resetCache'](){return this.#gasPrice=null,this.#updateCache(()=>this.#cache['reset']());}async['waitForLastTransaction'](){await this.#updateCache(()=>this.#waitForLastDigest());}async['executeTransaction'](a,b,c=[]){const {promise:d,resolve:e,reject:f}=promiseWithResolvers(),g=await this.#getUsedObjects(a),h=()=>{this.#executeQueue['runTask'](()=>{const j=this.#execute(a,g,b,c);return j['then'](e,f);});},i=new Set();return g['forEach'](j=>{const k=this.#objectIdQueues['get'](j);k?(i['add'](j),this.#objectIdQueues['get'](j)['push'](()=>{i['delete'](j),i['size']===0x0&&h();})):this.#objectIdQueues['set'](j,[]);}),i['size']===0x0&&h(),d;}async #getUsedObjects(a){const b=new Set();let c=![];return a['addSerializationPlugin'](async(d,e,f)=>{await f();if(c)return;c=!![],d['inputs']['forEach'](g=>{if(g['Object']?.['ImmOrOwnedObject']?.['objectId'])b['add'](g['Object']['ImmOrOwnedObject']['objectId']);else{if(g['Object']?.['Receiving']?.['objectId'])b['add'](g['Object']['Receiving']['objectId']);else g['UnresolvedObject']?.['objectId']&&!g['UnresolvedObject']['initialSharedVersion']&&b['add'](g['UnresolvedObject']['objectId']);}});}),await a['prepareForSerialization']({'client':this.#client}),b;}async #execute(a,b,c,d=[]){let e;try{a['setSenderIfNotSet'](this.#signer['toWAddress']()),await this.#buildQueue['runTask'](async()=>{const m=a['getData']();!m['gasData']['price']&&a['setGasPrice'](await this.#getGasPrice()),a['setGasBudgetIfNotSet'](this.#defaultGasBudget),await this.#updateCache(),e=await this.#getGasCoin(),this.#pendingTransactions++,a['setGasPayment']([{'objectId':e['id'],'version':e['version'],'digest':e['digest']}]),await this.#cache['buildTransaction']({'transaction':a,'onlyTransactionKind':!![]});});const f=await a['build']({'client':this.#client}),{signature:g}=await this.#signer['signTransaction'](f),h=await this.#cache['executeTransaction']({'transaction':f,'signature':[g,...d],'options':{...c,'showEffects':!![]}}),i=Uint8Array['from'](h['rawEffects']),j=bcs['TransactionEffects']['parse'](i),k=getGasCoinFromEffects(j),l=j['V2']?.['gasUsed'];if(e&&l&&k['owner']===this.#signer['toWAddress']()){const m=BigInt(l['computationCost'])+BigInt(l['storageCost'])+BigInt(l['storageCost'])-BigInt(l['storageRebate']),n=e['balance']-m;let o=![];new TransactionDataBuilder(a['getData']())['mapArguments'](p=>{return p['$kind']==='GasCoin'&&(o=!![]),p;}),!o&&n>=this.#minimumCoinBalance?this.#coinPool['push']({'id':k['ref']['objectId'],'version':k['ref']['version'],'digest':k['ref']['digest'],'balance':n}):(!this.#sourceCoins&&(this.#sourceCoins=new Map()),this.#sourceCoins['set'](k['ref']['objectId'],k['ref']));}return this.#lastDigest=h['digest'],{'digest':h['digest'],'effects':toBase64(i),'data':h};}catch(p){e&&(!this.#sourceCoins&&(this.#sourceCoins=new Map()),this.#sourceCoins['set'](e['id'],null));await this.#updateCache(async()=>{await Promise['all']([this.#cache['cache']['deleteObjects']([...b]),this.#waitForLastDigest()]);});throw p;}finally{b['forEach'](q=>{const r=this.#objectIdQueues['get'](q);if(r&&r['length']>0x0)r['shift']()();else r&&this.#objectIdQueues['delete'](q);}),this.#pendingTransactions--;}}async #updateCache(a){this.#cacheLock&&await this.#cacheLock,this.#cacheLock=a?.()['then'](()=>{this.#cacheLock=null;},()=>{})??null;}async #waitForLastDigest(){const a=this.#lastDigest;a&&(this.#lastDigest=null,await this.#client['waitForTransaction']({'digest':a}));}async #getGasCoin(){this.#coinPool['length']===0x0&&this.#pendingTransactions<=this.#maxPoolSize&&await this.#refillCoinPool();if(this.#coinPool['length']===0x0)throw new Error('No\x20coins\x20available');const a=this.#coinPool['shift']();return a;}async #getGasPrice(){const a=this.#gasPrice?this.#gasPrice['expiration']-this.#epochBoundaryWindow-Date['now']():0x0;if(a>0x0)return this.#gasPrice['price'];if(this.#gasPrice){const c=Math['max'](this.#gasPrice['expiration']+this.#epochBoundaryWindow-Date['now'](),0x3e8);await new Promise(d=>setTimeout(d,c));}const b=await this.#client['
|
|
1
|
+
import{toBase64}from'../../_deps/bcs/index.js';import{promiseWithResolvers}from'../../_deps/utils/index.js';import{bcs}from'../../bcs/index.js';import{Transaction}from'../Transaction.js';import{TransactionDataBuilder}from'../TransactionData.js';import{CachingTransactionExecutor}from'./caching.js';import{ParallelQueue,SerialQueue}from'./queue.js';import{getGasCoinFromEffects}from'./serial.js';const PARALLEL_EXECUTOR_DEFAULTS={'coinBatchSize':0x14,'initialCoinBalance':0xbebc200n,'minimumCoinBalance':0x2faf080n,'maxPoolSize':0x32,'epochBoundaryWindow':0x3e8};export class ParallelTransactionExecutor{#signer;#client;#coinBatchSize;#initialCoinBalance;#minimumCoinBalance;#epochBoundaryWindow;#defaultGasBudget;#maxPoolSize;#sourceCoins;#coinPool=[];#cache;#objectIdQueues=new Map();#buildQueue=new SerialQueue();#executeQueue;#lastDigest=null;#cacheLock=null;#pendingTransactions=0x0;#gasPrice=null;constructor(a){this.#signer=a['signer'],this.#client=a['client'],this.#coinBatchSize=a['coinBatchSize']??PARALLEL_EXECUTOR_DEFAULTS['coinBatchSize'],this.#initialCoinBalance=a['initialCoinBalance']??PARALLEL_EXECUTOR_DEFAULTS['initialCoinBalance'],this.#minimumCoinBalance=a['minimumCoinBalance']??PARALLEL_EXECUTOR_DEFAULTS['minimumCoinBalance'],this.#defaultGasBudget=a['defaultGasBudget']??this.#minimumCoinBalance,this.#epochBoundaryWindow=a['epochBoundaryWindow']??PARALLEL_EXECUTOR_DEFAULTS['epochBoundaryWindow'],this.#maxPoolSize=a['maxPoolSize']??PARALLEL_EXECUTOR_DEFAULTS['maxPoolSize'],this.#cache=new CachingTransactionExecutor({'client':a['client'],'cache':a['cache']}),this.#executeQueue=new ParallelQueue(this.#maxPoolSize),this.#sourceCoins=a['sourceCoins']?new Map(a['sourceCoins']['map'](b=>[b,null])):null;}['resetCache'](){return this.#gasPrice=null,this.#updateCache(()=>this.#cache['reset']());}async['waitForLastTransaction'](){await this.#updateCache(()=>this.#waitForLastDigest());}async['executeTransaction'](a,b,c=[]){const {promise:d,resolve:e,reject:f}=promiseWithResolvers(),g=await this.#getUsedObjects(a),h=()=>{this.#executeQueue['runTask'](()=>{const j=this.#execute(a,g,b,c);return j['then'](e,f);});},i=new Set();return g['forEach'](j=>{const k=this.#objectIdQueues['get'](j);k?(i['add'](j),this.#objectIdQueues['get'](j)['push'](()=>{i['delete'](j),i['size']===0x0&&h();})):this.#objectIdQueues['set'](j,[]);}),i['size']===0x0&&h(),d;}async #getUsedObjects(a){const b=new Set();let c=![];return a['addSerializationPlugin'](async(d,e,f)=>{await f();if(c)return;c=!![],d['inputs']['forEach'](g=>{if(g['Object']?.['ImmOrOwnedObject']?.['objectId'])b['add'](g['Object']['ImmOrOwnedObject']['objectId']);else{if(g['Object']?.['Receiving']?.['objectId'])b['add'](g['Object']['Receiving']['objectId']);else g['UnresolvedObject']?.['objectId']&&!g['UnresolvedObject']['initialSharedVersion']&&b['add'](g['UnresolvedObject']['objectId']);}});}),await a['prepareForSerialization']({'client':this.#client}),b;}async #execute(a,b,c,d=[]){let e;try{a['setSenderIfNotSet'](this.#signer['toWAddress']()),await this.#buildQueue['runTask'](async()=>{const m=a['getData']();!m['gasData']['price']&&a['setGasPrice'](await this.#getGasPrice()),a['setGasBudgetIfNotSet'](this.#defaultGasBudget),await this.#updateCache(),e=await this.#getGasCoin(),this.#pendingTransactions++,a['setGasPayment']([{'objectId':e['id'],'version':e['version'],'digest':e['digest']}]),await this.#cache['buildTransaction']({'transaction':a,'onlyTransactionKind':!![]});});const f=await a['build']({'client':this.#client}),{signature:g}=await this.#signer['signTransaction'](f),h=await this.#cache['executeTransaction']({'transaction':f,'signature':[g,...d],'options':{...c,'showEffects':!![]}}),i=Uint8Array['from'](h['rawEffects']),j=bcs['TransactionEffects']['parse'](i),k=getGasCoinFromEffects(j),l=j['V2']?.['gasUsed'];if(e&&l&&k['owner']===this.#signer['toWAddress']()){const m=BigInt(l['computationCost'])+BigInt(l['storageCost'])+BigInt(l['storageCost'])-BigInt(l['storageRebate']),n=e['balance']-m;let o=![];new TransactionDataBuilder(a['getData']())['mapArguments'](p=>{return p['$kind']==='GasCoin'&&(o=!![]),p;}),!o&&n>=this.#minimumCoinBalance?this.#coinPool['push']({'id':k['ref']['objectId'],'version':k['ref']['version'],'digest':k['ref']['digest'],'balance':n}):(!this.#sourceCoins&&(this.#sourceCoins=new Map()),this.#sourceCoins['set'](k['ref']['objectId'],k['ref']));}return this.#lastDigest=h['digest'],{'digest':h['digest'],'effects':toBase64(i),'data':h};}catch(p){e&&(!this.#sourceCoins&&(this.#sourceCoins=new Map()),this.#sourceCoins['set'](e['id'],null));await this.#updateCache(async()=>{await Promise['all']([this.#cache['cache']['deleteObjects']([...b]),this.#waitForLastDigest()]);});throw p;}finally{b['forEach'](q=>{const r=this.#objectIdQueues['get'](q);if(r&&r['length']>0x0)r['shift']()();else r&&this.#objectIdQueues['delete'](q);}),this.#pendingTransactions--;}}async #updateCache(a){this.#cacheLock&&await this.#cacheLock,this.#cacheLock=a?.()['then'](()=>{this.#cacheLock=null;},()=>{})??null;}async #waitForLastDigest(){const a=this.#lastDigest;a&&(this.#lastDigest=null,await this.#client['waitForTransaction']({'digest':a}));}async #getGasCoin(){this.#coinPool['length']===0x0&&this.#pendingTransactions<=this.#maxPoolSize&&await this.#refillCoinPool();if(this.#coinPool['length']===0x0)throw new Error('No\x20coins\x20available');const a=this.#coinPool['shift']();return a;}async #getGasPrice(){const a=this.#gasPrice?this.#gasPrice['expiration']-this.#epochBoundaryWindow-Date['now']():0x0;if(a>0x0)return this.#gasPrice['price'];if(this.#gasPrice){const c=Math['max'](this.#gasPrice['expiration']+this.#epochBoundaryWindow-Date['now'](),0x3e8);await new Promise(d=>setTimeout(d,c));}const b=await this.#client['getLatestWowSystemState']();return this.#gasPrice={'price':BigInt(b['referenceGasPrice']),'expiration':Number['parseInt'](b['epochStartTimestampMs'],0xa)+Number['parseInt'](b['epochDurationMs'],0xa)},this.#getGasPrice();}async #refillCoinPool(){const a=Math['min'](this.#coinBatchSize,this.#maxPoolSize-(this.#coinPool['length']+this.#pendingTransactions)+0x1);if(a===0x0)return;const b=new Transaction(),c=this.#signer['toWAddress']();b['setSender'](c);if(this.#sourceCoins){const k=[],l=[];for(const [m,n]of this.#sourceCoins){n?k['push'](n):l['push'](m);}if(l['length']>0x0){const o=await this.#client['multiGetObjects']({'ids':l});k['push'](...o['filter'](p=>p['data']!==null)['map'](({data:p})=>({'objectId':p['objectId'],'version':p['version'],'digest':p['digest']})));}b['setGasPayment'](k),this.#sourceCoins=new Map();}const d=new Array(a)['fill'](this.#initialCoinBalance),e=b['splitCoins'](b['gas'],d),f=[];for(let p=0x0;p<d['length'];p++){f['push'](e[p]);}b['transferObjects'](f,c),await this['waitForLastTransaction']();const g=await this.#client['signAndExecuteTransaction']({'transaction':b,'signer':this.#signer,'options':{'showRawEffects':!![]}}),h=bcs['TransactionEffects']['parse'](Uint8Array['from'](g['rawEffects']));h['V2']?.['changedObjects']['forEach'](([q,{outputState:r}],s)=>{if(s===h['V2']?.['gasObjectIndex']||!r['ObjectWrite'])return;this.#coinPool['push']({'id':q,'version':h['V2']['lamportVersion'],'digest':r['ObjectWrite'][0x0],'balance':BigInt(this.#initialCoinBalance)});});!this.#sourceCoins&&(this.#sourceCoins=new Map());const j=getGasCoinFromEffects(h)['ref'];this.#sourceCoins['set'](j['objectId'],j),await this.#client['waitForTransaction']({'digest':g['digest']});}}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { bcs } from "../../bcs/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { WowClient, WowTransactionBlockResponseOptions } from "../../client/index.js";
|
|
3
3
|
import type { Signer } from "../../cryptography/keypair.js";
|
|
4
4
|
import type { ObjectCacheOptions } from "../ObjectCache.js";
|
|
5
5
|
import { Transaction } from "../Transaction.js";
|
|
6
6
|
export declare class SerialTransactionExecutor {
|
|
7
7
|
#private;
|
|
8
8
|
constructor({ signer, defaultGasBudget, ...options }: Omit<ObjectCacheOptions, "address"> & {
|
|
9
|
-
client:
|
|
9
|
+
client: WowClient;
|
|
10
10
|
signer: Signer;
|
|
11
11
|
defaultGasBudget?: bigint;
|
|
12
12
|
});
|
|
@@ -14,10 +14,10 @@ export declare class SerialTransactionExecutor {
|
|
|
14
14
|
buildTransaction(transaction: Transaction): Promise<Uint8Array<ArrayBuffer>>;
|
|
15
15
|
resetCache(): Promise<void>;
|
|
16
16
|
waitForLastTransaction(): Promise<void>;
|
|
17
|
-
executeTransaction(transaction: Transaction | Uint8Array, options?:
|
|
17
|
+
executeTransaction(transaction: Transaction | Uint8Array, options?: WowTransactionBlockResponseOptions, additionalSignatures?: string[]): Promise<{
|
|
18
18
|
digest: string;
|
|
19
19
|
effects: string;
|
|
20
|
-
data: import("../../index.js").
|
|
20
|
+
data: import("../../index.js").WowTransactionBlockResponse;
|
|
21
21
|
}>;
|
|
22
22
|
}
|
|
23
23
|
export declare function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType): {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WowClient } from "../../client/index.js";
|
|
2
2
|
import type { BuildTransactionOptions } from "../resolve.js";
|
|
3
3
|
import type { Transaction, TransactionResult } from "../Transaction.js";
|
|
4
4
|
export declare function coinWithBalance({ type, balance, useGasCoin, }: {
|
|
@@ -6,4 +6,4 @@ export declare function coinWithBalance({ type, balance, useGasCoin, }: {
|
|
|
6
6
|
type?: string;
|
|
7
7
|
useGasCoin?: boolean;
|
|
8
8
|
}): (tx: Transaction) => TransactionResult;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function getWowClient(options: BuildTransactionOptions): WowClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bigint,object,parse,string}from'valibot';import{bcs}from'../../bcs/index.js';import{normalizeStructTag}from'../../utils/
|
|
1
|
+
import{bigint,object,parse,string}from'valibot';import{bcs}from'../../bcs/index.js';import{normalizeStructTag}from'../../utils/wow-types.js';import{Commands}from'../Commands.js';import{Inputs}from'../Inputs.js';import{getClient}from'../resolve.js';const COIN_WITH_BALANCE='CoinWithBalance',WOW_TYPE=normalizeStructTag('0x2::wow::WOW');export function coinWithBalance({type:type=WOW_TYPE,balance:a,useGasCoin:useGasCoin=!![]}){let b=null;return c=>{if(b)return b;c['addIntentResolver'](COIN_WITH_BALANCE,resolveCoinBalance);const d=type==='gas'?type:normalizeStructTag(type);return b=c['add'](Commands['Intent']({'name':COIN_WITH_BALANCE,'inputs':{},'data':{'type':d===WOW_TYPE&&useGasCoin?'gas':d,'balance':BigInt(a)}})),b;};}const CoinWithBalanceData=object({'type':string(),'balance':bigint()});async function resolveCoinBalance(a,b,c){const d=new Set(),e=new Map();if(!a['sender'])throw new Error('Sender\x20must\x20be\x20set\x20to\x20resolve\x20CoinWithBalance');for(const j of a['commands']){if(j['$kind']==='$Intent'&&j['$Intent']['name']===COIN_WITH_BALANCE){const {type:k,balance:l}=parse(CoinWithBalanceData,j['$Intent']['data']);k!=='gas'&&l>0x0n&&d['add'](k),e['set'](k,(e['get'](k)??0x0n)+l);}}const f=new Set();for(const m of a['inputs']){m['Object']?.['ImmOrOwnedObject']&&f['add'](m['Object']['ImmOrOwnedObject']['objectId']),m['UnresolvedObject']?.['objectId']&&f['add'](m['UnresolvedObject']['objectId']);}const g=new Map(),h=getWowClient(b);await Promise['all']([...d]['map'](async n=>{g['set'](n,await getCoinsOfType({'coinType':n,'balance':e['get'](n),'client':h,'owner':a['sender'],'usedIds':f}));}));const i=new Map();i['set']('gas',{'$kind':'GasCoin','GasCoin':!![]});for(const [n,o]of a['commands']['entries']()){if(o['$kind']!=='$Intent'||o['$Intent']['name']!==COIN_WITH_BALANCE)continue;const {type:p,balance:q}=o['$Intent']['data'];if(q===0x0n&&p!=='gas'){a['replaceCommand'](n,Commands['MoveCall']({'target':'0x2::coin::zero','typeArguments':[p]}));continue;}const r=[];if(!i['has'](p)){const [s,...t]=g['get'](p)['map'](u=>a['addInput']('object',Inputs['ObjectRef']({'objectId':u['coinObjectId'],'digest':u['digest'],'version':u['version']})));t['length']>0x0&&r['push'](Commands['MergeCoins'](s,t)),i['set'](p,s);}r['push'](Commands['SplitCoins'](i['get'](p),[a['addInput']('pure',Inputs['Pure'](bcs['u64']()['serialize'](q)))])),a['replaceCommand'](n,r),a['mapArguments'](u=>{if(u['$kind']==='Result'&&u['Result']===n)return{'$kind':'NestedResult','NestedResult':[n+r['length']-0x1,0x0]};return u;});}return c();}async function getCoinsOfType({coinType:a,balance:b,client:c,owner:d,usedIds:e}){let f=b;const g=[];return h();async function h(i=null){const {data:j,hasNextPage:k,nextCursor:l}=await c['getCoins']({'owner':d,'coinType':a,'cursor':i}),m=j['sort']((n,o)=>Number(BigInt(o['balance'])-BigInt(n['balance'])));for(const n of m){if(e['has'](n['coinObjectId']))continue;const o=BigInt(n['balance']);g['push'](n),f-=o;if(f<=0x0)return g;}if(k)return h(l);throw new Error('Not\x20enough\x20coins\x20of\x20type\x20'+a+'\x20to\x20satisfy\x20requested\x20balance');}}export function getWowClient(a){const b=getClient(a);if(!b['jsonRpc'])throw new Error('CoinWithBalance\x20intent\x20currently\x20only\x20works\x20with\x20WowClient');return b;}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BcsType } from "../_deps/bcs/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { WowMoveNormalizedType } from "../client/index.js";
|
|
3
3
|
import type { OpenMoveTypeSignature, OpenMoveTypeSignatureBody } from "./data/internal.js";
|
|
4
4
|
export declare function isTxContext(param: OpenMoveTypeSignature): boolean;
|
|
5
5
|
export declare function getPureBcsSchema(typeSignature: OpenMoveTypeSignatureBody): BcsType<any> | null;
|
|
6
|
-
export declare function normalizedTypeToMoveTypeSignature(type:
|
|
6
|
+
export declare function normalizedTypeToMoveTypeSignature(type: WowMoveNormalizedType): OpenMoveTypeSignature;
|
|
7
7
|
export declare function pureBcsSchemaFromOpenMoveTypeSignatureBody(typeSignature: OpenMoveTypeSignatureBody): BcsType<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bcs}from'../bcs/index.js';import{MOVE_STDLIB_ADDRESS,WOW_FRAMEWORK_ADDRESS}from'../utils/index.js';import{normalizeWowAddress}from'../utils/
|
|
1
|
+
import{bcs}from'../bcs/index.js';import{MOVE_STDLIB_ADDRESS,WOW_FRAMEWORK_ADDRESS}from'../utils/index.js';import{normalizeWowAddress}from'../utils/wow-types.js';const OBJECT_MODULE_NAME='object',ID_STRUCT_NAME='ID',STD_ASCII_MODULE_NAME='ascii',STD_ASCII_STRUCT_NAME='String',STD_UTF8_MODULE_NAME='string',STD_UTF8_STRUCT_NAME='String',STD_OPTION_MODULE_NAME='option',STD_OPTION_STRUCT_NAME='Option';export function isTxContext(a){const b=typeof a['body']==='object'&&'datatype'in a['body']?a['body']['datatype']:null;return!!b&&normalizeWowAddress(b['package'])===normalizeWowAddress('0x2')&&b['module']==='tx_context'&&b['type']==='TxContext';}export function getPureBcsSchema(a){if(typeof a==='string')switch(a){case'address':return bcs['Address'];case'bool':return bcs['Bool'];case'u8':return bcs['U8'];case'u16':return bcs['U16'];case'u32':return bcs['U32'];case'u64':return bcs['U64'];case'u128':return bcs['U128'];case'u256':return bcs['U256'];default:throw new Error('Unknown\x20type\x20signature\x20'+a);}if('vector'in a){if(a['vector']==='u8')return bcs['byteVector']()['transform']({'input':c=>typeof c==='string'?new TextEncoder()['encode'](c):c,'output':c=>c});const b=getPureBcsSchema(a['vector']);return b?bcs['vector'](b):null;}if('datatype'in a){const c=normalizeWowAddress(a['datatype']['package']);if(c===normalizeWowAddress(MOVE_STDLIB_ADDRESS)){if(a['datatype']['module']===STD_ASCII_MODULE_NAME&&a['datatype']['type']===STD_ASCII_STRUCT_NAME)return bcs['String'];if(a['datatype']['module']===STD_UTF8_MODULE_NAME&&a['datatype']['type']===STD_UTF8_STRUCT_NAME)return bcs['String'];if(a['datatype']['module']===STD_OPTION_MODULE_NAME&&a['datatype']['type']===STD_OPTION_STRUCT_NAME){const d=getPureBcsSchema(a['datatype']['typeParameters'][0x0]);return d?bcs['vector'](d):null;}}if(c===normalizeWowAddress(WOW_FRAMEWORK_ADDRESS)&&a['datatype']['module']===OBJECT_MODULE_NAME&&a['datatype']['type']===ID_STRUCT_NAME)return bcs['Address'];}return null;}export function normalizedTypeToMoveTypeSignature(a){if(typeof a==='object'&&'Reference'in a)return{'ref':'&','body':normalizedTypeToMoveTypeSignatureBody(a['Reference'])};if(typeof a==='object'&&'MutableReference'in a)return{'ref':'&mut','body':normalizedTypeToMoveTypeSignatureBody(a['MutableReference'])};return{'ref':null,'body':normalizedTypeToMoveTypeSignatureBody(a)};}function normalizedTypeToMoveTypeSignatureBody(a){if(typeof a==='string')switch(a){case'Address':return'address';case'Bool':return'bool';case'U8':return'u8';case'U16':return'u16';case'U32':return'u32';case'U64':return'u64';case'U128':return'u128';case'U256':return'u256';default:throw new Error('Unexpected\x20type\x20'+a);}if('Vector'in a)return{'vector':normalizedTypeToMoveTypeSignatureBody(a['Vector'])};if('Struct'in a)return{'datatype':{'package':a['Struct']['address'],'module':a['Struct']['module'],'type':a['Struct']['name'],'typeParameters':a['Struct']['typeArguments']['map'](normalizedTypeToMoveTypeSignatureBody)}};if('TypeParameter'in a)return{'typeParameter':a['TypeParameter']};throw new Error('Unexpected\x20type\x20'+JSON['stringify'](a));}export function pureBcsSchemaFromOpenMoveTypeSignatureBody(a){if(typeof a==='string')switch(a){case'address':return bcs['Address'];case'bool':return bcs['Bool'];case'u8':return bcs['U8'];case'u16':return bcs['U16'];case'u32':return bcs['U32'];case'u64':return bcs['U64'];case'u128':return bcs['U128'];case'u256':return bcs['U256'];default:throw new Error('Unknown\x20type\x20signature\x20'+a);}if('vector'in a)return bcs['vector'](pureBcsSchemaFromOpenMoveTypeSignatureBody(a['vector']));throw new Error('Expected\x20pure\x20typeSignature,\x20but\x20got\x20'+JSON['stringify'](a));}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WowMoveNormalizedType } from "../client/index.js";
|
|
2
2
|
import type { Argument, CallArg, Command } from "./data/internal.js";
|
|
3
|
-
export declare function extractMutableReference(normalizedType:
|
|
4
|
-
export declare function extractReference(normalizedType:
|
|
5
|
-
export declare function extractStructTag(normalizedType:
|
|
3
|
+
export declare function extractMutableReference(normalizedType: WowMoveNormalizedType): WowMoveNormalizedType | undefined;
|
|
4
|
+
export declare function extractReference(normalizedType: WowMoveNormalizedType): WowMoveNormalizedType | undefined;
|
|
5
|
+
export declare function extractStructTag(normalizedType: WowMoveNormalizedType): Extract<WowMoveNormalizedType, {
|
|
6
6
|
Struct: unknown;
|
|
7
7
|
}> | undefined;
|
|
8
8
|
export declare function getIdFromCallArg(arg: string | CallArg): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{is}from'valibot';import{normalizeWowAddress}from'../utils/
|
|
1
|
+
import{is}from'valibot';import{normalizeWowAddress}from'../utils/wow-types.js';import{ArgumentSchema}from'./data/internal.js';export function extractMutableReference(a){return typeof a==='object'&&'MutableReference'in a?a['MutableReference']:undefined;}export function extractReference(a){return typeof a==='object'&&'Reference'in a?a['Reference']:undefined;}export function extractStructTag(a){if(typeof a==='object'&&'Struct'in a)return a;const b=extractReference(a),c=extractMutableReference(a);if(typeof b==='object'&&'Struct'in b)return b;if(typeof c==='object'&&'Struct'in c)return c;return undefined;}export function getIdFromCallArg(a){if(typeof a==='string')return normalizeWowAddress(a);if(a['Object']){if(a['Object']['ImmOrOwnedObject'])return normalizeWowAddress(a['Object']['ImmOrOwnedObject']['objectId']);if(a['Object']['Receiving'])return normalizeWowAddress(a['Object']['Receiving']['objectId']);return normalizeWowAddress(a['Object']['SharedObject']['objectId']);}if(a['UnresolvedObject'])return normalizeWowAddress(a['UnresolvedObject']['objectId']);return undefined;}export function isArgument(a){return is(ArgumentSchema,a);}export function remapCommandArguments(a,b,c){const d=e=>{switch(e['$kind']){case'Input':{const f=b['get'](e['Input']);if(f===undefined)throw new Error('Input\x20'+e['Input']+'\x20not\x20found\x20in\x20input\x20mapping');return{...e,'Input':f};}case'Result':{const g=c['get'](e['Result']);if(g!==undefined)return{...e,'Result':g};return e;}case'NestedResult':{const h=c['get'](e['NestedResult'][0x0]);if(h!==undefined)return{...e,'NestedResult':[h,e['NestedResult'][0x1]]};return e;}default:return e;}};switch(a['$kind']){case'MoveCall':a['MoveCall']['arguments']=a['MoveCall']['arguments']['map'](d);break;case'TransferObjects':a['TransferObjects']['objects']=a['TransferObjects']['objects']['map'](d),a['TransferObjects']['address']=d(a['TransferObjects']['address']);break;case'SplitCoins':a['SplitCoins']['coin']=d(a['SplitCoins']['coin']),a['SplitCoins']['amounts']=a['SplitCoins']['amounts']['map'](d);break;case'MergeCoins':a['MergeCoins']['destination']=d(a['MergeCoins']['destination']),a['MergeCoins']['sources']=a['MergeCoins']['sources']['map'](d);break;case'MakeMoveVec':a['MakeMoveVec']['elements']=a['MakeMoveVec']['elements']['map'](d);break;case'Upgrade':a['Upgrade']['ticket']=d(a['Upgrade']['ticket']);break;case'$Intent':{const e=a['$Intent']['inputs'];a['$Intent']['inputs']={};for(const [f,g]of Object['entries'](e)){a['$Intent']['inputs'][f]=Array['isArray'](g)?g['map'](d):d(g);}break;}case'Publish':break;}}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export declare const SUI_DECIMALS = 9;
|
|
2
|
-
export declare const MIST_PER_SUI: bigint;
|
|
3
|
-
export declare const SUI_FRAMEWORK_ADDRESS = "0x2";
|
|
4
|
-
export declare const SUI_SYSTEM_ADDRESS = "0x3";
|
|
5
|
-
export declare const SUI_SYSTEM_MODULE_NAME = "sui_system";
|
|
6
|
-
export declare const SUI_TYPE_ARG = "0x2::sui::SUI";
|
|
7
1
|
export declare const WOW_DECIMALS = 9;
|
|
8
2
|
export declare const MIST_PER_WOW: bigint;
|
|
9
3
|
export declare const WOW_FRAMEWORK_ADDRESS = "0x2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeWowObjectId}from'./
|
|
1
|
+
import{normalizeWowObjectId}from'./wow-types.js';export const WOW_DECIMALS=0x9;export const MIST_PER_WOW=BigInt(0x3b9aca00);export const WOW_FRAMEWORK_ADDRESS='0x2';export const WOW_SYSTEM_ADDRESS='0x3';export const WOW_ADDRESS='0x4';export const WOW_CLOCK_OBJECT_ID=normalizeWowObjectId('0x6');export const WOW_SYSTEM_MODULE_NAME='wow_system';export const WOW_TYPE_ARG=WOW_FRAMEWORK_ADDRESS+'::wow::WOW';export const WOW_SYSTEM_STATE_OBJECT_ID=normalizeWowObjectId('0x5');export const WOW_RANDOM_OBJECT_ID=normalizeWowObjectId('0x8');export const MOVE_STDLIB_ADDRESS='0x1';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { formatAddress, formatDigest } from "./format.js";
|
|
2
|
-
export { isValidWowAddress, isValidWowObjectId, isValidTransactionDigest, normalizeStructTag, normalizeWowAddress, normalizeWowObjectId, parseStructTag, WOW_ADDRESS_LENGTH, } from "./
|
|
2
|
+
export { isValidWowAddress, isValidWowObjectId, isValidTransactionDigest, normalizeStructTag, normalizeWowAddress, normalizeWowObjectId, parseStructTag, WOW_ADDRESS_LENGTH, } from "./wow-types.js";
|
|
3
3
|
export { fromB64, toB64, fromHEX, toHex, toHEX, fromHex, fromBase64, toBase64, fromBase58, toBase58, } from "../_deps/bcs/index.js";
|
|
4
4
|
export { WOW_DECIMALS, MIST_PER_WOW, MOVE_STDLIB_ADDRESS, WOW_FRAMEWORK_ADDRESS, WOW_SYSTEM_ADDRESS, WOW_CLOCK_OBJECT_ID, WOW_SYSTEM_MODULE_NAME, WOW_TYPE_ARG, WOW_SYSTEM_STATE_OBJECT_ID, WOW_RANDOM_OBJECT_ID, } from "./constants.js";
|
|
5
5
|
export { isValidNamedPackage, isValidNamedType } from "./move-registry.js";
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{formatAddress,formatDigest}from'./format.js';export{isValidWowAddress,isValidWowObjectId,isValidTransactionDigest,normalizeStructTag,normalizeWowAddress,normalizeWowObjectId,parseStructTag,WOW_ADDRESS_LENGTH}from'./
|
|
1
|
+
export{formatAddress,formatDigest}from'./format.js';export{isValidWowAddress,isValidWowObjectId,isValidTransactionDigest,normalizeStructTag,normalizeWowAddress,normalizeWowObjectId,parseStructTag,WOW_ADDRESS_LENGTH}from'./wow-types.js';export{fromB64,toB64,fromHEX,toHex,toHEX,fromHex,fromBase64,toBase64,fromBase58,toBase58}from'../_deps/bcs/index.js';export{WOW_DECIMALS,MIST_PER_WOW,MOVE_STDLIB_ADDRESS,WOW_FRAMEWORK_ADDRESS,WOW_SYSTEM_ADDRESS,WOW_CLOCK_OBJECT_ID,WOW_SYSTEM_MODULE_NAME,WOW_TYPE_ARG,WOW_SYSTEM_STATE_OBJECT_ID,WOW_RANDOM_OBJECT_ID}from'./constants.js';export{isValidNamedPackage,isValidNamedType}from'./move-registry.js';export{deriveDynamicFieldID}from'./dynamic-fields.js';export{deriveObjectID}from'./derived-objects.js';export{normalizeTypeTag}from'../bcs/type-tag-serializer.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { verifySignature, verifyPersonalMessageSignature, verifyTransactionSignature, publicKeyFromRawBytes,
|
|
1
|
+
export { verifySignature, verifyPersonalMessageSignature, verifyTransactionSignature, publicKeyFromRawBytes, publicKeyFromWowBytes, } from "./verify.js";
|
package/dist/esm/verify/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{verifySignature,verifyPersonalMessageSignature,verifyTransactionSignature,publicKeyFromRawBytes,
|
|
1
|
+
export{verifySignature,verifyPersonalMessageSignature,verifyTransactionSignature,publicKeyFromRawBytes,publicKeyFromWowBytes}from'./verify.js';
|
|
@@ -11,6 +11,6 @@ export declare function verifyTransactionSignature(transaction: Uint8Array, sign
|
|
|
11
11
|
export declare function publicKeyFromRawBytes(signatureScheme: SignatureScheme, bytes: Uint8Array, options?: {
|
|
12
12
|
address?: string;
|
|
13
13
|
}): PublicKey;
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function publicKeyFromWowBytes(publicKey: string | Uint8Array, options?: {
|
|
15
15
|
address?: string;
|
|
16
16
|
}): PublicKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fromBase64}from'../_deps/bcs/index.js';import{parseSerializedSignature,SIGNATURE_FLAG_TO_SCHEME}from'../cryptography/index.js';import{Falcon512PublicKey}from'../keypairs/falcon512/publickey.js';export async function verifySignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verify'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20data');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}export async function verifyPersonalMessageSignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verifyPersonalMessage'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20message');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}export async function verifyTransactionSignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verifyTransaction'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20Transaction');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}async function parseSignature(a){const b=parseSerializedSignature(a);if(b['signatureScheme']==='MultiSig'){const {MultiSigPublicKey:d}=await import('../multisig/publickey.js');return{...b,'publicKey':new d(b['multisig']['multisig_pk'])};}const c=publicKeyFromRawBytes(b['signatureScheme'],b['publicKey']);return{...b,'publicKey':c};}export function publicKeyFromRawBytes(a,b,c){let d;switch(a){case'MultiSig':throw new Error('Use\x20parseSignature()\x20for\x20MultiSig\x20public\x20keys');case'Falcon512':d=new Falcon512PublicKey(b);break;default:throw new Error('Unsupported\x20signature\x20scheme\x20'+a);}if(c?.['address']&&!d['verifyAddress'](c['address']))throw new Error('Public\x20key\x20bytes\x20do\x20not\x20match\x20the\x20provided\x20address');return d;}export function
|
|
1
|
+
import{fromBase64}from'../_deps/bcs/index.js';import{parseSerializedSignature,SIGNATURE_FLAG_TO_SCHEME}from'../cryptography/index.js';import{Falcon512PublicKey}from'../keypairs/falcon512/publickey.js';export async function verifySignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verify'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20data');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}export async function verifyPersonalMessageSignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verifyPersonalMessage'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20message');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}export async function verifyTransactionSignature(a,b,c){const d=await parseSignature(b);if(!await d['publicKey']['verifyTransaction'](a,d['serializedSignature']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20Transaction');if(c?.['address']&&!d['publicKey']['verifyAddress'](c['address']))throw new Error('Signature\x20is\x20not\x20valid\x20for\x20the\x20provided\x20address');return d['publicKey'];}async function parseSignature(a){const b=parseSerializedSignature(a);if(b['signatureScheme']==='MultiSig'){const {MultiSigPublicKey:d}=await import('../multisig/publickey.js');return{...b,'publicKey':new d(b['multisig']['multisig_pk'])};}const c=publicKeyFromRawBytes(b['signatureScheme'],b['publicKey']);return{...b,'publicKey':c};}export function publicKeyFromRawBytes(a,b,c){let d;switch(a){case'MultiSig':throw new Error('Use\x20parseSignature()\x20for\x20MultiSig\x20public\x20keys');case'Falcon512':d=new Falcon512PublicKey(b);break;default:throw new Error('Unsupported\x20signature\x20scheme\x20'+a);}if(c?.['address']&&!d['verifyAddress'](c['address']))throw new Error('Public\x20key\x20bytes\x20do\x20not\x20match\x20the\x20provided\x20address');return d;}export function publicKeyFromWowBytes(a,b){const c=typeof a==='string'?fromBase64(a):a,d=SIGNATURE_FLAG_TO_SCHEME[c[0x0]];return publicKeyFromRawBytes(d,c['slice'](0x1),b);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isValidWowAddress}from'../../utils/
|
|
1
|
+
import{isValidWowAddress}from'../../utils/wow-types.js';import{toTxObject,isValidDescription,MAX_DESCRIPTION_LENGTH,PackageAddress,isValidU8,isValidU64,GetObjectExisted,GetObject,IsValidArgType}from'../common.js';import{W_ERROR,WErrors}from'../exception.js';import{GetAccountOrMark_Address,GetManyAccountOrMark_Address}from'../local/index.js';import{LocalMark}from'../local/local.js';import{ObjectType}from'../query/object.js';import{query_received}from'../query/received.js';import{parseObjectType,validObjects}from'../util.js';import{CallBase,getCoinParam}from'./base.js';import{get_guardSubmissions}from'./passport.js';import{paymentInfo}from'./payment.js';export class CallAllocation extends CallBase{['data'];['object_address']=undefined;['type_parameter']=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']));if(this['object_address'])this['content']=undefined,await this['update_content'](a,ObjectType['Allocation'],this['object_address']),!this['content']&&W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data.object:'+this['object_address']),this['type_parameter']=parseObjectType(this['content']['type_raw'],'allocation::Allocation'),!this['type_parameter']&&W_ERROR(WErrors['IsValidArgType'],'CallAllocation_Data.data.object.type_parameter\x20is\x20empty');else{const b=GetObject(this['data']['object']);(!b||!IsValidArgType(b?.['type_parameter']))&&W_ERROR(WErrors['IsValidArgType'],'CallAllocation_Data.data.object.type_parameter\x20is\x20empty'),this['type_parameter']=b?.['type_parameter'];}}async['call'](a){await this['prepare'](a);if('alloc_by_guard'in this['data']&&this['data']['alloc_by_guard']!=null){const b=await LocalMark['Instance']()['get_address'](this['data']['alloc_by_guard']);(!b||!isValidWowAddress(b))&&W_ERROR(WErrors['IsValidAddress'],'alloc_by_guard:\x20'+this['data']['alloc_by_guard']);this['content']&&!this['content']['allocators']['find'](d=>d['guard']===b)&&W_ERROR(WErrors['InvalidParam'],'alloc_by_guard:\x20'+this['data']['alloc_by_guard']+'\x20not\x20found\x20in\x20allocators\x20'+this['content']['allocators']['map'](d=>d['guard']));this['data']['alloc_by_guard']=b;const c=await get_guardSubmissions(a,[this['data']['alloc_by_guard']]);if(c['submission']['length']>0x0)return{'type':'submission','guard':c['guard'],'submission':c['submission']};return await this['check_passport'](a,c);}return await this['exec'](a);}async['operate'](a,b,c){if(this['object_address']){if('received_coins'in this['data']&&this['data']['received_coins']!=null){if(this['data']['received_coins']==='recently'){const d=await query_received({'object':this['object_address'],'network':a['network'],'no_cache':a['no_cache']});Array['isArray'](d)?W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data.received_coins:\x20received\x20is\x20ReceivedNormal[]'):this['data']['received_coins']=d;}if(typeof this['data']['received_coins']==='object'&&'received'in this['data']['received_coins']&&this['data']['received_coins']['received']?.['length']>0x0){this['data']['received_coins']?.['token_type']!==this['type_parameter']&&W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data.received_coins.token_type:'+this['data']['received_coins']?.['token_type']);for(const e of this['data']['received_coins']['received']){(!isValidWowAddress(e['id'])||!isValidWowAddress(e['payment']))&&W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data.received_coins:'+e['id']),receive(b,toTxObject(b,this['object_address']),this['type_parameter'],toTxObject(b,e['id']),toTxObject(b,e['payment']));}}}'alloc_by_guard'in this['data']&&this['data']['alloc_by_guard']!=null&&(!c&&W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data.alloc_by_guard:'+this['data']['alloc_by_guard']),alloc(b,toTxObject(b,this['object_address']),this['type_parameter'],this['data']['alloc_by_guard'],c));}else{const f=GetObject(this['data']['object']);!IsValidArgType(f?.['type_parameter'])&&W_ERROR(WErrors['IsValidArgType'],'CallAllocation_Data.data.object.type_parameter\x20'+f?.['type_parameter']);this['type_parameter']=f?.['type_parameter'];let g;'coin'in this['data']&&this['data']['coin']&&(g=await getCoinParam(a,b,this['data']['coin'],this['type_parameter']));if(g&&'allocators'in this['data']&&this['data']['allocators']&&this['type_parameter']){const h=newAllocation(b,this['type_parameter'],g,await allocators(b,this['data']['allocators']));await this['new_with_mark'](a,b,ObjectType['Allocation'],create(b,h,this['type_parameter'],await paymentInfo(a,b,this['data']['payment_info'])),f);}else W_ERROR(WErrors['InvalidParam'],'CallAllocation_Data.data\x20'+JSON['stringify'](this['data']));}}}export function allocationFn(a){return PackageAddress+'::allocation::'+a;}export const MAX_ALLOCATOR_COUNT=0x64;export const MAX_SHARING_COUNT=0x64;const getAllocationModeNumber=a=>{let b;if(typeof a==='number')b=a;else{if(typeof a==='string')switch(a){case'Amount':b=0x0;break;case'Rate':b=0x1;break;case'Surplus':b=0x2;break;default:b=Number(a);}else b=Number(a);}return b!==0x0&&b!==0x1&&b!==0x2&&W_ERROR(WErrors['InvalidParam'],'Invalid\x20allocation\x20mode:\x20'+a+'.\x20Only\x200\x20(Amount),\x201\x20(Rate),\x20or\x202\x20(Surplus)\x20are\x20allowed.'),b;};export const sharing=async(a,b,c)=>{const d=getAllocationModeNumber(b['mode']);if('GuardIdentifier'in b['who'])return!isValidU8(b['who']['GuardIdentifier'])&&W_ERROR(WErrors['IsValidU8'],'sharing\x20GuardIdentifier:\x20'+b['who']['GuardIdentifier']),a['moveCall']({'target':allocationFn('sharing_for_guard_identifier'),'arguments':[a['pure']['u8'](b['who']['GuardIdentifier']),a['pure']['u64'](b['sharing']),a['pure']['u8'](d)]});else{if('Entity'in b['who']){const e=c||await GetAccountOrMark_Address(b['who']['Entity']);return!e&&W_ERROR(WErrors['IsValidAddress'],'sharing\x20Entity:\x20'+b['who']['Entity']),a['moveCall']({'target':allocationFn('sharing_for_address'),'arguments':[a['pure']['address'](e),a['pure']['u64'](b['sharing']),a['pure']['u8'](d)]});}else return a['moveCall']({'target':allocationFn('sharing_for_signer'),'arguments':[a['pure']['u64'](b['sharing']),a['pure']['u8'](d)]});}};export const allocators=async(a,b)=>{!isValidDescription(b['description'])&&W_ERROR(WErrors['InvalidParam'],'Description\x20exceeds\x20maximum\x20length\x20'+MAX_DESCRIPTION_LENGTH);b['allocators']['length']>MAX_ALLOCATOR_COUNT&&W_ERROR(WErrors['InvalidParam'],'Allocator\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_ALLOCATOR_COUNT);b['allocators']['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'Allocator\x20array\x20cannot\x20be\x20empty');!isValidU64(b['threshold'])&&W_ERROR(WErrors['InvalidParam'],'threshold:\x20'+b['threshold']);const c=a['moveCall']({'target':allocationFn('allocators'),'arguments':[a['pure']['string'](b['description']),a['pure']['u64'](b['threshold'])]});for(let d=0x0;d<b['allocators']['length'];d++){const e=b['allocators'][d];e['sharing']['length']===0x0&&W_ERROR(WErrors['InvalidParam'],'sharing\x20array\x20cannot\x20be\x20empty');e['sharing']['length']>MAX_SHARING_COUNT&&W_ERROR(WErrors['InvalidParam'],'sharing\x20count\x20exceeds\x20maximum\x20limit\x20'+MAX_SHARING_COUNT);const f=e['sharing']['map']((n,o)=>{return'Entity'in n['who']?{'index':o,'name_or_address':n['who']['Entity']['name_or_address']}:null;})['filter'](n=>n!==null),[h,j]=await Promise['all']([LocalMark['Instance']()['get_address'](e['guard']),GetManyAccountOrMark_Address({'entities':f,'check_all_founded':!![]})]),k=new Array(e['sharing']['length']);f['forEach']((n,o)=>{k[n['index']]=j[o];});!h&&W_ERROR(WErrors['IsValidAddress'],'guard:\x20'+e['guard']);const l=await Promise['all'](e['sharing']['map'](async(n,o)=>{if('Entity'in n['who']){const p=k[o];return!p&&W_ERROR(WErrors['IsValidAddress'],'entity:\x20'+(typeof n['who']['Entity']==='string'?n['who']['Entity']:n['who']['Entity']['name_or_address'])),sharing(a,n,p);}else return sharing(a,n);})),m=a['makeMoveVec']({'elements':l,'type':PackageAddress+'::allocation::Sharing'});a['moveCall']({'target':allocationFn('allocator_add'),'arguments':[c,toTxObject(a,h),m,a['pure']['option']('u64',e?.['max'])]});}return c;};export function alloc(a,b,c,d,e){validObjects([b,d,e]),!IsValidArgType(c)&&W_ERROR(WErrors['InvalidParam'],'allocation_type:\x20'+c+'\x20invalid'),a['moveCall']({'target':allocationFn('alloc'),'arguments':[b,toTxObject(a,d),toTxObject(a,e),a['object']['mutRegistrar'](),a['object']['clock']()],'typeArguments':[c]});}export function newAllocation(a,b,c,d){return validObjects([c,d]),a['moveCall']({'target':allocationFn('new_with_coin'),'arguments':[c,d,a['object']['mutRegistrar'](),a['object']['clock']()],'typeArguments':[b]});}export function create(a,b,c,d){return validObjects([b,d]),!IsValidArgType(c)&&W_ERROR(WErrors['InvalidParam'],'allocation_type:\x20'+c+'\x20invalid'),a['moveCall']({'target':allocationFn('create'),'arguments':[b,toTxObject(a,d)],'typeArguments':[c]});}export function receive(a,b,c,d,e){return validObjects([b,e,d]),!IsValidArgType(c)&&W_ERROR(WErrors['InvalidParam'],'allocation_type:\x20'+c+'\x20invalid'),a['moveCall']({'target':allocationFn('receive'),'arguments':[b,toTxObject(a,d),toTxObject(a,e)],'typeArguments':[c]});}
|