stxer 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,12 +12,43 @@ yarn add stxer
12
12
 
13
13
  ## Features
14
14
 
15
- ### 1. Batch Operations
15
+ ### 1. Transaction Simulation
16
16
 
17
- The SDK provides efficient batch reading capabilities for Stacks blockchain:
17
+ Simulate complex transaction sequences before executing them on-chain:
18
18
 
19
19
  ```typescript
20
- import { batchRead, batchReadonly } from 'stxer';
20
+ import { SimulationBuilder } from 'stxer';
21
+
22
+ const simulationId = await SimulationBuilder.new({
23
+ network: 'mainnet', // or 'testnet'
24
+ })
25
+ .withSender('ST...') // Set default sender
26
+ .addContractCall({
27
+ contract_id: 'ST...contract-name',
28
+ function_name: 'my-function',
29
+ function_args: [/* clarity values */]
30
+ })
31
+ .addSTXTransfer({
32
+ recipient: 'ST...',
33
+ amount: 1000000 // in microSTX
34
+ })
35
+ .addContractDeploy({
36
+ contract_name: 'my-contract',
37
+ source_code: '(define-public (hello) (ok "world"))'
38
+ })
39
+ .run();
40
+
41
+ // View simulation results at: https://stxer.xyz/simulations/{network}/{simulationId}
42
+ ```
43
+
44
+ ### 2. Batch Operations
45
+
46
+ The SDK provides two approaches for efficient batch reading from the Stacks blockchain:
47
+
48
+ #### Direct Batch Reading
49
+
50
+ ```typescript
51
+ import { batchRead } from 'stxer';
21
52
 
22
53
  // Batch read variables and maps
23
54
  const result = await batchRead({
@@ -29,11 +60,7 @@ const result = await batchRead({
29
60
  contract: contractPrincipalCV(...),
30
61
  mapName: 'my-map',
31
62
  mapKey: someCV
32
- }]
33
- });
34
-
35
- // Batch readonly function calls
36
- const readonlyResult = await batchReadonly({
63
+ }],
37
64
  readonly: [{
38
65
  contract: contractPrincipalCV(...),
39
66
  functionName: 'my-function',
@@ -42,35 +69,114 @@ const readonlyResult = await batchReadonly({
42
69
  });
43
70
  ```
44
71
 
45
- ### 2. Transaction Simulation
72
+ #### BatchProcessor for Queue-based Operations
46
73
 
47
- Simulate complex transaction sequences before executing them on-chain:
74
+ The BatchProcessor allows you to queue multiple read operations and automatically batch them together after a specified delay:
48
75
 
49
76
  ```typescript
50
- import { SimulationBuilder } from 'stxer';
77
+ import { BatchProcessor } from 'stxer';
51
78
 
52
- const simulationId = await SimulationBuilder.new({
53
- network: 'mainnet', // or 'testnet'
54
- })
55
- .withSender('ST...') // Set default sender
56
- .addContractCall({
57
- contract_id: 'ST...contract-name',
58
- function_name: 'my-function',
59
- function_args: [/* clarity values */]
60
- })
61
- .addSTXTransfer({
62
- recipient: 'ST...',
63
- amount: 1000000 // in microSTX
64
- })
65
- .addContractDeploy({
66
- contract_name: 'my-contract',
67
- source_code: '(define-public (hello) (ok "world"))'
79
+ const processor = new BatchProcessor({
80
+ stxerAPIEndpoint: 'https://api.stxer.xyz', // optional
81
+ batchDelayMs: 1000, // delay before processing batch
82
+ });
83
+
84
+ // Queue multiple operations that will be batched together
85
+ const [resultA, resultB] = await Promise.all([
86
+ new Promise((resolve, reject) => {
87
+ processor.enqueue({
88
+ request: {
89
+ mode: 'variable',
90
+ contractAddress: 'SP...',
91
+ contractName: 'my-contract',
92
+ variableName: 'variable-a'
93
+ },
94
+ resolve,
95
+ reject
96
+ });
97
+ }),
98
+ new Promise((resolve, reject) => {
99
+ processor.enqueue({
100
+ request: {
101
+ mode: 'variable',
102
+ contractAddress: 'SP...',
103
+ contractName: 'my-contract',
104
+ variableName: 'variable-b'
105
+ },
106
+ resolve,
107
+ reject
108
+ });
68
109
  })
69
- .run();
110
+ ]);
111
+
112
+ // You can also queue different types of operations
113
+ processor.enqueue({
114
+ request: {
115
+ mode: 'readonly',
116
+ contractAddress: 'SP...',
117
+ contractName: 'my-contract',
118
+ functionName: 'get-value',
119
+ functionArgs: []
120
+ },
121
+ resolve: (value) => console.log('Function result:', value),
122
+ reject: (error) => console.error('Error:', error)
123
+ });
70
124
 
71
- // View simulation results at: https://stxer.xyz/simulations/{network}/{simulationId}
125
+ processor.enqueue({
126
+ request: {
127
+ mode: 'mapEntry',
128
+ contractAddress: 'SP...',
129
+ contractName: 'my-contract',
130
+ mapName: 'my-map',
131
+ mapKey: someKey
132
+ },
133
+ resolve: (value) => console.log('Map entry:', value),
134
+ reject: (error) => console.error('Error:', error)
135
+ });
72
136
  ```
73
137
 
138
+ The BatchProcessor automatically:
139
+ - Queues read operations
140
+ - Batches them together after the specified delay
141
+ - Makes a single API call for all queued operations
142
+ - Distributes results back to the respective promises
143
+
144
+ This is particularly useful when you need to make multiple blockchain reads and want to optimize network calls.
145
+
146
+ ### 3. Clarity API Utilities
147
+
148
+ The SDK provides convenient utilities for reading data from Clarity contracts:
149
+
150
+ ```typescript
151
+ import { callReadonly, readVariable, readMap } from 'stxer';
152
+ import { SIP010TraitABI } from 'clarity-abi/abis';
153
+ import { unwrapResponse } from 'ts-clarity';
154
+
155
+ // Read from a contract function
156
+ const supply = await callReadonly({
157
+ abi: SIP010TraitABI.functions,
158
+ functionName: 'get-total-supply',
159
+ contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
160
+ }).then(unwrapResponse);
161
+
162
+ // Read a contract variable
163
+ const paused = await readVariable({
164
+ abi: [{ name: 'paused', type: 'bool', access: 'variable' }],
165
+ variableName: 'paused',
166
+ contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
167
+ });
168
+
169
+ // Read from a contract map
170
+ const approved = await readMap({
171
+ abi: [{ key: 'principal', name: 'approved-tokens', value: 'bool' }],
172
+ mapName: 'approved-tokens',
173
+ key: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
174
+ contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
175
+ });
176
+ ```
177
+
178
+ These utilities provide type-safe ways to interact with Clarity contracts, with built-in ABI support and response unwrapping.
179
+
74
180
  ## Configuration
75
181
 
76
182
  You can customize the API endpoints:
@@ -32,12 +32,3 @@ export interface BatchApiOptions {
32
32
  stxerApi?: string;
33
33
  }
34
34
  export declare function batchRead(reads: BatchReads, options?: BatchApiOptions): Promise<BatchReadsResult>;
35
- export interface BatchReadonlyRequest {
36
- readonly: {
37
- contract: ContractPrincipalCV;
38
- functionName: string;
39
- functionArgs: ClarityValue[];
40
- }[];
41
- index_block_hash?: string;
42
- }
43
- export declare function batchReadonly(req: BatchReadonlyRequest, options?: BatchApiOptions): Promise<(ClarityValue | Error)[]>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WARNING:
3
+ *
4
+ * this file will be used in cross-runtime environments (browser, cloudflare workers, XLinkSDK, etc.),
5
+ * so please be careful when adding `import`s to it.
6
+ */
7
+ import { type ClarityValue, type OptionalCV } from '@stacks/transactions';
8
+ export interface ReadOnlyRequest {
9
+ mode: 'readonly';
10
+ contractAddress: string;
11
+ contractName: string;
12
+ functionName: string;
13
+ functionArgs: ClarityValue[];
14
+ }
15
+ export interface MapEntryRequest {
16
+ mode: 'mapEntry';
17
+ contractAddress: string;
18
+ contractName: string;
19
+ mapName: string;
20
+ mapKey: ClarityValue;
21
+ }
22
+ export interface VariableRequest {
23
+ mode: 'variable';
24
+ contractAddress: string;
25
+ contractName: string;
26
+ variableName: string;
27
+ }
28
+ export type BatchRequest = MapEntryRequest | VariableRequest | ReadOnlyRequest;
29
+ export interface QueuedRequest {
30
+ request: BatchRequest;
31
+ tip?: string;
32
+ resolve: (value: ClarityValue | OptionalCV) => void;
33
+ reject: (error: Error) => void;
34
+ }
35
+ export declare class BatchProcessor {
36
+ private queues;
37
+ private timeoutIds;
38
+ private readonly stxerAPIEndpoint;
39
+ private readonly batchDelayMs;
40
+ constructor(options: {
41
+ stxerAPIEndpoint?: string;
42
+ batchDelayMs: number;
43
+ });
44
+ private getQueueKey;
45
+ enqueue(request: QueuedRequest): void;
46
+ private processBatch;
47
+ }
@@ -0,0 +1,27 @@
1
+ import type { ClarityAbiFunction, ClarityAbiMap, ClarityAbiVariable, TContractPrincipal, TPrincipal } from 'clarity-abi';
2
+ import type { InferReadonlyCallParameterType, InferReadonlyCallResultType, InferMapValueType, InferReadMapParameterType, InferReadVariableParameterType, InferVariableType } from 'ts-clarity';
3
+ import { BatchProcessor } from './BatchProcessor';
4
+ export type ReadonlyCallRuntimeOptions = {
5
+ sender?: TPrincipal;
6
+ contract: TContractPrincipal;
7
+ stacksEndpoint?: string;
8
+ indexBlockHash?: string;
9
+ batchProcessor?: BatchProcessor;
10
+ };
11
+ export type ReadMapRuntimeParameters = {
12
+ contract: TContractPrincipal;
13
+ stacksEndpoint?: string;
14
+ proof?: boolean;
15
+ indexBlockHash?: string;
16
+ batchProcessor?: BatchProcessor;
17
+ };
18
+ export type ReadVariableRuntimeParameterType = {
19
+ contract: TContractPrincipal;
20
+ stacksEndpoint?: string;
21
+ proof?: boolean;
22
+ indexBlockHash?: string;
23
+ batchProcessor?: BatchProcessor;
24
+ };
25
+ export declare function callReadonly<Functions extends readonly ClarityAbiFunction[] | readonly unknown[], FunctionName extends string>(params: InferReadonlyCallParameterType<Functions, FunctionName> & ReadonlyCallRuntimeOptions): Promise<InferReadonlyCallResultType<Functions, FunctionName>>;
26
+ export declare function readMap<Maps extends readonly ClarityAbiMap[] | readonly unknown[] = readonly ClarityAbiMap[], MapName extends string = string>(params: InferReadMapParameterType<Maps, MapName> & ReadMapRuntimeParameters): Promise<InferMapValueType<Maps, MapName> | null>;
27
+ export declare function readVariable<Variables extends readonly ClarityAbiVariable[] | readonly unknown[] = readonly ClarityAbiVariable[], VariableName extends string = string>(params: InferReadVariableParameterType<Variables, VariableName> & ReadVariableRuntimeParameterType): Promise<InferVariableType<Variables, VariableName>>;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './batch-api';
1
+ export * from './BatchAPI';
2
2
  export * from './simulation';
3
+ export * from './clarity-api';
@@ -461,62 +461,6 @@ function _batchRead() {
461
461
  }));
462
462
  return _batchRead.apply(this, arguments);
463
463
  }
464
- function batchReadonly(_x3, _x4) {
465
- return _batchReadonly.apply(this, arguments);
466
- }
467
- function _batchReadonly() {
468
- _batchReadonly = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, options) {
469
- var _options$stxerApi2;
470
- var payload, ibh, url, data, text, results, rs, _iterator5, _step5, result;
471
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
472
- while (1) switch (_context2.prev = _context2.next) {
473
- case 0:
474
- if (options === void 0) {
475
- options = {};
476
- }
477
- payload = req.readonly.map(function (r) {
478
- return [transactions.serializeCV(r.contract), r.functionName].concat(r.functionArgs.map(function (arg) {
479
- return transactions.serializeCV(arg);
480
- }));
481
- });
482
- ibh = req.index_block_hash == null ? null : req.index_block_hash.startsWith('0x') ? req.index_block_hash.substring(2) : req.index_block_hash;
483
- url = ((_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API) + "/sidecar/v2/batch-readonly" + (ibh == null ? '' : "?tip=" + ibh);
484
- _context2.next = 6;
485
- return fetch(url, {
486
- method: 'POST',
487
- body: JSON.stringify(payload)
488
- });
489
- case 6:
490
- data = _context2.sent;
491
- _context2.next = 9;
492
- return data.text();
493
- case 9:
494
- text = _context2.sent;
495
- if (!(!text.includes('Ok') && !text.includes('Err'))) {
496
- _context2.next = 12;
497
- break;
498
- }
499
- throw new Error("Requesting batch readonly failed: " + text + ", url: " + url + ", payload: " + JSON.stringify(payload));
500
- case 12:
501
- results = JSON.parse(text);
502
- rs = [];
503
- for (_iterator5 = _createForOfIteratorHelperLoose(results); !(_step5 = _iterator5()).done;) {
504
- result = _step5.value;
505
- if ('Ok' in result) {
506
- rs.push(transactions.deserializeCV(result.Ok));
507
- } else {
508
- rs.push(new Error(result.Err));
509
- }
510
- }
511
- return _context2.abrupt("return", rs);
512
- case 16:
513
- case "end":
514
- return _context2.stop();
515
- }
516
- }, _callee2);
517
- }));
518
- return _batchReadonly.apply(this, arguments);
519
- }
520
464
 
521
465
  function runTx(tx) {
522
466
  // type 0: run transaction
@@ -963,9 +907,324 @@ var SimulationBuilder = /*#__PURE__*/function () {
963
907
  return SimulationBuilder;
964
908
  }();
965
909
 
910
+ var BatchProcessor = /*#__PURE__*/function () {
911
+ function BatchProcessor(options) {
912
+ var _options$stxerAPIEndp;
913
+ this.queues = new Map();
914
+ this.timeoutIds = new Map();
915
+ this.stxerAPIEndpoint = void 0;
916
+ this.batchDelayMs = void 0;
917
+ this.stxerAPIEndpoint = (_options$stxerAPIEndp = options.stxerAPIEndpoint) != null ? _options$stxerAPIEndp : 'https://api.stxer.xyz';
918
+ this.batchDelayMs = options.batchDelayMs;
919
+ }
920
+ var _proto = BatchProcessor.prototype;
921
+ _proto.getQueueKey = function getQueueKey(tip) {
922
+ return tip != null ? tip : '_undefined';
923
+ };
924
+ _proto.enqueue = function enqueue(request) {
925
+ var _this$queues$get,
926
+ _this = this;
927
+ var queueKey = this.getQueueKey(request.tip);
928
+ var queue = (_this$queues$get = this.queues.get(queueKey)) != null ? _this$queues$get : [];
929
+ if (!this.queues.has(queueKey)) {
930
+ this.queues.set(queueKey, queue);
931
+ }
932
+ queue.push(request);
933
+ if (!this.timeoutIds.has(queueKey)) {
934
+ var timeoutId = setTimeout(function () {
935
+ return _this.processBatch(queueKey);
936
+ }, this.batchDelayMs);
937
+ this.timeoutIds.set(queueKey, timeoutId);
938
+ }
939
+ };
940
+ _proto.processBatch = /*#__PURE__*/function () {
941
+ var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(queueKey) {
942
+ var _this$queues$get2;
943
+ var currentQueue, timeoutId, readonlyRequests, mapRequests, variableRequests, tip, batchRequest, results, _iterator, _step, _step$value, index, result, _iterator2, _step2, _step2$value, _index, _result, _iterator3, _step3, _step3$value, _index2, _result2, _iterator4, _step4, item;
944
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
945
+ while (1) switch (_context.prev = _context.next) {
946
+ case 0:
947
+ currentQueue = (_this$queues$get2 = this.queues.get(queueKey)) != null ? _this$queues$get2 : [];
948
+ this.queues["delete"](queueKey);
949
+ timeoutId = this.timeoutIds.get(queueKey);
950
+ if (timeoutId) {
951
+ clearTimeout(timeoutId);
952
+ this.timeoutIds["delete"](queueKey);
953
+ }
954
+ if (!(currentQueue.length === 0)) {
955
+ _context.next = 6;
956
+ break;
957
+ }
958
+ return _context.abrupt("return");
959
+ case 6:
960
+ _context.prev = 6;
961
+ readonlyRequests = currentQueue.filter(function (q) {
962
+ return q.request.mode === 'readonly';
963
+ });
964
+ mapRequests = currentQueue.filter(function (q) {
965
+ return q.request.mode === 'mapEntry';
966
+ });
967
+ variableRequests = currentQueue.filter(function (q) {
968
+ return q.request.mode === 'variable';
969
+ });
970
+ tip = queueKey === '_undefined' ? undefined : queueKey;
971
+ batchRequest = {
972
+ readonly: readonlyRequests.map(function (_ref) {
973
+ var request = _ref.request;
974
+ return {
975
+ contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
976
+ functionName: request.functionName,
977
+ functionArgs: request.functionArgs
978
+ };
979
+ }),
980
+ maps: mapRequests.map(function (_ref2) {
981
+ var request = _ref2.request;
982
+ return {
983
+ contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
984
+ mapName: request.mapName,
985
+ mapKey: request.mapKey
986
+ };
987
+ }),
988
+ variables: variableRequests.map(function (_ref3) {
989
+ var request = _ref3.request;
990
+ return {
991
+ contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
992
+ variableName: request.variableName
993
+ };
994
+ }),
995
+ index_block_hash: tip
996
+ };
997
+ _context.next = 14;
998
+ return batchRead(batchRequest, {
999
+ stxerApi: this.stxerAPIEndpoint
1000
+ });
1001
+ case 14:
1002
+ results = _context.sent;
1003
+ // Handle readonly results
1004
+ for (_iterator = _createForOfIteratorHelperLoose(results.readonly.entries()); !(_step = _iterator()).done;) {
1005
+ _step$value = _step.value, index = _step$value[0], result = _step$value[1];
1006
+ if (result instanceof Error) {
1007
+ readonlyRequests[index].reject(result);
1008
+ } else {
1009
+ readonlyRequests[index].resolve(result);
1010
+ }
1011
+ }
1012
+ // Handle variable results
1013
+ for (_iterator2 = _createForOfIteratorHelperLoose(results.vars.entries()); !(_step2 = _iterator2()).done;) {
1014
+ _step2$value = _step2.value, _index = _step2$value[0], _result = _step2$value[1];
1015
+ if (_result instanceof Error) {
1016
+ variableRequests[_index].reject(_result);
1017
+ } else {
1018
+ variableRequests[_index].resolve(_result);
1019
+ }
1020
+ }
1021
+ // Handle map results
1022
+ for (_iterator3 = _createForOfIteratorHelperLoose(results.maps.entries()); !(_step3 = _iterator3()).done;) {
1023
+ _step3$value = _step3.value, _index2 = _step3$value[0], _result2 = _step3$value[1];
1024
+ if (_result2 instanceof Error) {
1025
+ mapRequests[_index2].reject(_result2);
1026
+ } else {
1027
+ mapRequests[_index2].resolve(_result2);
1028
+ }
1029
+ }
1030
+ _context.next = 23;
1031
+ break;
1032
+ case 20:
1033
+ _context.prev = 20;
1034
+ _context.t0 = _context["catch"](6);
1035
+ for (_iterator4 = _createForOfIteratorHelperLoose(currentQueue); !(_step4 = _iterator4()).done;) {
1036
+ item = _step4.value;
1037
+ item.reject(_context.t0);
1038
+ }
1039
+ case 23:
1040
+ case "end":
1041
+ return _context.stop();
1042
+ }
1043
+ }, _callee, this, [[6, 20]]);
1044
+ }));
1045
+ function processBatch(_x) {
1046
+ return _processBatch.apply(this, arguments);
1047
+ }
1048
+ return processBatch;
1049
+ }();
1050
+ return BatchProcessor;
1051
+ }();
1052
+
1053
+ // Shared processor instance with default settings
1054
+ var defaultProcessor = /*#__PURE__*/new BatchProcessor({
1055
+ batchDelayMs: 100
1056
+ });
1057
+ function callReadonly(_x) {
1058
+ return _callReadonly.apply(this, arguments);
1059
+ }
1060
+ function _callReadonly() {
1061
+ _callReadonly = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
1062
+ var _params$batchProcesso;
1063
+ var processor, _params$contract$spli, deployer, contractName, fn, functionDef, argsKV, args, _iterator, _step, argDef;
1064
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1065
+ while (1) switch (_context.prev = _context.next) {
1066
+ case 0:
1067
+ processor = (_params$batchProcesso = params.batchProcessor) != null ? _params$batchProcesso : defaultProcessor;
1068
+ _params$contract$spli = params.contract.split('.', 2), deployer = _params$contract$spli[0], contractName = _params$contract$spli[1];
1069
+ fn = String(params.functionName);
1070
+ functionDef = params.abi.find(function (def) {
1071
+ return def.name === params.functionName;
1072
+ });
1073
+ if (functionDef) {
1074
+ _context.next = 6;
1075
+ break;
1076
+ }
1077
+ throw new Error("failed to find function definition for " + params.functionName);
1078
+ case 6:
1079
+ argsKV = params.args;
1080
+ args = [];
1081
+ for (_iterator = _createForOfIteratorHelperLoose(functionDef.args); !(_step = _iterator()).done;) {
1082
+ argDef = _step.value;
1083
+ args.push(tsClarity.encodeAbi(argDef.type, argsKV[argDef.name]));
1084
+ }
1085
+ return _context.abrupt("return", new Promise(function (_resolve, reject) {
1086
+ processor.enqueue({
1087
+ request: {
1088
+ mode: 'readonly',
1089
+ contractAddress: deployer,
1090
+ contractName: contractName,
1091
+ functionName: fn,
1092
+ functionArgs: args
1093
+ },
1094
+ tip: params.indexBlockHash,
1095
+ resolve: function resolve(result) {
1096
+ try {
1097
+ var decoded = tsClarity.decodeAbi(functionDef.outputs.type, result);
1098
+ _resolve(decoded);
1099
+ } catch (error) {
1100
+ reject(error);
1101
+ }
1102
+ },
1103
+ reject: reject
1104
+ });
1105
+ }));
1106
+ case 10:
1107
+ case "end":
1108
+ return _context.stop();
1109
+ }
1110
+ }, _callee);
1111
+ }));
1112
+ return _callReadonly.apply(this, arguments);
1113
+ }
1114
+ function readMap(_x2) {
1115
+ return _readMap.apply(this, arguments);
1116
+ }
1117
+ function _readMap() {
1118
+ _readMap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
1119
+ var _params$batchProcesso2;
1120
+ var processor, _params$contract$spli2, deployer, contractName, mapDef, key;
1121
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1122
+ while (1) switch (_context2.prev = _context2.next) {
1123
+ case 0:
1124
+ processor = (_params$batchProcesso2 = params.batchProcessor) != null ? _params$batchProcesso2 : defaultProcessor;
1125
+ _params$contract$spli2 = params.contract.split('.', 2), deployer = _params$contract$spli2[0], contractName = _params$contract$spli2[1];
1126
+ mapDef = params.abi.find(function (m) {
1127
+ return m.name === params.mapName;
1128
+ });
1129
+ if (mapDef) {
1130
+ _context2.next = 5;
1131
+ break;
1132
+ }
1133
+ throw new Error("failed to find map definition for " + params.mapName);
1134
+ case 5:
1135
+ key = tsClarity.encodeAbi(mapDef.key, params.key);
1136
+ return _context2.abrupt("return", new Promise(function (_resolve2, reject) {
1137
+ processor.enqueue({
1138
+ request: {
1139
+ mode: 'mapEntry',
1140
+ contractAddress: deployer,
1141
+ contractName: contractName,
1142
+ mapName: params.mapName,
1143
+ mapKey: key
1144
+ },
1145
+ tip: params.indexBlockHash,
1146
+ resolve: function resolve(result) {
1147
+ try {
1148
+ if (result.type === transactions.ClarityType.OptionalNone) {
1149
+ _resolve2(null);
1150
+ return;
1151
+ }
1152
+ if (result.type !== transactions.ClarityType.OptionalSome) {
1153
+ throw new Error("unexpected map value: " + result);
1154
+ }
1155
+ var someCV = result;
1156
+ var decoded = tsClarity.decodeAbi(mapDef.value, someCV.value);
1157
+ _resolve2(decoded);
1158
+ } catch (error) {
1159
+ reject(error);
1160
+ }
1161
+ },
1162
+ reject: reject
1163
+ });
1164
+ }));
1165
+ case 7:
1166
+ case "end":
1167
+ return _context2.stop();
1168
+ }
1169
+ }, _callee2);
1170
+ }));
1171
+ return _readMap.apply(this, arguments);
1172
+ }
1173
+ function readVariable(_x3) {
1174
+ return _readVariable.apply(this, arguments);
1175
+ }
1176
+ function _readVariable() {
1177
+ _readVariable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
1178
+ var _params$batchProcesso3;
1179
+ var processor, _params$contract$spli3, deployer, contractName, varDef;
1180
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1181
+ while (1) switch (_context3.prev = _context3.next) {
1182
+ case 0:
1183
+ processor = (_params$batchProcesso3 = params.batchProcessor) != null ? _params$batchProcesso3 : defaultProcessor;
1184
+ _params$contract$spli3 = params.contract.split('.', 2), deployer = _params$contract$spli3[0], contractName = _params$contract$spli3[1];
1185
+ varDef = params.abi.find(function (def) {
1186
+ return def.name === params.variableName;
1187
+ });
1188
+ if (varDef) {
1189
+ _context3.next = 5;
1190
+ break;
1191
+ }
1192
+ throw new Error("failed to find variable definition for " + params.variableName);
1193
+ case 5:
1194
+ return _context3.abrupt("return", new Promise(function (_resolve3, reject) {
1195
+ processor.enqueue({
1196
+ request: {
1197
+ mode: 'variable',
1198
+ contractAddress: deployer,
1199
+ contractName: contractName,
1200
+ variableName: params.variableName
1201
+ },
1202
+ tip: params.indexBlockHash,
1203
+ resolve: function resolve(result) {
1204
+ try {
1205
+ var decoded = tsClarity.decodeAbi(varDef.type, result);
1206
+ _resolve3(decoded);
1207
+ } catch (error) {
1208
+ reject(error);
1209
+ }
1210
+ },
1211
+ reject: reject
1212
+ });
1213
+ }));
1214
+ case 6:
1215
+ case "end":
1216
+ return _context3.stop();
1217
+ }
1218
+ }, _callee3);
1219
+ }));
1220
+ return _readVariable.apply(this, arguments);
1221
+ }
1222
+
966
1223
  exports.SimulationBuilder = SimulationBuilder;
967
1224
  exports.batchRead = batchRead;
968
- exports.batchReadonly = batchReadonly;
1225
+ exports.callReadonly = callReadonly;
1226
+ exports.readMap = readMap;
1227
+ exports.readVariable = readVariable;
969
1228
  exports.runEval = runEval;
970
1229
  exports.runSimulation = runSimulation;
971
1230
  //# sourceMappingURL=stxer.cjs.development.js.map