genlayer-js 0.8.0 → 0.9.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/CHANGELOG.md +7 -0
- package/dist/{index-BfeTR7rO.d.cts → index-BCbofn6t.d.cts} +1 -0
- package/dist/{index-CODAJePj.d.ts → index-Ctmshvtv.d.ts} +1 -0
- package/dist/index.cjs +91 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +84 -10
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/transactions/actions.ts +42 -1
- package/src/types/transactions.ts +1 -0
- package/src/utils/jsonifier.ts +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.9.0 (2025-03-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* decoding params ([#77](https://github.com/yeagerai/genlayer-js/issues/77)) ([ada41ce](https://github.com/yeagerai/genlayer-js/commit/ada41ce375eaf6a94886bc50c13c3f0df247d7c2))
|
|
9
|
+
|
|
3
10
|
## 0.8.0 (2025-03-12)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.cjs
CHANGED
|
@@ -514,6 +514,55 @@ async function sleep(ms) {
|
|
|
514
514
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
// src/abi/index.ts
|
|
518
|
+
var abi_exports = {};
|
|
519
|
+
_chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
|
|
520
|
+
calldata: () => calldata,
|
|
521
|
+
transactions: () => transactions
|
|
522
|
+
});
|
|
523
|
+
var calldata = calldata_exports;
|
|
524
|
+
var transactions = transactions_exports;
|
|
525
|
+
|
|
526
|
+
// src/utils/jsonifier.ts
|
|
527
|
+
function b64ToArray(b64) {
|
|
528
|
+
return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
529
|
+
}
|
|
530
|
+
function calldataToUserFriendlyJson(cd) {
|
|
531
|
+
return {
|
|
532
|
+
raw: Array.from(cd),
|
|
533
|
+
readable: calldata.toString(calldata.decode(cd))
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
var RESULT_CODES = /* @__PURE__ */ new Map([
|
|
537
|
+
[0, "return"],
|
|
538
|
+
[1, "rollback"],
|
|
539
|
+
[2, "contract_error"],
|
|
540
|
+
[3, "error"],
|
|
541
|
+
[4, "none"],
|
|
542
|
+
[5, "no_leaders"]
|
|
543
|
+
]);
|
|
544
|
+
function resultToUserFriendlyJson(cd64) {
|
|
545
|
+
const raw = b64ToArray(cd64);
|
|
546
|
+
const code = RESULT_CODES.get(raw[0]);
|
|
547
|
+
let status;
|
|
548
|
+
let payload = null;
|
|
549
|
+
if (code === void 0) {
|
|
550
|
+
status = "<unknown>";
|
|
551
|
+
} else {
|
|
552
|
+
status = code;
|
|
553
|
+
if ([1, 2].includes(raw[0])) {
|
|
554
|
+
payload = new TextDecoder("utf-8").decode(raw.slice(1));
|
|
555
|
+
} else if (raw[0] == 0) {
|
|
556
|
+
payload = calldataToUserFriendlyJson(raw.slice(1));
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
raw: cd64,
|
|
561
|
+
status,
|
|
562
|
+
payload
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
|
|
517
566
|
// src/transactions/actions.ts
|
|
518
567
|
var transactionActions = (client) => ({
|
|
519
568
|
waitForTransactionReceipt: async ({
|
|
@@ -527,7 +576,7 @@ var transactionActions = (client) => ({
|
|
|
527
576
|
throw new Error("Transaction not found");
|
|
528
577
|
}
|
|
529
578
|
if (transaction.status === status || status === "ACCEPTED" /* ACCEPTED */ && transaction.status === "FINALIZED" /* FINALIZED */) {
|
|
530
|
-
return transaction;
|
|
579
|
+
return _decodeTransaction(transaction);
|
|
531
580
|
}
|
|
532
581
|
if (retries === 0) {
|
|
533
582
|
throw new Error("Transaction status is not " + status);
|
|
@@ -541,6 +590,40 @@ var transactionActions = (client) => ({
|
|
|
541
590
|
});
|
|
542
591
|
}
|
|
543
592
|
});
|
|
593
|
+
var _decodeTransaction = (tx) => {
|
|
594
|
+
if (!tx.data) return tx;
|
|
595
|
+
try {
|
|
596
|
+
const leaderReceipt = _optionalChain([tx, 'access', _19 => _19.consensus_data, 'optionalAccess', _20 => _20.leader_receipt]);
|
|
597
|
+
if (leaderReceipt) {
|
|
598
|
+
if (leaderReceipt.result) {
|
|
599
|
+
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
600
|
+
}
|
|
601
|
+
if (leaderReceipt.calldata) {
|
|
602
|
+
leaderReceipt.calldata = {
|
|
603
|
+
base64: leaderReceipt.calldata,
|
|
604
|
+
...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata))
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (leaderReceipt.eq_outputs) {
|
|
608
|
+
leaderReceipt.eq_outputs = Object.fromEntries(
|
|
609
|
+
Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
|
|
610
|
+
const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
|
|
611
|
+
return [key, resultToUserFriendlyJson(decodedValue)];
|
|
612
|
+
})
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (tx.data.calldata) {
|
|
617
|
+
tx.data.calldata = {
|
|
618
|
+
base64: tx.data.calldata,
|
|
619
|
+
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
} catch (e) {
|
|
623
|
+
console.error("Error decoding transaction:", e);
|
|
624
|
+
}
|
|
625
|
+
return tx;
|
|
626
|
+
};
|
|
544
627
|
|
|
545
628
|
// src/config/snapID.ts
|
|
546
629
|
var snapID = {
|
|
@@ -569,7 +652,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
|
569
652
|
chainName: selectedNetwork.name,
|
|
570
653
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
571
654
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
572
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
655
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _21 => _21.blockExplorers, 'optionalAccess', _22 => _22.default, 'access', _23 => _23.url])]
|
|
573
656
|
};
|
|
574
657
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
575
658
|
if (currentChainId !== chainIdHex) {
|
|
@@ -605,10 +688,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
605
688
|
}
|
|
606
689
|
const isFlask = async () => {
|
|
607
690
|
try {
|
|
608
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
691
|
+
const clientVersion = await _optionalChain([window, 'access', _24 => _24.ethereum, 'optionalAccess', _25 => _25.request, 'call', _26 => _26({
|
|
609
692
|
method: "web3_clientVersion"
|
|
610
693
|
})]);
|
|
611
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
694
|
+
return _optionalChain([clientVersion, 'optionalAccess', _27 => _27.includes, 'call', _28 => _28("flask")]);
|
|
612
695
|
} catch (error) {
|
|
613
696
|
console.error("Error detecting Flask:", error);
|
|
614
697
|
return false;
|
|
@@ -616,7 +699,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
616
699
|
};
|
|
617
700
|
const installedSnaps = async () => {
|
|
618
701
|
try {
|
|
619
|
-
return await _optionalChain([window, 'access',
|
|
702
|
+
return await _optionalChain([window, 'access', _29 => _29.ethereum, 'optionalAccess', _30 => _30.request, 'call', _31 => _31({
|
|
620
703
|
method: "wallet_getSnaps"
|
|
621
704
|
})]);
|
|
622
705
|
} catch (error) {
|
|
@@ -651,10 +734,10 @@ function walletActions(client) {
|
|
|
651
734
|
function chainActions(client) {
|
|
652
735
|
return {
|
|
653
736
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
654
|
-
if (_optionalChain([client, 'access',
|
|
737
|
+
if (_optionalChain([client, 'access', _32 => _32.chain, 'optionalAccess', _33 => _33.id]) !== _chunkI6HC44KDcjs.simulator.id) {
|
|
655
738
|
throw new Error("Client is not connected to the simulator");
|
|
656
739
|
}
|
|
657
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
740
|
+
if (!forceReset && _optionalChain([client, 'access', _34 => _34.chain, 'access', _35 => _35.consensusMainContract, 'optionalAccess', _36 => _36.address]) && _optionalChain([client, 'access', _37 => _37.chain, 'access', _38 => _38.consensusMainContract, 'optionalAccess', _39 => _39.abi])) {
|
|
658
741
|
return;
|
|
659
742
|
}
|
|
660
743
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -689,7 +772,7 @@ var createClient = (config = { chain: _chunkI6HC44KDcjs.localnet }) => {
|
|
|
689
772
|
async request({ method, params }) {
|
|
690
773
|
if (method.startsWith("eth_") && isAddress) {
|
|
691
774
|
try {
|
|
692
|
-
return await _optionalChain([window, 'access',
|
|
775
|
+
return await _optionalChain([window, 'access', _40 => _40.ethereum, 'optionalAccess', _41 => _41.request, 'call', _42 => _42({ method, params })]);
|
|
693
776
|
} catch (err) {
|
|
694
777
|
console.warn(`Error using window.ethereum for method ${method}:`, err);
|
|
695
778
|
throw err;
|
|
@@ -740,15 +823,6 @@ var createAccount = (accountPrivateKey) => {
|
|
|
740
823
|
return account;
|
|
741
824
|
};
|
|
742
825
|
|
|
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
826
|
|
|
753
827
|
|
|
754
828
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
3
|
import { S as SimulatorChain } from './chains-C5PI_Nr_.cjs';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-BCbofn6t.cjs';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
3
|
import { S as SimulatorChain } from './chains-C5PI_Nr_.js';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-Ctmshvtv.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
package/dist/index.js
CHANGED
|
@@ -514,6 +514,55 @@ async function sleep(ms) {
|
|
|
514
514
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
// src/abi/index.ts
|
|
518
|
+
var abi_exports = {};
|
|
519
|
+
__export(abi_exports, {
|
|
520
|
+
calldata: () => calldata,
|
|
521
|
+
transactions: () => transactions
|
|
522
|
+
});
|
|
523
|
+
var calldata = calldata_exports;
|
|
524
|
+
var transactions = transactions_exports;
|
|
525
|
+
|
|
526
|
+
// src/utils/jsonifier.ts
|
|
527
|
+
function b64ToArray(b64) {
|
|
528
|
+
return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
529
|
+
}
|
|
530
|
+
function calldataToUserFriendlyJson(cd) {
|
|
531
|
+
return {
|
|
532
|
+
raw: Array.from(cd),
|
|
533
|
+
readable: calldata.toString(calldata.decode(cd))
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
var RESULT_CODES = /* @__PURE__ */ new Map([
|
|
537
|
+
[0, "return"],
|
|
538
|
+
[1, "rollback"],
|
|
539
|
+
[2, "contract_error"],
|
|
540
|
+
[3, "error"],
|
|
541
|
+
[4, "none"],
|
|
542
|
+
[5, "no_leaders"]
|
|
543
|
+
]);
|
|
544
|
+
function resultToUserFriendlyJson(cd64) {
|
|
545
|
+
const raw = b64ToArray(cd64);
|
|
546
|
+
const code = RESULT_CODES.get(raw[0]);
|
|
547
|
+
let status;
|
|
548
|
+
let payload = null;
|
|
549
|
+
if (code === void 0) {
|
|
550
|
+
status = "<unknown>";
|
|
551
|
+
} else {
|
|
552
|
+
status = code;
|
|
553
|
+
if ([1, 2].includes(raw[0])) {
|
|
554
|
+
payload = new TextDecoder("utf-8").decode(raw.slice(1));
|
|
555
|
+
} else if (raw[0] == 0) {
|
|
556
|
+
payload = calldataToUserFriendlyJson(raw.slice(1));
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
raw: cd64,
|
|
561
|
+
status,
|
|
562
|
+
payload
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
|
|
517
566
|
// src/transactions/actions.ts
|
|
518
567
|
var transactionActions = (client) => ({
|
|
519
568
|
waitForTransactionReceipt: async ({
|
|
@@ -527,7 +576,7 @@ var transactionActions = (client) => ({
|
|
|
527
576
|
throw new Error("Transaction not found");
|
|
528
577
|
}
|
|
529
578
|
if (transaction.status === status || status === "ACCEPTED" /* ACCEPTED */ && transaction.status === "FINALIZED" /* FINALIZED */) {
|
|
530
|
-
return transaction;
|
|
579
|
+
return _decodeTransaction(transaction);
|
|
531
580
|
}
|
|
532
581
|
if (retries === 0) {
|
|
533
582
|
throw new Error("Transaction status is not " + status);
|
|
@@ -541,6 +590,40 @@ var transactionActions = (client) => ({
|
|
|
541
590
|
});
|
|
542
591
|
}
|
|
543
592
|
});
|
|
593
|
+
var _decodeTransaction = (tx) => {
|
|
594
|
+
if (!tx.data) return tx;
|
|
595
|
+
try {
|
|
596
|
+
const leaderReceipt = tx.consensus_data?.leader_receipt;
|
|
597
|
+
if (leaderReceipt) {
|
|
598
|
+
if (leaderReceipt.result) {
|
|
599
|
+
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
600
|
+
}
|
|
601
|
+
if (leaderReceipt.calldata) {
|
|
602
|
+
leaderReceipt.calldata = {
|
|
603
|
+
base64: leaderReceipt.calldata,
|
|
604
|
+
...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata))
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (leaderReceipt.eq_outputs) {
|
|
608
|
+
leaderReceipt.eq_outputs = Object.fromEntries(
|
|
609
|
+
Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
|
|
610
|
+
const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
|
|
611
|
+
return [key, resultToUserFriendlyJson(decodedValue)];
|
|
612
|
+
})
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (tx.data.calldata) {
|
|
617
|
+
tx.data.calldata = {
|
|
618
|
+
base64: tx.data.calldata,
|
|
619
|
+
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
} catch (e) {
|
|
623
|
+
console.error("Error decoding transaction:", e);
|
|
624
|
+
}
|
|
625
|
+
return tx;
|
|
626
|
+
};
|
|
544
627
|
|
|
545
628
|
// src/config/snapID.ts
|
|
546
629
|
var snapID = {
|
|
@@ -739,15 +822,6 @@ var createAccount = (accountPrivateKey) => {
|
|
|
739
822
|
const account = privateKeyToAccount(privateKey);
|
|
740
823
|
return account;
|
|
741
824
|
};
|
|
742
|
-
|
|
743
|
-
// src/abi/index.ts
|
|
744
|
-
var abi_exports = {};
|
|
745
|
-
__export(abi_exports, {
|
|
746
|
-
calldata: () => calldata,
|
|
747
|
-
transactions: () => transactions
|
|
748
|
-
});
|
|
749
|
-
var calldata = calldata_exports;
|
|
750
|
-
var transactions = transactions_exports;
|
|
751
825
|
export {
|
|
752
826
|
abi_exports as abi,
|
|
753
827
|
chains_exports as chains,
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as Address, a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, G as GenLayerClient, b as GenLayerMethod, j as GenLayerTransaction, M as MethodDescription, N as Network, S as SnapSource, k as TransactionDataElement, h as TransactionHash, i as TransactionStatus } from '../index-
|
|
1
|
+
export { A as Address, a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, G as GenLayerClient, b as GenLayerMethod, j as GenLayerTransaction, M as MethodDescription, N as Network, S as SnapSource, k as TransactionDataElement, h as TransactionHash, i as TransactionStatus } from '../index-BCbofn6t.cjs';
|
|
2
2
|
export { S as SimulatorChain } from '../chains-C5PI_Nr_.cjs';
|
|
3
3
|
export { Account } from 'viem';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as Address, a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, G as GenLayerClient, b as GenLayerMethod, j as GenLayerTransaction, M as MethodDescription, N as Network, S as SnapSource, k as TransactionDataElement, h as TransactionHash, i as TransactionStatus } from '../index-
|
|
1
|
+
export { A as Address, a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, G as GenLayerClient, b as GenLayerMethod, j as GenLayerTransaction, M as MethodDescription, N as Network, S as SnapSource, k as TransactionDataElement, h as TransactionHash, i as TransactionStatus } from '../index-Ctmshvtv.js';
|
|
2
2
|
export { S as SimulatorChain } from '../chains-C5PI_Nr_.js';
|
|
3
3
|
export { Account } from 'viem';
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import {TransactionHash, TransactionStatus, GenLayerTransaction} from "../types/
|
|
|
3
3
|
import {transactionsConfig} from "../config/transactions";
|
|
4
4
|
import {sleep} from "../utils/async";
|
|
5
5
|
import {SimulatorChain} from "@/types";
|
|
6
|
+
import {b64ToArray, calldataToUserFriendlyJson, resultToUserFriendlyJson} from "@/utils/jsonifier";
|
|
6
7
|
|
|
7
8
|
export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
|
|
8
9
|
waitForTransactionReceipt: async ({
|
|
@@ -26,7 +27,7 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
|
|
|
26
27
|
transaction.status === status ||
|
|
27
28
|
(status === TransactionStatus.ACCEPTED && transaction.status === TransactionStatus.FINALIZED)
|
|
28
29
|
) {
|
|
29
|
-
return transaction;
|
|
30
|
+
return _decodeTransaction(transaction);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
if (retries === 0) {
|
|
@@ -42,3 +43,43 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
|
|
|
42
43
|
});
|
|
43
44
|
},
|
|
44
45
|
});
|
|
46
|
+
|
|
47
|
+
const _decodeTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
|
|
48
|
+
if (!tx.data) return tx;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const leaderReceipt = tx.consensus_data?.leader_receipt;
|
|
52
|
+
if (leaderReceipt) {
|
|
53
|
+
if (leaderReceipt.result) {
|
|
54
|
+
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (leaderReceipt.calldata) {
|
|
58
|
+
leaderReceipt.calldata = {
|
|
59
|
+
base64: leaderReceipt.calldata,
|
|
60
|
+
...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata)),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (leaderReceipt.eq_outputs) {
|
|
65
|
+
leaderReceipt.eq_outputs = Object.fromEntries(
|
|
66
|
+
Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
|
|
67
|
+
const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
|
|
68
|
+
return [key, resultToUserFriendlyJson(decodedValue)];
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (tx.data.calldata) {
|
|
75
|
+
tx.data.calldata = {
|
|
76
|
+
base64: tx.data.calldata as string,
|
|
77
|
+
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata as string)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error("Error decoding transaction:", e);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return tx;
|
|
85
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {calldata} from "@/abi";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function b64ToArray(b64: string): Uint8Array {
|
|
5
|
+
return Uint8Array.from(atob(b64 as string), (c) => c.charCodeAt(0));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function calldataToUserFriendlyJson(cd: Uint8Array): any {
|
|
9
|
+
return {
|
|
10
|
+
raw: Array.from(cd),
|
|
11
|
+
readable: calldata.toString(calldata.decode(cd)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const RESULT_CODES = new Map([
|
|
16
|
+
[0, 'return'],
|
|
17
|
+
[1, 'rollback'],
|
|
18
|
+
[2, 'contract_error'],
|
|
19
|
+
[3, 'error'],
|
|
20
|
+
[4, 'none'],
|
|
21
|
+
[5, 'no_leaders'],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function resultToUserFriendlyJson(cd64: string): any {
|
|
25
|
+
const raw = b64ToArray(cd64);
|
|
26
|
+
|
|
27
|
+
const code = RESULT_CODES.get(raw[0]);
|
|
28
|
+
let status: string;
|
|
29
|
+
let payload: string | null = null;
|
|
30
|
+
|
|
31
|
+
if (code === undefined) {
|
|
32
|
+
status = '<unknown>';
|
|
33
|
+
} else {
|
|
34
|
+
status = code;
|
|
35
|
+
if ([1, 2].includes(raw[0])) {
|
|
36
|
+
payload = new TextDecoder('utf-8').decode(raw.slice(1));
|
|
37
|
+
} else if (raw[0] == 0) {
|
|
38
|
+
payload = calldataToUserFriendlyJson(raw.slice(1));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
raw: cd64,
|
|
44
|
+
status,
|
|
45
|
+
payload,
|
|
46
|
+
};
|
|
47
|
+
}
|