@clarigen/core 0.3.1 → 1.0.0-next.4
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 +327 -51
- 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 +276 -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 -3
- 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,48 @@ 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());
|
|
232
|
+
} else if (type === 'trait_reference') {
|
|
233
|
+
if (typeof input !== 'string') throw new Error('Invalid input for trait_reference');
|
|
234
|
+
|
|
235
|
+
var _input$split = input.split('.'),
|
|
236
|
+
addr = _input$split[0],
|
|
237
|
+
name = _input$split[1];
|
|
238
|
+
|
|
239
|
+
return clarity.contractPrincipalCV(addr, name);
|
|
240
|
+
} else if (transactions.isClarityAbiBuffer(type)) {
|
|
241
|
+
return clarity.bufferCV(input);
|
|
179
242
|
}
|
|
180
243
|
|
|
181
244
|
return transactions.parseToCV(input, type);
|
|
@@ -186,62 +249,136 @@ function cvToString(val, encoding) {
|
|
|
186
249
|
}
|
|
187
250
|
|
|
188
251
|
switch (val.type) {
|
|
189
|
-
case
|
|
252
|
+
case clarity.ClarityType.BoolTrue:
|
|
190
253
|
return 'true';
|
|
191
254
|
|
|
192
|
-
case
|
|
255
|
+
case clarity.ClarityType.BoolFalse:
|
|
193
256
|
return 'false';
|
|
194
257
|
|
|
195
|
-
case
|
|
258
|
+
case clarity.ClarityType.Int:
|
|
196
259
|
return val.value.toString();
|
|
197
260
|
|
|
198
|
-
case
|
|
261
|
+
case clarity.ClarityType.UInt:
|
|
199
262
|
return "u" + val.value.toString();
|
|
200
263
|
|
|
201
|
-
case
|
|
264
|
+
case clarity.ClarityType.Buffer:
|
|
202
265
|
if (encoding === 'tryAscii') {
|
|
203
|
-
var str = val.buffer
|
|
266
|
+
var str = common.bytesToAscii(val.buffer);
|
|
204
267
|
|
|
205
268
|
if (/[ -~]/.test(str)) {
|
|
206
269
|
return JSON.stringify(str);
|
|
207
270
|
}
|
|
208
271
|
}
|
|
209
272
|
|
|
210
|
-
return "0x" + val.buffer
|
|
273
|
+
return "0x" + common.bytesToHex(val.buffer);
|
|
211
274
|
|
|
212
|
-
case
|
|
275
|
+
case clarity.ClarityType.OptionalNone:
|
|
213
276
|
return 'none';
|
|
214
277
|
|
|
215
|
-
case
|
|
278
|
+
case clarity.ClarityType.OptionalSome:
|
|
216
279
|
return "(some " + cvToString(val.value, encoding) + ")";
|
|
217
280
|
|
|
218
|
-
case
|
|
281
|
+
case clarity.ClarityType.ResponseErr:
|
|
219
282
|
return "(err " + cvToString(val.value, encoding) + ")";
|
|
220
283
|
|
|
221
|
-
case
|
|
284
|
+
case clarity.ClarityType.ResponseOk:
|
|
222
285
|
return "(ok " + cvToString(val.value, encoding) + ")";
|
|
223
286
|
|
|
224
|
-
case
|
|
225
|
-
case
|
|
287
|
+
case clarity.ClarityType.PrincipalStandard:
|
|
288
|
+
case clarity.ClarityType.PrincipalContract:
|
|
226
289
|
return "'" + principalToString(val);
|
|
227
290
|
|
|
228
|
-
case
|
|
291
|
+
case clarity.ClarityType.List:
|
|
229
292
|
return "(list " + val.list.map(function (v) {
|
|
230
293
|
return cvToString(v, encoding);
|
|
231
294
|
}).join(' ') + ")";
|
|
232
295
|
|
|
233
|
-
case
|
|
296
|
+
case clarity.ClarityType.Tuple:
|
|
234
297
|
return "(tuple " + Object.keys(val.data).map(function (key) {
|
|
235
298
|
return "(" + key + " " + cvToString(val.data[key], encoding) + ")";
|
|
236
299
|
}).join(' ') + ")";
|
|
237
300
|
|
|
238
|
-
case
|
|
301
|
+
case clarity.ClarityType.StringASCII:
|
|
239
302
|
return "\"" + val.data + "\"";
|
|
240
303
|
|
|
241
|
-
case
|
|
304
|
+
case clarity.ClarityType.StringUTF8:
|
|
242
305
|
return "u\"" + val.data + "\"";
|
|
243
306
|
}
|
|
244
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
|
+
};
|
|
245
382
|
|
|
246
383
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
247
384
|
try {
|
|
@@ -1045,6 +1182,136 @@ var BaseProvider = /*#__PURE__*/function () {
|
|
|
1045
1182
|
return BaseProvider;
|
|
1046
1183
|
}();
|
|
1047
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
|
+
});
|
|
1204
|
+
|
|
1205
|
+
case 2:
|
|
1206
|
+
result = _context.sent;
|
|
1207
|
+
return _context.abrupt("return", cvToValue(result, true));
|
|
1208
|
+
|
|
1209
|
+
case 4:
|
|
1210
|
+
case "end":
|
|
1211
|
+
return _context.stop();
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}, _callee);
|
|
1215
|
+
}));
|
|
1216
|
+
return _ro.apply(this, arguments);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function roOk(_x3, _x4) {
|
|
1220
|
+
return _roOk.apply(this, arguments);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
function _roOk() {
|
|
1224
|
+
_roOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tx, options) {
|
|
1225
|
+
var result;
|
|
1226
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1227
|
+
while (1) {
|
|
1228
|
+
switch (_context2.prev = _context2.next) {
|
|
1229
|
+
case 0:
|
|
1230
|
+
_context2.next = 2;
|
|
1231
|
+
return ro(tx, options);
|
|
1232
|
+
|
|
1233
|
+
case 2:
|
|
1234
|
+
result = _context2.sent;
|
|
1235
|
+
return _context2.abrupt("return", expectOk(result));
|
|
1236
|
+
|
|
1237
|
+
case 4:
|
|
1238
|
+
case "end":
|
|
1239
|
+
return _context2.stop();
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}, _callee2);
|
|
1243
|
+
}));
|
|
1244
|
+
return _roOk.apply(this, arguments);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function roErr(_x5, _x6) {
|
|
1248
|
+
return _roErr.apply(this, arguments);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function _roErr() {
|
|
1252
|
+
_roErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx, options) {
|
|
1253
|
+
var result;
|
|
1254
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1255
|
+
while (1) {
|
|
1256
|
+
switch (_context3.prev = _context3.next) {
|
|
1257
|
+
case 0:
|
|
1258
|
+
_context3.next = 2;
|
|
1259
|
+
return ro(tx, options);
|
|
1260
|
+
|
|
1261
|
+
case 2:
|
|
1262
|
+
result = _context3.sent;
|
|
1263
|
+
return _context3.abrupt("return", expectErr(result));
|
|
1264
|
+
|
|
1265
|
+
case 4:
|
|
1266
|
+
case "end":
|
|
1267
|
+
return _context3.stop();
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}, _callee3);
|
|
1271
|
+
}));
|
|
1272
|
+
return _roErr.apply(this, arguments);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
function broadcast(_x7, _x8) {
|
|
1276
|
+
return _broadcast.apply(this, arguments);
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
function _broadcast() {
|
|
1280
|
+
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(transaction, options) {
|
|
1281
|
+
var result;
|
|
1282
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1283
|
+
while (1) {
|
|
1284
|
+
switch (_context4.prev = _context4.next) {
|
|
1285
|
+
case 0:
|
|
1286
|
+
_context4.next = 2;
|
|
1287
|
+
return transactions.broadcastTransaction(transaction, options.network);
|
|
1288
|
+
|
|
1289
|
+
case 2:
|
|
1290
|
+
result = _context4.sent;
|
|
1291
|
+
|
|
1292
|
+
if (!('error' in result)) {
|
|
1293
|
+
_context4.next = 7;
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
throw new Error("Error broadcasting tx: " + result.error + " - " + result.reason + " - " + result.reason_data);
|
|
1298
|
+
|
|
1299
|
+
case 7:
|
|
1300
|
+
return _context4.abrupt("return", {
|
|
1301
|
+
txId: result.txid,
|
|
1302
|
+
stacksTransaction: transaction
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
case 8:
|
|
1306
|
+
case "end":
|
|
1307
|
+
return _context4.stop();
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}, _callee4);
|
|
1311
|
+
}));
|
|
1312
|
+
return _broadcast.apply(this, arguments);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1048
1315
|
var makeHandler = function makeHandler(provider) {
|
|
1049
1316
|
var handler = {
|
|
1050
1317
|
get: function get(contract, property) {
|
|
@@ -1086,12 +1353,21 @@ exports.BaseProvider = BaseProvider;
|
|
|
1086
1353
|
exports.MAINNET_BURN_ADDRESS = MAINNET_BURN_ADDRESS;
|
|
1087
1354
|
exports.TESTNET_BURN_ADDRESS = TESTNET_BURN_ADDRESS;
|
|
1088
1355
|
exports.bootContractIdentifier = bootContractIdentifier;
|
|
1356
|
+
exports.broadcast = broadcast;
|
|
1089
1357
|
exports.cvToString = cvToString;
|
|
1090
1358
|
exports.cvToValue = cvToValue;
|
|
1359
|
+
exports.expectErr = expectErr;
|
|
1360
|
+
exports.expectOk = expectOk;
|
|
1091
1361
|
exports.getContractIdentifier = getContractIdentifier;
|
|
1092
1362
|
exports.getContractNameFromPath = getContractNameFromPath;
|
|
1093
1363
|
exports.getContractPrincipalCV = getContractPrincipalCV;
|
|
1364
|
+
exports.hexToCvValue = hexToCvValue;
|
|
1365
|
+
exports.makeContracts = makeContracts;
|
|
1094
1366
|
exports.parseToCV = parseToCV;
|
|
1095
1367
|
exports.proxy = proxy;
|
|
1368
|
+
exports.pureProxy = pureProxy;
|
|
1369
|
+
exports.ro = ro;
|
|
1370
|
+
exports.roErr = roErr;
|
|
1371
|
+
exports.roOk = roOk;
|
|
1096
1372
|
exports.toCamelCase = toCamelCase;
|
|
1097
1373
|
//# sourceMappingURL=core.cjs.development.js.map
|