@clarigen/core 1.0.0-next.4 → 1.0.0-next.8
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 +102 -25
- 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 +105 -29
- package/dist/core.esm.js.map +1 -1
- 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);
|
|
@@ -1188,30 +1187,69 @@ function ro(_x, _x2) {
|
|
|
1188
1187
|
|
|
1189
1188
|
function _ro() {
|
|
1190
1189
|
_ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, options) {
|
|
1191
|
-
var
|
|
1190
|
+
var urlBase, url, body, response, msg, parsed;
|
|
1192
1191
|
return runtime_1.wrap(function _callee$(_context) {
|
|
1193
1192
|
while (1) {
|
|
1194
1193
|
switch (_context.prev = _context.next) {
|
|
1195
1194
|
case 0:
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1195
|
+
urlBase = options.network.getReadOnlyFunctionCallApiUrl(tx.contractAddress, tx.contractName, tx["function"].name);
|
|
1196
|
+
url = urlBase + "?tip=latest";
|
|
1197
|
+
body = JSON.stringify({
|
|
1198
|
+
sender: tx.contractAddress,
|
|
1199
|
+
arguments: tx.functionArgs.map(function (arg) {
|
|
1200
|
+
return typeof arg === 'string' ? arg : clarity.cvToHex(arg);
|
|
1201
|
+
})
|
|
1202
|
+
});
|
|
1203
|
+
_context.next = 5;
|
|
1204
|
+
return common.fetchPrivate(url, {
|
|
1205
|
+
method: 'POST',
|
|
1206
|
+
body: body,
|
|
1207
|
+
headers: {
|
|
1208
|
+
'Content-Type': 'application/json'
|
|
1209
|
+
}
|
|
1203
1210
|
});
|
|
1204
1211
|
|
|
1205
|
-
case
|
|
1206
|
-
|
|
1207
|
-
return _context.abrupt("return", cvToValue(result, true));
|
|
1212
|
+
case 5:
|
|
1213
|
+
response = _context.sent;
|
|
1208
1214
|
|
|
1209
|
-
|
|
1215
|
+
if (response.ok) {
|
|
1216
|
+
_context.next = 17;
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
msg = '';
|
|
1221
|
+
_context.prev = 8;
|
|
1222
|
+
_context.next = 11;
|
|
1223
|
+
return response.text();
|
|
1224
|
+
|
|
1225
|
+
case 11:
|
|
1226
|
+
msg = _context.sent;
|
|
1227
|
+
_context.next = 16;
|
|
1228
|
+
break;
|
|
1229
|
+
|
|
1230
|
+
case 14:
|
|
1231
|
+
_context.prev = 14;
|
|
1232
|
+
_context.t0 = _context["catch"](8);
|
|
1233
|
+
|
|
1234
|
+
case 16:
|
|
1235
|
+
throw new Error("Error calling read-only function. Response " + response.status + ": " + response.statusText + ". Attempted to fetch " + url + " and failed with the message: \"" + msg + "\"");
|
|
1236
|
+
|
|
1237
|
+
case 17:
|
|
1238
|
+
_context.t1 = api.parseReadOnlyResponse;
|
|
1239
|
+
_context.next = 20;
|
|
1240
|
+
return response.json();
|
|
1241
|
+
|
|
1242
|
+
case 20:
|
|
1243
|
+
_context.t2 = _context.sent;
|
|
1244
|
+
parsed = (0, _context.t1)(_context.t2);
|
|
1245
|
+
return _context.abrupt("return", cvToValue(parsed, true));
|
|
1246
|
+
|
|
1247
|
+
case 23:
|
|
1210
1248
|
case "end":
|
|
1211
1249
|
return _context.stop();
|
|
1212
1250
|
}
|
|
1213
1251
|
}
|
|
1214
|
-
}, _callee);
|
|
1252
|
+
}, _callee, null, [[8, 14]]);
|
|
1215
1253
|
}));
|
|
1216
1254
|
return _ro.apply(this, arguments);
|
|
1217
1255
|
}
|
|
@@ -1272,42 +1310,80 @@ function _roErr() {
|
|
|
1272
1310
|
return _roErr.apply(this, arguments);
|
|
1273
1311
|
}
|
|
1274
1312
|
|
|
1275
|
-
function
|
|
1313
|
+
function fetchMapGet(_x7, _x8) {
|
|
1314
|
+
return _fetchMapGet.apply(this, arguments);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function _fetchMapGet() {
|
|
1318
|
+
_fetchMapGet = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(map, options) {
|
|
1319
|
+
var lookupKey, response, valueCV;
|
|
1320
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1321
|
+
while (1) {
|
|
1322
|
+
switch (_context4.prev = _context4.next) {
|
|
1323
|
+
case 0:
|
|
1324
|
+
lookupKey = clarity.cvToHex(map.key);
|
|
1325
|
+
_context4.next = 3;
|
|
1326
|
+
return api.fetchContractDataMapEntry({
|
|
1327
|
+
contract_address: map.contractAddress,
|
|
1328
|
+
contract_name: map.contractName,
|
|
1329
|
+
map_name: map.map.name,
|
|
1330
|
+
lookup_key: lookupKey,
|
|
1331
|
+
tip: 'latest',
|
|
1332
|
+
url: options.network.getCoreApiUrl(),
|
|
1333
|
+
proof: 0
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
case 3:
|
|
1337
|
+
response = _context4.sent;
|
|
1338
|
+
valueCV = clarity.hexToCV(response.data);
|
|
1339
|
+
return _context4.abrupt("return", cvToValue(valueCV, true));
|
|
1340
|
+
|
|
1341
|
+
case 6:
|
|
1342
|
+
case "end":
|
|
1343
|
+
return _context4.stop();
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}, _callee4);
|
|
1347
|
+
}));
|
|
1348
|
+
return _fetchMapGet.apply(this, arguments);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
function broadcast(_x9, _x10) {
|
|
1276
1352
|
return _broadcast.apply(this, arguments);
|
|
1277
1353
|
}
|
|
1278
1354
|
|
|
1279
1355
|
function _broadcast() {
|
|
1280
|
-
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1356
|
+
_broadcast = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(transaction, options) {
|
|
1281
1357
|
var result;
|
|
1282
|
-
return runtime_1.wrap(function
|
|
1358
|
+
return runtime_1.wrap(function _callee5$(_context5) {
|
|
1283
1359
|
while (1) {
|
|
1284
|
-
switch (
|
|
1360
|
+
switch (_context5.prev = _context5.next) {
|
|
1285
1361
|
case 0:
|
|
1286
|
-
|
|
1362
|
+
_context5.next = 2;
|
|
1287
1363
|
return transactions.broadcastTransaction(transaction, options.network);
|
|
1288
1364
|
|
|
1289
1365
|
case 2:
|
|
1290
|
-
result =
|
|
1366
|
+
result = _context5.sent;
|
|
1291
1367
|
|
|
1292
1368
|
if (!('error' in result)) {
|
|
1293
|
-
|
|
1369
|
+
_context5.next = 7;
|
|
1294
1370
|
break;
|
|
1295
1371
|
}
|
|
1296
1372
|
|
|
1297
1373
|
throw new Error("Error broadcasting tx: " + result.error + " - " + result.reason + " - " + result.reason_data);
|
|
1298
1374
|
|
|
1299
1375
|
case 7:
|
|
1300
|
-
return
|
|
1376
|
+
return _context5.abrupt("return", {
|
|
1301
1377
|
txId: result.txid,
|
|
1302
1378
|
stacksTransaction: transaction
|
|
1303
1379
|
});
|
|
1304
1380
|
|
|
1305
1381
|
case 8:
|
|
1306
1382
|
case "end":
|
|
1307
|
-
return
|
|
1383
|
+
return _context5.stop();
|
|
1308
1384
|
}
|
|
1309
1385
|
}
|
|
1310
|
-
},
|
|
1386
|
+
}, _callee5);
|
|
1311
1387
|
}));
|
|
1312
1388
|
return _broadcast.apply(this, arguments);
|
|
1313
1389
|
}
|
|
@@ -1358,6 +1434,7 @@ exports.cvToString = cvToString;
|
|
|
1358
1434
|
exports.cvToValue = cvToValue;
|
|
1359
1435
|
exports.expectErr = expectErr;
|
|
1360
1436
|
exports.expectOk = expectOk;
|
|
1437
|
+
exports.fetchMapGet = fetchMapGet;
|
|
1361
1438
|
exports.getContractIdentifier = getContractIdentifier;
|
|
1362
1439
|
exports.getContractNameFromPath = getContractNameFromPath;
|
|
1363
1440
|
exports.getContractPrincipalCV = getContractPrincipalCV;
|