@clarigen/core 1.0.0-next.6 → 1.0.0-next.9
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 +2 -1
- package/dist/core.cjs.development.js +109 -26
- 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 +111 -30
- package/dist/core.esm.js.map +1 -1
- package/dist/events.d.ts +11 -0
- package/package.json +2 -2
package/dist/api.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { StacksNetwork } from 'micro-stacks/network';
|
|
2
2
|
import { StacksTransaction } from 'micro-stacks/transactions';
|
|
3
3
|
import { ClarityTypes } from './clarity-types';
|
|
4
|
-
import { ContractCall } from './pure';
|
|
4
|
+
import { ContractCall, ContractCalls } from './pure';
|
|
5
5
|
interface ApiOptions {
|
|
6
6
|
network: StacksNetwork;
|
|
7
7
|
}
|
|
8
8
|
export declare function ro<T>(tx: ContractCall<T>, options: ApiOptions): Promise<T>;
|
|
9
9
|
export declare function roOk<Ok>(tx: ContractCall<ClarityTypes.Response<Ok, any>>, options: ApiOptions): Promise<Ok>;
|
|
10
10
|
export declare function roErr<Err>(tx: ContractCall<ClarityTypes.Response<any, Err>>, options: ApiOptions): Promise<Err>;
|
|
11
|
+
export declare function fetchMapGet<T extends ContractCalls.Map<any, Val>, Val>(map: T, options: ApiOptions): Promise<Val | null>;
|
|
11
12
|
export declare function broadcast(transaction: StacksTransaction, options: ApiOptions): Promise<{
|
|
12
13
|
txId: string;
|
|
13
14
|
stacksTransaction: StacksTransaction;
|
|
@@ -34,8 +34,7 @@ var getContractNameFromPath = function getContractNameFromPath(path) {
|
|
|
34
34
|
return contractName;
|
|
35
35
|
};
|
|
36
36
|
var getContractIdentifier = function getContractIdentifier(contract) {
|
|
37
|
-
|
|
38
|
-
return contract.address + "." + contractName;
|
|
37
|
+
return contract.address + "." + contract.name;
|
|
39
38
|
};
|
|
40
39
|
var getContractPrincipalCV = function getContractPrincipalCV(contract) {
|
|
41
40
|
var contractName = getContractNameFromPath(contract.contractFile);
|
|
@@ -60,6 +59,12 @@ function bootContractIdentifier(name, mainnet) {
|
|
|
60
59
|
CoreNodeEventType["FtBurnEvent"] = "ft_burn_event";
|
|
61
60
|
})(exports.CoreNodeEventType || (exports.CoreNodeEventType = {}));
|
|
62
61
|
|
|
62
|
+
function filterEvents(events, type) {
|
|
63
|
+
return events.filter(function (event) {
|
|
64
|
+
return event.type === type;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
function makeContracts(contracts, options) {
|
|
64
69
|
if (options === void 0) {
|
|
65
70
|
options = {};
|
|
@@ -1188,31 +1193,69 @@ function ro(_x, _x2) {
|
|
|
1188
1193
|
|
|
1189
1194
|
function _ro() {
|
|
1190
1195
|
_ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, options) {
|
|
1191
|
-
var
|
|
1196
|
+
var urlBase, url, body, response, msg, parsed;
|
|
1192
1197
|
return runtime_1.wrap(function _callee$(_context) {
|
|
1193
1198
|
while (1) {
|
|
1194
1199
|
switch (_context.prev = _context.next) {
|
|
1195
1200
|
case 0:
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1201
|
+
urlBase = options.network.getReadOnlyFunctionCallApiUrl(tx.contractAddress, tx.contractName, tx["function"].name);
|
|
1202
|
+
url = urlBase + "?tip=latest";
|
|
1203
|
+
body = JSON.stringify({
|
|
1204
|
+
sender: tx.contractAddress,
|
|
1205
|
+
arguments: tx.functionArgs.map(function (arg) {
|
|
1206
|
+
return typeof arg === 'string' ? arg : clarity.cvToHex(arg);
|
|
1207
|
+
})
|
|
1208
|
+
});
|
|
1209
|
+
_context.next = 5;
|
|
1210
|
+
return common.fetchPrivate(url, {
|
|
1211
|
+
method: 'POST',
|
|
1212
|
+
body: body,
|
|
1213
|
+
headers: {
|
|
1214
|
+
'Content-Type': 'application/json'
|
|
1215
|
+
}
|
|
1204
1216
|
});
|
|
1205
1217
|
|
|
1206
|
-
case
|
|
1207
|
-
|
|
1208
|
-
return _context.abrupt("return", cvToValue(result, true));
|
|
1218
|
+
case 5:
|
|
1219
|
+
response = _context.sent;
|
|
1209
1220
|
|
|
1210
|
-
|
|
1221
|
+
if (response.ok) {
|
|
1222
|
+
_context.next = 17;
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
msg = '';
|
|
1227
|
+
_context.prev = 8;
|
|
1228
|
+
_context.next = 11;
|
|
1229
|
+
return response.text();
|
|
1230
|
+
|
|
1231
|
+
case 11:
|
|
1232
|
+
msg = _context.sent;
|
|
1233
|
+
_context.next = 16;
|
|
1234
|
+
break;
|
|
1235
|
+
|
|
1236
|
+
case 14:
|
|
1237
|
+
_context.prev = 14;
|
|
1238
|
+
_context.t0 = _context["catch"](8);
|
|
1239
|
+
|
|
1240
|
+
case 16:
|
|
1241
|
+
throw new Error("Error calling read-only function. Response " + response.status + ": " + response.statusText + ". Attempted to fetch " + url + " and failed with the message: \"" + msg + "\"");
|
|
1242
|
+
|
|
1243
|
+
case 17:
|
|
1244
|
+
_context.t1 = api.parseReadOnlyResponse;
|
|
1245
|
+
_context.next = 20;
|
|
1246
|
+
return response.json();
|
|
1247
|
+
|
|
1248
|
+
case 20:
|
|
1249
|
+
_context.t2 = _context.sent;
|
|
1250
|
+
parsed = (0, _context.t1)(_context.t2);
|
|
1251
|
+
return _context.abrupt("return", cvToValue(parsed, true));
|
|
1252
|
+
|
|
1253
|
+
case 23:
|
|
1211
1254
|
case "end":
|
|
1212
1255
|
return _context.stop();
|
|
1213
1256
|
}
|
|
1214
1257
|
}
|
|
1215
|
-
}, _callee);
|
|
1258
|
+
}, _callee, null, [[8, 14]]);
|
|
1216
1259
|
}));
|
|
1217
1260
|
return _ro.apply(this, arguments);
|
|
1218
1261
|
}
|
|
@@ -1273,42 +1316,80 @@ function _roErr() {
|
|
|
1273
1316
|
return _roErr.apply(this, arguments);
|
|
1274
1317
|
}
|
|
1275
1318
|
|
|
1276
|
-
function
|
|
1319
|
+
function fetchMapGet(_x7, _x8) {
|
|
1320
|
+
return _fetchMapGet.apply(this, arguments);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
function _fetchMapGet() {
|
|
1324
|
+
_fetchMapGet = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(map, options) {
|
|
1325
|
+
var lookupKey, response, valueCV;
|
|
1326
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1327
|
+
while (1) {
|
|
1328
|
+
switch (_context4.prev = _context4.next) {
|
|
1329
|
+
case 0:
|
|
1330
|
+
lookupKey = clarity.cvToHex(map.key);
|
|
1331
|
+
_context4.next = 3;
|
|
1332
|
+
return api.fetchContractDataMapEntry({
|
|
1333
|
+
contract_address: map.contractAddress,
|
|
1334
|
+
contract_name: map.contractName,
|
|
1335
|
+
map_name: map.map.name,
|
|
1336
|
+
lookup_key: lookupKey,
|
|
1337
|
+
tip: 'latest',
|
|
1338
|
+
url: options.network.getCoreApiUrl(),
|
|
1339
|
+
proof: 0
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
case 3:
|
|
1343
|
+
response = _context4.sent;
|
|
1344
|
+
valueCV = clarity.hexToCV(response.data);
|
|
1345
|
+
return _context4.abrupt("return", cvToValue(valueCV, true));
|
|
1346
|
+
|
|
1347
|
+
case 6:
|
|
1348
|
+
case "end":
|
|
1349
|
+
return _context4.stop();
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}, _callee4);
|
|
1353
|
+
}));
|
|
1354
|
+
return _fetchMapGet.apply(this, arguments);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
function broadcast(_x9, _x10) {
|
|
1277
1358
|
return _broadcast.apply(this, arguments);
|
|
1278
1359
|
}
|
|
1279
1360
|
|
|
1280
1361
|
function _broadcast() {
|
|
1281
|
-
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1362
|
+
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(transaction, options) {
|
|
1282
1363
|
var result;
|
|
1283
|
-
return runtime_1.wrap(function
|
|
1364
|
+
return runtime_1.wrap(function _callee5$(_context5) {
|
|
1284
1365
|
while (1) {
|
|
1285
|
-
switch (
|
|
1366
|
+
switch (_context5.prev = _context5.next) {
|
|
1286
1367
|
case 0:
|
|
1287
|
-
|
|
1368
|
+
_context5.next = 2;
|
|
1288
1369
|
return transactions.broadcastTransaction(transaction, options.network);
|
|
1289
1370
|
|
|
1290
1371
|
case 2:
|
|
1291
|
-
result =
|
|
1372
|
+
result = _context5.sent;
|
|
1292
1373
|
|
|
1293
1374
|
if (!('error' in result)) {
|
|
1294
|
-
|
|
1375
|
+
_context5.next = 7;
|
|
1295
1376
|
break;
|
|
1296
1377
|
}
|
|
1297
1378
|
|
|
1298
1379
|
throw new Error("Error broadcasting tx: " + result.error + " - " + result.reason + " - " + result.reason_data);
|
|
1299
1380
|
|
|
1300
1381
|
case 7:
|
|
1301
|
-
return
|
|
1382
|
+
return _context5.abrupt("return", {
|
|
1302
1383
|
txId: result.txid,
|
|
1303
1384
|
stacksTransaction: transaction
|
|
1304
1385
|
});
|
|
1305
1386
|
|
|
1306
1387
|
case 8:
|
|
1307
1388
|
case "end":
|
|
1308
|
-
return
|
|
1389
|
+
return _context5.stop();
|
|
1309
1390
|
}
|
|
1310
1391
|
}
|
|
1311
|
-
},
|
|
1392
|
+
}, _callee5);
|
|
1312
1393
|
}));
|
|
1313
1394
|
return _broadcast.apply(this, arguments);
|
|
1314
1395
|
}
|
|
@@ -1359,6 +1440,8 @@ exports.cvToString = cvToString;
|
|
|
1359
1440
|
exports.cvToValue = cvToValue;
|
|
1360
1441
|
exports.expectErr = expectErr;
|
|
1361
1442
|
exports.expectOk = expectOk;
|
|
1443
|
+
exports.fetchMapGet = fetchMapGet;
|
|
1444
|
+
exports.filterEvents = filterEvents;
|
|
1362
1445
|
exports.getContractIdentifier = getContractIdentifier;
|
|
1363
1446
|
exports.getContractNameFromPath = getContractNameFromPath;
|
|
1364
1447
|
exports.getContractPrincipalCV = getContractPrincipalCV;
|