@palliora.org/chainsdk 0.4.0 → 0.5.0
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/AGENTS.md +61 -0
- package/CHAIN-RULES.md +760 -0
- package/README.md +161 -26
- package/dist/index.cjs +1301 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1270 -24
- package/dist/index.d.ts +1270 -24
- package/dist/index.js +1270 -93
- package/dist/index.js.map +1 -1
- package/package.json +20 -11
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
2
|
var __typeError = (msg) => {
|
|
3
3
|
throw TypeError(msg);
|
|
4
4
|
};
|
|
@@ -71,6 +71,9 @@ async function createAccount(input, type, name = "default", cryptoType = "sr2551
|
|
|
71
71
|
throw new Error("Invalid input type");
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
async function createAccountFromMagicLink(signature, name = "default", cryptoType = "sr25519" /* SR25519 */) {
|
|
75
|
+
return createAccount(signature, "derived" /* DERIVED */, name, cryptoType);
|
|
76
|
+
}
|
|
74
77
|
function pairFromPrivateKeyHex(privateKeyHex, cryptoType) {
|
|
75
78
|
const privateKey = _util.hexToU8a.call(void 0, privateKeyHex);
|
|
76
79
|
switch (cryptoType) {
|
|
@@ -379,9 +382,15 @@ var API_TYPES = {
|
|
|
379
382
|
StoreType: {
|
|
380
383
|
_enum: {
|
|
381
384
|
Dataset: "Null",
|
|
385
|
+
// 0
|
|
382
386
|
Model: "Null",
|
|
387
|
+
// 1
|
|
383
388
|
Agent: "Null",
|
|
389
|
+
// 2
|
|
390
|
+
Executable: "Null",
|
|
391
|
+
// 3
|
|
384
392
|
Other: "Null"
|
|
393
|
+
// 4
|
|
385
394
|
}
|
|
386
395
|
},
|
|
387
396
|
ComputeMetadata: {
|
|
@@ -430,13 +439,16 @@ var API_TYPES = {
|
|
|
430
439
|
fhe: "bool",
|
|
431
440
|
zkp: "bool"
|
|
432
441
|
},
|
|
442
|
+
ComputeType: {
|
|
443
|
+
_enum: ["Trusted", "Tee", "Mpc", "Fhe", "Zkp"]
|
|
444
|
+
},
|
|
433
445
|
GuardianPrefs: {
|
|
434
446
|
pubKey: "[u8; 32]",
|
|
435
447
|
guardian: "bool",
|
|
436
448
|
verifier: "bool",
|
|
437
449
|
compute: "bool",
|
|
438
450
|
computePrefs: "Option<ComputePrefs>",
|
|
439
|
-
|
|
451
|
+
feeThresholds: "Vec<(ComputeType, u128)>"
|
|
440
452
|
},
|
|
441
453
|
BlockLengthColumns: "Compact<u32>",
|
|
442
454
|
BlockLengthRows: "Compact<u32>",
|
|
@@ -847,18 +859,49 @@ function assert(condition, message) {
|
|
|
847
859
|
|
|
848
860
|
// src/config.ts
|
|
849
861
|
|
|
850
|
-
var
|
|
851
|
-
var
|
|
852
|
-
var
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
function
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
+
var config = null;
|
|
863
|
+
var cachedProvider = null;
|
|
864
|
+
var cachedProviderUrl = null;
|
|
865
|
+
function init(options) {
|
|
866
|
+
config = { ...config, ...options };
|
|
867
|
+
}
|
|
868
|
+
function isInitialized() {
|
|
869
|
+
return config !== null;
|
|
870
|
+
}
|
|
871
|
+
function resetConfig() {
|
|
872
|
+
config = null;
|
|
873
|
+
cachedProvider = null;
|
|
874
|
+
cachedProviderUrl = null;
|
|
875
|
+
}
|
|
876
|
+
function read(key) {
|
|
877
|
+
if (!config) {
|
|
878
|
+
throw new Error(
|
|
879
|
+
`Palliora SDK is not initialized: cannot read "${key}". Call init({ ${key}: ... }) before using the SDK.`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
const value = config[key];
|
|
883
|
+
if (value === void 0) {
|
|
884
|
+
throw new Error(
|
|
885
|
+
`Palliora SDK config "${key}" is not set. Pass it to init({ ${key}: ... }).`
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
return value;
|
|
889
|
+
}
|
|
890
|
+
var getPallioraWs = () => read("pallioraWs");
|
|
891
|
+
var getPallioraRpcUrl = () => read("pallioraRpcUrl");
|
|
892
|
+
var getCostEstimatorUrl = () => read("costEstimatorUrl");
|
|
893
|
+
var getAuthServiceUrl = () => read("authServiceUrl");
|
|
894
|
+
var getAwsRegion = () => read("awsRegion");
|
|
895
|
+
var getAwsS3Bucket = () => read("awsS3Bucket");
|
|
896
|
+
var isDebug = () => _nullishCoalesce(_optionalChain([config, 'optionalAccess', _29 => _29.debug]), () => ( false));
|
|
897
|
+
var waitsForFinalization = () => _nullishCoalesce(_optionalChain([config, 'optionalAccess', _30 => _30.txWaitFinalization]), () => ( false));
|
|
898
|
+
function getProvider() {
|
|
899
|
+
const url = getPallioraWs();
|
|
900
|
+
if (!cachedProvider || cachedProviderUrl !== url) {
|
|
901
|
+
cachedProvider = new (0, _api2.WsProvider)(url, 1e4);
|
|
902
|
+
cachedProviderUrl = url;
|
|
903
|
+
}
|
|
904
|
+
return cachedProvider;
|
|
862
905
|
}
|
|
863
906
|
|
|
864
907
|
// src/utils/helper.ts
|
|
@@ -906,7 +949,7 @@ var decodeField = (field, expectedLength) => {
|
|
|
906
949
|
return bytes;
|
|
907
950
|
};
|
|
908
951
|
var debugLog = (message, ...optionalParams) => {
|
|
909
|
-
if (
|
|
952
|
+
if (isDebug()) {
|
|
910
953
|
console.log(message, ...optionalParams);
|
|
911
954
|
}
|
|
912
955
|
};
|
|
@@ -934,11 +977,11 @@ async function fetchTokenProperties() {
|
|
|
934
977
|
return tokenCache;
|
|
935
978
|
}
|
|
936
979
|
try {
|
|
937
|
-
const systemProperties = await _asyncOptionalChain([(await await _asyncOptionalChain([(await getApi()), 'optionalAccess', async
|
|
980
|
+
const systemProperties = await _asyncOptionalChain([(await await _asyncOptionalChain([(await getApi()), 'optionalAccess', async _31 => _31.rpc, 'access', async _32 => _32.system, 'access', async _33 => _33.properties, 'call', async _34 => _34()])), 'optionalAccess', async _35 => _35.toHuman, 'call', async _36 => _36()]);
|
|
938
981
|
assert(systemProperties, "Failed to fetch system properties from RPC");
|
|
939
982
|
const tokenProperties = {
|
|
940
|
-
symbol: (_optionalChain([systemProperties, 'optionalAccess',
|
|
941
|
-
decimals: Number((_optionalChain([systemProperties, 'optionalAccess',
|
|
983
|
+
symbol: (_optionalChain([systemProperties, 'optionalAccess', _37 => _37.tokenSymbol]) || [PALI_SYMBOL])[0],
|
|
984
|
+
decimals: Number((_optionalChain([systemProperties, 'optionalAccess', _38 => _38.tokenDecimals]) || [String(PALI_DECIMALS)])[0])
|
|
942
985
|
};
|
|
943
986
|
tokenCache = tokenProperties;
|
|
944
987
|
return tokenProperties;
|
|
@@ -968,8 +1011,8 @@ var encKeyring = null;
|
|
|
968
1011
|
var apiListenersAttached = false;
|
|
969
1012
|
var apiTeardownInProgress = false;
|
|
970
1013
|
async function getApi(cb) {
|
|
971
|
-
|
|
972
|
-
if (api &&
|
|
1014
|
+
const pallioraWs = getPallioraWs();
|
|
1015
|
+
if (api && pallioraWs !== apiUrl) {
|
|
973
1016
|
const staleApi = api;
|
|
974
1017
|
api = null;
|
|
975
1018
|
apiUrl = null;
|
|
@@ -980,15 +1023,15 @@ async function getApi(cb) {
|
|
|
980
1023
|
}
|
|
981
1024
|
if (!api) {
|
|
982
1025
|
api = await _api2.ApiPromise.create({
|
|
983
|
-
provider,
|
|
1026
|
+
provider: getProvider(),
|
|
984
1027
|
rpc: API_RPC,
|
|
985
1028
|
types: API_TYPES,
|
|
986
1029
|
signedExtensions: API_EXTENSIONS
|
|
987
1030
|
});
|
|
988
|
-
apiUrl =
|
|
1031
|
+
apiUrl = pallioraWs;
|
|
989
1032
|
}
|
|
990
1033
|
const isNode = typeof process !== "undefined" && typeof process.exit === "function";
|
|
991
|
-
const isTest = typeof process !== "undefined" && _optionalChain([process, 'access',
|
|
1034
|
+
const isTest = typeof process !== "undefined" && _optionalChain([process, 'access', _39 => _39.env, 'optionalAccess', _40 => _40.NODE_ENV]) === "test";
|
|
992
1035
|
if (isNode && !isTest && api && !apiListenersAttached) {
|
|
993
1036
|
apiListenersAttached = true;
|
|
994
1037
|
api.on("error", (err) => {
|
|
@@ -997,7 +1040,7 @@ async function getApi(cb) {
|
|
|
997
1040
|
apiListenersAttached = false;
|
|
998
1041
|
const currentApi = api;
|
|
999
1042
|
api = null;
|
|
1000
|
-
void _optionalChain([currentApi, 'optionalAccess',
|
|
1043
|
+
void _optionalChain([currentApi, 'optionalAccess', _41 => _41.disconnect, 'call', _42 => _42(), 'access', _43 => _43.catch, 'call', _44 => _44((disconnectErr) => {
|
|
1001
1044
|
apiTeardownInProgress = false;
|
|
1002
1045
|
console.error("api disconnect after error failed:", disconnectErr);
|
|
1003
1046
|
})]);
|
|
@@ -1011,6 +1054,16 @@ async function getApi(cb) {
|
|
|
1011
1054
|
}
|
|
1012
1055
|
return api;
|
|
1013
1056
|
}
|
|
1057
|
+
async function disconnectApi() {
|
|
1058
|
+
if (!api) return;
|
|
1059
|
+
const current = api;
|
|
1060
|
+
api = null;
|
|
1061
|
+
apiUrl = null;
|
|
1062
|
+
apiListenersAttached = false;
|
|
1063
|
+
apiTeardownInProgress = false;
|
|
1064
|
+
await current.disconnect().catch(() => {
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1014
1067
|
async function getKeyring() {
|
|
1015
1068
|
if (!keyring) {
|
|
1016
1069
|
await _wasmcrypto.waitReady.call(void 0, );
|
|
@@ -1034,6 +1087,7 @@ var _bs58 = require('bs58'); var _bs582 = _interopRequireDefault(_bs58);
|
|
|
1034
1087
|
|
|
1035
1088
|
// src/guardian/active.ts
|
|
1036
1089
|
|
|
1090
|
+
|
|
1037
1091
|
var getGuardianList = async () => {
|
|
1038
1092
|
const api2 = await getApi();
|
|
1039
1093
|
if (!api2) throw new Error("API not initialized");
|
|
@@ -1041,12 +1095,32 @@ var getGuardianList = async () => {
|
|
|
1041
1095
|
const section = "guardian";
|
|
1042
1096
|
const method = "guardianList";
|
|
1043
1097
|
assert(
|
|
1044
|
-
_util.isFunction.call(void 0, _optionalChain([rpc, 'access',
|
|
1098
|
+
_util.isFunction.call(void 0, _optionalChain([rpc, 'access', _45 => _45[section], 'optionalAccess', _46 => _46[method]])),
|
|
1045
1099
|
`api.rpc.${section}.${method} does not exist`
|
|
1046
1100
|
);
|
|
1047
1101
|
const list = (await rpc[section]["guardianList"]()).map((item) => [item.toString()]).flat(1);
|
|
1048
1102
|
return list;
|
|
1049
1103
|
};
|
|
1104
|
+
async function getActiveGuardians(apiInstance) {
|
|
1105
|
+
await _wasmcrypto.waitReady.call(void 0, );
|
|
1106
|
+
const api2 = await _asyncNullishCoalesce(apiInstance, async () => ( await getApi()));
|
|
1107
|
+
if (!api2) throw new Error("API not initialized");
|
|
1108
|
+
const guardians = await api2.query.guardian.guardians();
|
|
1109
|
+
const accounts = _optionalChain([guardians, 'optionalAccess', _47 => _47.toJSON, 'call', _48 => _48()]) || [];
|
|
1110
|
+
return Promise.all(
|
|
1111
|
+
accounts.map(async (account) => {
|
|
1112
|
+
const [prefs, ledger] = await Promise.all([
|
|
1113
|
+
api2.query.staking.guardians(account),
|
|
1114
|
+
api2.query.staking.ledger(account)
|
|
1115
|
+
]);
|
|
1116
|
+
return {
|
|
1117
|
+
account,
|
|
1118
|
+
guardianPrefs: _nullishCoalesce(_optionalChain([prefs, 'optionalAccess', _49 => _49.toHuman, 'optionalCall', _50 => _50()]), () => ( null)),
|
|
1119
|
+
stakersOverview: _nullishCoalesce(_optionalChain([ledger, 'optionalAccess', _51 => _51.toHuman, 'optionalCall', _52 => _52()]), () => ( null))
|
|
1120
|
+
};
|
|
1121
|
+
})
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1050
1124
|
|
|
1051
1125
|
// src/guardian/group.ts
|
|
1052
1126
|
var createGuardianGroup = async (account, selectedGuardians) => {
|
|
@@ -1078,7 +1152,7 @@ var createGuardianGroupAndWatch = async (account, guardians, maxBlocks = 20) =>
|
|
|
1078
1152
|
assert(api2, "Failed to initialize API");
|
|
1079
1153
|
debugLog(`Submitting guardian group creation...`);
|
|
1080
1154
|
const creationResult = await createGuardianGroup(account, guardians);
|
|
1081
|
-
const startBlock = (_nullishCoalesce(_optionalChain([creationResult, 'optionalAccess',
|
|
1155
|
+
const startBlock = (_nullishCoalesce(_optionalChain([creationResult, 'optionalAccess', _53 => _53.blockNumber]), () => ( 0))) + 1;
|
|
1082
1156
|
debugLog(`Group creation tx confirmed at block ${startBlock - 1}. Listening for DaccGuardianGroup event from block ${startBlock}...`);
|
|
1083
1157
|
const match = await scanForBlockEvent(
|
|
1084
1158
|
api2,
|
|
@@ -1087,7 +1161,7 @@ var createGuardianGroupAndWatch = async (account, guardians, maxBlocks = 20) =>
|
|
|
1087
1161
|
if (event.section.toLowerCase() !== "dataavailability" || event.method.toLowerCase() !== "daccguardiangroup") return false;
|
|
1088
1162
|
if (!phase.isApplyExtrinsic) return false;
|
|
1089
1163
|
const ext2 = block2.block.extrinsics[phase.asApplyExtrinsic.toNumber()];
|
|
1090
|
-
return _optionalChain([ext2, 'optionalAccess',
|
|
1164
|
+
return _optionalChain([ext2, 'optionalAccess', _54 => _54.method, 'optionalAccess', _55 => _55.section, 'optionalAccess', _56 => _56.toLowerCase, 'call', _57 => _57()]) === "dataavailability" && _optionalChain([ext2, 'optionalAccess', _58 => _58.method, 'optionalAccess', _59 => _59.method, 'optionalAccess', _60 => _60.toLowerCase, 'call', _61 => _61()]) === "daccguardiangroupinfo";
|
|
1091
1165
|
}
|
|
1092
1166
|
},
|
|
1093
1167
|
startBlock,
|
|
@@ -1107,32 +1181,125 @@ var createGuardianGroupAndWatch = async (account, guardians, maxBlocks = 20) =>
|
|
|
1107
1181
|
guardians
|
|
1108
1182
|
};
|
|
1109
1183
|
};
|
|
1184
|
+
async function findGuardianGroupInfoExtrinsic(api2, startBlock, maxBlocks) {
|
|
1185
|
+
const tip = (await api2.rpc.chain.getHeader()).number.toNumber();
|
|
1186
|
+
const endBlock = maxBlocks > 0 ? Math.min(startBlock + maxBlocks - 1, tip) : tip;
|
|
1187
|
+
for (let blockNumber = startBlock; blockNumber <= endBlock; blockNumber++) {
|
|
1188
|
+
const blockHash = await api2.rpc.chain.getBlockHash(blockNumber);
|
|
1189
|
+
const signedBlock = await api2.rpc.chain.getBlock(blockHash);
|
|
1190
|
+
const extrinsics = signedBlock.block.extrinsics;
|
|
1191
|
+
for (let index = 0; index < extrinsics.length; index++) {
|
|
1192
|
+
const ext = extrinsics[index];
|
|
1193
|
+
if (_optionalChain([ext, 'optionalAccess', _62 => _62.method, 'optionalAccess', _63 => _63.section, 'optionalAccess', _64 => _64.toLowerCase, 'call', _65 => _65()]) === "dataavailability" && _optionalChain([ext, 'optionalAccess', _66 => _66.method, 'optionalAccess', _67 => _67.method, 'optionalAccess', _68 => _68.toLowerCase, 'call', _69 => _69()]) === "daccguardiangroupinfo") {
|
|
1194
|
+
return { blockNumber, index };
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
throw new Error(
|
|
1199
|
+
`No daccGuardianGroupInfo extrinsic found in blocks ${startBlock}-${endBlock} (searched ${Math.max(endBlock - startBlock + 1, 0)} block(s) after the creation extrinsic)`
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1202
|
+
var getGuardianGroupInfo = async (creationRef, resultRef, maxBlocks = 20) => {
|
|
1203
|
+
assert(creationRef, "Group creation extrinsic reference is required");
|
|
1204
|
+
const api2 = await getApi();
|
|
1205
|
+
assert(api2, "Failed to initialize API");
|
|
1206
|
+
debugLog(`Reading guardian group creation extrinsic at block ${creationRef.blockNumber}, index ${creationRef.index}...`);
|
|
1207
|
+
const { raw: creationExt } = await fetchAndDecodeExtrinsic(creationRef.blockNumber, creationRef.index);
|
|
1208
|
+
assert(
|
|
1209
|
+
_optionalChain([creationExt, 'optionalAccess', _70 => _70.method, 'optionalAccess', _71 => _71.section, 'optionalAccess', _72 => _72.toLowerCase, 'call', _73 => _73()]) === "dataavailability" && _optionalChain([creationExt, 'optionalAccess', _74 => _74.method, 'optionalAccess', _75 => _75.method, 'optionalAccess', _76 => _76.toLowerCase, 'call', _77 => _77()]) === "daccguardiangroup",
|
|
1210
|
+
`Extrinsic at block ${creationRef.blockNumber}, index ${creationRef.index} is not a daccGuardianGroup call (found ${_optionalChain([creationExt, 'optionalAccess', _78 => _78.method, 'optionalAccess', _79 => _79.section])}.${_optionalChain([creationExt, 'optionalAccess', _80 => _80.method, 'optionalAccess', _81 => _81.method])})`
|
|
1211
|
+
);
|
|
1212
|
+
const [selectedGuardiansArg] = creationExt.method.args;
|
|
1213
|
+
const guardians = Array.from(selectedGuardiansArg).map((g) => g.toString());
|
|
1214
|
+
debugLog(`Guardian group creation extrinsic decoded: guardians=${guardians.join(", ")}`);
|
|
1215
|
+
const resolvedResultRef = await _asyncNullishCoalesce(resultRef, async () => ( await (async () => {
|
|
1216
|
+
debugLog(
|
|
1217
|
+
`No result extrinsic reference given, scanning forward from block ${creationRef.blockNumber + 1} for daccGuardianGroupInfo...`
|
|
1218
|
+
);
|
|
1219
|
+
return findGuardianGroupInfoExtrinsic(api2, creationRef.blockNumber + 1, maxBlocks);
|
|
1220
|
+
})()));
|
|
1221
|
+
debugLog(`Reading guardian group result extrinsic at block ${resolvedResultRef.blockNumber}, index ${resolvedResultRef.index}...`);
|
|
1222
|
+
const { raw: resultExt } = await fetchAndDecodeExtrinsic(resolvedResultRef.blockNumber, resolvedResultRef.index);
|
|
1223
|
+
assert(
|
|
1224
|
+
_optionalChain([resultExt, 'optionalAccess', _82 => _82.method, 'optionalAccess', _83 => _83.section, 'optionalAccess', _84 => _84.toLowerCase, 'call', _85 => _85()]) === "dataavailability" && _optionalChain([resultExt, 'optionalAccess', _86 => _86.method, 'optionalAccess', _87 => _87.method, 'optionalAccess', _88 => _88.toLowerCase, 'call', _89 => _89()]) === "daccguardiangroupinfo",
|
|
1225
|
+
`Extrinsic at block ${resolvedResultRef.blockNumber}, index ${resolvedResultRef.index} is not a daccGuardianGroupInfo call (found ${_optionalChain([resultExt, 'optionalAccess', _90 => _90.method, 'optionalAccess', _91 => _91.section])}.${_optionalChain([resultExt, 'optionalAccess', _92 => _92.method, 'optionalAccess', _93 => _93.method])})`
|
|
1226
|
+
);
|
|
1227
|
+
const [group_id, group_pk, tau_params, agg_key] = resultExt.method.args;
|
|
1228
|
+
debugLog(`Guardian group result extrinsic decoded: group_id=${group_id.toHex()}`);
|
|
1229
|
+
return {
|
|
1230
|
+
groupId: group_id.toHex(),
|
|
1231
|
+
groupPk: group_pk.toHex(),
|
|
1232
|
+
tauParams: tau_params.toHex(),
|
|
1233
|
+
aggKey: agg_key.toHex(),
|
|
1234
|
+
guardians
|
|
1235
|
+
};
|
|
1236
|
+
};
|
|
1110
1237
|
|
|
1111
1238
|
// src/guardian/join.ts
|
|
1239
|
+
var COMPUTE_TYPES = ["trusted", "tee", "mpc", "fhe", "zkp"];
|
|
1240
|
+
var CHAIN_COMPUTE_TYPE = {
|
|
1241
|
+
trusted: "Trusted",
|
|
1242
|
+
tee: "Tee",
|
|
1243
|
+
mpc: "Mpc",
|
|
1244
|
+
fhe: "Fhe",
|
|
1245
|
+
zkp: "Zkp"
|
|
1246
|
+
};
|
|
1247
|
+
function parseComputeTypes(compute) {
|
|
1248
|
+
const requested = (compute || "").split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
1249
|
+
return COMPUTE_TYPES.filter((type) => requested.includes(type));
|
|
1250
|
+
}
|
|
1251
|
+
function buildFeeThresholds(fee, computeTypes) {
|
|
1252
|
+
if (fee === void 0 || fee === null || fee === "") {
|
|
1253
|
+
return [];
|
|
1254
|
+
}
|
|
1255
|
+
if (typeof fee !== "object") {
|
|
1256
|
+
assert(
|
|
1257
|
+
computeTypes.length > 0,
|
|
1258
|
+
"A single fee threshold needs compute preferences to apply to. Set compute preferences, or declare thresholds per compute type."
|
|
1259
|
+
);
|
|
1260
|
+
return computeTypes.map((type) => [CHAIN_COMPUTE_TYPE[type], BigInt(fee)]);
|
|
1261
|
+
}
|
|
1262
|
+
return Object.entries(fee).map(([type, amount]) => {
|
|
1263
|
+
assert(
|
|
1264
|
+
COMPUTE_TYPES.includes(type),
|
|
1265
|
+
`Unknown compute type "${type}" in fee thresholds. Allowed: ${COMPUTE_TYPES.join(", ")}`
|
|
1266
|
+
);
|
|
1267
|
+
assert(
|
|
1268
|
+
computeTypes.includes(type),
|
|
1269
|
+
`Fee threshold declared for "${type}", which is not among the compute preferences (${computeTypes.join(", ") || "none"})`
|
|
1270
|
+
);
|
|
1271
|
+
return [CHAIN_COMPUTE_TYPE[type], BigInt(amount)];
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1112
1274
|
async function joinGuardian(account, prefs) {
|
|
1113
1275
|
const api2 = await getApi();
|
|
1114
1276
|
assert(api2, "API not initialized");
|
|
1115
1277
|
assert(account, "Account not initialized");
|
|
1116
|
-
const
|
|
1117
|
-
const
|
|
1278
|
+
const computeTypes = parseComputeTypes(prefs.compute);
|
|
1279
|
+
const feeThresholds = buildFeeThresholds(prefs.fee, computeTypes);
|
|
1118
1280
|
const guardianPrefs = {
|
|
1119
1281
|
pubKey: account.publicKey,
|
|
1120
1282
|
guardian: prefs.standard,
|
|
1121
1283
|
verifier: prefs.verifier,
|
|
1122
1284
|
compute: prefs.compute ? true : false,
|
|
1123
1285
|
computePrefs: {
|
|
1124
|
-
trusted:
|
|
1125
|
-
tee:
|
|
1126
|
-
mpc:
|
|
1127
|
-
fhe:
|
|
1128
|
-
zkp:
|
|
1286
|
+
trusted: computeTypes.includes("trusted"),
|
|
1287
|
+
tee: computeTypes.includes("tee"),
|
|
1288
|
+
mpc: computeTypes.includes("mpc"),
|
|
1289
|
+
fhe: computeTypes.includes("fhe"),
|
|
1290
|
+
zkp: computeTypes.includes("zkp")
|
|
1129
1291
|
},
|
|
1130
|
-
|
|
1292
|
+
feeThresholds
|
|
1131
1293
|
};
|
|
1132
1294
|
debugLog(
|
|
1133
1295
|
account.address,
|
|
1134
1296
|
"joining as guardian with preferences:",
|
|
1135
|
-
{
|
|
1297
|
+
{
|
|
1298
|
+
...guardianPrefs,
|
|
1299
|
+
feeThresholds: feeThresholds.map(
|
|
1300
|
+
([type, threshold]) => `${type}: ${formatPaliAmount(threshold)}`
|
|
1301
|
+
)
|
|
1302
|
+
}
|
|
1136
1303
|
);
|
|
1137
1304
|
const guardTx = api2.tx.staking.guard(guardianPrefs);
|
|
1138
1305
|
const hash = await signAndSend(guardTx, account);
|
|
@@ -1140,14 +1307,14 @@ async function joinGuardian(account, prefs) {
|
|
|
1140
1307
|
}
|
|
1141
1308
|
|
|
1142
1309
|
// src/chain/utils.ts
|
|
1143
|
-
var signAndSend = async (
|
|
1310
|
+
var signAndSend = async (request2, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
|
|
1144
1311
|
const signOpts = { currencyId: null, ...opts };
|
|
1145
1312
|
const tx_result = await new Promise((res, err) => {
|
|
1146
|
-
|
|
1313
|
+
request2.signAndSend(account, signOpts, (result) => {
|
|
1147
1314
|
if (result.isFinalized) {
|
|
1148
1315
|
res(result);
|
|
1149
1316
|
}
|
|
1150
|
-
if (!
|
|
1317
|
+
if (!waitsForFinalization() && result.isInBlock) {
|
|
1151
1318
|
res(result);
|
|
1152
1319
|
}
|
|
1153
1320
|
if (result.isError) err(result);
|
|
@@ -1165,12 +1332,27 @@ var signAndSend = async (request, account, opts = DEFAULT_COMPUTE_PAYLOAD) => {
|
|
|
1165
1332
|
`Transaction ${tx_result.txHash.toHex()} included in timepoint ${tx_result.blockNumber}-${tx_result.txIndex}`
|
|
1166
1333
|
);
|
|
1167
1334
|
return {
|
|
1168
|
-
blockNumber: _nullishCoalesce(_optionalChain([tx_result, 'access',
|
|
1335
|
+
blockNumber: _nullishCoalesce(_optionalChain([tx_result, 'access', _94 => _94.blockNumber, 'optionalAccess', _95 => _95.toNumber, 'call', _96 => _96()]), () => ( 0)),
|
|
1169
1336
|
index: _nullishCoalesce(tx_result.txIndex, () => ( 0)),
|
|
1170
1337
|
hash: tx_result.txHash.toHex(),
|
|
1171
1338
|
tx_result
|
|
1172
1339
|
};
|
|
1173
1340
|
};
|
|
1341
|
+
var retrySignAndSend = async (request2, account, opts, retries = 3, backoffMs = 1e3) => {
|
|
1342
|
+
let lastError;
|
|
1343
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
1344
|
+
try {
|
|
1345
|
+
return await signAndSend(request2, account, opts);
|
|
1346
|
+
} catch (err) {
|
|
1347
|
+
lastError = err;
|
|
1348
|
+
if (attempt === retries) break;
|
|
1349
|
+
const delay = backoffMs * 2 ** attempt;
|
|
1350
|
+
debugLog(`retrySignAndSend: attempt ${attempt + 1} failed, retrying in ${delay}ms`, err);
|
|
1351
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
throw lastError;
|
|
1355
|
+
};
|
|
1174
1356
|
var getFileMetadataCall = async (api2, metadataRef) => {
|
|
1175
1357
|
const block = await getBlock(api2, metadataRef[0]);
|
|
1176
1358
|
const call = block.block.extrinsics[metadataRef[1]];
|
|
@@ -1184,7 +1366,7 @@ var getGuardianAddress = async () => {
|
|
|
1184
1366
|
const api2 = await getApi();
|
|
1185
1367
|
if (!api2) throw new Error("API not initialized");
|
|
1186
1368
|
assert(
|
|
1187
|
-
_util.isFunction.call(void 0, _optionalChain([api2, 'access',
|
|
1369
|
+
_util.isFunction.call(void 0, _optionalChain([api2, 'access', _97 => _97.query, 'access', _98 => _98["guardian"], 'optionalAccess', _99 => _99["workerByKey"]])),
|
|
1188
1370
|
`api.query.guardian.workerByKey does not exist`
|
|
1189
1371
|
);
|
|
1190
1372
|
const list = await getGuardianList();
|
|
@@ -1204,7 +1386,7 @@ var getGuardianNwParams = async () => {
|
|
|
1204
1386
|
const section = "guardian";
|
|
1205
1387
|
const method = "guardianNwParams";
|
|
1206
1388
|
assert(
|
|
1207
|
-
_util.isFunction.call(void 0, _optionalChain([rpc, 'access',
|
|
1389
|
+
_util.isFunction.call(void 0, _optionalChain([rpc, 'access', _100 => _100[section], 'optionalAccess', _101 => _101[method]])),
|
|
1208
1390
|
`api.rpc.${section}.guardianNwParams does not exist`
|
|
1209
1391
|
);
|
|
1210
1392
|
const guardianNwParams = await rpc[section][method]();
|
|
@@ -1218,6 +1400,26 @@ var getGuardianNwParams = async () => {
|
|
|
1218
1400
|
throw error;
|
|
1219
1401
|
}
|
|
1220
1402
|
};
|
|
1403
|
+
async function getContractInfo(contractId) {
|
|
1404
|
+
const api2 = await getApi();
|
|
1405
|
+
if (!api2) throw new Error("API not initialized");
|
|
1406
|
+
assert(
|
|
1407
|
+
_util.isFunction.call(void 0, _optionalChain([api2, 'access', _102 => _102.query, 'access', _103 => _103["compute"], 'optionalAccess', _104 => _104["contracts"]])),
|
|
1408
|
+
`api.query.compute.contracts does not exist`
|
|
1409
|
+
);
|
|
1410
|
+
const raw = await api2.query["compute"]["contracts"](contractId);
|
|
1411
|
+
const info = raw.toPrimitive();
|
|
1412
|
+
if (!info) return null;
|
|
1413
|
+
return {
|
|
1414
|
+
status: info.status,
|
|
1415
|
+
owner: info.owner,
|
|
1416
|
+
originBlock: info.originBlock,
|
|
1417
|
+
invocationBlock: info.invocationBlock,
|
|
1418
|
+
index: info.index,
|
|
1419
|
+
usagePrice: BigInt(info.usagePrice),
|
|
1420
|
+
contractType: info.contractType
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1221
1423
|
async function fetchAndDecodeExtrinsic(blockHeight, extrinsicIndex) {
|
|
1222
1424
|
const api2 = await getApi();
|
|
1223
1425
|
if (!api2) throw new Error("API not initialized");
|
|
@@ -1233,6 +1435,11 @@ async function fetchAndDecodeExtrinsic(blockHeight, extrinsicIndex) {
|
|
|
1233
1435
|
const decoded = raw.toHuman();
|
|
1234
1436
|
return { raw, decoded };
|
|
1235
1437
|
}
|
|
1438
|
+
function findEvent(events, section, method) {
|
|
1439
|
+
return events.find(
|
|
1440
|
+
(record) => record.event.section.toLowerCase() === section.toLowerCase() && record.event.method.toLowerCase() === method.toLowerCase()
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1236
1443
|
var scanForBlockEvent = (api2, filter, startBlock, maxBlocks = 20) => {
|
|
1237
1444
|
const hasPredicate = "predicate" in filter;
|
|
1238
1445
|
let blocksScanned = 0;
|
|
@@ -1277,6 +1484,28 @@ var scanForBlockEvent = (api2, filter, startBlock, maxBlocks = 20) => {
|
|
|
1277
1484
|
);
|
|
1278
1485
|
});
|
|
1279
1486
|
};
|
|
1487
|
+
async function waitForNextBlock() {
|
|
1488
|
+
const api2 = await getApi();
|
|
1489
|
+
if (!api2) throw new Error("API not initialized");
|
|
1490
|
+
return new Promise((resolve, reject) => {
|
|
1491
|
+
let unsubFn;
|
|
1492
|
+
let settled = false;
|
|
1493
|
+
api2.rpc.chain.subscribeNewHeads((header) => {
|
|
1494
|
+
if (settled) return;
|
|
1495
|
+
settled = true;
|
|
1496
|
+
_optionalChain([unsubFn, 'optionalCall', _105 => _105()]);
|
|
1497
|
+
resolve({ blockNumber: header.number.toNumber(), blockHash: header.hash.toHex() });
|
|
1498
|
+
}).then((fn) => {
|
|
1499
|
+
if (settled) fn();
|
|
1500
|
+
else unsubFn = fn;
|
|
1501
|
+
}).catch((err) => {
|
|
1502
|
+
if (!settled) {
|
|
1503
|
+
settled = true;
|
|
1504
|
+
reject(err);
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1280
1509
|
async function watchForSubmissionReceipt(requestId, timeoutMs = 10 * 60 * 1e3) {
|
|
1281
1510
|
const api2 = await getApi();
|
|
1282
1511
|
if (!api2) throw new Error("API not initialized");
|
|
@@ -1286,7 +1515,7 @@ async function watchForSubmissionReceipt(requestId, timeoutMs = 10 * 60 * 1e3) {
|
|
|
1286
1515
|
const cleanup = (settleFn) => {
|
|
1287
1516
|
if (settled) return;
|
|
1288
1517
|
settled = true;
|
|
1289
|
-
_optionalChain([unsubFn, 'optionalCall',
|
|
1518
|
+
_optionalChain([unsubFn, 'optionalCall', _106 => _106()]);
|
|
1290
1519
|
settleFn();
|
|
1291
1520
|
};
|
|
1292
1521
|
const timer = setTimeout(
|
|
@@ -1303,10 +1532,10 @@ async function watchForSubmissionReceipt(requestId, timeoutMs = 10 * 60 * 1e3) {
|
|
|
1303
1532
|
for (let i = 0; i < extrinsics.length; i++) {
|
|
1304
1533
|
const ext = extrinsics[i];
|
|
1305
1534
|
const decoded = ext.toHuman();
|
|
1306
|
-
const method = _optionalChain([decoded, 'optionalAccess',
|
|
1307
|
-
if (String(_nullishCoalesce(_optionalChain([method, 'optionalAccess',
|
|
1308
|
-
const args = _optionalChain([method, 'optionalAccess',
|
|
1309
|
-
const onChainId = String(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
1535
|
+
const method = _optionalChain([decoded, 'optionalAccess', _107 => _107.method]);
|
|
1536
|
+
if (String(_nullishCoalesce(_optionalChain([method, 'optionalAccess', _108 => _108.section]), () => ( ""))).toLowerCase() === "compute" && String(_nullishCoalesce(_optionalChain([method, 'optionalAccess', _109 => _109.method]), () => ( ""))).toLowerCase() === "result") {
|
|
1537
|
+
const args = _optionalChain([method, 'optionalAccess', _110 => _110.args]);
|
|
1538
|
+
const onChainId = String(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([args, 'optionalAccess', _111 => _111.request_id]), () => ( _optionalChain([args, 'optionalAccess', _112 => _112.requestId]))), () => ( _optionalChain([args, 'optionalAccess', _113 => _113[0]]))), () => ( "")));
|
|
1310
1539
|
if (onChainId === requestId) {
|
|
1311
1540
|
clearTimeout(timer);
|
|
1312
1541
|
cleanup(
|
|
@@ -1342,22 +1571,18 @@ async function getAgreementCreatedRequestId(blockHeight, extrinsicIndex) {
|
|
|
1342
1571
|
const blockHash = await api2.rpc.chain.getBlockHash(blockHeight);
|
|
1343
1572
|
const apiAt = await api2.at(blockHash);
|
|
1344
1573
|
const allEvents = await apiAt.query.system.events();
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
} else if (dataHuman !== null && typeof dataHuman === "object") {
|
|
1358
|
-
const id = _nullishCoalesce(_nullishCoalesce(dataHuman["requestId"], () => ( dataHuman["request_id"])), () => ( dataHuman["id"]));
|
|
1359
|
-
if (id != null) return String(id);
|
|
1360
|
-
}
|
|
1574
|
+
const extrinsicEvents = allEvents.filter(
|
|
1575
|
+
(record) => record.phase.isApplyExtrinsic && record.phase.asApplyExtrinsic.toNumber() === extrinsicIndex
|
|
1576
|
+
);
|
|
1577
|
+
const match = findEvent(extrinsicEvents, "compute", "AgreementCreated");
|
|
1578
|
+
if (!match) return null;
|
|
1579
|
+
const dataHuman = match.event.data.toHuman();
|
|
1580
|
+
if (Array.isArray(dataHuman)) {
|
|
1581
|
+
const first = dataHuman[0];
|
|
1582
|
+
if (first != null) return String(first);
|
|
1583
|
+
} else if (dataHuman !== null && typeof dataHuman === "object") {
|
|
1584
|
+
const id = _nullishCoalesce(_nullishCoalesce(dataHuman["requestId"], () => ( dataHuman["request_id"])), () => ( dataHuman["id"]));
|
|
1585
|
+
if (id != null) return String(id);
|
|
1361
1586
|
}
|
|
1362
1587
|
return null;
|
|
1363
1588
|
}
|
|
@@ -1458,15 +1683,15 @@ var MCryptFsWriter = class {
|
|
|
1458
1683
|
return new Blob([blockNumberBuffer, extIndexBuffer, chunk]);
|
|
1459
1684
|
}
|
|
1460
1685
|
async writeChunk(chunk) {
|
|
1461
|
-
const
|
|
1686
|
+
const request2 = this._api.tx.dataAvailability.submitData(
|
|
1462
1687
|
Array.from(new Uint8Array(await chunk.arrayBuffer()))
|
|
1463
1688
|
);
|
|
1464
1689
|
console.log("account: ", this._account);
|
|
1465
1690
|
return new Promise((resolve) => {
|
|
1466
|
-
|
|
1691
|
+
request2.signAndSend(this._account, { app_id: 1, currencyId: null }, (result) => {
|
|
1467
1692
|
if (result.isInBlock || result.isFinalized || result.isError) {
|
|
1468
1693
|
resolve({
|
|
1469
|
-
blockNumber: _nullishCoalesce(_optionalChain([result, 'access',
|
|
1694
|
+
blockNumber: _nullishCoalesce(_optionalChain([result, 'access', _114 => _114.blockNumber, 'optionalAccess', _115 => _115.toNumber, 'call', _116 => _116()]), () => ( 0)),
|
|
1470
1695
|
index: _nullishCoalesce(result.txIndex, () => ( 0))
|
|
1471
1696
|
});
|
|
1472
1697
|
}
|
|
@@ -1493,15 +1718,15 @@ var MCryptFsWriter = class {
|
|
|
1493
1718
|
chosen_guardians: this._guardianInfo.guardians,
|
|
1494
1719
|
blobRef: [blobRef.blockNumber, blobRef.extrinsicIndex]
|
|
1495
1720
|
});
|
|
1496
|
-
const
|
|
1497
|
-
return await signAndSend(
|
|
1721
|
+
const request2 = this._api.tx.dataAvailability.submitData(modelSubmit);
|
|
1722
|
+
return await signAndSend(request2, account);
|
|
1498
1723
|
}
|
|
1499
1724
|
async writeMetadata() {
|
|
1500
1725
|
const encoder = new TextEncoder();
|
|
1501
1726
|
const fileName = this._fileName;
|
|
1502
1727
|
const datasetRef = await this.submitKey(this._account, this._fileKey);
|
|
1503
1728
|
const keyRef = [datasetRef.blockNumber, datasetRef.index];
|
|
1504
|
-
const
|
|
1729
|
+
const request2 = this._api.tx.dataAvailability.daccRegisterData(
|
|
1505
1730
|
Array.from(new TextEncoder().encode(fileName)),
|
|
1506
1731
|
Array.from(new TextEncoder().encode(this._description)),
|
|
1507
1732
|
keyRef,
|
|
@@ -1510,7 +1735,7 @@ var MCryptFsWriter = class {
|
|
|
1510
1735
|
Array.from(encoder.encode(this._ownerL2Address)),
|
|
1511
1736
|
this._guardianInfo.groupId
|
|
1512
1737
|
);
|
|
1513
|
-
return await signAndSend(
|
|
1738
|
+
return await signAndSend(request2, this._account);
|
|
1514
1739
|
}
|
|
1515
1740
|
async writeFile() {
|
|
1516
1741
|
const chunks = [];
|
|
@@ -1577,11 +1802,106 @@ var FileFromMetadataRef = async (mcryptApi, metadataRef) => {
|
|
|
1577
1802
|
return new MCryptFs(mcryptApi, metadataRef, metadata);
|
|
1578
1803
|
};
|
|
1579
1804
|
|
|
1805
|
+
// src/chain/blocks.ts
|
|
1806
|
+
|
|
1807
|
+
async function getLatestBlocks(count, page = 0, apiInstance) {
|
|
1808
|
+
await _wasmcrypto.waitReady.call(void 0, );
|
|
1809
|
+
const api2 = await _asyncNullishCoalesce(apiInstance, async () => ( await getApi()));
|
|
1810
|
+
if (!api2) throw new Error("API not initialized");
|
|
1811
|
+
const header = await api2.rpc.chain.getHeader();
|
|
1812
|
+
const latestHeight = header.number.toNumber();
|
|
1813
|
+
const start = latestHeight - page * count;
|
|
1814
|
+
if (start < 0) {
|
|
1815
|
+
return { blocks: [], latestHeight };
|
|
1816
|
+
}
|
|
1817
|
+
const heights = [];
|
|
1818
|
+
for (let height = start; height >= Math.max(0, start - count + 1); height -= 1) {
|
|
1819
|
+
heights.push(height);
|
|
1820
|
+
}
|
|
1821
|
+
const blocks = await Promise.all(
|
|
1822
|
+
heights.map(async (height) => {
|
|
1823
|
+
const hash = await api2.rpc.chain.getBlockHash(height);
|
|
1824
|
+
const [signed, derived, at] = await Promise.all([
|
|
1825
|
+
api2.rpc.chain.getBlock(hash),
|
|
1826
|
+
api2.derive.chain.getHeader(hash).catch(() => null),
|
|
1827
|
+
api2.at(hash)
|
|
1828
|
+
]);
|
|
1829
|
+
const [timestamp, events] = await Promise.all([
|
|
1830
|
+
at.query.timestamp.now(),
|
|
1831
|
+
at.query.system.events()
|
|
1832
|
+
]);
|
|
1833
|
+
return {
|
|
1834
|
+
height,
|
|
1835
|
+
hash: hash.toHex(),
|
|
1836
|
+
time: Number(timestamp.toString()),
|
|
1837
|
+
validator: _nullishCoalesce(_optionalChain([derived, 'optionalAccess', _117 => _117.author, 'optionalAccess', _118 => _118.toString, 'optionalCall', _119 => _119()]), () => ( "")),
|
|
1838
|
+
extrinsicsCount: signed.block.extrinsics.length,
|
|
1839
|
+
eventsCount: events.length
|
|
1840
|
+
};
|
|
1841
|
+
})
|
|
1842
|
+
);
|
|
1843
|
+
return { blocks, latestHeight };
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// src/token/balance.ts
|
|
1847
|
+
async function getBalance(address) {
|
|
1848
|
+
const api2 = await getApi();
|
|
1849
|
+
assert(api2, "API not initialized");
|
|
1850
|
+
const account = (await api2.query.system.account(address)).toPrimitive();
|
|
1851
|
+
const free = BigInt(account.data.free);
|
|
1852
|
+
const reserved = BigInt(account.data.reserved);
|
|
1853
|
+
const frozen = BigInt(account.data.frozen);
|
|
1854
|
+
return {
|
|
1855
|
+
free,
|
|
1856
|
+
reserved,
|
|
1857
|
+
frozen,
|
|
1858
|
+
formatted: await formatBalanceWithTokenProperties(free)
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
// src/account/info.ts
|
|
1863
|
+
function extractDisplayName(display) {
|
|
1864
|
+
if (!display || display === "None") return null;
|
|
1865
|
+
if (typeof display === "string") return display;
|
|
1866
|
+
if (typeof display === "object" && "Raw" in display) {
|
|
1867
|
+
return String(display.Raw);
|
|
1868
|
+
}
|
|
1869
|
+
return null;
|
|
1870
|
+
}
|
|
1871
|
+
async function getAccountInfo(address) {
|
|
1872
|
+
const api2 = await getApi();
|
|
1873
|
+
assert(api2, "API not initialized");
|
|
1874
|
+
const [accountData, balance, identity] = await Promise.all([
|
|
1875
|
+
api2.query.system.account(address),
|
|
1876
|
+
getBalance(address),
|
|
1877
|
+
api2.query.identity.identityOf(address)
|
|
1878
|
+
]);
|
|
1879
|
+
const nonce = accountData.toPrimitive().nonce;
|
|
1880
|
+
const identityHuman = identity.toHuman();
|
|
1881
|
+
return {
|
|
1882
|
+
address,
|
|
1883
|
+
nonce,
|
|
1884
|
+
balance,
|
|
1885
|
+
displayName: extractDisplayName(_optionalChain([identityHuman, 'optionalAccess', _120 => _120.info, 'optionalAccess', _121 => _121.display]))
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1580
1889
|
// src/compute/agreement.ts
|
|
1581
1890
|
function buildFee(fee) {
|
|
1582
1891
|
return {
|
|
1583
|
-
fees: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess',
|
|
1584
|
-
computeRate: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess',
|
|
1892
|
+
fees: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess', _122 => _122.amount]), () => ( "0"))),
|
|
1893
|
+
computeRate: toAtomicPaliAmount(_nullishCoalesce(_optionalChain([fee, 'optionalAccess', _123 => _123.computeRate]), () => ( "0")))
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
var NO_GUARDIAN_GROUP = `0x${"00".repeat(32)}`;
|
|
1897
|
+
function buildComputeMetadata(metadata) {
|
|
1898
|
+
if (!metadata) return null;
|
|
1899
|
+
const encoder = new TextEncoder();
|
|
1900
|
+
return {
|
|
1901
|
+
name: Array.from(encoder.encode(metadata.name)),
|
|
1902
|
+
description: Array.from(encoder.encode(metadata.description)),
|
|
1903
|
+
storeType: metadata.storeType,
|
|
1904
|
+
groupId: _nullishCoalesce(metadata.groupId, () => ( NO_GUARDIAN_GROUP))
|
|
1585
1905
|
};
|
|
1586
1906
|
}
|
|
1587
1907
|
async function createAgreement(contract, account, oracle_quore_id = void 0) {
|
|
@@ -1602,18 +1922,14 @@ async function createAgreement(contract, account, oracle_quore_id = void 0) {
|
|
|
1602
1922
|
opts
|
|
1603
1923
|
);
|
|
1604
1924
|
if (!tx_result.isError) {
|
|
1605
|
-
const agreementCreatedEvent = tx_result.events
|
|
1606
|
-
(event) => {
|
|
1607
|
-
return event.event.section === "compute" && event.event.method === "AgreementCreated";
|
|
1608
|
-
}
|
|
1609
|
-
);
|
|
1925
|
+
const agreementCreatedEvent = findEvent(tx_result.events, "compute", "AgreementCreated");
|
|
1610
1926
|
if (agreementCreatedEvent) {
|
|
1611
1927
|
debugLog("Agreement data:", agreementCreatedEvent.event.data.toString());
|
|
1612
1928
|
return {
|
|
1613
1929
|
blockNumber,
|
|
1614
1930
|
index: _nullishCoalesce(index, () => ( 0)),
|
|
1615
1931
|
hash,
|
|
1616
|
-
agreementId: _nullishCoalesce(_optionalChain([agreementCreatedEvent, 'access',
|
|
1932
|
+
agreementId: _nullishCoalesce(_optionalChain([agreementCreatedEvent, 'access', _124 => _124.event, 'access', _125 => _125.data, 'access', _126 => _126[0], 'optionalAccess', _127 => _127.toHex, 'optionalCall', _128 => _128()]), () => ( agreementCreatedEvent.event.data.toString()))
|
|
1617
1933
|
};
|
|
1618
1934
|
} else {
|
|
1619
1935
|
debugLog("AgreementCreated event not found");
|
|
@@ -1621,6 +1937,17 @@ async function createAgreement(contract, account, oracle_quore_id = void 0) {
|
|
|
1621
1937
|
}
|
|
1622
1938
|
return { blockNumber, index: _nullishCoalesce(index, () => ( 0)), hash };
|
|
1623
1939
|
}
|
|
1940
|
+
async function invokeAgreement(agreementId, input, account, opts) {
|
|
1941
|
+
const api2 = await getApi();
|
|
1942
|
+
if (!api2) throw new Error("Api not initialized");
|
|
1943
|
+
const tx = api2.tx["compute"]["invoke"](
|
|
1944
|
+
agreementId,
|
|
1945
|
+
input.guardians,
|
|
1946
|
+
input.cipher,
|
|
1947
|
+
{ Inline: { data: Array.from(input.data) } }
|
|
1948
|
+
);
|
|
1949
|
+
return signAndSend(tx, account, opts);
|
|
1950
|
+
}
|
|
1624
1951
|
async function createSimpleAgreement() {
|
|
1625
1952
|
const guardianIds = (await getGuardianAddress()).slice(0, 3).map((g) => g.address);
|
|
1626
1953
|
assert(guardianIds.length === 3, "Not enough guardians to create agreement");
|
|
@@ -1650,6 +1977,17 @@ async function createSimpleAgreement() {
|
|
|
1650
1977
|
// src/compute/data.ts
|
|
1651
1978
|
async function dataContract(params, account) {
|
|
1652
1979
|
const plaintextCipher = "Plaintext";
|
|
1980
|
+
assert(
|
|
1981
|
+
params.url === void 0 !== (params.data === void 0),
|
|
1982
|
+
"dataContract requires exactly one of `url` or `data`"
|
|
1983
|
+
);
|
|
1984
|
+
const input = params.url !== void 0 ? { Url: { url: Array.from(new TextEncoder().encode(params.url)) } } : {
|
|
1985
|
+
Inline: {
|
|
1986
|
+
data: Array.from(
|
|
1987
|
+
typeof params.data === "string" ? new TextEncoder().encode(params.data) : params.data
|
|
1988
|
+
)
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1653
1991
|
const computeStep = {
|
|
1654
1992
|
cipher: plaintextCipher,
|
|
1655
1993
|
computerIndices: params.guardians.map((_, i) => i),
|
|
@@ -1657,14 +1995,11 @@ async function dataContract(params, account) {
|
|
|
1657
1995
|
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
1658
1996
|
confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
|
|
1659
1997
|
feeFunction: null,
|
|
1660
|
-
input
|
|
1661
|
-
Url: {
|
|
1662
|
-
url: Array.from(new TextEncoder().encode(params.url))
|
|
1663
|
-
}
|
|
1664
|
-
},
|
|
1998
|
+
input,
|
|
1665
1999
|
program: {
|
|
1666
2000
|
NativeData: "DaFalse"
|
|
1667
|
-
}
|
|
2001
|
+
},
|
|
2002
|
+
metadata: buildComputeMetadata(params.metadata)
|
|
1668
2003
|
};
|
|
1669
2004
|
const contract = {
|
|
1670
2005
|
contractType: "Dormant",
|
|
@@ -1677,6 +2012,60 @@ async function dataContract(params, account) {
|
|
|
1677
2012
|
return createAgreement(contract, account);
|
|
1678
2013
|
}
|
|
1679
2014
|
|
|
2015
|
+
// src/compute/fees.ts
|
|
2016
|
+
async function readMillisecondsPerBlock() {
|
|
2017
|
+
const api2 = await getApi();
|
|
2018
|
+
assert(api2, "Api not initialized");
|
|
2019
|
+
const expectedBlockTime = _optionalChain([api2, 'access', _129 => _129.consts, 'access', _130 => _130.babe, 'optionalAccess', _131 => _131.expectedBlockTime]);
|
|
2020
|
+
if (expectedBlockTime) {
|
|
2021
|
+
return BigInt(expectedBlockTime.toString());
|
|
2022
|
+
}
|
|
2023
|
+
const minimumPeriod = _optionalChain([api2, 'access', _132 => _132.consts, 'access', _133 => _133.timestamp, 'optionalAccess', _134 => _134.minimumPeriod]);
|
|
2024
|
+
assert(minimumPeriod, "Cannot determine block time: neither babe.expectedBlockTime nor timestamp.minimumPeriod exists");
|
|
2025
|
+
return BigInt(minimumPeriod.toString()) * 2n;
|
|
2026
|
+
}
|
|
2027
|
+
async function getFeeParams() {
|
|
2028
|
+
const api2 = await getApi();
|
|
2029
|
+
assert(api2, "Api not initialized");
|
|
2030
|
+
assert(
|
|
2031
|
+
_optionalChain([api2, 'access', _135 => _135.query, 'access', _136 => _136.compute, 'optionalAccess', _137 => _137.maxDaStorageSize]),
|
|
2032
|
+
"compute.maxDaStorageSize does not exist on this runtime: the connected chain predates metered compute, and has no fee floor. Check PALLIORA_WS points at a current node."
|
|
2033
|
+
);
|
|
2034
|
+
const [maxDaStorageSize, providerStorageRate, thresholdDecryptionFee, millisecondsPerBlock] = await Promise.all([
|
|
2035
|
+
api2.query.compute.maxDaStorageSize(),
|
|
2036
|
+
api2.query.compute.providerStorageRate(),
|
|
2037
|
+
api2.query.compute.thresholdDecryptionFee(),
|
|
2038
|
+
readMillisecondsPerBlock()
|
|
2039
|
+
]);
|
|
2040
|
+
return {
|
|
2041
|
+
maxDaStorageSize: BigInt(maxDaStorageSize.toString()),
|
|
2042
|
+
providerStorageRate: BigInt(providerStorageRate.toString()),
|
|
2043
|
+
thresholdDecryptionFee: BigInt(thresholdDecryptionFee.toString()),
|
|
2044
|
+
millisecondsPerBlock
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
async function estimateMinFee(input) {
|
|
2048
|
+
const api2 = await getApi();
|
|
2049
|
+
assert(api2, "Api not initialized");
|
|
2050
|
+
const params = await getFeeParams();
|
|
2051
|
+
const resultFee = params.maxDaStorageSize * params.providerStorageRate;
|
|
2052
|
+
let inputFee = 0n;
|
|
2053
|
+
if (input.inputContractId) {
|
|
2054
|
+
const contract = (await api2.query.compute.contracts(input.inputContractId)).toJSON();
|
|
2055
|
+
if (contract) {
|
|
2056
|
+
inputFee = BigInt(String(_nullishCoalesce(_nullishCoalesce(contract["usagePrice"], () => ( contract["usage_price"])), () => ( 0))));
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
const offeredComponent = toAtomicPaliAmount(input.computeRate) * params.millisecondsPerBlock;
|
|
2060
|
+
return {
|
|
2061
|
+
resultFee,
|
|
2062
|
+
inputFee,
|
|
2063
|
+
thresholdDecryptionFee: params.thresholdDecryptionFee,
|
|
2064
|
+
offeredComponent,
|
|
2065
|
+
minFee: resultFee + inputFee + params.thresholdDecryptionFee + offeredComponent
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
|
|
1680
2069
|
// src/compute/encryptedInference.ts
|
|
1681
2070
|
|
|
1682
2071
|
|
|
@@ -1811,8 +2200,8 @@ async function getGuardianParticipants() {
|
|
|
1811
2200
|
const _peerid = _bs582.default.decode((peerid || "").toString());
|
|
1812
2201
|
const account = await api2.query.guardian.workerByKey(_peerid.slice(6, 38));
|
|
1813
2202
|
const nextIndex = currentIndex ? Number(currentIndex) + 1 : 1;
|
|
1814
|
-
const guardiansList = _optionalChain([guardians, 'optionalAccess',
|
|
1815
|
-
const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess',
|
|
2203
|
+
const guardiansList = _optionalChain([guardians, 'optionalAccess', _138 => _138.toJSON, 'call', _139 => _139()]) || [];
|
|
2204
|
+
const nextGuardiansList = _optionalChain([nextGuardians, 'optionalAccess', _140 => _140.toJSON, 'call', _141 => _141()]) || [];
|
|
1816
2205
|
const buildDetails = async (list) => {
|
|
1817
2206
|
return Promise.all(
|
|
1818
2207
|
list.map(async (guardian) => {
|
|
@@ -1821,21 +2210,21 @@ async function getGuardianParticipants() {
|
|
|
1821
2210
|
const bonded = await api2.query.staking.bonded(guardian);
|
|
1822
2211
|
const payee = await api2.query.staking.payee(guardian);
|
|
1823
2212
|
const stakersOverview = await api2.query.staking.erasStakersOverview(
|
|
1824
|
-
_optionalChain([currentEra, 'optionalAccess',
|
|
2213
|
+
_optionalChain([currentEra, 'optionalAccess', _142 => _142.toPrimitive, 'call', _143 => _143()]),
|
|
1825
2214
|
guardian
|
|
1826
2215
|
);
|
|
1827
2216
|
const guardianErasPrefs = await api2.query.staking.erasGuardianPrefs(
|
|
1828
|
-
_optionalChain([currentEra, 'optionalAccess',
|
|
2217
|
+
_optionalChain([currentEra, 'optionalAccess', _144 => _144.toPrimitive, 'call', _145 => _145()]),
|
|
1829
2218
|
guardian
|
|
1830
2219
|
);
|
|
1831
2220
|
return {
|
|
1832
2221
|
guardian,
|
|
1833
|
-
rewardDestination: _optionalChain([payee, 'optionalAccess',
|
|
1834
|
-
currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess',
|
|
1835
|
-
upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess',
|
|
1836
|
-
stash: _optionalChain([bonded, 'optionalAccess',
|
|
1837
|
-
currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess',
|
|
1838
|
-
upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess',
|
|
2222
|
+
rewardDestination: _optionalChain([payee, 'optionalAccess', _146 => _146.toHuman]) ? payee.toHuman() : null,
|
|
2223
|
+
currentPreferences: _optionalChain([guardianErasPrefs, 'optionalAccess', _147 => _147.toHuman]) ? guardianErasPrefs.toHuman() : null,
|
|
2224
|
+
upcomingPreferences: _optionalChain([guardianPrefs, 'optionalAccess', _148 => _148.toHuman]) ? guardianPrefs.toHuman() : null,
|
|
2225
|
+
stash: _optionalChain([bonded, 'optionalAccess', _149 => _149.toHuman]) ? bonded.toHuman() : null,
|
|
2226
|
+
currentStakeOverview: _optionalChain([stakersOverview, 'optionalAccess', _150 => _150.toHuman]) ? stakersOverview.toHuman() : null,
|
|
2227
|
+
upcomingStakeOverview: _optionalChain([ledger, 'optionalAccess', _151 => _151.toHuman]) ? ledger.toHuman() : null
|
|
1839
2228
|
};
|
|
1840
2229
|
})
|
|
1841
2230
|
);
|
|
@@ -1844,19 +2233,19 @@ async function getGuardianParticipants() {
|
|
|
1844
2233
|
const upcomingGuardians = await buildDetails(nextGuardiansList);
|
|
1845
2234
|
return {
|
|
1846
2235
|
nwState: {
|
|
1847
|
-
localPeerId: _optionalChain([peerid, 'optionalAccess',
|
|
1848
|
-
worker: _optionalChain([account, 'optionalAccess',
|
|
1849
|
-
currentEra: _optionalChain([currentEra, 'optionalAccess',
|
|
1850
|
-
guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess',
|
|
1851
|
-
nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess',
|
|
1852
|
-
currentIndex: _optionalChain([currentIndex, 'optionalAccess',
|
|
2236
|
+
localPeerId: _optionalChain([peerid, 'optionalAccess', _152 => _152.toString, 'call', _153 => _153()]),
|
|
2237
|
+
worker: _optionalChain([account, 'optionalAccess', _154 => _154.toHuman]) ? account.toHuman() : null,
|
|
2238
|
+
currentEra: _optionalChain([currentEra, 'optionalAccess', _155 => _155.toHuman]) ? currentEra.toHuman() : null,
|
|
2239
|
+
guardians: JSON.stringify(_optionalChain([guardians, 'optionalAccess', _156 => _156.toHuman]) ? guardians.toHuman() : null, null, 2),
|
|
2240
|
+
nextGuardians: JSON.stringify(_optionalChain([nextGuardians, 'optionalAccess', _157 => _157.toHuman]) ? nextGuardians.toHuman() : null, null, 2),
|
|
2241
|
+
currentIndex: _optionalChain([currentIndex, 'optionalAccess', _158 => _158.toHuman]) ? currentIndex.toHuman() : null,
|
|
1853
2242
|
nextIndex
|
|
1854
2243
|
},
|
|
1855
2244
|
currentGuardians,
|
|
1856
2245
|
upcomingGuardians
|
|
1857
2246
|
};
|
|
1858
2247
|
} finally {
|
|
1859
|
-
|
|
2248
|
+
await disconnectApi();
|
|
1860
2249
|
}
|
|
1861
2250
|
}
|
|
1862
2251
|
|
|
@@ -1888,6 +2277,179 @@ async function simpleCompute(params, account) {
|
|
|
1888
2277
|
return createAgreement(contract, account);
|
|
1889
2278
|
}
|
|
1890
2279
|
|
|
2280
|
+
// src/compute/stored.ts
|
|
2281
|
+
async function storedCompute(params, account) {
|
|
2282
|
+
assert(!!params.programContractId, "storedCompute requires a programContractId");
|
|
2283
|
+
assert(!!params.inputContractId, "storedCompute requires an inputContractId");
|
|
2284
|
+
const plaintextCipher = "Plaintext";
|
|
2285
|
+
const computeStep = {
|
|
2286
|
+
cipher: plaintextCipher,
|
|
2287
|
+
computerIndices: params.guardians.map((_, i) => i),
|
|
2288
|
+
...buildFee(params.fee),
|
|
2289
|
+
deadline: _nullishCoalesce(params.deadline, () => ( 0)),
|
|
2290
|
+
confidentiality: { Trusted: _nullishCoalesce(params.trustIndex, () => ( 0)) },
|
|
2291
|
+
feeFunction: null,
|
|
2292
|
+
input: { ContractId: { id: params.inputContractId } },
|
|
2293
|
+
program: { ContractId: { id: params.programContractId } },
|
|
2294
|
+
metadata: buildComputeMetadata(params.metadata)
|
|
2295
|
+
};
|
|
2296
|
+
const contract = {
|
|
2297
|
+
contractType: "Active",
|
|
2298
|
+
guardians: params.guardians,
|
|
2299
|
+
preCheck: null,
|
|
2300
|
+
compute: computeStep,
|
|
2301
|
+
postCheck: null,
|
|
2302
|
+
resultCipher: plaintextCipher
|
|
2303
|
+
};
|
|
2304
|
+
return createAgreement(contract, account);
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
// src/costEstimation/client.ts
|
|
2308
|
+
var CostEstimationError = class extends Error {
|
|
2309
|
+
constructor(message, status) {
|
|
2310
|
+
super(message);
|
|
2311
|
+
this.status = status;
|
|
2312
|
+
this.name = "CostEstimationError";
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
async function request(method, path2, body) {
|
|
2316
|
+
const url = `${getCostEstimatorUrl()}${path2}`;
|
|
2317
|
+
debugLog(`cost estimation service: ${method} ${url}`, body);
|
|
2318
|
+
const res = await fetch(url, {
|
|
2319
|
+
method,
|
|
2320
|
+
headers: body !== void 0 ? { "Content-Type": "application/json" } : void 0,
|
|
2321
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
2322
|
+
});
|
|
2323
|
+
const text = await res.text();
|
|
2324
|
+
const data = text ? JSON.parse(text) : void 0;
|
|
2325
|
+
if (!res.ok) {
|
|
2326
|
+
const message = data && typeof data === "object" && "error" in data ? String(data.error) : `cost estimation service returned ${res.status}`;
|
|
2327
|
+
throw new CostEstimationError(message, res.status);
|
|
2328
|
+
}
|
|
2329
|
+
return data;
|
|
2330
|
+
}
|
|
2331
|
+
var costEstimationClient = {
|
|
2332
|
+
get: (path2) => request("GET", path2),
|
|
2333
|
+
post: (path2, body) => request("POST", path2, body)
|
|
2334
|
+
};
|
|
2335
|
+
|
|
2336
|
+
// src/costEstimation/estimate.ts
|
|
2337
|
+
function toGuardianEntry(raw) {
|
|
2338
|
+
return {
|
|
2339
|
+
address: raw.address,
|
|
2340
|
+
pubKey: raw.pubKey,
|
|
2341
|
+
feeThreshold: BigInt(raw.feeThreshold)
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
function toEstimateResult(raw) {
|
|
2345
|
+
return {
|
|
2346
|
+
predictedDurationMs: raw.predictedDurationMs,
|
|
2347
|
+
auctionedRate: BigInt(raw.auctionedRate),
|
|
2348
|
+
estimatedCost: BigInt(raw.estimatedCost),
|
|
2349
|
+
guardians: raw.guardians.map(toGuardianEntry)
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
function toEstimateStatusResponse(raw) {
|
|
2353
|
+
if (raw.status === "completed") {
|
|
2354
|
+
return { status: "completed", auctionId: raw.auctionId, result: toEstimateResult(raw.result) };
|
|
2355
|
+
}
|
|
2356
|
+
return raw;
|
|
2357
|
+
}
|
|
2358
|
+
async function startEstimate(params) {
|
|
2359
|
+
return costEstimationClient.post("/estimate", params);
|
|
2360
|
+
}
|
|
2361
|
+
async function getEstimateResult(estimateId) {
|
|
2362
|
+
const raw = await costEstimationClient.get(
|
|
2363
|
+
`/estimates/${encodeURIComponent(estimateId)}`
|
|
2364
|
+
);
|
|
2365
|
+
return toEstimateStatusResponse(raw);
|
|
2366
|
+
}
|
|
2367
|
+
async function waitForEstimate(params, options = {}) {
|
|
2368
|
+
const { intervalMs = 5e3, timeoutMs = 6e4 } = options;
|
|
2369
|
+
const { estimateId } = await startEstimate(params);
|
|
2370
|
+
const deadline = Date.now() + timeoutMs;
|
|
2371
|
+
for (; ; ) {
|
|
2372
|
+
const status = await getEstimateResult(estimateId);
|
|
2373
|
+
if (status.status !== "pending") {
|
|
2374
|
+
return { estimateId, status };
|
|
2375
|
+
}
|
|
2376
|
+
const remaining = deadline - Date.now();
|
|
2377
|
+
if (remaining <= 0) {
|
|
2378
|
+
throw new Error(
|
|
2379
|
+
`waitForEstimate: estimate ${estimateId} still pending after ${timeoutMs}ms`
|
|
2380
|
+
);
|
|
2381
|
+
}
|
|
2382
|
+
await sleep(Math.min(intervalMs, remaining));
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
function sleep(ms) {
|
|
2386
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
// src/costEstimation/auction.ts
|
|
2390
|
+
|
|
2391
|
+
function toAuctionWinner(raw) {
|
|
2392
|
+
return { guardian: raw.guardian, rate: BigInt(raw.rate) };
|
|
2393
|
+
}
|
|
2394
|
+
async function listOpenAuctions() {
|
|
2395
|
+
const { auctions } = await costEstimationClient.get("/auctions");
|
|
2396
|
+
return auctions;
|
|
2397
|
+
}
|
|
2398
|
+
async function listGuardianAuctions(guardianAddress) {
|
|
2399
|
+
const { auctions } = await costEstimationClient.get(
|
|
2400
|
+
`/guardians/${encodeURIComponent(guardianAddress)}/auctions`
|
|
2401
|
+
);
|
|
2402
|
+
return auctions;
|
|
2403
|
+
}
|
|
2404
|
+
async function getAuction(auctionId) {
|
|
2405
|
+
const raw = await costEstimationClient.get(
|
|
2406
|
+
`/auctions/${encodeURIComponent(auctionId)}`
|
|
2407
|
+
);
|
|
2408
|
+
return {
|
|
2409
|
+
auctionId: raw.auctionId,
|
|
2410
|
+
contractId: raw.contractId,
|
|
2411
|
+
guardians: raw.guardians,
|
|
2412
|
+
deadline: raw.deadline,
|
|
2413
|
+
resolved: raw.resolved,
|
|
2414
|
+
winner: raw.winner ? toAuctionWinner(raw.winner) : void 0
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
async function listResolvedGuardianAuctions(guardianAddress) {
|
|
2418
|
+
const { auctions } = await costEstimationClient.get(
|
|
2419
|
+
`/guardians/${encodeURIComponent(guardianAddress)}/auctions?resolved=true`
|
|
2420
|
+
);
|
|
2421
|
+
return auctions.map((a) => ({
|
|
2422
|
+
auctionId: a.auctionId,
|
|
2423
|
+
contractId: a.contractId,
|
|
2424
|
+
guardians: a.guardians,
|
|
2425
|
+
deadline: a.deadline,
|
|
2426
|
+
winner: toAuctionWinner(a.winner)
|
|
2427
|
+
}));
|
|
2428
|
+
}
|
|
2429
|
+
async function submitAuctionBid(auctionId, rate, guardian) {
|
|
2430
|
+
const signature = _util.u8aToHex.call(void 0, guardian.sign(`${auctionId}:${rate}`));
|
|
2431
|
+
await costEstimationClient.post(
|
|
2432
|
+
`/auctions/${encodeURIComponent(auctionId)}/bid`,
|
|
2433
|
+
{ guardian: guardian.address, rate, signature }
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
// src/costEstimation/webhook.ts
|
|
2438
|
+
|
|
2439
|
+
async function registerGuardianWebhook(url, guardian) {
|
|
2440
|
+
const signature = _util.u8aToHex.call(void 0, guardian.sign(`webhook:${url}`));
|
|
2441
|
+
await costEstimationClient.post(
|
|
2442
|
+
`/guardians/${encodeURIComponent(guardian.address)}/webhook`,
|
|
2443
|
+
{ url, signature }
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// src/costEstimation/health.ts
|
|
2448
|
+
async function healthCheck() {
|
|
2449
|
+
const { status } = await costEstimationClient.get("/health");
|
|
2450
|
+
return status === "ok";
|
|
2451
|
+
}
|
|
2452
|
+
|
|
1891
2453
|
// src/da/register.ts
|
|
1892
2454
|
async function writeMetadata(account, name, description, ref, price, dataType, l2Owner, groupId) {
|
|
1893
2455
|
const blobRef = [ref.blockNumber, ref.index];
|
|
@@ -1898,7 +2460,7 @@ async function writeMetadata(account, name, description, ref, price, dataType, l
|
|
|
1898
2460
|
const api2 = await getApi();
|
|
1899
2461
|
assert(api2, "Failed to get API connection");
|
|
1900
2462
|
debugLog(`Registering metadata for ${name} at ${formatPaliAmount(price)}`);
|
|
1901
|
-
const
|
|
2463
|
+
const request2 = api2.tx.dataAvailability.daccRegisterData(
|
|
1902
2464
|
nameBytes,
|
|
1903
2465
|
descriptionBytes,
|
|
1904
2466
|
blobRef,
|
|
@@ -1907,7 +2469,7 @@ async function writeMetadata(account, name, description, ref, price, dataType, l
|
|
|
1907
2469
|
ownerBytes,
|
|
1908
2470
|
groupId
|
|
1909
2471
|
);
|
|
1910
|
-
const hash = await signAndSend(
|
|
2472
|
+
const hash = await signAndSend(request2, account);
|
|
1911
2473
|
debugLog(`Metadata registration transaction sent with hash: ${hash.hash}`);
|
|
1912
2474
|
return hash;
|
|
1913
2475
|
}
|
|
@@ -1917,13 +2479,7 @@ async function registerDataAgreement(account, params) {
|
|
|
1917
2479
|
);
|
|
1918
2480
|
const cipher = _nullishCoalesce(params.cipher, () => ( "Plaintext"));
|
|
1919
2481
|
const resultCipher = _nullishCoalesce(params.resultCipher, () => ( "Plaintext"));
|
|
1920
|
-
const
|
|
1921
|
-
const computeMetadata = params.metadata ? {
|
|
1922
|
-
name: Array.from(encoder.encode(params.metadata.name)),
|
|
1923
|
-
description: Array.from(encoder.encode(params.metadata.description)),
|
|
1924
|
-
storeType: params.metadata.storeType,
|
|
1925
|
-
groupId: params.metadata.groupId
|
|
1926
|
-
} : null;
|
|
2482
|
+
const computeMetadata = buildComputeMetadata(params.metadata);
|
|
1927
2483
|
const computeStep = {
|
|
1928
2484
|
cipher,
|
|
1929
2485
|
computerIndices: params.guardians.map((_, i) => i),
|
|
@@ -1959,7 +2515,7 @@ async function runAgent(account, agentRef, nonce, ciphertext, tdParams, pkBytes,
|
|
|
1959
2515
|
const baseModelTuple = [baseModel.blockNumber, baseModel.index];
|
|
1960
2516
|
const api2 = await getApi();
|
|
1961
2517
|
assert(api2, "Failed to get API connection");
|
|
1962
|
-
const
|
|
2518
|
+
const request2 = api2.tx.dataAvailability.daccRunAgent(
|
|
1963
2519
|
agentRefTuple,
|
|
1964
2520
|
Array.from(nonce),
|
|
1965
2521
|
Array.from(ciphertext),
|
|
@@ -1979,7 +2535,7 @@ async function runAgent(account, agentRef, nonce, ciphertext, tdParams, pkBytes,
|
|
|
1979
2535
|
agreement: [agreementId]
|
|
1980
2536
|
}
|
|
1981
2537
|
};
|
|
1982
|
-
const hash = await signAndSend(
|
|
2538
|
+
const hash = await signAndSend(request2, account, opts);
|
|
1983
2539
|
debugLog(`Run agent transaction sent with hash: ${hash.hash}`);
|
|
1984
2540
|
return hash;
|
|
1985
2541
|
}
|
|
@@ -2011,8 +2567,8 @@ async function submitTEData(account, data, chosenGuardians, tau_params, agg_key,
|
|
|
2011
2567
|
});
|
|
2012
2568
|
const api2 = await getApi();
|
|
2013
2569
|
assert(api2, "Failed to get API connection");
|
|
2014
|
-
const
|
|
2015
|
-
const hash = await signAndSend(
|
|
2570
|
+
const request2 = await api2.tx.dataAvailability.submitData(modelSubmit);
|
|
2571
|
+
const hash = await signAndSend(request2, account, DEFAULT_EMPTY_PAYLOAD);
|
|
2016
2572
|
debugLog(`TE data availability transaction sent with hash: ${hash.hash}`);
|
|
2017
2573
|
return hash;
|
|
2018
2574
|
}
|
|
@@ -2025,8 +2581,8 @@ async function submitTEDataWithCipher(account, data, chosenGuardians, tau_params
|
|
|
2025
2581
|
const ciphertextHex = "0x" + Array.from(ciphertext).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2026
2582
|
const api2 = await getApi();
|
|
2027
2583
|
assert(api2, "Failed to get API connection");
|
|
2028
|
-
const
|
|
2029
|
-
const ref = await signAndSend(
|
|
2584
|
+
const request2 = await api2.tx.dataAvailability.submitData(ciphertextHex);
|
|
2585
|
+
const ref = await signAndSend(request2, account, DEFAULT_EMPTY_PAYLOAD);
|
|
2030
2586
|
debugLog(`TE data availability transaction sent with hash: ${ref.hash}`);
|
|
2031
2587
|
return {
|
|
2032
2588
|
ref,
|
|
@@ -2061,7 +2617,7 @@ async function uploadData(options) {
|
|
|
2061
2617
|
if (filePath) {
|
|
2062
2618
|
throw new Error("uploadData: file path upload is not implemented");
|
|
2063
2619
|
} else {
|
|
2064
|
-
const storeType = type === "model" ? "Model" : type === "agent" ? "Agent" : "Dataset";
|
|
2620
|
+
const storeType = type === "model" ? "Model" : type === "agent" ? "Agent" : type === "executable" ? "Executable" : "Dataset";
|
|
2065
2621
|
const { ref: dataRef, cipher } = await submitTEDataWithCipher(
|
|
2066
2622
|
account,
|
|
2067
2623
|
ref || "",
|
|
@@ -2123,7 +2679,7 @@ async function uploadDataLegacy(options) {
|
|
|
2123
2679
|
guardianGroupInfo.aggKey,
|
|
2124
2680
|
guardianGroupInfo.groupPk
|
|
2125
2681
|
);
|
|
2126
|
-
const dtype = type === "model" ? 1 : type === "agent" ? 2 : 0;
|
|
2682
|
+
const dtype = type === "model" ? 1 : type === "agent" ? 2 : type === "executable" ? 4 : 0;
|
|
2127
2683
|
await writeMetadata(
|
|
2128
2684
|
account,
|
|
2129
2685
|
name,
|
|
@@ -2203,9 +2759,9 @@ async function removeStake(account) {
|
|
|
2203
2759
|
const api2 = await getApi();
|
|
2204
2760
|
assert(api2, "API not initialized");
|
|
2205
2761
|
assert(account, "Account not initialized");
|
|
2206
|
-
const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async
|
|
2207
|
-
debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess',
|
|
2208
|
-
const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess',
|
|
2762
|
+
const stakeAmount = await _asyncOptionalChain([(await api2.query.staking.ledger(account.address)), 'optionalAccess', async _159 => _159.toPrimitive, 'call', async _160 => _160()]);
|
|
2763
|
+
debugLog("Removing entire stake amount:", formatPaliAmount(_optionalChain([stakeAmount, 'optionalAccess', _161 => _161.active]) || 0n));
|
|
2764
|
+
const unstakeTx = api2.tx.staking.unbond(_optionalChain([stakeAmount, 'optionalAccess', _162 => _162.active]) || 0n);
|
|
2209
2765
|
const hash = await signAndSend(unstakeTx, account);
|
|
2210
2766
|
debugLog(`Unstake transaction sent with hash: ${hash.hash}`);
|
|
2211
2767
|
}
|
|
@@ -2220,6 +2776,67 @@ async function withdrawStake(account) {
|
|
|
2220
2776
|
debugLog(`Unstake transaction sent with hash: ${hash.hash}`);
|
|
2221
2777
|
}
|
|
2222
2778
|
|
|
2779
|
+
// src/storage/s3.ts
|
|
2780
|
+
var S3Provider = class {
|
|
2781
|
+
constructor() {
|
|
2782
|
+
this.id = "s3";
|
|
2783
|
+
}
|
|
2784
|
+
getDeterministicUrl(hash) {
|
|
2785
|
+
return `https://${getAwsS3Bucket()}.s3.${getAwsRegion()}.amazonaws.com/Contracts/${hash}`;
|
|
2786
|
+
}
|
|
2787
|
+
async getUploadUrl(txHash, fileHash, blockNumber, expectedUrl) {
|
|
2788
|
+
const response = await fetch(`${getAuthServiceUrl()}/api/s3/auth`, {
|
|
2789
|
+
method: "POST",
|
|
2790
|
+
headers: { "Content-Type": "application/json" },
|
|
2791
|
+
body: JSON.stringify({ txHash, fileHash, blockNumber, url: expectedUrl })
|
|
2792
|
+
});
|
|
2793
|
+
if (!response.ok) {
|
|
2794
|
+
let errorMessage = response.statusText;
|
|
2795
|
+
try {
|
|
2796
|
+
const errData = await response.json();
|
|
2797
|
+
if (errData.error) errorMessage = errData.error;
|
|
2798
|
+
} catch (e) {
|
|
2799
|
+
}
|
|
2800
|
+
throw new Error(`Auth Service failed: ${errorMessage}`);
|
|
2801
|
+
}
|
|
2802
|
+
const { presignedUrl } = await response.json();
|
|
2803
|
+
if (!presignedUrl) {
|
|
2804
|
+
throw new Error("No presignedUrl returned from Auth Service");
|
|
2805
|
+
}
|
|
2806
|
+
return presignedUrl;
|
|
2807
|
+
}
|
|
2808
|
+
async upload(url, data) {
|
|
2809
|
+
const response = await fetch(url, {
|
|
2810
|
+
method: "PUT",
|
|
2811
|
+
body: data
|
|
2812
|
+
});
|
|
2813
|
+
if (!response.ok) {
|
|
2814
|
+
throw new Error(`Storage Upload failed: ${response.statusText}`);
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
// src/storage/router.ts
|
|
2820
|
+
var StorageRouter = class {
|
|
2821
|
+
constructor() {
|
|
2822
|
+
this.providers = /* @__PURE__ */ new Map();
|
|
2823
|
+
this.register(new S3Provider());
|
|
2824
|
+
this.defaultProvider = "s3";
|
|
2825
|
+
}
|
|
2826
|
+
register(provider) {
|
|
2827
|
+
this.providers.set(provider.id, provider);
|
|
2828
|
+
}
|
|
2829
|
+
getProvider(id) {
|
|
2830
|
+
const targetId = id || this.defaultProvider;
|
|
2831
|
+
const provider = this.providers.get(targetId);
|
|
2832
|
+
if (!provider) {
|
|
2833
|
+
throw new Error(`Storage provider '${targetId}' not found`);
|
|
2834
|
+
}
|
|
2835
|
+
return provider;
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
var storageRouter = new StorageRouter();
|
|
2839
|
+
|
|
2223
2840
|
// src/token/fund.ts
|
|
2224
2841
|
async function fundAccount(account, amountBaseUnits, address) {
|
|
2225
2842
|
const addr = address ? address : account.address;
|
|
@@ -2266,15 +2883,499 @@ Setting identity for account: ${account.address} as ${display}`);
|
|
|
2266
2883
|
debugLog(`Set identity transaction sent with hash: ${hash.hash}`);
|
|
2267
2884
|
}
|
|
2268
2885
|
|
|
2886
|
+
// src/indexer/client.ts
|
|
2887
|
+
var DEFAULT_BASE_URL = "http://localhost:5020";
|
|
2888
|
+
var IndexerClient = class {
|
|
2889
|
+
constructor(options = {}) {
|
|
2890
|
+
this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "").replace(/\/api$/i, "");
|
|
2891
|
+
this._fetch = _nullishCoalesce(options.fetch, () => ( globalThis.fetch.bind(globalThis)));
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Performs a GET request against the indexer and returns the parsed JSON body.
|
|
2895
|
+
*
|
|
2896
|
+
* @throws {IndexerHttpError} When the response indicates failure (`success: false`)
|
|
2897
|
+
* or the HTTP status is not 2xx.
|
|
2898
|
+
*/
|
|
2899
|
+
async get(path2, params) {
|
|
2900
|
+
const url = new URL(`${this.baseUrl}${path2}`);
|
|
2901
|
+
if (params) {
|
|
2902
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2903
|
+
if (value !== void 0 && value !== null) {
|
|
2904
|
+
url.searchParams.set(key, String(value));
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
const response = await this._fetch(url.toString(), {
|
|
2909
|
+
method: "GET",
|
|
2910
|
+
headers: { Accept: "application/json" }
|
|
2911
|
+
});
|
|
2912
|
+
const raw = await response.text();
|
|
2913
|
+
let body;
|
|
2914
|
+
try {
|
|
2915
|
+
body = raw ? JSON.parse(raw) : null;
|
|
2916
|
+
} catch (e2) {
|
|
2917
|
+
if (!response.ok) {
|
|
2918
|
+
throw new IndexerHttpError(
|
|
2919
|
+
response.status,
|
|
2920
|
+
raw || response.statusText
|
|
2921
|
+
);
|
|
2922
|
+
}
|
|
2923
|
+
throw new IndexerHttpError(
|
|
2924
|
+
response.status,
|
|
2925
|
+
`Invalid JSON response from ${url.toString()}: ${raw.slice(0, 120)}`
|
|
2926
|
+
);
|
|
2927
|
+
}
|
|
2928
|
+
if (!response.ok) {
|
|
2929
|
+
const errBody = body;
|
|
2930
|
+
throw new IndexerHttpError(
|
|
2931
|
+
response.status,
|
|
2932
|
+
_nullishCoalesce(_optionalChain([errBody, 'optionalAccess', _163 => _163.message]), () => ( response.statusText))
|
|
2933
|
+
);
|
|
2934
|
+
}
|
|
2935
|
+
return body;
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
var IndexerHttpError = class extends Error {
|
|
2939
|
+
constructor(statusCode, message) {
|
|
2940
|
+
super(message);
|
|
2941
|
+
this.name = "IndexerHttpError";
|
|
2942
|
+
this.statusCode = statusCode;
|
|
2943
|
+
}
|
|
2944
|
+
};
|
|
2945
|
+
|
|
2946
|
+
// src/indexer/artefacts.ts
|
|
2947
|
+
async function getArtefacts(client, query) {
|
|
2948
|
+
return client.get("/api/artefacts", query ? { ...query } : void 0);
|
|
2949
|
+
}
|
|
2950
|
+
async function getArtefactsByStoreType(client, storeType) {
|
|
2951
|
+
const response = await getArtefacts(client);
|
|
2952
|
+
return {
|
|
2953
|
+
success: true,
|
|
2954
|
+
data: response.data.filter((item) => item.storeType === storeType)
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
async function getDatasets(client) {
|
|
2958
|
+
return getArtefactsByStoreType(client, "Dataset");
|
|
2959
|
+
}
|
|
2960
|
+
async function getModels(client) {
|
|
2961
|
+
return getArtefactsByStoreType(client, "Model");
|
|
2962
|
+
}
|
|
2963
|
+
async function getAgents(client) {
|
|
2964
|
+
return getArtefactsByStoreType(client, "Agent");
|
|
2965
|
+
}
|
|
2966
|
+
async function getExecutables(client) {
|
|
2967
|
+
return getArtefactsByStoreType(client, "Executable");
|
|
2968
|
+
}
|
|
2969
|
+
async function getArtefact(client, id) {
|
|
2970
|
+
return client.get(`/api/artefact/${encodeURIComponent(id)}`);
|
|
2971
|
+
}
|
|
2972
|
+
async function getArtefactAccess(client, id, query) {
|
|
2973
|
+
return client.get(
|
|
2974
|
+
`/api/artefact/${encodeURIComponent(id)}/access`,
|
|
2975
|
+
query ? { ...query } : void 0
|
|
2976
|
+
);
|
|
2977
|
+
}
|
|
2978
|
+
function nestedContractId(value) {
|
|
2979
|
+
if (typeof value === "string") return value;
|
|
2980
|
+
if (value && typeof value === "object" && "id" in value) {
|
|
2981
|
+
const id = value.id;
|
|
2982
|
+
return typeof id === "string" ? id : void 0;
|
|
2983
|
+
}
|
|
2984
|
+
return void 0;
|
|
2985
|
+
}
|
|
2986
|
+
function isArtefactUsage(doc, artefactId) {
|
|
2987
|
+
if (!doc || doc.contractId === artefactId) return false;
|
|
2988
|
+
if (doc.inputContractId === artefactId) return true;
|
|
2989
|
+
const compute = doc.compute;
|
|
2990
|
+
const inputId = nestedContractId(_optionalChain([compute, 'optionalAccess', _164 => _164.input, 'optionalAccess', _165 => _165.contractId]));
|
|
2991
|
+
const programId = nestedContractId(_optionalChain([compute, 'optionalAccess', _166 => _166.program, 'optionalAccess', _167 => _167.contractId]));
|
|
2992
|
+
return inputId === artefactId || programId === artefactId;
|
|
2993
|
+
}
|
|
2994
|
+
async function getArtefactContracts(client, id, query) {
|
|
2995
|
+
const response = await client.get(
|
|
2996
|
+
`/api/artefact/${encodeURIComponent(id)}/contracts`,
|
|
2997
|
+
query ? { ...query } : void 0
|
|
2998
|
+
);
|
|
2999
|
+
const list = Array.isArray(response.data) ? response.data : [];
|
|
3000
|
+
const usages = list.filter((item) => isArtefactUsage(item, id));
|
|
3001
|
+
if (usages.length > 0) {
|
|
3002
|
+
return { ...response, data: usages };
|
|
3003
|
+
}
|
|
3004
|
+
const looksLikeSelfOnly = list.length > 0 && list.every((item) => _optionalChain([item, 'optionalAccess', _168 => _168.contractId]) === id);
|
|
3005
|
+
if (!looksLikeSelfOnly) {
|
|
3006
|
+
return {
|
|
3007
|
+
...response,
|
|
3008
|
+
data: list.filter((item) => _optionalChain([item, 'optionalAccess', _169 => _169.contractId]) !== id)
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
const artefacts = await getArtefacts(client);
|
|
3012
|
+
return {
|
|
3013
|
+
success: true,
|
|
3014
|
+
data: (artefacts.data || []).filter(
|
|
3015
|
+
(item) => isArtefactUsage(item, id)
|
|
3016
|
+
)
|
|
3017
|
+
};
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// src/indexer/contracts.ts
|
|
3021
|
+
async function getContracts(client, query) {
|
|
3022
|
+
return client.get("/api/contracts", query ? { ...query } : void 0);
|
|
3023
|
+
}
|
|
3024
|
+
async function getContract(client, id) {
|
|
3025
|
+
return client.get(`/api/contract/${encodeURIComponent(id)}`);
|
|
3026
|
+
}
|
|
3027
|
+
async function getCompute(client, id) {
|
|
3028
|
+
return client.get(`/api/compute/${encodeURIComponent(id)}`);
|
|
3029
|
+
}
|
|
3030
|
+
async function getResults(client, query) {
|
|
3031
|
+
return client.get("/api/results", { contractId: query.contractId });
|
|
3032
|
+
}
|
|
3033
|
+
async function getResult(client, id) {
|
|
3034
|
+
return client.get(`/api/result/${encodeURIComponent(id)}`);
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
// src/indexer/blobs.ts
|
|
3038
|
+
async function getBlob(client, id) {
|
|
3039
|
+
return client.get(`/api/blob/${encodeURIComponent(String(id))}`);
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
// src/indexer/flow.ts
|
|
3043
|
+
function computeTime(item) {
|
|
3044
|
+
return _nullishCoalesce(_optionalChain([item, 'access', _170 => _170.indexer, 'optionalAccess', _171 => _171.blockTime]), () => ( 0));
|
|
3045
|
+
}
|
|
3046
|
+
function isComputeRequest(item) {
|
|
3047
|
+
return Boolean(
|
|
3048
|
+
item.jobId || item.orchestrator || item.resultTx || item.computeReward || item.decryptionFee
|
|
3049
|
+
);
|
|
3050
|
+
}
|
|
3051
|
+
function normalizeComputes(compute) {
|
|
3052
|
+
if (!compute) return [];
|
|
3053
|
+
const list = Array.isArray(compute) ? compute : Array.isArray(compute.computes) ? compute.computes : [compute];
|
|
3054
|
+
return [...list].filter(isComputeRequest).sort((a, b) => computeTime(a) - computeTime(b));
|
|
3055
|
+
}
|
|
3056
|
+
function resultToCompute(result) {
|
|
3057
|
+
const indexer = result.indexer;
|
|
3058
|
+
return {
|
|
3059
|
+
...result,
|
|
3060
|
+
jobId: result.resultId,
|
|
3061
|
+
contractId: result.contractId,
|
|
3062
|
+
orchestrator: result.submitor,
|
|
3063
|
+
resultTx: indexer ? {
|
|
3064
|
+
blockHeight: indexer.blockHeight,
|
|
3065
|
+
extrinsicIndex: indexer.extrinsicIndex,
|
|
3066
|
+
blockHash: indexer.blockHash,
|
|
3067
|
+
hash: indexer.blockHash
|
|
3068
|
+
} : { hash: result.resultId },
|
|
3069
|
+
computeReward: _optionalChain([result, 'access', _172 => _172.feeBreakdown, 'optionalAccess', _173 => _173.submitorFee, 'optionalAccess', _174 => _174.amount]),
|
|
3070
|
+
fee: _optionalChain([result, 'access', _175 => _175.feeBreakdown, 'optionalAccess', _176 => _176.resultFee]),
|
|
3071
|
+
decryptionFee: _optionalChain([result, 'access', _177 => _177.feeBreakdown, 'optionalAccess', _178 => _178.thresholdDecryptionFee]),
|
|
3072
|
+
indexer
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
function mergeComputes(fromResults, fromCompute) {
|
|
3076
|
+
if (fromResults.length === 0) return fromCompute;
|
|
3077
|
+
const ids = new Set(
|
|
3078
|
+
fromResults.flatMap((item) => [item.jobId, item.contractId].filter(Boolean))
|
|
3079
|
+
);
|
|
3080
|
+
const extras = fromCompute.filter(
|
|
3081
|
+
(item) => !ids.has(_nullishCoalesce(item.jobId, () => ( ""))) && !ids.has(_nullishCoalesce(item.contractId, () => ( "")))
|
|
3082
|
+
);
|
|
3083
|
+
return normalizeComputes([...fromResults, ...extras]);
|
|
3084
|
+
}
|
|
3085
|
+
function withParties(agreement) {
|
|
3086
|
+
if (_optionalChain([agreement, 'access', _179 => _179.parties, 'optionalAccess', _180 => _180.length])) return agreement;
|
|
3087
|
+
const guardians = agreement.guardians;
|
|
3088
|
+
if (Array.isArray(guardians) && guardians.length) {
|
|
3089
|
+
return { ...agreement, parties: guardians };
|
|
3090
|
+
}
|
|
3091
|
+
return agreement;
|
|
3092
|
+
}
|
|
3093
|
+
function deriveContractStatus(agreement, compute) {
|
|
3094
|
+
if (!agreement) return "\u2014";
|
|
3095
|
+
const computes = normalizeComputes(compute);
|
|
3096
|
+
if (computes.length === 0) {
|
|
3097
|
+
return (_nullishCoalesce(_optionalChain([agreement, 'access', _181 => _181.responses, 'optionalAccess', _182 => _182.length]), () => ( 0))) > 0 ? "ACCEPTED" : "PENDING";
|
|
3098
|
+
}
|
|
3099
|
+
if (computes.every((item) => !!item.resultTx)) return "COMPLETED";
|
|
3100
|
+
return "PROCESSING";
|
|
3101
|
+
}
|
|
3102
|
+
function buildContractPhases(agreement, compute) {
|
|
3103
|
+
const computes = normalizeComputes(compute);
|
|
3104
|
+
const latest = _nullishCoalesce(computes[computes.length - 1], () => ( null));
|
|
3105
|
+
const settledCount = computes.filter((item) => !!item.resultTx).length;
|
|
3106
|
+
const status = deriveContractStatus(agreement, computes);
|
|
3107
|
+
const phase1Active = !!agreement;
|
|
3108
|
+
const phase1Complete = status === "ACCEPTED" || status === "PROCESSING" || status === "COMPLETED";
|
|
3109
|
+
const phase2Active = computes.length > 0;
|
|
3110
|
+
const allSettled = computes.length > 0 && settledCount === computes.length;
|
|
3111
|
+
const phase5Complete = status === "COMPLETED";
|
|
3112
|
+
const requestsJson = computes.map((item) => {
|
|
3113
|
+
const { _id: _ignored, ...rest } = item;
|
|
3114
|
+
return rest;
|
|
3115
|
+
});
|
|
3116
|
+
return [
|
|
3117
|
+
{
|
|
3118
|
+
id: "phase-1",
|
|
3119
|
+
title: "Phase 1: Contract Agreement",
|
|
3120
|
+
status: agreement ? `RESPONSES (${_nullishCoalesce(_optionalChain([agreement, 'access', _183 => _183.responses, 'optionalAccess', _184 => _184.length]), () => ( 0))})` : "\u2014",
|
|
3121
|
+
description: "Established once and reused by every compute request in this session.",
|
|
3122
|
+
json: agreement ? {
|
|
3123
|
+
contractId: agreement.contractId,
|
|
3124
|
+
creator: agreement.creator,
|
|
3125
|
+
fee: agreement.fee,
|
|
3126
|
+
creationTime: agreement.creationTime,
|
|
3127
|
+
parties: agreement.parties,
|
|
3128
|
+
responses: agreement.responses,
|
|
3129
|
+
indexer: agreement.indexer,
|
|
3130
|
+
computeTx: agreement.computeTx
|
|
3131
|
+
} : {},
|
|
3132
|
+
active: phase1Active,
|
|
3133
|
+
complete: phase1Complete,
|
|
3134
|
+
pending: phase1Active && !phase1Complete
|
|
3135
|
+
},
|
|
3136
|
+
{
|
|
3137
|
+
id: "phase-2",
|
|
3138
|
+
title: "Phase 2: Compute Request",
|
|
3139
|
+
status: phase2Active ? `${computes.length} SUBMITTED` : "PENDING",
|
|
3140
|
+
description: "Each iteration submits a compute request that is broadcast to all guardians.",
|
|
3141
|
+
json: { requestCount: computes.length, requests: requestsJson },
|
|
3142
|
+
active: phase2Active,
|
|
3143
|
+
complete: phase2Active,
|
|
3144
|
+
pending: phase1Complete && !phase2Active
|
|
3145
|
+
},
|
|
3146
|
+
{
|
|
3147
|
+
id: "phase-3",
|
|
3148
|
+
title: "Phase 3: Guardian Execution",
|
|
3149
|
+
status: allSettled ? `${settledCount}/${computes.length} RESULT_SUBMITTED` : phase2Active ? `${settledCount}/${computes.length} PROCESSING` : "PENDING",
|
|
3150
|
+
description: "One guardian claims each request, executes compute, and submits the result on-chain.",
|
|
3151
|
+
json: _optionalChain([latest, 'optionalAccess', _185 => _185.resultTx]) ? {
|
|
3152
|
+
jobId: latest.jobId,
|
|
3153
|
+
contractId: latest.contractId,
|
|
3154
|
+
orchestrator: latest.orchestrator,
|
|
3155
|
+
resultTx: latest.resultTx,
|
|
3156
|
+
settledCount,
|
|
3157
|
+
requestCount: computes.length
|
|
3158
|
+
} : { settledCount, requestCount: computes.length },
|
|
3159
|
+
active: phase2Active,
|
|
3160
|
+
complete: allSettled,
|
|
3161
|
+
pending: phase2Active && !allSettled
|
|
3162
|
+
},
|
|
3163
|
+
{
|
|
3164
|
+
id: "phase-4",
|
|
3165
|
+
title: "Phase 4: Fee Distribution",
|
|
3166
|
+
status: allSettled ? `${settledCount}/${computes.length} SETTLED` : phase2Active ? "PROCESSING" : "PENDING",
|
|
3167
|
+
description: "Executor reward is paid per completed request. TD fee was locked once at agreement.",
|
|
3168
|
+
json: allSettled ? {
|
|
3169
|
+
requestCount: computes.length,
|
|
3170
|
+
settledCount,
|
|
3171
|
+
computeReward: _optionalChain([latest, 'optionalAccess', _186 => _186.computeReward]),
|
|
3172
|
+
decryptionFee: _optionalChain([latest, 'optionalAccess', _187 => _187.decryptionFee]),
|
|
3173
|
+
fee: _optionalChain([latest, 'optionalAccess', _188 => _188.fee])
|
|
3174
|
+
} : { requestCount: computes.length, settledCount },
|
|
3175
|
+
active: allSettled,
|
|
3176
|
+
complete: allSettled,
|
|
3177
|
+
pending: phase2Active && !allSettled
|
|
3178
|
+
},
|
|
3179
|
+
{
|
|
3180
|
+
id: "phase-5",
|
|
3181
|
+
title: "Phase 5: Close Out",
|
|
3182
|
+
status: phase5Complete ? "SETTLED" : phase1Complete ? "PENDING" : "\u2014",
|
|
3183
|
+
description: "User sends closeout, guardians clean up, remaining funds are refunded.",
|
|
3184
|
+
json: {
|
|
3185
|
+
requestCount: computes.length,
|
|
3186
|
+
settledCount,
|
|
3187
|
+
finalStatus: phase5Complete ? "SETTLED" : status
|
|
3188
|
+
},
|
|
3189
|
+
active: phase5Complete,
|
|
3190
|
+
complete: phase5Complete,
|
|
3191
|
+
pending: phase1Complete && !phase5Complete
|
|
3192
|
+
}
|
|
3193
|
+
];
|
|
3194
|
+
}
|
|
3195
|
+
async function getContractFlow(client, id) {
|
|
3196
|
+
const [agreementResponse, compute, results] = await Promise.all([
|
|
3197
|
+
getContract(client, id),
|
|
3198
|
+
getCompute(client, id).then((response) => response.data).catch((err) => {
|
|
3199
|
+
if (err instanceof IndexerHttpError && err.statusCode === 404) return null;
|
|
3200
|
+
throw err;
|
|
3201
|
+
}),
|
|
3202
|
+
getResults(client, { contractId: id }).then((response) => response.data).catch((err) => {
|
|
3203
|
+
if (err instanceof IndexerHttpError && err.statusCode === 404) return [];
|
|
3204
|
+
throw err;
|
|
3205
|
+
})
|
|
3206
|
+
]);
|
|
3207
|
+
const agreement = withParties(agreementResponse.data);
|
|
3208
|
+
const computes = mergeComputes(
|
|
3209
|
+
(_nullishCoalesce(results, () => ( []))).map(resultToCompute),
|
|
3210
|
+
normalizeComputes(compute)
|
|
3211
|
+
);
|
|
3212
|
+
const latest = _nullishCoalesce(computes[computes.length - 1], () => ( null));
|
|
3213
|
+
return {
|
|
3214
|
+
success: true,
|
|
3215
|
+
data: {
|
|
3216
|
+
agreement,
|
|
3217
|
+
compute: latest,
|
|
3218
|
+
computes,
|
|
3219
|
+
results: _nullishCoalesce(results, () => ( [])),
|
|
3220
|
+
status: deriveContractStatus(agreement, computes),
|
|
3221
|
+
phases: buildContractPhases(agreement, computes)
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
function blobHeightsFromArtefact(artefact) {
|
|
3226
|
+
const refs = artefact.blobRefs;
|
|
3227
|
+
if (!Array.isArray(refs)) return [];
|
|
3228
|
+
const heights = [];
|
|
3229
|
+
for (const ref of refs) {
|
|
3230
|
+
const raw = Array.isArray(ref) ? ref[0] : ref;
|
|
3231
|
+
const height = typeof raw === "number" ? raw : Number(raw);
|
|
3232
|
+
if (Number.isFinite(height)) heights.push(height);
|
|
3233
|
+
}
|
|
3234
|
+
return heights;
|
|
3235
|
+
}
|
|
3236
|
+
async function getArtefactFlow(client, id, accessQuery) {
|
|
3237
|
+
const artefactResponse = await getArtefact(client, id);
|
|
3238
|
+
const artefact = artefactResponse.data;
|
|
3239
|
+
let access = [];
|
|
3240
|
+
try {
|
|
3241
|
+
const accessResponse = await getArtefactAccess(client, id, accessQuery);
|
|
3242
|
+
access = Array.isArray(accessResponse.data) ? accessResponse.data : [];
|
|
3243
|
+
} catch (err) {
|
|
3244
|
+
if (!(err instanceof IndexerHttpError && err.statusCode === 404)) throw err;
|
|
3245
|
+
}
|
|
3246
|
+
const blobs = [];
|
|
3247
|
+
for (const height of blobHeightsFromArtefact(artefact)) {
|
|
3248
|
+
try {
|
|
3249
|
+
const blobResponse = await getBlob(client, height);
|
|
3250
|
+
if (blobResponse.data) blobs.push(blobResponse.data);
|
|
3251
|
+
} catch (err) {
|
|
3252
|
+
if (err instanceof IndexerHttpError && err.statusCode === 404) continue;
|
|
3253
|
+
throw err;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
return {
|
|
3257
|
+
success: true,
|
|
3258
|
+
data: { artefact, access, blobs }
|
|
3259
|
+
};
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
// src/indexer/blocks.ts
|
|
3263
|
+
async function getBlocks(client, query) {
|
|
3264
|
+
return client.get("/api/blocks", query ? { ...query } : void 0);
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
// src/indexer/calls.ts
|
|
3268
|
+
async function getCall(client, query) {
|
|
3269
|
+
return client.get("/api/call", { ...query });
|
|
3270
|
+
}
|
|
3271
|
+
async function getCallMetadata(client, query) {
|
|
3272
|
+
return client.get("/api/call-metadata", { ...query });
|
|
3273
|
+
}
|
|
3274
|
+
async function getCallArgs(client, query) {
|
|
3275
|
+
return client.get("/api/call-args", { ...query });
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
// src/indexer/transfers.ts
|
|
3279
|
+
async function getTransfers(client, query) {
|
|
3280
|
+
return client.get("/api/transfers", query ? { ...query } : void 0);
|
|
3281
|
+
}
|
|
3282
|
+
|
|
3283
|
+
// src/indexer/extrinsics.ts
|
|
3284
|
+
async function getExtrinsics(client, query) {
|
|
3285
|
+
if (!query) {
|
|
3286
|
+
return client.get("/api/extrinsics");
|
|
3287
|
+
}
|
|
3288
|
+
const { signed_only, ...rest } = query;
|
|
3289
|
+
const params = { ...rest };
|
|
3290
|
+
if (signed_only !== void 0) {
|
|
3291
|
+
params.signed_only = signed_only === true || signed_only === "true" ? "true" : "false";
|
|
3292
|
+
}
|
|
3293
|
+
return client.get("/api/extrinsics", params);
|
|
3294
|
+
}
|
|
3295
|
+
async function getExtrinsic(client, indexOrHash) {
|
|
3296
|
+
return client.get(`/api/extrinsic/${encodeURIComponent(indexOrHash)}`);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// src/indexer/addresses.ts
|
|
3300
|
+
async function getAddresses(client) {
|
|
3301
|
+
return client.get("/api/addresses");
|
|
3302
|
+
}
|
|
3303
|
+
async function getAddress(client, address) {
|
|
3304
|
+
return client.get(`/api/address/${encodeURIComponent(address)}`);
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
// src/indexer/guardians.ts
|
|
3308
|
+
function displayNameForAccount(groups, account) {
|
|
3309
|
+
for (const group of groups) {
|
|
3310
|
+
const addresses = _nullishCoalesce(group.guardians, () => ( []));
|
|
3311
|
+
const names = _nullishCoalesce(group.guardianNames, () => ( []));
|
|
3312
|
+
const index = addresses.indexOf(account);
|
|
3313
|
+
if (index === -1) continue;
|
|
3314
|
+
const rawName = names[index];
|
|
3315
|
+
if (typeof rawName === "string" && rawName.length > 0) return rawName;
|
|
3316
|
+
}
|
|
3317
|
+
return null;
|
|
3318
|
+
}
|
|
3319
|
+
function uniqueGuardians(groups) {
|
|
3320
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3321
|
+
for (const group of groups) {
|
|
3322
|
+
const addresses = _nullishCoalesce(group.guardians, () => ( []));
|
|
3323
|
+
const names = _nullishCoalesce(group.guardianNames, () => ( []));
|
|
3324
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
3325
|
+
const account = addresses[i];
|
|
3326
|
+
if (!account || seen.has(account)) continue;
|
|
3327
|
+
const rawName = names[i];
|
|
3328
|
+
seen.set(account, typeof rawName === "string" && rawName.length > 0 ? rawName : null);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
return Array.from(seen, ([account, displayName]) => ({ account, displayName }));
|
|
3332
|
+
}
|
|
3333
|
+
async function guardianGroupsOrEmpty(client, query) {
|
|
3334
|
+
try {
|
|
3335
|
+
const response = await getGuardianGroups(client, query);
|
|
3336
|
+
return _nullishCoalesce(response.data, () => ( []));
|
|
3337
|
+
} catch (err) {
|
|
3338
|
+
if (err instanceof IndexerHttpError && err.statusCode === 404) {
|
|
3339
|
+
return [];
|
|
3340
|
+
}
|
|
3341
|
+
throw err;
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
async function getGuardianGroups(client, query) {
|
|
3345
|
+
return client.get("/api/guardian-groups", query ? { ...query } : void 0);
|
|
3346
|
+
}
|
|
3347
|
+
async function getGuardians(client) {
|
|
3348
|
+
const groups = await guardianGroupsOrEmpty(client);
|
|
3349
|
+
return { success: true, data: uniqueGuardians(groups) };
|
|
3350
|
+
}
|
|
3351
|
+
async function getGuardian(client, account) {
|
|
3352
|
+
const groups = await guardianGroupsOrEmpty(client, { guardian: account });
|
|
3353
|
+
return {
|
|
3354
|
+
success: true,
|
|
3355
|
+
data: {
|
|
3356
|
+
account,
|
|
3357
|
+
displayName: displayNameForAccount(groups, account)
|
|
3358
|
+
}
|
|
3359
|
+
};
|
|
3360
|
+
}
|
|
3361
|
+
async function getGuardianGroup(client, id) {
|
|
3362
|
+
return client.get(`/api/guardian-group/${encodeURIComponent(id)}`);
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
// src/indexer/access.ts
|
|
3366
|
+
async function getAccess(client, query) {
|
|
3367
|
+
return client.get("/api/access", query ? { ...query } : void 0);
|
|
3368
|
+
}
|
|
3369
|
+
|
|
2269
3370
|
// src/rotateKeys.ts
|
|
2270
3371
|
|
|
2271
3372
|
|
|
2272
3373
|
async function rotateAndSetKeys(account) {
|
|
2273
3374
|
const api2 = await getApi();
|
|
2274
3375
|
_assert2.default.call(void 0, api2, "API not initialized");
|
|
2275
|
-
debugLog(`Rotating session keys for ${account.meta.name} on ${
|
|
3376
|
+
debugLog(`Rotating session keys for ${account.meta.name} on ${getProvider().endpoint}`);
|
|
2276
3377
|
const newKeys = await api2.rpc.author.rotateKeys();
|
|
2277
|
-
debugLog(`${account.meta.name} rotated keys on ${
|
|
3378
|
+
debugLog(`${account.meta.name} rotated keys on ${getProvider().endpoint}:`, _nullishCoalesce(_optionalChain([newKeys, 'optionalAccess', _189 => _189.toHex, 'optionalCall', _190 => _190()]), () => ( newKeys)));
|
|
2278
3379
|
const setKeysTx = api2.tx.session.setKeys(newKeys, []);
|
|
2279
3380
|
const hash = await signAndSend(setKeysTx, account);
|
|
2280
3381
|
debugLog(`Rotate session transaction sent with hash: ${hash.hash}`);
|
|
@@ -2848,5 +3949,81 @@ _ss58 = new WeakMap();
|
|
|
2848
3949
|
|
|
2849
3950
|
|
|
2850
3951
|
|
|
2851
|
-
|
|
3952
|
+
|
|
3953
|
+
|
|
3954
|
+
|
|
3955
|
+
|
|
3956
|
+
|
|
3957
|
+
|
|
3958
|
+
|
|
3959
|
+
|
|
3960
|
+
|
|
3961
|
+
|
|
3962
|
+
|
|
3963
|
+
|
|
3964
|
+
|
|
3965
|
+
|
|
3966
|
+
|
|
3967
|
+
|
|
3968
|
+
|
|
3969
|
+
|
|
3970
|
+
|
|
3971
|
+
|
|
3972
|
+
|
|
3973
|
+
|
|
3974
|
+
|
|
3975
|
+
|
|
3976
|
+
|
|
3977
|
+
|
|
3978
|
+
|
|
3979
|
+
|
|
3980
|
+
|
|
3981
|
+
|
|
3982
|
+
|
|
3983
|
+
|
|
3984
|
+
|
|
3985
|
+
|
|
3986
|
+
|
|
3987
|
+
|
|
3988
|
+
|
|
3989
|
+
|
|
3990
|
+
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
|
|
3996
|
+
|
|
3997
|
+
|
|
3998
|
+
|
|
3999
|
+
|
|
4000
|
+
|
|
4001
|
+
|
|
4002
|
+
|
|
4003
|
+
|
|
4004
|
+
|
|
4005
|
+
|
|
4006
|
+
|
|
4007
|
+
|
|
4008
|
+
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
4018
|
+
|
|
4019
|
+
|
|
4020
|
+
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
exports.API_EXTENSIONS = API_EXTENSIONS; exports.API_RPC = API_RPC; exports.API_TYPES = API_TYPES; exports.AccountSourceType = AccountSourceType; exports.ApiPromise = _api2.ApiPromise; exports.COMPUTE_TYPES = COMPUTE_TYPES; exports.CostEstimationError = CostEstimationError; exports.CryptoType = CryptoType; exports.DEFAULT_COMPUTE_PAYLOAD = DEFAULT_COMPUTE_PAYLOAD; exports.DEFAULT_EMPTY_PAYLOAD = DEFAULT_EMPTY_PAYLOAD; exports.FileFromMetadataRef = FileFromMetadataRef; exports.HttpProvider = _api2.HttpProvider; exports.IndexerClient = IndexerClient; exports.IndexerHttpError = IndexerHttpError; exports.Keyring = Keyring3; exports.MCryptFs = MCryptFs; exports.MCryptFsReader = MCryptFsReader; exports.MCryptFsWriter = MCryptFsWriter; exports.NO_GUARDIAN_GROUP = NO_GUARDIAN_GROUP; exports.PALI_DECIMALS = PALI_DECIMALS; exports.PALI_SYMBOL = PALI_SYMBOL; exports.S3Provider = S3Provider; exports.StorageRouter = StorageRouter; exports.WsProvider = _api2.WsProvider; exports.addStake = addStake; exports.base64ToUint8Array = base64ToUint8Array; exports.buildComputeMetadata = buildComputeMetadata; exports.buildContractPhases = buildContractPhases; exports.buildFee = buildFee; exports.clearTokenCache = clearTokenCache; exports.createAccount = createAccount; exports.createAccountFromMagicLink = createAccountFromMagicLink; exports.createAgreement = createAgreement; exports.createGuardianGroup = createGuardianGroup; exports.createGuardianGroupAndWatch = createGuardianGroupAndWatch; exports.createSimpleAgreement = createSimpleAgreement; exports.dataContract = dataContract; exports.debugLog = debugLog; exports.decodeAggregateKey = decodeAggregateKey; exports.decodeField = decodeField; exports.decodePowersOfTau = decodePowersOfTau; exports.decrypt = decrypt; exports.deriveContractStatus = deriveContractStatus; exports.disconnectApi = disconnectApi; exports.ecncryptTest = encrypt; exports.encodeCiphertext = encodeCiphertext; exports.encrypt = encrypt2; exports.encryptedInferenceCompute = encryptedInferenceCompute; exports.encryptedInferenceSubscription = encryptedInferenceSubscription; exports.encryptedInferenceSubscriptionInvocation = encryptedInferenceSubscriptionInvocation; exports.estimateMinFee = estimateMinFee; exports.fetchAndDecodeExtrinsic = fetchAndDecodeExtrinsic; exports.fetchTokenProperties = fetchTokenProperties; exports.findEvent = findEvent; exports.formatBalanceWithTokenProperties = formatBalanceWithTokenProperties; exports.formatPaliAmount = formatPaliAmount; exports.fromAtomicPaliAmount = fromAtomicPaliAmount; exports.fundAccount = fundAccount; exports.gen_shared_key = gen_shared_key; exports.gen_stretched_key = gen_stretched_key; exports.generateRandomBytes = generateRandomBytes; exports.getAccess = getAccess; exports.getAccountInfo = getAccountInfo; exports.getActiveGuardians = getActiveGuardians; exports.getAddress = getAddress; exports.getAddresses = getAddresses; exports.getAgents = getAgents; exports.getAgreementCreatedRequestId = getAgreementCreatedRequestId; exports.getApi = getApi; exports.getArtefact = getArtefact; exports.getArtefactAccess = getArtefactAccess; exports.getArtefactContracts = getArtefactContracts; exports.getArtefactFlow = getArtefactFlow; exports.getArtefacts = getArtefacts; exports.getArtefactsByStoreType = getArtefactsByStoreType; exports.getAuction = getAuction; exports.getAuthServiceUrl = getAuthServiceUrl; exports.getAwsRegion = getAwsRegion; exports.getAwsS3Bucket = getAwsS3Bucket; exports.getBalance = getBalance; exports.getBlob = getBlob; exports.getBlocks = getBlocks; exports.getCachedTokenProperties = getCachedTokenProperties; exports.getCall = getCall; exports.getCallArgs = getCallArgs; exports.getCallMetadata = getCallMetadata; exports.getCompute = getCompute; exports.getContract = getContract; exports.getContractFlow = getContractFlow; exports.getContractInfo = getContractInfo; exports.getContracts = getContracts; exports.getCostEstimatorUrl = getCostEstimatorUrl; exports.getDatasets = getDatasets; exports.getEncKeyring = getEncKeyring; exports.getEstimateResult = getEstimateResult; exports.getExecutables = getExecutables; exports.getExtrinsic = getExtrinsic; exports.getExtrinsics = getExtrinsics; exports.getFeeParams = getFeeParams; exports.getFileMetadataCall = getFileMetadataCall; exports.getGuardian = getGuardian; exports.getGuardianAddress = getGuardianAddress; exports.getGuardianGroup = getGuardianGroup; exports.getGuardianGroupInfo = getGuardianGroupInfo; exports.getGuardianGroups = getGuardianGroups; exports.getGuardianList = getGuardianList; exports.getGuardianNwParams = getGuardianNwParams; exports.getGuardianParticipants = getGuardianParticipants; exports.getGuardians = getGuardians; exports.getKeyring = getKeyring; exports.getLatestBlocks = getLatestBlocks; exports.getModels = getModels; exports.getPallioraRpcUrl = getPallioraRpcUrl; exports.getPallioraWs = getPallioraWs; exports.getProvider = getProvider; exports.getResult = getResult; exports.getResults = getResults; exports.getTransfers = getTransfers; exports.healthCheck = healthCheck; exports.hexToUint8Array = hexToUint8Array; exports.inferenceCompute = inferenceCompute; exports.init = init; exports.invokeAgreement = invokeAgreement; exports.isArtefactUsage = isArtefactUsage; exports.isDebug = isDebug; exports.isInitialized = isInitialized; exports.joinGuardian = joinGuardian; exports.joinIdleStaker = joinIdleStaker; exports.joinValidator = joinValidator; exports.listGuardianAuctions = listGuardianAuctions; exports.listOpenAuctions = listOpenAuctions; exports.listResolvedGuardianAuctions = listResolvedGuardianAuctions; exports.newStake = newStake; exports.normalizeComputes = normalizeComputes; exports.pairFromPrivateKeyHex = pairFromPrivateKeyHex; exports.payoutStake = payoutStake; exports.reduceStake = reduceStake; exports.registerDataAgreement = registerDataAgreement; exports.registerGuardianWebhook = registerGuardianWebhook; exports.removeStake = removeStake; exports.resetConfig = resetConfig; exports.resultToCompute = resultToCompute; exports.retrySignAndSend = retrySignAndSend; exports.rotateAndSetKeys = rotateAndSetKeys; exports.runAgent = runAgent; exports.scanForBlockEvent = scanForBlockEvent; exports.setIdentity = setIdentity; exports.setWorker = setWorker; exports.signAndSend = signAndSend; exports.simpleCompute = simpleCompute; exports.startEstimate = startEstimate; exports.storageRouter = storageRouter; exports.storedCompute = storedCompute; exports.submitAuctionBid = submitAuctionBid; exports.submitData = submitData; exports.submitTEData = submitTEData; exports.submitTEDataWithCipher = submitTEDataWithCipher; exports.testCrypt = testCrypt; exports.toAtomicPaliAmount = toAtomicPaliAmount; exports.tokenToBigint = tokenToBigint; exports.transfer = transfer; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uploadData = uploadData; exports.uploadDataLegacy = uploadDataLegacy; exports.utilCrypto = utilCrypto; exports.waitForEstimate = waitForEstimate; exports.waitForNextBlock = waitForNextBlock; exports.waitsForFinalization = waitsForFinalization; exports.wasmCrypto = wasmCrypto; exports.watchForSubmissionReceipt = watchForSubmissionReceipt; exports.withdrawStake = withdrawStake; exports.writeMetadata = writeMetadata;
|
|
2852
4029
|
//# sourceMappingURL=index.cjs.map
|