stxer 0.3.3 → 0.4.1
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 +115 -29
- package/dist/{batch-api.d.ts → BatchAPI.d.ts} +0 -9
- package/dist/BatchProcessor.d.ts +48 -0
- package/dist/clarity-api.d.ts +27 -0
- package/dist/index.d.ts +2 -1
- package/dist/stxer.cjs.development.js +326 -57
- package/dist/stxer.cjs.development.js.map +1 -1
- package/dist/stxer.cjs.production.min.js +1 -1
- package/dist/stxer.cjs.production.min.js.map +1 -1
- package/dist/stxer.esm.js +326 -59
- package/dist/stxer.esm.js.map +1 -1
- package/package.json +6 -4
- package/src/{batch-api.ts → BatchAPI.ts} +1 -54
- package/src/BatchProcessor.ts +178 -0
- package/src/clarity-api.ts +186 -0
- package/src/index.ts +2 -1
- package/src/sample/read.ts +139 -124
package/README.md
CHANGED
|
@@ -12,12 +12,43 @@ yarn add stxer
|
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
-
### 1.
|
|
15
|
+
### 1. Transaction Simulation
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Simulate complex transaction sequences before executing them on-chain:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
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
|
|
18
49
|
|
|
19
50
|
```typescript
|
|
20
|
-
import { batchRead
|
|
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,94 @@ const readonlyResult = await batchReadonly({
|
|
|
42
69
|
});
|
|
43
70
|
```
|
|
44
71
|
|
|
45
|
-
|
|
72
|
+
#### BatchProcessor for Queue-based Operations
|
|
46
73
|
|
|
47
|
-
|
|
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 {
|
|
77
|
+
import { BatchProcessor } from 'stxer';
|
|
51
78
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
processor.read({
|
|
87
|
+
mode: 'variable',
|
|
88
|
+
contractAddress: 'SP...',
|
|
89
|
+
contractName: 'my-contract',
|
|
90
|
+
variableName: 'variable-a'
|
|
91
|
+
}),
|
|
92
|
+
processor.read({
|
|
93
|
+
mode: 'variable',
|
|
94
|
+
contractAddress: 'SP...',
|
|
95
|
+
contractName: 'my-contract',
|
|
96
|
+
variableName: 'variable-b'
|
|
68
97
|
})
|
|
69
|
-
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
// You can also queue different types of operations
|
|
101
|
+
processor.read({
|
|
102
|
+
mode: 'readonly',
|
|
103
|
+
contractAddress: 'SP...',
|
|
104
|
+
contractName: 'my-contract',
|
|
105
|
+
functionName: 'get-value',
|
|
106
|
+
functionArgs: []
|
|
107
|
+
});
|
|
70
108
|
|
|
71
|
-
|
|
109
|
+
processor.read({
|
|
110
|
+
mode: 'mapEntry',
|
|
111
|
+
contractAddress: 'SP...',
|
|
112
|
+
contractName: 'my-contract',
|
|
113
|
+
mapName: 'my-map',
|
|
114
|
+
mapKey: someKey
|
|
115
|
+
});
|
|
72
116
|
```
|
|
73
117
|
|
|
118
|
+
The BatchProcessor automatically:
|
|
119
|
+
- Queues read operations
|
|
120
|
+
- Batches them together after the specified delay
|
|
121
|
+
- Makes a single API call for all queued operations
|
|
122
|
+
- Distributes results back to the respective promises
|
|
123
|
+
|
|
124
|
+
This is particularly useful when you need to make multiple blockchain reads and want to optimize network calls.
|
|
125
|
+
|
|
126
|
+
### 3. Clarity API Utilities
|
|
127
|
+
|
|
128
|
+
The SDK provides convenient utilities for reading data from Clarity contracts:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { callReadonly, readVariable, readMap } from 'stxer';
|
|
132
|
+
import { SIP010TraitABI } from 'clarity-abi/abis';
|
|
133
|
+
import { unwrapResponse } from 'ts-clarity';
|
|
134
|
+
|
|
135
|
+
// Read from a contract function
|
|
136
|
+
const supply = await callReadonly({
|
|
137
|
+
abi: SIP010TraitABI.functions,
|
|
138
|
+
functionName: 'get-total-supply',
|
|
139
|
+
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
|
140
|
+
}).then(unwrapResponse);
|
|
141
|
+
|
|
142
|
+
// Read a contract variable
|
|
143
|
+
const paused = await readVariable({
|
|
144
|
+
abi: [{ name: 'paused', type: 'bool', access: 'variable' }],
|
|
145
|
+
variableName: 'paused',
|
|
146
|
+
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Read from a contract map
|
|
150
|
+
const approved = await readMap({
|
|
151
|
+
abi: [{ key: 'principal', name: 'approved-tokens', value: 'bool' }],
|
|
152
|
+
mapName: 'approved-tokens',
|
|
153
|
+
key: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
|
154
|
+
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
These utilities provide type-safe ways to interact with Clarity contracts, with built-in ABI support and response unwrapping.
|
|
159
|
+
|
|
74
160
|
## Configuration
|
|
75
161
|
|
|
76
162
|
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,48 @@
|
|
|
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
|
+
read(request: BatchRequest): Promise<ClarityValue | OptionalCV>;
|
|
46
|
+
enqueue(request: QueuedRequest): void;
|
|
47
|
+
private processBatch;
|
|
48
|
+
}
|
|
@@ -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
|
@@ -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,334 @@ 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.read = function read(request) {
|
|
925
|
+
var _this = this;
|
|
926
|
+
return new Promise(function (resolve, reject) {
|
|
927
|
+
_this.enqueue({
|
|
928
|
+
request: request,
|
|
929
|
+
resolve: resolve,
|
|
930
|
+
reject: reject
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
_proto.enqueue = function enqueue(request) {
|
|
935
|
+
var _this$queues$get,
|
|
936
|
+
_this2 = this;
|
|
937
|
+
var queueKey = this.getQueueKey(request.tip);
|
|
938
|
+
var queue = (_this$queues$get = this.queues.get(queueKey)) != null ? _this$queues$get : [];
|
|
939
|
+
if (!this.queues.has(queueKey)) {
|
|
940
|
+
this.queues.set(queueKey, queue);
|
|
941
|
+
}
|
|
942
|
+
queue.push(request);
|
|
943
|
+
if (!this.timeoutIds.has(queueKey)) {
|
|
944
|
+
var timeoutId = setTimeout(function () {
|
|
945
|
+
return _this2.processBatch(queueKey);
|
|
946
|
+
}, this.batchDelayMs);
|
|
947
|
+
this.timeoutIds.set(queueKey, timeoutId);
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
_proto.processBatch = /*#__PURE__*/function () {
|
|
951
|
+
var _processBatch = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(queueKey) {
|
|
952
|
+
var _this$queues$get2;
|
|
953
|
+
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;
|
|
954
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
955
|
+
while (1) switch (_context.prev = _context.next) {
|
|
956
|
+
case 0:
|
|
957
|
+
currentQueue = (_this$queues$get2 = this.queues.get(queueKey)) != null ? _this$queues$get2 : [];
|
|
958
|
+
this.queues["delete"](queueKey);
|
|
959
|
+
timeoutId = this.timeoutIds.get(queueKey);
|
|
960
|
+
if (timeoutId) {
|
|
961
|
+
clearTimeout(timeoutId);
|
|
962
|
+
this.timeoutIds["delete"](queueKey);
|
|
963
|
+
}
|
|
964
|
+
if (!(currentQueue.length === 0)) {
|
|
965
|
+
_context.next = 6;
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
return _context.abrupt("return");
|
|
969
|
+
case 6:
|
|
970
|
+
_context.prev = 6;
|
|
971
|
+
readonlyRequests = currentQueue.filter(function (q) {
|
|
972
|
+
return q.request.mode === 'readonly';
|
|
973
|
+
});
|
|
974
|
+
mapRequests = currentQueue.filter(function (q) {
|
|
975
|
+
return q.request.mode === 'mapEntry';
|
|
976
|
+
});
|
|
977
|
+
variableRequests = currentQueue.filter(function (q) {
|
|
978
|
+
return q.request.mode === 'variable';
|
|
979
|
+
});
|
|
980
|
+
tip = queueKey === '_undefined' ? undefined : queueKey;
|
|
981
|
+
batchRequest = {
|
|
982
|
+
readonly: readonlyRequests.map(function (_ref) {
|
|
983
|
+
var request = _ref.request;
|
|
984
|
+
return {
|
|
985
|
+
contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
|
|
986
|
+
functionName: request.functionName,
|
|
987
|
+
functionArgs: request.functionArgs
|
|
988
|
+
};
|
|
989
|
+
}),
|
|
990
|
+
maps: mapRequests.map(function (_ref2) {
|
|
991
|
+
var request = _ref2.request;
|
|
992
|
+
return {
|
|
993
|
+
contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
|
|
994
|
+
mapName: request.mapName,
|
|
995
|
+
mapKey: request.mapKey
|
|
996
|
+
};
|
|
997
|
+
}),
|
|
998
|
+
variables: variableRequests.map(function (_ref3) {
|
|
999
|
+
var request = _ref3.request;
|
|
1000
|
+
return {
|
|
1001
|
+
contract: transactions.contractPrincipalCV(request.contractAddress, request.contractName),
|
|
1002
|
+
variableName: request.variableName
|
|
1003
|
+
};
|
|
1004
|
+
}),
|
|
1005
|
+
index_block_hash: tip
|
|
1006
|
+
};
|
|
1007
|
+
_context.next = 14;
|
|
1008
|
+
return batchRead(batchRequest, {
|
|
1009
|
+
stxerApi: this.stxerAPIEndpoint
|
|
1010
|
+
});
|
|
1011
|
+
case 14:
|
|
1012
|
+
results = _context.sent;
|
|
1013
|
+
// Handle readonly results
|
|
1014
|
+
for (_iterator = _createForOfIteratorHelperLoose(results.readonly.entries()); !(_step = _iterator()).done;) {
|
|
1015
|
+
_step$value = _step.value, index = _step$value[0], result = _step$value[1];
|
|
1016
|
+
if (result instanceof Error) {
|
|
1017
|
+
readonlyRequests[index].reject(result);
|
|
1018
|
+
} else {
|
|
1019
|
+
readonlyRequests[index].resolve(result);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
// Handle variable results
|
|
1023
|
+
for (_iterator2 = _createForOfIteratorHelperLoose(results.vars.entries()); !(_step2 = _iterator2()).done;) {
|
|
1024
|
+
_step2$value = _step2.value, _index = _step2$value[0], _result = _step2$value[1];
|
|
1025
|
+
if (_result instanceof Error) {
|
|
1026
|
+
variableRequests[_index].reject(_result);
|
|
1027
|
+
} else {
|
|
1028
|
+
variableRequests[_index].resolve(_result);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
// Handle map results
|
|
1032
|
+
for (_iterator3 = _createForOfIteratorHelperLoose(results.maps.entries()); !(_step3 = _iterator3()).done;) {
|
|
1033
|
+
_step3$value = _step3.value, _index2 = _step3$value[0], _result2 = _step3$value[1];
|
|
1034
|
+
if (_result2 instanceof Error) {
|
|
1035
|
+
mapRequests[_index2].reject(_result2);
|
|
1036
|
+
} else {
|
|
1037
|
+
mapRequests[_index2].resolve(_result2);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
_context.next = 23;
|
|
1041
|
+
break;
|
|
1042
|
+
case 20:
|
|
1043
|
+
_context.prev = 20;
|
|
1044
|
+
_context.t0 = _context["catch"](6);
|
|
1045
|
+
for (_iterator4 = _createForOfIteratorHelperLoose(currentQueue); !(_step4 = _iterator4()).done;) {
|
|
1046
|
+
item = _step4.value;
|
|
1047
|
+
item.reject(_context.t0);
|
|
1048
|
+
}
|
|
1049
|
+
case 23:
|
|
1050
|
+
case "end":
|
|
1051
|
+
return _context.stop();
|
|
1052
|
+
}
|
|
1053
|
+
}, _callee, this, [[6, 20]]);
|
|
1054
|
+
}));
|
|
1055
|
+
function processBatch(_x) {
|
|
1056
|
+
return _processBatch.apply(this, arguments);
|
|
1057
|
+
}
|
|
1058
|
+
return processBatch;
|
|
1059
|
+
}();
|
|
1060
|
+
return BatchProcessor;
|
|
1061
|
+
}();
|
|
1062
|
+
|
|
1063
|
+
// Shared processor instance with default settings
|
|
1064
|
+
var defaultProcessor = /*#__PURE__*/new BatchProcessor({
|
|
1065
|
+
batchDelayMs: 100
|
|
1066
|
+
});
|
|
1067
|
+
function callReadonly(_x) {
|
|
1068
|
+
return _callReadonly.apply(this, arguments);
|
|
1069
|
+
}
|
|
1070
|
+
function _callReadonly() {
|
|
1071
|
+
_callReadonly = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
1072
|
+
var _params$batchProcesso;
|
|
1073
|
+
var processor, _params$contract$spli, deployer, contractName, fn, functionDef, argsKV, args, _iterator, _step, argDef;
|
|
1074
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1075
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1076
|
+
case 0:
|
|
1077
|
+
processor = (_params$batchProcesso = params.batchProcessor) != null ? _params$batchProcesso : defaultProcessor;
|
|
1078
|
+
_params$contract$spli = params.contract.split('.', 2), deployer = _params$contract$spli[0], contractName = _params$contract$spli[1];
|
|
1079
|
+
fn = String(params.functionName);
|
|
1080
|
+
functionDef = params.abi.find(function (def) {
|
|
1081
|
+
return def.name === params.functionName;
|
|
1082
|
+
});
|
|
1083
|
+
if (functionDef) {
|
|
1084
|
+
_context.next = 6;
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
throw new Error("failed to find function definition for " + params.functionName);
|
|
1088
|
+
case 6:
|
|
1089
|
+
argsKV = params.args;
|
|
1090
|
+
args = [];
|
|
1091
|
+
for (_iterator = _createForOfIteratorHelperLoose(functionDef.args); !(_step = _iterator()).done;) {
|
|
1092
|
+
argDef = _step.value;
|
|
1093
|
+
args.push(tsClarity.encodeAbi(argDef.type, argsKV[argDef.name]));
|
|
1094
|
+
}
|
|
1095
|
+
return _context.abrupt("return", new Promise(function (_resolve, reject) {
|
|
1096
|
+
processor.enqueue({
|
|
1097
|
+
request: {
|
|
1098
|
+
mode: 'readonly',
|
|
1099
|
+
contractAddress: deployer,
|
|
1100
|
+
contractName: contractName,
|
|
1101
|
+
functionName: fn,
|
|
1102
|
+
functionArgs: args
|
|
1103
|
+
},
|
|
1104
|
+
tip: params.indexBlockHash,
|
|
1105
|
+
resolve: function resolve(result) {
|
|
1106
|
+
try {
|
|
1107
|
+
var decoded = tsClarity.decodeAbi(functionDef.outputs.type, result);
|
|
1108
|
+
_resolve(decoded);
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
reject(error);
|
|
1111
|
+
}
|
|
1112
|
+
},
|
|
1113
|
+
reject: reject
|
|
1114
|
+
});
|
|
1115
|
+
}));
|
|
1116
|
+
case 10:
|
|
1117
|
+
case "end":
|
|
1118
|
+
return _context.stop();
|
|
1119
|
+
}
|
|
1120
|
+
}, _callee);
|
|
1121
|
+
}));
|
|
1122
|
+
return _callReadonly.apply(this, arguments);
|
|
1123
|
+
}
|
|
1124
|
+
function readMap(_x2) {
|
|
1125
|
+
return _readMap.apply(this, arguments);
|
|
1126
|
+
}
|
|
1127
|
+
function _readMap() {
|
|
1128
|
+
_readMap = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
1129
|
+
var _params$batchProcesso2;
|
|
1130
|
+
var processor, _params$contract$spli2, deployer, contractName, mapDef, key;
|
|
1131
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1132
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
processor = (_params$batchProcesso2 = params.batchProcessor) != null ? _params$batchProcesso2 : defaultProcessor;
|
|
1135
|
+
_params$contract$spli2 = params.contract.split('.', 2), deployer = _params$contract$spli2[0], contractName = _params$contract$spli2[1];
|
|
1136
|
+
mapDef = params.abi.find(function (m) {
|
|
1137
|
+
return m.name === params.mapName;
|
|
1138
|
+
});
|
|
1139
|
+
if (mapDef) {
|
|
1140
|
+
_context2.next = 5;
|
|
1141
|
+
break;
|
|
1142
|
+
}
|
|
1143
|
+
throw new Error("failed to find map definition for " + params.mapName);
|
|
1144
|
+
case 5:
|
|
1145
|
+
key = tsClarity.encodeAbi(mapDef.key, params.key);
|
|
1146
|
+
return _context2.abrupt("return", new Promise(function (_resolve2, reject) {
|
|
1147
|
+
processor.enqueue({
|
|
1148
|
+
request: {
|
|
1149
|
+
mode: 'mapEntry',
|
|
1150
|
+
contractAddress: deployer,
|
|
1151
|
+
contractName: contractName,
|
|
1152
|
+
mapName: params.mapName,
|
|
1153
|
+
mapKey: key
|
|
1154
|
+
},
|
|
1155
|
+
tip: params.indexBlockHash,
|
|
1156
|
+
resolve: function resolve(result) {
|
|
1157
|
+
try {
|
|
1158
|
+
if (result.type === transactions.ClarityType.OptionalNone) {
|
|
1159
|
+
_resolve2(null);
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
if (result.type !== transactions.ClarityType.OptionalSome) {
|
|
1163
|
+
throw new Error("unexpected map value: " + result);
|
|
1164
|
+
}
|
|
1165
|
+
var someCV = result;
|
|
1166
|
+
var decoded = tsClarity.decodeAbi(mapDef.value, someCV.value);
|
|
1167
|
+
_resolve2(decoded);
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
reject(error);
|
|
1170
|
+
}
|
|
1171
|
+
},
|
|
1172
|
+
reject: reject
|
|
1173
|
+
});
|
|
1174
|
+
}));
|
|
1175
|
+
case 7:
|
|
1176
|
+
case "end":
|
|
1177
|
+
return _context2.stop();
|
|
1178
|
+
}
|
|
1179
|
+
}, _callee2);
|
|
1180
|
+
}));
|
|
1181
|
+
return _readMap.apply(this, arguments);
|
|
1182
|
+
}
|
|
1183
|
+
function readVariable(_x3) {
|
|
1184
|
+
return _readVariable.apply(this, arguments);
|
|
1185
|
+
}
|
|
1186
|
+
function _readVariable() {
|
|
1187
|
+
_readVariable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
1188
|
+
var _params$batchProcesso3;
|
|
1189
|
+
var processor, _params$contract$spli3, deployer, contractName, varDef;
|
|
1190
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1191
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1192
|
+
case 0:
|
|
1193
|
+
processor = (_params$batchProcesso3 = params.batchProcessor) != null ? _params$batchProcesso3 : defaultProcessor;
|
|
1194
|
+
_params$contract$spli3 = params.contract.split('.', 2), deployer = _params$contract$spli3[0], contractName = _params$contract$spli3[1];
|
|
1195
|
+
varDef = params.abi.find(function (def) {
|
|
1196
|
+
return def.name === params.variableName;
|
|
1197
|
+
});
|
|
1198
|
+
if (varDef) {
|
|
1199
|
+
_context3.next = 5;
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
throw new Error("failed to find variable definition for " + params.variableName);
|
|
1203
|
+
case 5:
|
|
1204
|
+
return _context3.abrupt("return", new Promise(function (_resolve3, reject) {
|
|
1205
|
+
processor.enqueue({
|
|
1206
|
+
request: {
|
|
1207
|
+
mode: 'variable',
|
|
1208
|
+
contractAddress: deployer,
|
|
1209
|
+
contractName: contractName,
|
|
1210
|
+
variableName: params.variableName
|
|
1211
|
+
},
|
|
1212
|
+
tip: params.indexBlockHash,
|
|
1213
|
+
resolve: function resolve(result) {
|
|
1214
|
+
try {
|
|
1215
|
+
var decoded = tsClarity.decodeAbi(varDef.type, result);
|
|
1216
|
+
_resolve3(decoded);
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
reject(error);
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
reject: reject
|
|
1222
|
+
});
|
|
1223
|
+
}));
|
|
1224
|
+
case 6:
|
|
1225
|
+
case "end":
|
|
1226
|
+
return _context3.stop();
|
|
1227
|
+
}
|
|
1228
|
+
}, _callee3);
|
|
1229
|
+
}));
|
|
1230
|
+
return _readVariable.apply(this, arguments);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
966
1233
|
exports.SimulationBuilder = SimulationBuilder;
|
|
967
1234
|
exports.batchRead = batchRead;
|
|
968
|
-
exports.
|
|
1235
|
+
exports.callReadonly = callReadonly;
|
|
1236
|
+
exports.readMap = readMap;
|
|
1237
|
+
exports.readVariable = readVariable;
|
|
969
1238
|
exports.runEval = runEval;
|
|
970
1239
|
exports.runSimulation = runSimulation;
|
|
971
1240
|
//# sourceMappingURL=stxer.cjs.development.js.map
|