@clarigen/core 0.3.2 → 1.0.0-next.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/api.d.ts +15 -0
- package/dist/base-provider.d.ts +1 -1
- package/dist/clarity-types.d.ts +21 -33
- package/dist/contracts.d.ts +6 -0
- package/dist/core.cjs.development.js +321 -52
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +269 -9
- package/dist/core.esm.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/pure/index.d.ts +36 -0
- package/dist/transaction.d.ts +5 -1
- package/dist/types.d.ts +5 -4
- package/dist/utils.d.ts +1 -1
- package/package.json +5 -8
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StacksNetwork } from 'micro-stacks/network';
|
|
2
|
+
import { StacksTransaction } from 'micro-stacks/transactions';
|
|
3
|
+
import { ClarityTypes } from './clarity-types';
|
|
4
|
+
import { ContractCall } from './pure';
|
|
5
|
+
interface ApiOptions {
|
|
6
|
+
network: StacksNetwork;
|
|
7
|
+
}
|
|
8
|
+
export declare function ro<T>(tx: ContractCall<T>, options: ApiOptions): Promise<T>;
|
|
9
|
+
export declare function roOk<Ok>(tx: ContractCall<ClarityTypes.Response<Ok, any>>, options: ApiOptions): Promise<Ok>;
|
|
10
|
+
export declare function roErr<Err>(tx: ContractCall<ClarityTypes.Response<any, Err>>, options: ApiOptions): Promise<Err>;
|
|
11
|
+
export declare function broadcast(transaction: StacksTransaction, options: ApiOptions): Promise<{
|
|
12
|
+
txId: string;
|
|
13
|
+
stacksTransaction: StacksTransaction;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
package/dist/base-provider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClarityAbiFunction } from '
|
|
1
|
+
import { ClarityAbiFunction } from 'micro-stacks/clarity';
|
|
2
2
|
import { Transaction } from './transaction';
|
|
3
3
|
export declare abstract class BaseProvider {
|
|
4
4
|
callReadOnly(func: ClarityAbiFunction, args: any[]): Promise<void>;
|
package/dist/clarity-types.d.ts
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ClarityAbi as _ClarityAbi, ClarityAbiType, ClarityAbiTypeTuple, ClarityValue } from '@stacks/transactions';
|
|
1
|
+
import { ClarityAbi as _ClarityAbi, ClarityAbiType, ClarityValue, ClarityAbiFunction } from 'micro-stacks/clarity';
|
|
3
2
|
import { Result } from 'neverthrow';
|
|
3
|
+
export declare namespace ClarityTypes {
|
|
4
|
+
type Response<Ok, Err> = Result<Ok, Err>;
|
|
5
|
+
}
|
|
4
6
|
export interface ClarityAbiMap {
|
|
5
7
|
name: string;
|
|
6
|
-
key:
|
|
7
|
-
|
|
8
|
-
type: ClarityAbiType;
|
|
9
|
-
}[] | ClarityAbiTypeTuple | ClarityAbiType;
|
|
10
|
-
value: {
|
|
11
|
-
name: string;
|
|
12
|
-
type: ClarityAbiType;
|
|
13
|
-
}[] | ClarityAbiTypeTuple | ClarityAbiType;
|
|
8
|
+
key: ClarityAbiType;
|
|
9
|
+
value: ClarityAbiType;
|
|
14
10
|
}
|
|
15
11
|
export interface ClarityAbi extends Omit<_ClarityAbi, 'maps'> {
|
|
16
12
|
maps: ClarityAbiMap[];
|
|
17
13
|
clarity_version?: string;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type ResponseErrorCV = Clarity.ResponseErrorCV;
|
|
32
|
-
type PrincipalCV = Clarity.PrincipalCV;
|
|
33
|
-
type StandardPrincipalCV = Clarity.StandardPrincipalCV;
|
|
34
|
-
type ContractPrincipalCV = Clarity.ContractPrincipalCV;
|
|
35
|
-
type ListCV = Clarity.ListCV;
|
|
36
|
-
type TupleCV = Clarity.TupleCV;
|
|
37
|
-
type StringAsciiCV = Clarity.StringAsciiCV;
|
|
38
|
-
type StringUtf8CV = Clarity.StringUtf8CV;
|
|
39
|
-
type Response<Ok, Err> = Result<Ok, Err>;
|
|
40
|
-
}
|
|
41
|
-
export declare function cvToValue(val: ClarityValue): any;
|
|
15
|
+
/**
|
|
16
|
+
* @param val - ClarityValue
|
|
17
|
+
* @param returnResponse - if true, this will return a "response" object from the `neverthrow`
|
|
18
|
+
* library. Otherwise, it returns the inner value of the response (whether ok or err)
|
|
19
|
+
*/
|
|
20
|
+
export declare function cvToValue<T = any>(val: ClarityValue, returnResponse?: boolean): T;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a hex encoded string to the javascript clarity value object {type: string; value: any}
|
|
23
|
+
* @param hex - the hex encoded string with or without `0x` prefix
|
|
24
|
+
* @param jsonCompat - enable to serialize bigints to strings
|
|
25
|
+
*/
|
|
26
|
+
export declare function hexToCvValue<T>(hex: string, jsonCompat?: boolean): any;
|
|
42
27
|
declare type TupleInput = Record<string, any>;
|
|
43
28
|
declare type CVInput = string | boolean | TupleInput | number | bigint;
|
|
44
29
|
export declare function parseToCV(input: CVInput, type: ClarityAbiType): ClarityValue;
|
|
45
30
|
export declare function cvToString(val: ClarityValue, encoding?: 'tryAscii' | 'hex'): string;
|
|
31
|
+
export declare function transformArgsToCV(func: ClarityAbiFunction, args: any[]): ClarityValue[];
|
|
32
|
+
export declare function expectOk<Ok>(response: ClarityTypes.Response<Ok, any>): Ok;
|
|
33
|
+
export declare function expectErr<Err>(response: ClarityTypes.Response<any, Err>): Err;
|
|
46
34
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Contracts, ContractInstances } from './types';
|
|
2
|
+
interface MakeContractsOptions {
|
|
3
|
+
deployerAddress?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function makeContracts<T extends Contracts<any>>(contracts: T, options?: MakeContractsOptions): ContractInstances<T>;
|
|
6
|
+
export {};
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var clarity = require('micro-stacks/clarity');
|
|
6
|
+
var transactions = require('micro-stacks/transactions');
|
|
7
|
+
var common = require('micro-stacks/common');
|
|
8
|
+
var neverthrow = require('neverthrow');
|
|
9
|
+
var api = require('micro-stacks/api');
|
|
6
10
|
|
|
7
11
|
var TESTNET_BURN_ADDRESS = 'ST000000000000000000002AMW42H';
|
|
8
12
|
var MAINNET_BURN_ADDRESS = 'SP000000000000000000002Q6VF78';
|
|
@@ -35,7 +39,7 @@ var getContractIdentifier = function getContractIdentifier(contract) {
|
|
|
35
39
|
};
|
|
36
40
|
var getContractPrincipalCV = function getContractPrincipalCV(contract) {
|
|
37
41
|
var contractName = getContractNameFromPath(contract.contractFile);
|
|
38
|
-
return
|
|
42
|
+
return clarity.contractPrincipalCV(contract.address, contractName);
|
|
39
43
|
};
|
|
40
44
|
function bootContractIdentifier(name, mainnet) {
|
|
41
45
|
var addr = mainnet ? MAINNET_BURN_ADDRESS : TESTNET_BURN_ADDRESS;
|
|
@@ -56,69 +60,118 @@ function bootContractIdentifier(name, mainnet) {
|
|
|
56
60
|
CoreNodeEventType["FtBurnEvent"] = "ft_burn_event";
|
|
57
61
|
})(exports.CoreNodeEventType || (exports.CoreNodeEventType = {}));
|
|
58
62
|
|
|
63
|
+
function makeContracts(contracts, options) {
|
|
64
|
+
if (options === void 0) {
|
|
65
|
+
options = {};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var instances = {};
|
|
69
|
+
|
|
70
|
+
for (var k in contracts) {
|
|
71
|
+
var contract = contracts[k];
|
|
72
|
+
var address = options.deployerAddress || contract.address;
|
|
73
|
+
var identifier = address + "." + contract.name;
|
|
74
|
+
var instance = contract.contract(address, contract.name);
|
|
75
|
+
instances[k] = {
|
|
76
|
+
identifier: identifier,
|
|
77
|
+
contract: instance
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return instances;
|
|
82
|
+
}
|
|
83
|
+
|
|
59
84
|
function principalToString(principal) {
|
|
60
|
-
if (principal.type ===
|
|
61
|
-
return
|
|
62
|
-
} else if (principal.type ===
|
|
63
|
-
var address =
|
|
85
|
+
if (principal.type === clarity.ClarityType.PrincipalStandard) {
|
|
86
|
+
return clarity.addressToString(principal.address);
|
|
87
|
+
} else if (principal.type === clarity.ClarityType.PrincipalContract) {
|
|
88
|
+
var address = clarity.addressToString(principal.address);
|
|
64
89
|
return address + "." + principal.contractName.content;
|
|
65
90
|
} else {
|
|
66
91
|
throw new Error("Unexpected principal data: " + JSON.stringify(principal));
|
|
67
92
|
}
|
|
68
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* @param val - ClarityValue
|
|
96
|
+
* @param returnResponse - if true, this will return a "response" object from the `neverthrow`
|
|
97
|
+
* library. Otherwise, it returns the inner value of the response (whether ok or err)
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
function cvToValue(val, returnResponse) {
|
|
102
|
+
if (returnResponse === void 0) {
|
|
103
|
+
returnResponse = false;
|
|
104
|
+
}
|
|
69
105
|
|
|
70
|
-
function cvToValue(val) {
|
|
71
106
|
switch (val.type) {
|
|
72
|
-
case
|
|
107
|
+
case clarity.ClarityType.BoolTrue:
|
|
73
108
|
return true;
|
|
74
109
|
|
|
75
|
-
case
|
|
110
|
+
case clarity.ClarityType.BoolFalse:
|
|
76
111
|
return false;
|
|
77
112
|
|
|
78
|
-
case
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case transactions.ClarityType.UInt:
|
|
113
|
+
case clarity.ClarityType.Int:
|
|
114
|
+
case clarity.ClarityType.UInt:
|
|
82
115
|
return val.value;
|
|
83
116
|
|
|
84
|
-
case
|
|
117
|
+
case clarity.ClarityType.Buffer:
|
|
85
118
|
return val.buffer;
|
|
86
119
|
|
|
87
|
-
case
|
|
120
|
+
case clarity.ClarityType.OptionalNone:
|
|
88
121
|
return null;
|
|
89
122
|
|
|
90
|
-
case
|
|
123
|
+
case clarity.ClarityType.OptionalSome:
|
|
91
124
|
return cvToValue(val.value);
|
|
92
125
|
|
|
93
|
-
case
|
|
126
|
+
case clarity.ClarityType.ResponseErr:
|
|
127
|
+
if (returnResponse) return neverthrow.err(cvToValue(val.value));
|
|
94
128
|
return cvToValue(val.value);
|
|
95
129
|
|
|
96
|
-
case
|
|
130
|
+
case clarity.ClarityType.ResponseOk:
|
|
131
|
+
if (returnResponse) return neverthrow.ok(cvToValue(val.value));
|
|
97
132
|
return cvToValue(val.value);
|
|
98
133
|
|
|
99
|
-
case
|
|
100
|
-
case
|
|
134
|
+
case clarity.ClarityType.PrincipalStandard:
|
|
135
|
+
case clarity.ClarityType.PrincipalContract:
|
|
101
136
|
return principalToString(val);
|
|
102
137
|
|
|
103
|
-
case
|
|
138
|
+
case clarity.ClarityType.List:
|
|
104
139
|
return val.list.map(function (v) {
|
|
105
140
|
return cvToValue(v);
|
|
106
141
|
});
|
|
107
142
|
|
|
108
|
-
case
|
|
143
|
+
case clarity.ClarityType.Tuple:
|
|
109
144
|
var result = {};
|
|
110
|
-
Object.keys(val.data).
|
|
111
|
-
|
|
145
|
+
var arr = Object.keys(val.data).map(function (key) {
|
|
146
|
+
return [key, cvToValue(val.data[key])];
|
|
147
|
+
});
|
|
148
|
+
arr.forEach(function (_ref) {
|
|
149
|
+
var key = _ref[0],
|
|
150
|
+
value = _ref[1];
|
|
151
|
+
result[key] = value;
|
|
112
152
|
});
|
|
113
153
|
return result;
|
|
114
154
|
|
|
115
|
-
case
|
|
155
|
+
case clarity.ClarityType.StringASCII:
|
|
116
156
|
return val.data;
|
|
117
157
|
|
|
118
|
-
case
|
|
158
|
+
case clarity.ClarityType.StringUTF8:
|
|
119
159
|
return val.data;
|
|
120
160
|
}
|
|
121
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts a hex encoded string to the javascript clarity value object {type: string; value: any}
|
|
164
|
+
* @param hex - the hex encoded string with or without `0x` prefix
|
|
165
|
+
* @param jsonCompat - enable to serialize bigints to strings
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
function hexToCvValue(hex, jsonCompat) {
|
|
169
|
+
if (jsonCompat === void 0) {
|
|
170
|
+
jsonCompat = false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return cvToValue(clarity.hexToCV(hex), jsonCompat);
|
|
174
|
+
}
|
|
122
175
|
|
|
123
176
|
function inputToBigInt(input) {
|
|
124
177
|
var isBigInt = typeof input === 'bigint';
|
|
@@ -144,38 +197,38 @@ function parseToCV(input, type) {
|
|
|
144
197
|
var val = input[key.name];
|
|
145
198
|
tuple[key.name] = parseToCV(val, key.type);
|
|
146
199
|
});
|
|
147
|
-
return
|
|
200
|
+
return clarity.tupleCV(tuple);
|
|
148
201
|
} else if (transactions.isClarityAbiList(type)) {
|
|
149
202
|
var inputs = input;
|
|
150
203
|
var values = inputs.map(function (input) {
|
|
151
204
|
return parseToCV(input, type.list.type);
|
|
152
205
|
});
|
|
153
|
-
return
|
|
206
|
+
return clarity.listCV(values);
|
|
154
207
|
} else if (transactions.isClarityAbiOptional(type)) {
|
|
155
|
-
if (!input) return
|
|
156
|
-
return
|
|
208
|
+
if (!input) return clarity.noneCV();
|
|
209
|
+
return clarity.someCV(parseToCV(input, type.optional));
|
|
157
210
|
} else if (transactions.isClarityAbiStringAscii(type)) {
|
|
158
211
|
if (typeof input !== 'string') {
|
|
159
212
|
throw new Error('Invalid string-ascii input');
|
|
160
213
|
}
|
|
161
214
|
|
|
162
|
-
return
|
|
215
|
+
return clarity.stringAsciiCV(input);
|
|
163
216
|
} else if (transactions.isClarityAbiStringUtf8(type)) {
|
|
164
217
|
if (typeof input !== 'string') {
|
|
165
218
|
throw new Error('Invalid string-ascii input');
|
|
166
219
|
}
|
|
167
220
|
|
|
168
|
-
return
|
|
221
|
+
return clarity.stringUtf8CV(input);
|
|
169
222
|
} else if (type === 'bool') {
|
|
170
223
|
var inputString = typeof input === 'boolean' ? input.toString() : input;
|
|
171
224
|
return transactions.parseToCV(inputString, type);
|
|
172
225
|
} else if (type === 'uint128') {
|
|
173
226
|
var bigi = inputToBigInt(input);
|
|
174
|
-
return
|
|
227
|
+
return clarity.uintCV(bigi.toString());
|
|
175
228
|
} else if (type === 'int128') {
|
|
176
229
|
var _bigi = inputToBigInt(input);
|
|
177
230
|
|
|
178
|
-
return
|
|
231
|
+
return clarity.intCV(_bigi.toString());
|
|
179
232
|
} else if (type === 'trait_reference') {
|
|
180
233
|
if (typeof input !== 'string') throw new Error('Invalid input for trait_reference');
|
|
181
234
|
|
|
@@ -183,7 +236,9 @@ function parseToCV(input, type) {
|
|
|
183
236
|
addr = _input$split[0],
|
|
184
237
|
name = _input$split[1];
|
|
185
238
|
|
|
186
|
-
return
|
|
239
|
+
return clarity.contractPrincipalCV(addr, name);
|
|
240
|
+
} else if (transactions.isClarityAbiBuffer(type)) {
|
|
241
|
+
return clarity.bufferCV(input);
|
|
187
242
|
}
|
|
188
243
|
|
|
189
244
|
return transactions.parseToCV(input, type);
|
|
@@ -194,62 +249,136 @@ function cvToString(val, encoding) {
|
|
|
194
249
|
}
|
|
195
250
|
|
|
196
251
|
switch (val.type) {
|
|
197
|
-
case
|
|
252
|
+
case clarity.ClarityType.BoolTrue:
|
|
198
253
|
return 'true';
|
|
199
254
|
|
|
200
|
-
case
|
|
255
|
+
case clarity.ClarityType.BoolFalse:
|
|
201
256
|
return 'false';
|
|
202
257
|
|
|
203
|
-
case
|
|
258
|
+
case clarity.ClarityType.Int:
|
|
204
259
|
return val.value.toString();
|
|
205
260
|
|
|
206
|
-
case
|
|
261
|
+
case clarity.ClarityType.UInt:
|
|
207
262
|
return "u" + val.value.toString();
|
|
208
263
|
|
|
209
|
-
case
|
|
264
|
+
case clarity.ClarityType.Buffer:
|
|
210
265
|
if (encoding === 'tryAscii') {
|
|
211
|
-
var str = val.buffer
|
|
266
|
+
var str = common.bytesToAscii(val.buffer);
|
|
212
267
|
|
|
213
268
|
if (/[ -~]/.test(str)) {
|
|
214
269
|
return JSON.stringify(str);
|
|
215
270
|
}
|
|
216
271
|
}
|
|
217
272
|
|
|
218
|
-
return "0x" + val.buffer
|
|
273
|
+
return "0x" + common.bytesToHex(val.buffer);
|
|
219
274
|
|
|
220
|
-
case
|
|
275
|
+
case clarity.ClarityType.OptionalNone:
|
|
221
276
|
return 'none';
|
|
222
277
|
|
|
223
|
-
case
|
|
278
|
+
case clarity.ClarityType.OptionalSome:
|
|
224
279
|
return "(some " + cvToString(val.value, encoding) + ")";
|
|
225
280
|
|
|
226
|
-
case
|
|
281
|
+
case clarity.ClarityType.ResponseErr:
|
|
227
282
|
return "(err " + cvToString(val.value, encoding) + ")";
|
|
228
283
|
|
|
229
|
-
case
|
|
284
|
+
case clarity.ClarityType.ResponseOk:
|
|
230
285
|
return "(ok " + cvToString(val.value, encoding) + ")";
|
|
231
286
|
|
|
232
|
-
case
|
|
233
|
-
case
|
|
287
|
+
case clarity.ClarityType.PrincipalStandard:
|
|
288
|
+
case clarity.ClarityType.PrincipalContract:
|
|
234
289
|
return "'" + principalToString(val);
|
|
235
290
|
|
|
236
|
-
case
|
|
291
|
+
case clarity.ClarityType.List:
|
|
237
292
|
return "(list " + val.list.map(function (v) {
|
|
238
293
|
return cvToString(v, encoding);
|
|
239
294
|
}).join(' ') + ")";
|
|
240
295
|
|
|
241
|
-
case
|
|
296
|
+
case clarity.ClarityType.Tuple:
|
|
242
297
|
return "(tuple " + Object.keys(val.data).map(function (key) {
|
|
243
298
|
return "(" + key + " " + cvToString(val.data[key], encoding) + ")";
|
|
244
299
|
}).join(' ') + ")";
|
|
245
300
|
|
|
246
|
-
case
|
|
301
|
+
case clarity.ClarityType.StringASCII:
|
|
247
302
|
return "\"" + val.data + "\"";
|
|
248
303
|
|
|
249
|
-
case
|
|
304
|
+
case clarity.ClarityType.StringUTF8:
|
|
250
305
|
return "u\"" + val.data + "\"";
|
|
251
306
|
}
|
|
252
307
|
}
|
|
308
|
+
function transformArgsToCV(func, args) {
|
|
309
|
+
return args.map(function (arg, index) {
|
|
310
|
+
return parseToCV(arg, func.args[index].type);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function expectOk(response) {
|
|
314
|
+
return response.match(function (ok) {
|
|
315
|
+
return ok;
|
|
316
|
+
}, function (err) {
|
|
317
|
+
throw new Error("Expected OK, received error: " + err);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function expectErr(response) {
|
|
321
|
+
return response.match(function (ok) {
|
|
322
|
+
throw new Error("Expected Err, received Ok: " + ok);
|
|
323
|
+
}, function (err) {
|
|
324
|
+
return err;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function transformArguments(func, args) {
|
|
329
|
+
return transformArgsToCV(func, args);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function getter(contract, property) {
|
|
333
|
+
var foundFunction = contract.abi.functions.find(function (func) {
|
|
334
|
+
return toCamelCase(func.name) === property;
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (foundFunction) {
|
|
338
|
+
return function () {
|
|
339
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
340
|
+
args[_key] = arguments[_key];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
var functionArgs = transformArguments(foundFunction, args);
|
|
344
|
+
return {
|
|
345
|
+
functionArgs: functionArgs,
|
|
346
|
+
contractAddress: contract.contractAddress,
|
|
347
|
+
contractName: contract.contractName,
|
|
348
|
+
"function": foundFunction,
|
|
349
|
+
nativeArgs: args
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
var foundMap = contract.abi.maps.find(function (map) {
|
|
355
|
+
return toCamelCase(map.name) === property;
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (foundMap) {
|
|
359
|
+
return function (key) {
|
|
360
|
+
var keyCV = parseToCV(key, foundMap.key);
|
|
361
|
+
var mapGet = {
|
|
362
|
+
contractAddress: contract.contractAddress,
|
|
363
|
+
contractName: contract.contractName,
|
|
364
|
+
map: foundMap,
|
|
365
|
+
nativeKey: key,
|
|
366
|
+
key: keyCV
|
|
367
|
+
};
|
|
368
|
+
return mapGet;
|
|
369
|
+
};
|
|
370
|
+
} // TODO: variables, tokens
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
throw new Error("Invalid function call: no function exists for " + String(property));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
var proxyHandler = {
|
|
377
|
+
get: getter
|
|
378
|
+
};
|
|
379
|
+
var pureProxy = function pureProxy(target) {
|
|
380
|
+
return new Proxy(target, proxyHandler);
|
|
381
|
+
};
|
|
253
382
|
|
|
254
383
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
255
384
|
try {
|
|
@@ -1053,6 +1182,137 @@ var BaseProvider = /*#__PURE__*/function () {
|
|
|
1053
1182
|
return BaseProvider;
|
|
1054
1183
|
}();
|
|
1055
1184
|
|
|
1185
|
+
function ro(_x, _x2) {
|
|
1186
|
+
return _ro.apply(this, arguments);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function _ro() {
|
|
1190
|
+
_ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, options) {
|
|
1191
|
+
var result;
|
|
1192
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1193
|
+
while (1) {
|
|
1194
|
+
switch (_context.prev = _context.next) {
|
|
1195
|
+
case 0:
|
|
1196
|
+
_context.next = 2;
|
|
1197
|
+
return api.callReadOnlyFunction({
|
|
1198
|
+
contractAddress: tx.contractAddress,
|
|
1199
|
+
contractName: tx.contractName,
|
|
1200
|
+
functionArgs: tx.functionArgs,
|
|
1201
|
+
functionName: tx["function"].name,
|
|
1202
|
+
network: options.network,
|
|
1203
|
+
tip: 'latest'
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
case 2:
|
|
1207
|
+
result = _context.sent;
|
|
1208
|
+
return _context.abrupt("return", cvToValue(result, true));
|
|
1209
|
+
|
|
1210
|
+
case 4:
|
|
1211
|
+
case "end":
|
|
1212
|
+
return _context.stop();
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}, _callee);
|
|
1216
|
+
}));
|
|
1217
|
+
return _ro.apply(this, arguments);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
function roOk(_x3, _x4) {
|
|
1221
|
+
return _roOk.apply(this, arguments);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
function _roOk() {
|
|
1225
|
+
_roOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tx, options) {
|
|
1226
|
+
var result;
|
|
1227
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1228
|
+
while (1) {
|
|
1229
|
+
switch (_context2.prev = _context2.next) {
|
|
1230
|
+
case 0:
|
|
1231
|
+
_context2.next = 2;
|
|
1232
|
+
return ro(tx, options);
|
|
1233
|
+
|
|
1234
|
+
case 2:
|
|
1235
|
+
result = _context2.sent;
|
|
1236
|
+
return _context2.abrupt("return", expectOk(result));
|
|
1237
|
+
|
|
1238
|
+
case 4:
|
|
1239
|
+
case "end":
|
|
1240
|
+
return _context2.stop();
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}, _callee2);
|
|
1244
|
+
}));
|
|
1245
|
+
return _roOk.apply(this, arguments);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
function roErr(_x5, _x6) {
|
|
1249
|
+
return _roErr.apply(this, arguments);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function _roErr() {
|
|
1253
|
+
_roErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx, options) {
|
|
1254
|
+
var result;
|
|
1255
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1256
|
+
while (1) {
|
|
1257
|
+
switch (_context3.prev = _context3.next) {
|
|
1258
|
+
case 0:
|
|
1259
|
+
_context3.next = 2;
|
|
1260
|
+
return ro(tx, options);
|
|
1261
|
+
|
|
1262
|
+
case 2:
|
|
1263
|
+
result = _context3.sent;
|
|
1264
|
+
return _context3.abrupt("return", expectErr(result));
|
|
1265
|
+
|
|
1266
|
+
case 4:
|
|
1267
|
+
case "end":
|
|
1268
|
+
return _context3.stop();
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}, _callee3);
|
|
1272
|
+
}));
|
|
1273
|
+
return _roErr.apply(this, arguments);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
function broadcast(_x7, _x8) {
|
|
1277
|
+
return _broadcast.apply(this, arguments);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
function _broadcast() {
|
|
1281
|
+
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(transaction, options) {
|
|
1282
|
+
var result;
|
|
1283
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1284
|
+
while (1) {
|
|
1285
|
+
switch (_context4.prev = _context4.next) {
|
|
1286
|
+
case 0:
|
|
1287
|
+
_context4.next = 2;
|
|
1288
|
+
return transactions.broadcastTransaction(transaction, options.network);
|
|
1289
|
+
|
|
1290
|
+
case 2:
|
|
1291
|
+
result = _context4.sent;
|
|
1292
|
+
|
|
1293
|
+
if (!('error' in result)) {
|
|
1294
|
+
_context4.next = 7;
|
|
1295
|
+
break;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
throw new Error("Error broadcasting tx: " + result.error + " - " + result.reason + " - " + result.reason_data);
|
|
1299
|
+
|
|
1300
|
+
case 7:
|
|
1301
|
+
return _context4.abrupt("return", {
|
|
1302
|
+
txId: result.txid,
|
|
1303
|
+
stacksTransaction: transaction
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
case 8:
|
|
1307
|
+
case "end":
|
|
1308
|
+
return _context4.stop();
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}, _callee4);
|
|
1312
|
+
}));
|
|
1313
|
+
return _broadcast.apply(this, arguments);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1056
1316
|
var makeHandler = function makeHandler(provider) {
|
|
1057
1317
|
var handler = {
|
|
1058
1318
|
get: function get(contract, property) {
|
|
@@ -1094,12 +1354,21 @@ exports.BaseProvider = BaseProvider;
|
|
|
1094
1354
|
exports.MAINNET_BURN_ADDRESS = MAINNET_BURN_ADDRESS;
|
|
1095
1355
|
exports.TESTNET_BURN_ADDRESS = TESTNET_BURN_ADDRESS;
|
|
1096
1356
|
exports.bootContractIdentifier = bootContractIdentifier;
|
|
1357
|
+
exports.broadcast = broadcast;
|
|
1097
1358
|
exports.cvToString = cvToString;
|
|
1098
1359
|
exports.cvToValue = cvToValue;
|
|
1360
|
+
exports.expectErr = expectErr;
|
|
1361
|
+
exports.expectOk = expectOk;
|
|
1099
1362
|
exports.getContractIdentifier = getContractIdentifier;
|
|
1100
1363
|
exports.getContractNameFromPath = getContractNameFromPath;
|
|
1101
1364
|
exports.getContractPrincipalCV = getContractPrincipalCV;
|
|
1365
|
+
exports.hexToCvValue = hexToCvValue;
|
|
1366
|
+
exports.makeContracts = makeContracts;
|
|
1102
1367
|
exports.parseToCV = parseToCV;
|
|
1103
1368
|
exports.proxy = proxy;
|
|
1369
|
+
exports.pureProxy = pureProxy;
|
|
1370
|
+
exports.ro = ro;
|
|
1371
|
+
exports.roErr = roErr;
|
|
1372
|
+
exports.roOk = roOk;
|
|
1104
1373
|
exports.toCamelCase = toCamelCase;
|
|
1105
1374
|
//# sourceMappingURL=core.cjs.development.js.map
|