genlayer-js 0.8.0 → 0.9.1
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/CHANGELOG.md +9 -0
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.d.cts +2 -2
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains/index.js +3 -3
- package/dist/chains-BYSCF33g.d.cts +18 -0
- package/dist/chains-BYSCF33g.d.ts +18 -0
- package/dist/chunk-7YZQQWJZ.js +4056 -0
- package/dist/chunk-AZSICIZ3.cjs +132 -0
- package/dist/chunk-FPFZLPXI.cjs +4056 -0
- package/dist/chunk-RS7NCSOQ.js +132 -0
- package/dist/index-BM9hOtGg.d.cts +13 -0
- package/dist/index-C7Colsnk.d.ts +13 -0
- package/dist/index-DvSbRKD5.d.ts +370 -0
- package/dist/index-kDM_9wW1.d.cts +370 -0
- package/dist/index.cjs +393 -134
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +385 -126
- package/dist/types/index.cjs +18 -2
- package/dist/types/index.d.cts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +19 -3
- package/package.json +2 -2
- package/src/accounts/IAccountActions.ts +2 -2
- package/src/accounts/actions.ts +10 -4
- package/src/chains/actions.ts +5 -5
- package/src/chains/index.ts +1 -1
- package/src/chains/localnet.ts +4 -3
- package/src/chains/testnet.ts +4015 -0
- package/src/client/client.ts +64 -21
- package/src/contracts/actions.ts +185 -137
- package/src/transactions/actions.ts +173 -8
- package/src/types/accounts.ts +1 -2
- package/src/types/chains.ts +8 -2
- package/src/types/clients.ts +14 -13
- package/src/types/transactions.ts +250 -8
- package/src/utils/jsonifier.ts +47 -0
- package/src/wallet/actions.ts +4 -4
- package/src/wallet/connect.ts +12 -14
- package/tests/client.test.ts +105 -45
- package/dist/chains-C5PI_Nr_.d.cts +0 -13
- package/dist/chains-C5PI_Nr_.d.ts +0 -13
- package/dist/chunk-I6HC44KD.cjs +0 -72
- package/dist/chunk-K72OSU5N.js +0 -28
- package/dist/chunk-WEXFFND6.js +0 -72
- package/dist/chunk-YDFRDDP5.cjs +0 -28
- package/dist/index-B8E0qiOq.d.cts +0 -13
- package/dist/index-BfeTR7rO.d.cts +0 -187
- package/dist/index-CODAJePj.d.ts +0 -187
- package/dist/index-ZoW0HQ_m.d.ts +0 -13
- package/src/chains/simulator.ts +0 -30
package/dist/index.cjs
CHANGED
|
@@ -2,22 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkFPFZLPXIcjs = require('./chunk-FPFZLPXI.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkAZSICIZ3cjs = require('./chunk-AZSICIZ3.cjs');
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
12
16
|
|
|
13
17
|
// src/client/client.ts
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
14
24
|
var _viem = require('viem');
|
|
15
25
|
|
|
16
26
|
// src/accounts/actions.ts
|
|
17
27
|
function accountActions(client) {
|
|
18
28
|
return {
|
|
19
29
|
fundAccount: async ({ address, amount }) => {
|
|
20
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
30
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkFPFZLPXIcjs.localnet.id) {
|
|
21
31
|
throw new Error("Client is not connected to the localnet");
|
|
22
32
|
}
|
|
23
33
|
return client.request({
|
|
@@ -25,7 +35,10 @@ function accountActions(client) {
|
|
|
25
35
|
params: [address, amount]
|
|
26
36
|
});
|
|
27
37
|
},
|
|
28
|
-
getCurrentNonce: async ({
|
|
38
|
+
getCurrentNonce: async ({
|
|
39
|
+
address,
|
|
40
|
+
block = "latest"
|
|
41
|
+
}) => {
|
|
29
42
|
const addressToUse = address || _optionalChain([client, 'access', _3 => _3.account, 'optionalAccess', _4 => _4.address]);
|
|
30
43
|
if (!addressToUse) {
|
|
31
44
|
throw new Error("No address provided and no account is connected");
|
|
@@ -168,7 +181,7 @@ function encodeImpl(to, data) {
|
|
|
168
181
|
}
|
|
169
182
|
} else if (data instanceof Map) {
|
|
170
183
|
encodeMap(to, data);
|
|
171
|
-
} else if (data instanceof
|
|
184
|
+
} else if (data instanceof _chunkAZSICIZ3cjs.CalldataAddress) {
|
|
172
185
|
to.push(SPECIAL_ADDR);
|
|
173
186
|
for (const c of data.bytes) {
|
|
174
187
|
to.push(c);
|
|
@@ -217,7 +230,7 @@ function decodeImpl(data, index) {
|
|
|
217
230
|
case BigInt(SPECIAL_ADDR): {
|
|
218
231
|
const res = data.slice(index.i, index.i + 20);
|
|
219
232
|
index.i += 20;
|
|
220
|
-
return new (0,
|
|
233
|
+
return new (0, _chunkAZSICIZ3cjs.CalldataAddress)(res);
|
|
221
234
|
}
|
|
222
235
|
}
|
|
223
236
|
const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
|
|
@@ -329,7 +342,7 @@ function toStringImpl(data, to) {
|
|
|
329
342
|
to.push("]");
|
|
330
343
|
} else if (data instanceof Map) {
|
|
331
344
|
toStringImplMap(data.entries(), to);
|
|
332
|
-
} else if (data instanceof
|
|
345
|
+
} else if (data instanceof _chunkAZSICIZ3cjs.CalldataAddress) {
|
|
333
346
|
to.push("addr#");
|
|
334
347
|
for (const c of data.bytes) {
|
|
335
348
|
to.push(c.toString(16));
|
|
@@ -393,9 +406,12 @@ function makeCalldataObject(method, args, kwargs) {
|
|
|
393
406
|
}
|
|
394
407
|
return ret;
|
|
395
408
|
}
|
|
396
|
-
var contractActions = (client) => {
|
|
409
|
+
var contractActions = (client, publicClient) => {
|
|
397
410
|
return {
|
|
398
411
|
getContractSchema: async (address) => {
|
|
412
|
+
if (client.chain.id !== _chunkFPFZLPXIcjs.localnet.id) {
|
|
413
|
+
throw new Error("Contract schema is not supported on this network");
|
|
414
|
+
}
|
|
399
415
|
const schema = await client.request({
|
|
400
416
|
method: "gen_getContractSchema",
|
|
401
417
|
params: [address]
|
|
@@ -403,104 +419,154 @@ var contractActions = (client) => {
|
|
|
403
419
|
return schema;
|
|
404
420
|
},
|
|
405
421
|
getContractSchemaForCode: async (contractCode) => {
|
|
422
|
+
if (client.chain.id !== _chunkFPFZLPXIcjs.localnet.id) {
|
|
423
|
+
throw new Error("Contract schema is not supported on this network");
|
|
424
|
+
}
|
|
406
425
|
const schema = await client.request({
|
|
407
426
|
method: "gen_getContractSchemaForCode",
|
|
408
427
|
params: [_viem.toHex.call(void 0, contractCode)]
|
|
409
428
|
});
|
|
410
429
|
return schema;
|
|
430
|
+
},
|
|
431
|
+
readContract: async (args) => {
|
|
432
|
+
const { account, address, functionName, args: callArgs, kwargs, leaderOnly = false } = args;
|
|
433
|
+
const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
434
|
+
const serializedData = serialize(encodedData);
|
|
435
|
+
const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address])));
|
|
436
|
+
const requestParams = {
|
|
437
|
+
type: "read",
|
|
438
|
+
to: address,
|
|
439
|
+
from: senderAddress,
|
|
440
|
+
data: serializedData,
|
|
441
|
+
transaction_hash_variant: "latest-final"
|
|
442
|
+
};
|
|
443
|
+
const result = await client.request({
|
|
444
|
+
method: "gen_call",
|
|
445
|
+
params: [requestParams]
|
|
446
|
+
});
|
|
447
|
+
const prefixedResult = `0x${result}`;
|
|
448
|
+
if (args.rawReturn) {
|
|
449
|
+
return prefixedResult;
|
|
450
|
+
}
|
|
451
|
+
const resultBinary = _viem.fromHex.call(void 0, prefixedResult, "bytes");
|
|
452
|
+
return decode(resultBinary);
|
|
453
|
+
},
|
|
454
|
+
writeContract: async (args) => {
|
|
455
|
+
const {
|
|
456
|
+
account,
|
|
457
|
+
address,
|
|
458
|
+
functionName,
|
|
459
|
+
args: callArgs,
|
|
460
|
+
kwargs,
|
|
461
|
+
value = 0n,
|
|
462
|
+
leaderOnly = false,
|
|
463
|
+
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
464
|
+
} = args;
|
|
465
|
+
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
466
|
+
const serializedData = serialize(data);
|
|
467
|
+
return _sendTransaction({
|
|
468
|
+
client,
|
|
469
|
+
publicClient,
|
|
470
|
+
recipient: address,
|
|
471
|
+
data: serializedData,
|
|
472
|
+
senderAccount: account || client.account,
|
|
473
|
+
consensusMaxRotations,
|
|
474
|
+
value
|
|
475
|
+
});
|
|
476
|
+
},
|
|
477
|
+
deployContract: async (args) => {
|
|
478
|
+
const {
|
|
479
|
+
account,
|
|
480
|
+
code,
|
|
481
|
+
args: constructorArgs,
|
|
482
|
+
kwargs,
|
|
483
|
+
leaderOnly = false,
|
|
484
|
+
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
485
|
+
} = args;
|
|
486
|
+
const data = [
|
|
487
|
+
code,
|
|
488
|
+
encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
|
|
489
|
+
leaderOnly
|
|
490
|
+
];
|
|
491
|
+
const serializedData = serialize(data);
|
|
492
|
+
return _sendTransaction({
|
|
493
|
+
client,
|
|
494
|
+
publicClient,
|
|
495
|
+
recipient: _viem.zeroAddress,
|
|
496
|
+
data: serializedData,
|
|
497
|
+
senderAccount: account || client.account,
|
|
498
|
+
consensusMaxRotations
|
|
499
|
+
});
|
|
411
500
|
}
|
|
412
501
|
};
|
|
413
502
|
};
|
|
414
|
-
var
|
|
415
|
-
client
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (!senderAccount) {
|
|
456
|
-
throw new Error(
|
|
457
|
-
"No account set. Configure the client with an account or pass an account to this function."
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
if (!_optionalChain([client, 'access', _8 => _8.chain, 'access', _9 => _9.consensusMainContract, 'optionalAccess', _10 => _10.address])) {
|
|
461
|
-
throw new Error(
|
|
462
|
-
"Consensus main contract not initialized. Please ensure client is properly initialized."
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
const encodedData = _viem.encodeFunctionData.call(void 0, {
|
|
466
|
-
abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.abi]),
|
|
467
|
-
functionName: "addTransaction",
|
|
468
|
-
args: [
|
|
469
|
-
senderAccount.address,
|
|
470
|
-
recipient,
|
|
471
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
472
|
-
consensusMaxRotations,
|
|
473
|
-
data
|
|
474
|
-
]
|
|
475
|
-
});
|
|
476
|
-
const nonce = await client.getCurrentNonce({ address: senderAccount.address });
|
|
477
|
-
const transactionRequest = await client.prepareTransactionRequest({
|
|
478
|
-
account: senderAccount,
|
|
479
|
-
to: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.address]),
|
|
503
|
+
var _sendTransaction = async ({
|
|
504
|
+
client,
|
|
505
|
+
publicClient,
|
|
506
|
+
recipient,
|
|
507
|
+
data,
|
|
508
|
+
senderAccount,
|
|
509
|
+
consensusMaxRotations,
|
|
510
|
+
value
|
|
511
|
+
}) => {
|
|
512
|
+
if (!senderAccount) {
|
|
513
|
+
throw new Error(
|
|
514
|
+
"No account set. Configure the client with an account or pass an account to this function."
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
if (!_optionalChain([client, 'access', _8 => _8.chain, 'access', _9 => _9.consensusMainContract, 'optionalAccess', _10 => _10.address])) {
|
|
518
|
+
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
519
|
+
}
|
|
520
|
+
const encodedData = _viem.encodeFunctionData.call(void 0, {
|
|
521
|
+
abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.abi]),
|
|
522
|
+
functionName: "addTransaction",
|
|
523
|
+
args: [
|
|
524
|
+
senderAccount.address,
|
|
525
|
+
recipient,
|
|
526
|
+
client.chain.defaultNumberOfInitialValidators,
|
|
527
|
+
consensusMaxRotations,
|
|
528
|
+
data
|
|
529
|
+
]
|
|
530
|
+
});
|
|
531
|
+
const nonce = await client.getCurrentNonce({ address: senderAccount.address });
|
|
532
|
+
const transactionRequest = await client.prepareTransactionRequest({
|
|
533
|
+
account: senderAccount,
|
|
534
|
+
to: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.address]),
|
|
535
|
+
data: encodedData,
|
|
536
|
+
type: "legacy",
|
|
537
|
+
nonce: Number(nonce),
|
|
538
|
+
value: _nullishCoalesce(value, () => ( 0n))
|
|
539
|
+
});
|
|
540
|
+
if (_optionalChain([senderAccount, 'optionalAccess', _17 => _17.type]) !== "local") {
|
|
541
|
+
const formattedRequest = {
|
|
542
|
+
from: transactionRequest.from,
|
|
543
|
+
to: transactionRequest.to,
|
|
480
544
|
data: encodedData,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
545
|
+
value: transactionRequest.value ? `0x${transactionRequest.value.toString(16)}` : "0x0"
|
|
546
|
+
};
|
|
547
|
+
return await client.request({
|
|
548
|
+
method: "eth_sendTransaction",
|
|
549
|
+
params: [formattedRequest]
|
|
484
550
|
});
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
return
|
|
551
|
+
}
|
|
552
|
+
if (!_optionalChain([senderAccount, 'optionalAccess', _18 => _18.signTransaction])) {
|
|
553
|
+
throw new Error("Account does not support signTransaction");
|
|
554
|
+
}
|
|
555
|
+
const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
|
|
556
|
+
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
557
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
558
|
+
if (receipt.status === "reverted") {
|
|
559
|
+
throw new Error("Transaction reverted");
|
|
560
|
+
}
|
|
561
|
+
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
562
|
+
abi: _optionalChain([client, 'access', _19 => _19.chain, 'access', _20 => _20.consensusMainContract, 'optionalAccess', _21 => _21.abi]),
|
|
563
|
+
eventName: "NewTransaction",
|
|
564
|
+
logs: receipt.logs
|
|
565
|
+
});
|
|
566
|
+
if (newTxEvents.length === 0) {
|
|
567
|
+
throw new Error("Transaction not processed by consensus");
|
|
568
|
+
}
|
|
569
|
+
return newTxEvents[0].args["txId"];
|
|
504
570
|
};
|
|
505
571
|
|
|
506
572
|
// src/config/transactions.ts
|
|
@@ -514,26 +580,84 @@ async function sleep(ms) {
|
|
|
514
580
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
515
581
|
}
|
|
516
582
|
|
|
583
|
+
// src/abi/index.ts
|
|
584
|
+
var abi_exports = {};
|
|
585
|
+
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
586
|
+
calldata: () => calldata,
|
|
587
|
+
transactions: () => transactions
|
|
588
|
+
});
|
|
589
|
+
var calldata = calldata_exports;
|
|
590
|
+
var transactions = transactions_exports;
|
|
591
|
+
|
|
592
|
+
// src/utils/jsonifier.ts
|
|
593
|
+
function b64ToArray(b64) {
|
|
594
|
+
return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
595
|
+
}
|
|
596
|
+
function calldataToUserFriendlyJson(cd) {
|
|
597
|
+
return {
|
|
598
|
+
raw: Array.from(cd),
|
|
599
|
+
readable: calldata.toString(calldata.decode(cd))
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
var RESULT_CODES = /* @__PURE__ */ new Map([
|
|
603
|
+
[0, "return"],
|
|
604
|
+
[1, "rollback"],
|
|
605
|
+
[2, "contract_error"],
|
|
606
|
+
[3, "error"],
|
|
607
|
+
[4, "none"],
|
|
608
|
+
[5, "no_leaders"]
|
|
609
|
+
]);
|
|
610
|
+
function resultToUserFriendlyJson(cd64) {
|
|
611
|
+
const raw = b64ToArray(cd64);
|
|
612
|
+
const code = RESULT_CODES.get(raw[0]);
|
|
613
|
+
let status;
|
|
614
|
+
let payload = null;
|
|
615
|
+
if (code === void 0) {
|
|
616
|
+
status = "<unknown>";
|
|
617
|
+
} else {
|
|
618
|
+
status = code;
|
|
619
|
+
if ([1, 2].includes(raw[0])) {
|
|
620
|
+
payload = new TextDecoder("utf-8").decode(raw.slice(1));
|
|
621
|
+
} else if (raw[0] == 0) {
|
|
622
|
+
payload = calldataToUserFriendlyJson(raw.slice(1));
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return {
|
|
626
|
+
raw: cd64,
|
|
627
|
+
status,
|
|
628
|
+
payload
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
517
632
|
// src/transactions/actions.ts
|
|
518
|
-
|
|
633
|
+
|
|
634
|
+
var receiptActions = (client, publicClient) => ({
|
|
519
635
|
waitForTransactionReceipt: async ({
|
|
520
636
|
hash,
|
|
521
637
|
status = "ACCEPTED" /* ACCEPTED */,
|
|
522
638
|
interval = transactionsConfig.waitInterval,
|
|
523
639
|
retries = transactionsConfig.retries
|
|
524
640
|
}) => {
|
|
525
|
-
const transaction = await client.getTransaction({
|
|
641
|
+
const transaction = await client.getTransaction({
|
|
642
|
+
hash
|
|
643
|
+
});
|
|
526
644
|
if (!transaction) {
|
|
527
645
|
throw new Error("Transaction not found");
|
|
528
646
|
}
|
|
529
|
-
|
|
647
|
+
const transactionStatusString = String(transaction.status);
|
|
648
|
+
const transactionStatusFinalized = _chunkAZSICIZ3cjs.transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
|
|
649
|
+
const requestedStatus = _chunkAZSICIZ3cjs.transactionsStatusNameToNumber[status];
|
|
650
|
+
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
|
|
651
|
+
if (client.chain.id === _chunkFPFZLPXIcjs.localnet.id) {
|
|
652
|
+
return _decodeLocalnetTransaction(transaction);
|
|
653
|
+
}
|
|
530
654
|
return transaction;
|
|
531
655
|
}
|
|
532
656
|
if (retries === 0) {
|
|
533
657
|
throw new Error("Transaction status is not " + status);
|
|
534
658
|
}
|
|
535
659
|
await sleep(interval);
|
|
536
|
-
return
|
|
660
|
+
return receiptActions(client, publicClient).waitForTransactionReceipt({
|
|
537
661
|
hash,
|
|
538
662
|
status,
|
|
539
663
|
interval,
|
|
@@ -541,6 +665,128 @@ var transactionActions = (client) => ({
|
|
|
541
665
|
});
|
|
542
666
|
}
|
|
543
667
|
});
|
|
668
|
+
var transactionActions = (client, publicClient) => ({
|
|
669
|
+
getTransaction: async ({ hash }) => {
|
|
670
|
+
const transaction = await publicClient.readContract({
|
|
671
|
+
address: _optionalChain([client, 'access', _22 => _22.chain, 'access', _23 => _23.consensusDataContract, 'optionalAccess', _24 => _24.address]),
|
|
672
|
+
abi: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusDataContract, 'optionalAccess', _27 => _27.abi]),
|
|
673
|
+
functionName: "getTransactionData",
|
|
674
|
+
args: [
|
|
675
|
+
hash,
|
|
676
|
+
Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3)
|
|
677
|
+
// unix seconds
|
|
678
|
+
]
|
|
679
|
+
});
|
|
680
|
+
return _decodeTransaction(transaction);
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
var _decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
684
|
+
if (!rlpEncodedAppData || rlpEncodedAppData === "0x" || rlpEncodedAppData.length <= 2) {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
try {
|
|
688
|
+
const rlpDecodedArray = _viem.fromRlp.call(void 0, rlpEncodedAppData);
|
|
689
|
+
if (rlpDecodedArray.length === 3) {
|
|
690
|
+
return {
|
|
691
|
+
code: _viem.fromHex.call(void 0, rlpDecodedArray[0], "string"),
|
|
692
|
+
constructorArgs: rlpDecodedArray[1] && rlpDecodedArray[1] !== "0x" ? decode(_viem.fromHex.call(void 0, rlpDecodedArray[1], "bytes")) : null,
|
|
693
|
+
leaderOnly: rlpDecodedArray[2] === "0x01",
|
|
694
|
+
type: "deploy",
|
|
695
|
+
contractAddress: recipient
|
|
696
|
+
};
|
|
697
|
+
} else if (rlpDecodedArray.length === 2) {
|
|
698
|
+
return {
|
|
699
|
+
callData: rlpDecodedArray[0] && rlpDecodedArray[0] !== "0x" ? decode(_viem.fromHex.call(void 0, rlpDecodedArray[0], "bytes")) : null,
|
|
700
|
+
leaderOnly: rlpDecodedArray[1] === "0x01",
|
|
701
|
+
type: "call"
|
|
702
|
+
};
|
|
703
|
+
} else {
|
|
704
|
+
console.warn(
|
|
705
|
+
"[decodeInputData] WRITE: Unexpected RLP array length:",
|
|
706
|
+
rlpDecodedArray.length,
|
|
707
|
+
rlpDecodedArray
|
|
708
|
+
);
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
} catch (e) {
|
|
712
|
+
console.error(
|
|
713
|
+
"[decodeInputData] Error during comprehensive decoding:",
|
|
714
|
+
e,
|
|
715
|
+
"Raw RLP App Data:",
|
|
716
|
+
rlpEncodedAppData
|
|
717
|
+
);
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
var _decodeTransaction = (tx) => {
|
|
722
|
+
const txDataDecoded = _decodeInputData(tx.txData, tx.recipient);
|
|
723
|
+
const decodedTx = {
|
|
724
|
+
...tx,
|
|
725
|
+
txData: tx.txData,
|
|
726
|
+
txDataDecoded,
|
|
727
|
+
currentTimestamp: tx.currentTimestamp.toString(),
|
|
728
|
+
numOfInitialValidators: tx.numOfInitialValidators.toString(),
|
|
729
|
+
txSlot: tx.txSlot.toString(),
|
|
730
|
+
createdTimestamp: tx.createdTimestamp.toString(),
|
|
731
|
+
lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
|
|
732
|
+
queuePosition: tx.queuePosition.toString(),
|
|
733
|
+
numOfRounds: tx.numOfRounds.toString(),
|
|
734
|
+
readStateBlockRange: {
|
|
735
|
+
...tx.readStateBlockRange,
|
|
736
|
+
activationBlock: tx.readStateBlockRange.activationBlock.toString(),
|
|
737
|
+
processingBlock: tx.readStateBlockRange.processingBlock.toString(),
|
|
738
|
+
proposalBlock: tx.readStateBlockRange.proposalBlock.toString()
|
|
739
|
+
},
|
|
740
|
+
statusName: _chunkAZSICIZ3cjs.transactionsStatusNumberToName[String(tx.status)],
|
|
741
|
+
resultName: _chunkAZSICIZ3cjs.transactionResultNumberToName[String(tx.result)],
|
|
742
|
+
lastRound: {
|
|
743
|
+
...tx.lastRound,
|
|
744
|
+
round: tx.lastRound.round.toString(),
|
|
745
|
+
leaderIndex: tx.lastRound.leaderIndex.toString(),
|
|
746
|
+
votesCommitted: tx.lastRound.votesCommitted.toString(),
|
|
747
|
+
votesRevealed: tx.lastRound.votesRevealed.toString(),
|
|
748
|
+
appealBond: tx.lastRound.appealBond.toString(),
|
|
749
|
+
rotationsLeft: tx.lastRound.rotationsLeft.toString(),
|
|
750
|
+
validatorVotesName: tx.lastRound.validatorVotes.map(
|
|
751
|
+
(vote) => _chunkAZSICIZ3cjs.voteTypeNumberToName[String(vote)]
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
return decodedTx;
|
|
756
|
+
};
|
|
757
|
+
var _decodeLocalnetTransaction = (tx) => {
|
|
758
|
+
try {
|
|
759
|
+
const leaderReceipt = _optionalChain([tx, 'access', _28 => _28.consensus_data, 'optionalAccess', _29 => _29.leader_receipt]);
|
|
760
|
+
if (leaderReceipt) {
|
|
761
|
+
if (leaderReceipt.result) {
|
|
762
|
+
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
763
|
+
}
|
|
764
|
+
if (leaderReceipt.calldata) {
|
|
765
|
+
leaderReceipt.calldata = {
|
|
766
|
+
base64: leaderReceipt.calldata,
|
|
767
|
+
...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata))
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
if (leaderReceipt.eq_outputs) {
|
|
771
|
+
leaderReceipt.eq_outputs = Object.fromEntries(
|
|
772
|
+
Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
|
|
773
|
+
const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
|
|
774
|
+
return [key, resultToUserFriendlyJson(decodedValue)];
|
|
775
|
+
})
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (_optionalChain([tx, 'access', _30 => _30.data, 'optionalAccess', _31 => _31.calldata])) {
|
|
780
|
+
tx.data.calldata = {
|
|
781
|
+
base64: tx.data.calldata,
|
|
782
|
+
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
} catch (e) {
|
|
786
|
+
console.error("Error in _decodeLocalnetTransaction:", e);
|
|
787
|
+
}
|
|
788
|
+
return tx;
|
|
789
|
+
};
|
|
544
790
|
|
|
545
791
|
// src/config/snapID.ts
|
|
546
792
|
var snapID = {
|
|
@@ -550,7 +796,7 @@ var snapID = {
|
|
|
550
796
|
|
|
551
797
|
// src/wallet/connect.ts
|
|
552
798
|
var networks = {
|
|
553
|
-
localnet:
|
|
799
|
+
localnet: _chunkFPFZLPXIcjs.localnet
|
|
554
800
|
};
|
|
555
801
|
var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
556
802
|
if (!window.ethereum) {
|
|
@@ -569,7 +815,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
|
569
815
|
chainName: selectedNetwork.name,
|
|
570
816
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
571
817
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
572
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
818
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _32 => _32.blockExplorers, 'optionalAccess', _33 => _33.default, 'access', _34 => _34.url])]
|
|
573
819
|
};
|
|
574
820
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
575
821
|
if (currentChainId !== chainIdHex) {
|
|
@@ -584,9 +830,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
|
584
830
|
}
|
|
585
831
|
const id = snapSource === "local" ? snapID.local : snapID.npm;
|
|
586
832
|
const installedSnaps = await window.ethereum.request({ method: "wallet_getSnaps" });
|
|
587
|
-
const isGenLayerSnapInstalled = Object.values(installedSnaps).some(
|
|
588
|
-
(snap) => snap.id === id
|
|
589
|
-
);
|
|
833
|
+
const isGenLayerSnapInstalled = Object.values(installedSnaps).some((snap) => snap.id === id);
|
|
590
834
|
if (!isGenLayerSnapInstalled) {
|
|
591
835
|
await window.ethereum.request({
|
|
592
836
|
method: "wallet_requestSnaps",
|
|
@@ -605,10 +849,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
605
849
|
}
|
|
606
850
|
const isFlask = async () => {
|
|
607
851
|
try {
|
|
608
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
852
|
+
const clientVersion = await _optionalChain([window, 'access', _35 => _35.ethereum, 'optionalAccess', _36 => _36.request, 'call', _37 => _37({
|
|
609
853
|
method: "web3_clientVersion"
|
|
610
854
|
})]);
|
|
611
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
855
|
+
return _optionalChain([clientVersion, 'optionalAccess', _38 => _38.includes, 'call', _39 => _39("flask")]);
|
|
612
856
|
} catch (error) {
|
|
613
857
|
console.error("Error detecting Flask:", error);
|
|
614
858
|
return false;
|
|
@@ -616,7 +860,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
616
860
|
};
|
|
617
861
|
const installedSnaps = async () => {
|
|
618
862
|
try {
|
|
619
|
-
return await _optionalChain([window, 'access',
|
|
863
|
+
return await _optionalChain([window, 'access', _40 => _40.ethereum, 'optionalAccess', _41 => _41.request, 'call', _42 => _42({
|
|
620
864
|
method: "wallet_getSnaps"
|
|
621
865
|
})]);
|
|
622
866
|
} catch (error) {
|
|
@@ -651,10 +895,10 @@ function walletActions(client) {
|
|
|
651
895
|
function chainActions(client) {
|
|
652
896
|
return {
|
|
653
897
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
654
|
-
if (_optionalChain([client, 'access',
|
|
655
|
-
|
|
898
|
+
if (_optionalChain([client, 'access', _43 => _43.chain, 'optionalAccess', _44 => _44.id]) !== _chunkFPFZLPXIcjs.testnet.id) {
|
|
899
|
+
return;
|
|
656
900
|
}
|
|
657
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
901
|
+
if (!forceReset && _optionalChain([client, 'access', _45 => _45.chain, 'access', _46 => _46.consensusMainContract, 'optionalAccess', _47 => _47.address]) && _optionalChain([client, 'access', _48 => _48.chain, 'access', _49 => _49.consensusMainContract, 'optionalAccess', _50 => _50.abi])) {
|
|
658
902
|
return;
|
|
659
903
|
}
|
|
660
904
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -679,24 +923,23 @@ function chainActions(client) {
|
|
|
679
923
|
}
|
|
680
924
|
|
|
681
925
|
// src/client/client.ts
|
|
682
|
-
var
|
|
683
|
-
const chainConfig = config.chain || _chunkI6HC44KDcjs.localnet;
|
|
684
|
-
if (config.endpoint) {
|
|
685
|
-
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
686
|
-
}
|
|
926
|
+
var getCustomTransportConfig = (config) => {
|
|
687
927
|
const isAddress = typeof config.account !== "object";
|
|
688
|
-
|
|
689
|
-
async request({ method, params }) {
|
|
928
|
+
return {
|
|
929
|
+
async request({ method, params = [] }) {
|
|
690
930
|
if (method.startsWith("eth_") && isAddress) {
|
|
691
931
|
try {
|
|
692
|
-
return await _optionalChain([window, 'access',
|
|
932
|
+
return await _optionalChain([window, 'access', _51 => _51.ethereum, 'optionalAccess', _52 => _52.request, 'call', _53 => _53({ method, params })]);
|
|
693
933
|
} catch (err) {
|
|
694
934
|
console.warn(`Error using window.ethereum for method ${method}:`, err);
|
|
695
935
|
throw err;
|
|
696
936
|
}
|
|
697
937
|
} else {
|
|
938
|
+
if (!config.chain) {
|
|
939
|
+
throw new Error("Chain is not set");
|
|
940
|
+
}
|
|
698
941
|
try {
|
|
699
|
-
const response = await fetch(
|
|
942
|
+
const response = await fetch(config.chain.rpcUrls.default.http[0], {
|
|
700
943
|
method: "POST",
|
|
701
944
|
headers: {
|
|
702
945
|
"Content-Type": "application/json"
|
|
@@ -720,15 +963,40 @@ var createClient = (config = { chain: _chunkI6HC44KDcjs.localnet }) => {
|
|
|
720
963
|
}
|
|
721
964
|
}
|
|
722
965
|
};
|
|
966
|
+
};
|
|
967
|
+
var createClient = (config = { chain: _chunkFPFZLPXIcjs.localnet }) => {
|
|
968
|
+
const chainConfig = config.chain || _chunkFPFZLPXIcjs.localnet;
|
|
969
|
+
if (config.endpoint) {
|
|
970
|
+
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
971
|
+
}
|
|
972
|
+
const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config));
|
|
973
|
+
const publicClient = createPublicClient(chainConfig, customTransport).extend(
|
|
974
|
+
_viem.publicActions
|
|
975
|
+
);
|
|
723
976
|
const baseClient = _viem.createClient.call(void 0, {
|
|
724
977
|
chain: chainConfig,
|
|
725
|
-
transport:
|
|
978
|
+
transport: customTransport,
|
|
726
979
|
...config.account ? { account: config.account } : {}
|
|
727
|
-
})
|
|
728
|
-
baseClient.
|
|
980
|
+
});
|
|
981
|
+
const clientWithBasicActions = baseClient.extend(_viem.publicActions).extend(_viem.walletActions).extend((client) => accountActions(client));
|
|
982
|
+
const clientWithAllActions = {
|
|
983
|
+
...clientWithBasicActions,
|
|
984
|
+
...contractActions(clientWithBasicActions, publicClient),
|
|
985
|
+
...chainActions(clientWithBasicActions),
|
|
986
|
+
...walletActions(clientWithBasicActions),
|
|
987
|
+
...transactionActions(clientWithBasicActions, publicClient)
|
|
988
|
+
};
|
|
989
|
+
const finalClient = {
|
|
990
|
+
...clientWithAllActions,
|
|
991
|
+
...receiptActions(clientWithAllActions, publicClient)
|
|
992
|
+
};
|
|
993
|
+
finalClient.initializeConsensusSmartContract().catch((error) => {
|
|
729
994
|
console.error("Failed to initialize consensus smart contract:", error);
|
|
730
995
|
});
|
|
731
|
-
return
|
|
996
|
+
return finalClient;
|
|
997
|
+
};
|
|
998
|
+
var createPublicClient = (chainConfig, customTransport) => {
|
|
999
|
+
return _viem.createPublicClient.call(void 0, { chain: chainConfig, transport: customTransport });
|
|
732
1000
|
};
|
|
733
1001
|
|
|
734
1002
|
// src/accounts/account.ts
|
|
@@ -740,18 +1008,9 @@ var createAccount = (accountPrivateKey) => {
|
|
|
740
1008
|
return account;
|
|
741
1009
|
};
|
|
742
1010
|
|
|
743
|
-
// src/abi/index.ts
|
|
744
|
-
var abi_exports = {};
|
|
745
|
-
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
746
|
-
calldata: () => calldata,
|
|
747
|
-
transactions: () => transactions
|
|
748
|
-
});
|
|
749
|
-
var calldata = calldata_exports;
|
|
750
|
-
var transactions = transactions_exports;
|
|
751
|
-
|
|
752
1011
|
|
|
753
1012
|
|
|
754
1013
|
|
|
755
1014
|
|
|
756
1015
|
|
|
757
|
-
exports.abi = abi_exports; exports.chains =
|
|
1016
|
+
exports.abi = abi_exports; exports.chains = _chunkFPFZLPXIcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.generatePrivateKey = generatePrivateKey;
|