@clarigen/core 0.2.3 → 1.0.0-next.3
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 -54
- 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 +274 -13
- package/dist/core.esm.js.map +1 -1
- package/dist/events.d.ts +129 -0
- package/dist/index.d.ts +5 -1
- package/dist/pure/index.d.ts +36 -0
- package/dist/transaction.d.ts +7 -2
- package/dist/types.d.ts +5 -3
- package/dist/utils.d.ts +2 -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,76 +39,118 @@ 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;
|
|
42
46
|
return addr + "." + name;
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
(function (CoreNodeEventType) {
|
|
50
|
+
CoreNodeEventType["ContractEvent"] = "contract_event";
|
|
51
|
+
CoreNodeEventType["StxTransferEvent"] = "stx_transfer_event";
|
|
52
|
+
CoreNodeEventType["StxMintEvent"] = "stx_mint_event";
|
|
53
|
+
CoreNodeEventType["StxBurnEvent"] = "stx_burn_event";
|
|
54
|
+
CoreNodeEventType["StxLockEvent"] = "stx_lock_event";
|
|
55
|
+
CoreNodeEventType["NftTransferEvent"] = "nft_transfer_event";
|
|
56
|
+
CoreNodeEventType["NftMintEvent"] = "nft_mint_event";
|
|
57
|
+
CoreNodeEventType["NftBurnEvent"] = "nft_burn_event";
|
|
58
|
+
CoreNodeEventType["FtTransferEvent"] = "ft_transfer_event";
|
|
59
|
+
CoreNodeEventType["FtMintEvent"] = "ft_mint_event";
|
|
60
|
+
CoreNodeEventType["FtBurnEvent"] = "ft_burn_event";
|
|
61
|
+
})(exports.CoreNodeEventType || (exports.CoreNodeEventType = {}));
|
|
62
|
+
|
|
45
63
|
function principalToString(principal) {
|
|
46
|
-
if (principal.type ===
|
|
47
|
-
return
|
|
48
|
-
} else if (principal.type ===
|
|
49
|
-
var address =
|
|
64
|
+
if (principal.type === clarity.ClarityType.PrincipalStandard) {
|
|
65
|
+
return clarity.addressToString(principal.address);
|
|
66
|
+
} else if (principal.type === clarity.ClarityType.PrincipalContract) {
|
|
67
|
+
var address = clarity.addressToString(principal.address);
|
|
50
68
|
return address + "." + principal.contractName.content;
|
|
51
69
|
} else {
|
|
52
70
|
throw new Error("Unexpected principal data: " + JSON.stringify(principal));
|
|
53
71
|
}
|
|
54
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* @param val - ClarityValue
|
|
75
|
+
* @param returnResponse - if true, this will return a "response" object from the `neverthrow`
|
|
76
|
+
* library. Otherwise, it returns the inner value of the response (whether ok or err)
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
function cvToValue(val, returnResponse) {
|
|
81
|
+
if (returnResponse === void 0) {
|
|
82
|
+
returnResponse = false;
|
|
83
|
+
}
|
|
55
84
|
|
|
56
|
-
function cvToValue(val) {
|
|
57
85
|
switch (val.type) {
|
|
58
|
-
case
|
|
86
|
+
case clarity.ClarityType.BoolTrue:
|
|
59
87
|
return true;
|
|
60
88
|
|
|
61
|
-
case
|
|
89
|
+
case clarity.ClarityType.BoolFalse:
|
|
62
90
|
return false;
|
|
63
91
|
|
|
64
|
-
case
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case transactions.ClarityType.UInt:
|
|
68
|
-
return BigInt("0x" + val.value.toString('hex'));
|
|
92
|
+
case clarity.ClarityType.Int:
|
|
93
|
+
case clarity.ClarityType.UInt:
|
|
94
|
+
return val.value;
|
|
69
95
|
|
|
70
|
-
case
|
|
96
|
+
case clarity.ClarityType.Buffer:
|
|
71
97
|
return val.buffer;
|
|
72
98
|
|
|
73
|
-
case
|
|
99
|
+
case clarity.ClarityType.OptionalNone:
|
|
74
100
|
return null;
|
|
75
101
|
|
|
76
|
-
case
|
|
102
|
+
case clarity.ClarityType.OptionalSome:
|
|
77
103
|
return cvToValue(val.value);
|
|
78
104
|
|
|
79
|
-
case
|
|
105
|
+
case clarity.ClarityType.ResponseErr:
|
|
106
|
+
if (returnResponse) return neverthrow.err(cvToValue(val.value));
|
|
80
107
|
return cvToValue(val.value);
|
|
81
108
|
|
|
82
|
-
case
|
|
109
|
+
case clarity.ClarityType.ResponseOk:
|
|
110
|
+
if (returnResponse) return neverthrow.ok(cvToValue(val.value));
|
|
83
111
|
return cvToValue(val.value);
|
|
84
112
|
|
|
85
|
-
case
|
|
86
|
-
case
|
|
113
|
+
case clarity.ClarityType.PrincipalStandard:
|
|
114
|
+
case clarity.ClarityType.PrincipalContract:
|
|
87
115
|
return principalToString(val);
|
|
88
116
|
|
|
89
|
-
case
|
|
117
|
+
case clarity.ClarityType.List:
|
|
90
118
|
return val.list.map(function (v) {
|
|
91
119
|
return cvToValue(v);
|
|
92
120
|
});
|
|
93
121
|
|
|
94
|
-
case
|
|
122
|
+
case clarity.ClarityType.Tuple:
|
|
95
123
|
var result = {};
|
|
96
|
-
Object.keys(val.data).
|
|
97
|
-
|
|
124
|
+
var arr = Object.keys(val.data).map(function (key) {
|
|
125
|
+
return [key, cvToValue(val.data[key])];
|
|
126
|
+
});
|
|
127
|
+
arr.forEach(function (_ref) {
|
|
128
|
+
var key = _ref[0],
|
|
129
|
+
value = _ref[1];
|
|
130
|
+
result[key] = value;
|
|
98
131
|
});
|
|
99
132
|
return result;
|
|
100
133
|
|
|
101
|
-
case
|
|
134
|
+
case clarity.ClarityType.StringASCII:
|
|
102
135
|
return val.data;
|
|
103
136
|
|
|
104
|
-
case
|
|
137
|
+
case clarity.ClarityType.StringUTF8:
|
|
105
138
|
return val.data;
|
|
106
139
|
}
|
|
107
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Converts a hex encoded string to the javascript clarity value object {type: string; value: any}
|
|
143
|
+
* @param hex - the hex encoded string with or without `0x` prefix
|
|
144
|
+
* @param jsonCompat - enable to serialize bigints to strings
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
function hexToCvValue(hex, jsonCompat) {
|
|
148
|
+
if (jsonCompat === void 0) {
|
|
149
|
+
jsonCompat = false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return cvToValue(clarity.hexToCV(hex), jsonCompat);
|
|
153
|
+
}
|
|
108
154
|
|
|
109
155
|
function inputToBigInt(input) {
|
|
110
156
|
var isBigInt = typeof input === 'bigint';
|
|
@@ -130,105 +176,188 @@ function parseToCV(input, type) {
|
|
|
130
176
|
var val = input[key.name];
|
|
131
177
|
tuple[key.name] = parseToCV(val, key.type);
|
|
132
178
|
});
|
|
133
|
-
return
|
|
179
|
+
return clarity.tupleCV(tuple);
|
|
134
180
|
} else if (transactions.isClarityAbiList(type)) {
|
|
135
181
|
var inputs = input;
|
|
136
182
|
var values = inputs.map(function (input) {
|
|
137
183
|
return parseToCV(input, type.list.type);
|
|
138
184
|
});
|
|
139
|
-
return
|
|
185
|
+
return clarity.listCV(values);
|
|
140
186
|
} else if (transactions.isClarityAbiOptional(type)) {
|
|
141
|
-
if (!input) return
|
|
142
|
-
return
|
|
187
|
+
if (!input) return clarity.noneCV();
|
|
188
|
+
return clarity.someCV(parseToCV(input, type.optional));
|
|
143
189
|
} else if (transactions.isClarityAbiStringAscii(type)) {
|
|
144
190
|
if (typeof input !== 'string') {
|
|
145
191
|
throw new Error('Invalid string-ascii input');
|
|
146
192
|
}
|
|
147
193
|
|
|
148
|
-
return
|
|
194
|
+
return clarity.stringAsciiCV(input);
|
|
149
195
|
} else if (transactions.isClarityAbiStringUtf8(type)) {
|
|
150
196
|
if (typeof input !== 'string') {
|
|
151
197
|
throw new Error('Invalid string-ascii input');
|
|
152
198
|
}
|
|
153
199
|
|
|
154
|
-
return
|
|
200
|
+
return clarity.stringUtf8CV(input);
|
|
155
201
|
} else if (type === 'bool') {
|
|
156
202
|
var inputString = typeof input === 'boolean' ? input.toString() : input;
|
|
157
203
|
return transactions.parseToCV(inputString, type);
|
|
158
204
|
} else if (type === 'uint128') {
|
|
159
205
|
var bigi = inputToBigInt(input);
|
|
160
|
-
return
|
|
206
|
+
return clarity.uintCV(bigi.toString());
|
|
161
207
|
} else if (type === 'int128') {
|
|
162
208
|
var _bigi = inputToBigInt(input);
|
|
163
209
|
|
|
164
|
-
return
|
|
210
|
+
return clarity.intCV(_bigi.toString());
|
|
211
|
+
} else if (type === 'trait_reference') {
|
|
212
|
+
if (typeof input !== 'string') throw new Error('Invalid input for trait_reference');
|
|
213
|
+
|
|
214
|
+
var _input$split = input.split('.'),
|
|
215
|
+
addr = _input$split[0],
|
|
216
|
+
name = _input$split[1];
|
|
217
|
+
|
|
218
|
+
return clarity.contractPrincipalCV(addr, name);
|
|
219
|
+
} else if (transactions.isClarityAbiBuffer(type)) {
|
|
220
|
+
return clarity.bufferCV(input);
|
|
165
221
|
}
|
|
166
222
|
|
|
167
223
|
return transactions.parseToCV(input, type);
|
|
168
224
|
}
|
|
169
|
-
var CLARITY_INT_SIZE = 128;
|
|
170
225
|
function cvToString(val, encoding) {
|
|
171
226
|
if (encoding === void 0) {
|
|
172
227
|
encoding = 'hex';
|
|
173
228
|
}
|
|
174
229
|
|
|
175
230
|
switch (val.type) {
|
|
176
|
-
case
|
|
231
|
+
case clarity.ClarityType.BoolTrue:
|
|
177
232
|
return 'true';
|
|
178
233
|
|
|
179
|
-
case
|
|
234
|
+
case clarity.ClarityType.BoolFalse:
|
|
180
235
|
return 'false';
|
|
181
236
|
|
|
182
|
-
case
|
|
183
|
-
return val.value.
|
|
237
|
+
case clarity.ClarityType.Int:
|
|
238
|
+
return val.value.toString();
|
|
184
239
|
|
|
185
|
-
case
|
|
240
|
+
case clarity.ClarityType.UInt:
|
|
186
241
|
return "u" + val.value.toString();
|
|
187
242
|
|
|
188
|
-
case
|
|
243
|
+
case clarity.ClarityType.Buffer:
|
|
189
244
|
if (encoding === 'tryAscii') {
|
|
190
|
-
var str = val.buffer
|
|
245
|
+
var str = common.bytesToAscii(val.buffer);
|
|
191
246
|
|
|
192
247
|
if (/[ -~]/.test(str)) {
|
|
193
248
|
return JSON.stringify(str);
|
|
194
249
|
}
|
|
195
250
|
}
|
|
196
251
|
|
|
197
|
-
return "0x" + val.buffer
|
|
252
|
+
return "0x" + common.bytesToHex(val.buffer);
|
|
198
253
|
|
|
199
|
-
case
|
|
254
|
+
case clarity.ClarityType.OptionalNone:
|
|
200
255
|
return 'none';
|
|
201
256
|
|
|
202
|
-
case
|
|
257
|
+
case clarity.ClarityType.OptionalSome:
|
|
203
258
|
return "(some " + cvToString(val.value, encoding) + ")";
|
|
204
259
|
|
|
205
|
-
case
|
|
260
|
+
case clarity.ClarityType.ResponseErr:
|
|
206
261
|
return "(err " + cvToString(val.value, encoding) + ")";
|
|
207
262
|
|
|
208
|
-
case
|
|
263
|
+
case clarity.ClarityType.ResponseOk:
|
|
209
264
|
return "(ok " + cvToString(val.value, encoding) + ")";
|
|
210
265
|
|
|
211
|
-
case
|
|
212
|
-
case
|
|
266
|
+
case clarity.ClarityType.PrincipalStandard:
|
|
267
|
+
case clarity.ClarityType.PrincipalContract:
|
|
213
268
|
return "'" + principalToString(val);
|
|
214
269
|
|
|
215
|
-
case
|
|
270
|
+
case clarity.ClarityType.List:
|
|
216
271
|
return "(list " + val.list.map(function (v) {
|
|
217
272
|
return cvToString(v, encoding);
|
|
218
273
|
}).join(' ') + ")";
|
|
219
274
|
|
|
220
|
-
case
|
|
275
|
+
case clarity.ClarityType.Tuple:
|
|
221
276
|
return "(tuple " + Object.keys(val.data).map(function (key) {
|
|
222
277
|
return "(" + key + " " + cvToString(val.data[key], encoding) + ")";
|
|
223
278
|
}).join(' ') + ")";
|
|
224
279
|
|
|
225
|
-
case
|
|
280
|
+
case clarity.ClarityType.StringASCII:
|
|
226
281
|
return "\"" + val.data + "\"";
|
|
227
282
|
|
|
228
|
-
case
|
|
283
|
+
case clarity.ClarityType.StringUTF8:
|
|
229
284
|
return "u\"" + val.data + "\"";
|
|
230
285
|
}
|
|
231
286
|
}
|
|
287
|
+
function transformArgsToCV(func, args) {
|
|
288
|
+
return args.map(function (arg, index) {
|
|
289
|
+
return parseToCV(arg, func.args[index].type);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function expectOk(response) {
|
|
293
|
+
return response.match(function (ok) {
|
|
294
|
+
return ok;
|
|
295
|
+
}, function (err) {
|
|
296
|
+
throw new Error("Expected OK, received error: " + err);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
function expectErr(response) {
|
|
300
|
+
return response.match(function (ok) {
|
|
301
|
+
throw new Error("Expected Err, received Ok: " + ok);
|
|
302
|
+
}, function (err) {
|
|
303
|
+
return err;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function transformArguments(func, args) {
|
|
308
|
+
return transformArgsToCV(func, args);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getter(contract, property) {
|
|
312
|
+
var foundFunction = contract.abi.functions.find(function (func) {
|
|
313
|
+
return toCamelCase(func.name) === property;
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
if (foundFunction) {
|
|
317
|
+
return function () {
|
|
318
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
319
|
+
args[_key] = arguments[_key];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
var functionArgs = transformArguments(foundFunction, args);
|
|
323
|
+
return {
|
|
324
|
+
functionArgs: functionArgs,
|
|
325
|
+
contractAddress: contract.contractAddress,
|
|
326
|
+
contractName: contract.contractName,
|
|
327
|
+
"function": foundFunction,
|
|
328
|
+
nativeArgs: args
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
var foundMap = contract.abi.maps.find(function (map) {
|
|
334
|
+
return toCamelCase(map.name) === property;
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (foundMap) {
|
|
338
|
+
return function (key) {
|
|
339
|
+
var keyCV = parseToCV(key, foundMap.key);
|
|
340
|
+
var mapGet = {
|
|
341
|
+
contractAddress: contract.contractAddress,
|
|
342
|
+
contractName: contract.contractName,
|
|
343
|
+
map: foundMap,
|
|
344
|
+
nativeKey: key,
|
|
345
|
+
key: keyCV
|
|
346
|
+
};
|
|
347
|
+
return mapGet;
|
|
348
|
+
};
|
|
349
|
+
} // TODO: variables, tokens
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
throw new Error("Invalid function call: no function exists for " + String(property));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
var proxyHandler = {
|
|
356
|
+
get: getter
|
|
357
|
+
};
|
|
358
|
+
var pureProxy = function pureProxy(target) {
|
|
359
|
+
return new Proxy(target, proxyHandler);
|
|
360
|
+
};
|
|
232
361
|
|
|
233
362
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
234
363
|
try {
|
|
@@ -1032,6 +1161,136 @@ var BaseProvider = /*#__PURE__*/function () {
|
|
|
1032
1161
|
return BaseProvider;
|
|
1033
1162
|
}();
|
|
1034
1163
|
|
|
1164
|
+
function ro(_x, _x2) {
|
|
1165
|
+
return _ro.apply(this, arguments);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function _ro() {
|
|
1169
|
+
_ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, options) {
|
|
1170
|
+
var result;
|
|
1171
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1172
|
+
while (1) {
|
|
1173
|
+
switch (_context.prev = _context.next) {
|
|
1174
|
+
case 0:
|
|
1175
|
+
_context.next = 2;
|
|
1176
|
+
return api.callReadOnlyFunction({
|
|
1177
|
+
contractAddress: tx.contractAddress,
|
|
1178
|
+
contractName: tx.contractName,
|
|
1179
|
+
functionArgs: tx.functionArgs,
|
|
1180
|
+
functionName: tx["function"].name,
|
|
1181
|
+
network: options.network
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
case 2:
|
|
1185
|
+
result = _context.sent;
|
|
1186
|
+
return _context.abrupt("return", cvToValue(result, true));
|
|
1187
|
+
|
|
1188
|
+
case 4:
|
|
1189
|
+
case "end":
|
|
1190
|
+
return _context.stop();
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}, _callee);
|
|
1194
|
+
}));
|
|
1195
|
+
return _ro.apply(this, arguments);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function roOk(_x3, _x4) {
|
|
1199
|
+
return _roOk.apply(this, arguments);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function _roOk() {
|
|
1203
|
+
_roOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tx, options) {
|
|
1204
|
+
var result;
|
|
1205
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1206
|
+
while (1) {
|
|
1207
|
+
switch (_context2.prev = _context2.next) {
|
|
1208
|
+
case 0:
|
|
1209
|
+
_context2.next = 2;
|
|
1210
|
+
return ro(tx, options);
|
|
1211
|
+
|
|
1212
|
+
case 2:
|
|
1213
|
+
result = _context2.sent;
|
|
1214
|
+
return _context2.abrupt("return", expectOk(result));
|
|
1215
|
+
|
|
1216
|
+
case 4:
|
|
1217
|
+
case "end":
|
|
1218
|
+
return _context2.stop();
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}, _callee2);
|
|
1222
|
+
}));
|
|
1223
|
+
return _roOk.apply(this, arguments);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
function roErr(_x5, _x6) {
|
|
1227
|
+
return _roErr.apply(this, arguments);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function _roErr() {
|
|
1231
|
+
_roErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx, options) {
|
|
1232
|
+
var result;
|
|
1233
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1234
|
+
while (1) {
|
|
1235
|
+
switch (_context3.prev = _context3.next) {
|
|
1236
|
+
case 0:
|
|
1237
|
+
_context3.next = 2;
|
|
1238
|
+
return ro(tx, options);
|
|
1239
|
+
|
|
1240
|
+
case 2:
|
|
1241
|
+
result = _context3.sent;
|
|
1242
|
+
return _context3.abrupt("return", expectErr(result));
|
|
1243
|
+
|
|
1244
|
+
case 4:
|
|
1245
|
+
case "end":
|
|
1246
|
+
return _context3.stop();
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}, _callee3);
|
|
1250
|
+
}));
|
|
1251
|
+
return _roErr.apply(this, arguments);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
function broadcast(_x7, _x8) {
|
|
1255
|
+
return _broadcast.apply(this, arguments);
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
function _broadcast() {
|
|
1259
|
+
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(transaction, options) {
|
|
1260
|
+
var result;
|
|
1261
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1262
|
+
while (1) {
|
|
1263
|
+
switch (_context4.prev = _context4.next) {
|
|
1264
|
+
case 0:
|
|
1265
|
+
_context4.next = 2;
|
|
1266
|
+
return transactions.broadcastTransaction(transaction, options.network);
|
|
1267
|
+
|
|
1268
|
+
case 2:
|
|
1269
|
+
result = _context4.sent;
|
|
1270
|
+
|
|
1271
|
+
if (!('error' in result)) {
|
|
1272
|
+
_context4.next = 7;
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
throw new Error("Error broadcasting tx: " + result.error + " - " + result.reason + " - " + result.reason_data);
|
|
1277
|
+
|
|
1278
|
+
case 7:
|
|
1279
|
+
return _context4.abrupt("return", {
|
|
1280
|
+
txId: result.txid,
|
|
1281
|
+
stacksTransaction: transaction
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1284
|
+
case 8:
|
|
1285
|
+
case "end":
|
|
1286
|
+
return _context4.stop();
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}, _callee4);
|
|
1290
|
+
}));
|
|
1291
|
+
return _broadcast.apply(this, arguments);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1035
1294
|
var makeHandler = function makeHandler(provider) {
|
|
1036
1295
|
var handler = {
|
|
1037
1296
|
get: function get(contract, property) {
|
|
@@ -1073,12 +1332,20 @@ exports.BaseProvider = BaseProvider;
|
|
|
1073
1332
|
exports.MAINNET_BURN_ADDRESS = MAINNET_BURN_ADDRESS;
|
|
1074
1333
|
exports.TESTNET_BURN_ADDRESS = TESTNET_BURN_ADDRESS;
|
|
1075
1334
|
exports.bootContractIdentifier = bootContractIdentifier;
|
|
1335
|
+
exports.broadcast = broadcast;
|
|
1076
1336
|
exports.cvToString = cvToString;
|
|
1077
1337
|
exports.cvToValue = cvToValue;
|
|
1338
|
+
exports.expectErr = expectErr;
|
|
1339
|
+
exports.expectOk = expectOk;
|
|
1078
1340
|
exports.getContractIdentifier = getContractIdentifier;
|
|
1079
1341
|
exports.getContractNameFromPath = getContractNameFromPath;
|
|
1080
1342
|
exports.getContractPrincipalCV = getContractPrincipalCV;
|
|
1343
|
+
exports.hexToCvValue = hexToCvValue;
|
|
1081
1344
|
exports.parseToCV = parseToCV;
|
|
1082
1345
|
exports.proxy = proxy;
|
|
1346
|
+
exports.pureProxy = pureProxy;
|
|
1347
|
+
exports.ro = ro;
|
|
1348
|
+
exports.roErr = roErr;
|
|
1349
|
+
exports.roOk = roOk;
|
|
1083
1350
|
exports.toCamelCase = toCamelCase;
|
|
1084
1351
|
//# sourceMappingURL=core.cjs.development.js.map
|