genlayer-js 0.19.0 → 0.19.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/dist/index.cjs +115 -47
- package/dist/index.js +93 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -624,6 +624,7 @@ var contractActions = (client, publicClient) => {
|
|
|
624
624
|
leaderOnly = false,
|
|
625
625
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
626
626
|
} = args;
|
|
627
|
+
await client.initializeConsensusSmartContract();
|
|
627
628
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
628
629
|
const serializedData = serialize(data);
|
|
629
630
|
const senderAccount = account || client.account;
|
|
@@ -651,6 +652,7 @@ var contractActions = (client, publicClient) => {
|
|
|
651
652
|
leaderOnly = false,
|
|
652
653
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
653
654
|
} = args;
|
|
655
|
+
await client.initializeConsensusSmartContract();
|
|
654
656
|
const data = [
|
|
655
657
|
code,
|
|
656
658
|
encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
|
|
@@ -693,6 +695,50 @@ var validateAccount = (Account4) => {
|
|
|
693
695
|
}
|
|
694
696
|
return Account4;
|
|
695
697
|
};
|
|
698
|
+
var ADD_TRANSACTION_ABI_V5 = [
|
|
699
|
+
{
|
|
700
|
+
type: "function",
|
|
701
|
+
name: "addTransaction",
|
|
702
|
+
stateMutability: "nonpayable",
|
|
703
|
+
inputs: [
|
|
704
|
+
{ name: "_sender", type: "address" },
|
|
705
|
+
{ name: "_recipient", type: "address" },
|
|
706
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
707
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
708
|
+
{ name: "_txData", type: "bytes" }
|
|
709
|
+
],
|
|
710
|
+
outputs: []
|
|
711
|
+
}
|
|
712
|
+
];
|
|
713
|
+
var ADD_TRANSACTION_ABI_V6 = [
|
|
714
|
+
{
|
|
715
|
+
type: "function",
|
|
716
|
+
name: "addTransaction",
|
|
717
|
+
stateMutability: "nonpayable",
|
|
718
|
+
inputs: [
|
|
719
|
+
{ name: "_sender", type: "address" },
|
|
720
|
+
{ name: "_recipient", type: "address" },
|
|
721
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
722
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
723
|
+
{ name: "_txData", type: "bytes" },
|
|
724
|
+
{ name: "_validUntil", type: "uint256" }
|
|
725
|
+
],
|
|
726
|
+
outputs: []
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
var getAddTransactionInputCount = (abi) => {
|
|
730
|
+
if (!abi || !Array.isArray(abi)) {
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
const addTransactionFunction = abi.find((item) => {
|
|
734
|
+
if (!item || typeof item !== "object") {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const candidate = item;
|
|
738
|
+
return candidate.type === "function" && candidate.name === "addTransaction";
|
|
739
|
+
});
|
|
740
|
+
return Array.isArray(_optionalChain([addTransactionFunction, 'optionalAccess', _11 => _11.inputs])) ? addTransactionFunction.inputs.length : 0;
|
|
741
|
+
};
|
|
696
742
|
var _encodeAddTransactionData = ({
|
|
697
743
|
client,
|
|
698
744
|
senderAccount,
|
|
@@ -701,16 +747,24 @@ var _encodeAddTransactionData = ({
|
|
|
701
747
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
702
748
|
}) => {
|
|
703
749
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
750
|
+
const addTransactionArgs = [
|
|
751
|
+
validatedSenderAccount.address,
|
|
752
|
+
recipient,
|
|
753
|
+
client.chain.defaultNumberOfInitialValidators,
|
|
754
|
+
consensusMaxRotations,
|
|
755
|
+
data
|
|
756
|
+
];
|
|
757
|
+
if (getAddTransactionInputCount(_optionalChain([client, 'access', _12 => _12.chain, 'access', _13 => _13.consensusMainContract, 'optionalAccess', _14 => _14.abi])) >= 6) {
|
|
758
|
+
return _viem.encodeFunctionData.call(void 0, {
|
|
759
|
+
abi: ADD_TRANSACTION_ABI_V6,
|
|
760
|
+
functionName: "addTransaction",
|
|
761
|
+
args: [...addTransactionArgs, 0n]
|
|
762
|
+
});
|
|
763
|
+
}
|
|
704
764
|
return _viem.encodeFunctionData.call(void 0, {
|
|
705
|
-
abi:
|
|
765
|
+
abi: ADD_TRANSACTION_ABI_V5,
|
|
706
766
|
functionName: "addTransaction",
|
|
707
|
-
args:
|
|
708
|
-
validatedSenderAccount.address,
|
|
709
|
-
recipient,
|
|
710
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
711
|
-
consensusMaxRotations,
|
|
712
|
-
data
|
|
713
|
-
]
|
|
767
|
+
args: addTransactionArgs
|
|
714
768
|
});
|
|
715
769
|
};
|
|
716
770
|
var _encodeSubmitAppealData = ({
|
|
@@ -718,7 +772,7 @@ var _encodeSubmitAppealData = ({
|
|
|
718
772
|
txId
|
|
719
773
|
}) => {
|
|
720
774
|
return _viem.encodeFunctionData.call(void 0, {
|
|
721
|
-
abi: _optionalChain([client, 'access',
|
|
775
|
+
abi: _optionalChain([client, 'access', _15 => _15.chain, 'access', _16 => _16.consensusMainContract, 'optionalAccess', _17 => _17.abi]),
|
|
722
776
|
functionName: "submitAppeal",
|
|
723
777
|
args: [txId]
|
|
724
778
|
});
|
|
@@ -730,7 +784,7 @@ var _sendTransaction = async ({
|
|
|
730
784
|
senderAccount,
|
|
731
785
|
value = 0n
|
|
732
786
|
}) => {
|
|
733
|
-
if (!_optionalChain([client, 'access',
|
|
787
|
+
if (!_optionalChain([client, 'access', _18 => _18.chain, 'access', _19 => _19.consensusMainContract, 'optionalAccess', _20 => _20.address])) {
|
|
734
788
|
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
735
789
|
}
|
|
736
790
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
@@ -739,7 +793,7 @@ var _sendTransaction = async ({
|
|
|
739
793
|
try {
|
|
740
794
|
estimatedGas = await client.estimateTransactionGas({
|
|
741
795
|
from: validatedSenderAccount.address,
|
|
742
|
-
to: _optionalChain([client, 'access',
|
|
796
|
+
to: _optionalChain([client, 'access', _21 => _21.chain, 'access', _22 => _22.consensusMainContract, 'optionalAccess', _23 => _23.address]),
|
|
743
797
|
data: encodedData,
|
|
744
798
|
value
|
|
745
799
|
});
|
|
@@ -747,8 +801,8 @@ var _sendTransaction = async ({
|
|
|
747
801
|
console.error("Gas estimation failed, using default 200_000:", err);
|
|
748
802
|
estimatedGas = 200000n;
|
|
749
803
|
}
|
|
750
|
-
if (_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
751
|
-
if (!_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
804
|
+
if (_optionalChain([validatedSenderAccount, 'optionalAccess', _24 => _24.type]) === "local") {
|
|
805
|
+
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _25 => _25.signTransaction])) {
|
|
752
806
|
throw new Error("Account does not support signTransaction");
|
|
753
807
|
}
|
|
754
808
|
const gasPriceHex = await client.request({
|
|
@@ -756,7 +810,7 @@ var _sendTransaction = async ({
|
|
|
756
810
|
});
|
|
757
811
|
const transactionRequest2 = {
|
|
758
812
|
account: validatedSenderAccount,
|
|
759
|
-
to: _optionalChain([client, 'access',
|
|
813
|
+
to: _optionalChain([client, 'access', _26 => _26.chain, 'access', _27 => _27.consensusMainContract, 'optionalAccess', _28 => _28.address]),
|
|
760
814
|
data: encodedData,
|
|
761
815
|
type: "legacy",
|
|
762
816
|
nonce: Number(nonce),
|
|
@@ -772,7 +826,7 @@ var _sendTransaction = async ({
|
|
|
772
826
|
throw new Error("Transaction reverted");
|
|
773
827
|
}
|
|
774
828
|
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
775
|
-
abi: _optionalChain([client, 'access',
|
|
829
|
+
abi: _optionalChain([client, 'access', _29 => _29.chain, 'access', _30 => _30.consensusMainContract, 'optionalAccess', _31 => _31.abi]),
|
|
776
830
|
eventName: "NewTransaction",
|
|
777
831
|
logs: receipt.logs
|
|
778
832
|
});
|
|
@@ -783,7 +837,7 @@ var _sendTransaction = async ({
|
|
|
783
837
|
}
|
|
784
838
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
785
839
|
account: validatedSenderAccount,
|
|
786
|
-
to: _optionalChain([client, 'access',
|
|
840
|
+
to: _optionalChain([client, 'access', _32 => _32.chain, 'access', _33 => _33.consensusMainContract, 'optionalAccess', _34 => _34.address]),
|
|
787
841
|
data: encodedData,
|
|
788
842
|
type: "legacy",
|
|
789
843
|
nonce: Number(nonce),
|
|
@@ -1007,7 +1061,7 @@ var simplifyTransactionReceipt = (tx) => {
|
|
|
1007
1061
|
var decodeLocalnetTransaction = (tx) => {
|
|
1008
1062
|
if (!tx.data) return tx;
|
|
1009
1063
|
try {
|
|
1010
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
1064
|
+
const leaderReceipt = _optionalChain([tx, 'access', _35 => _35.consensus_data, 'optionalAccess', _36 => _36.leader_receipt]);
|
|
1011
1065
|
if (leaderReceipt) {
|
|
1012
1066
|
const receipts = Array.isArray(leaderReceipt) ? leaderReceipt : [leaderReceipt];
|
|
1013
1067
|
receipts.forEach((receipt) => {
|
|
@@ -1038,7 +1092,7 @@ var decodeLocalnetTransaction = (tx) => {
|
|
|
1038
1092
|
}
|
|
1039
1093
|
});
|
|
1040
1094
|
}
|
|
1041
|
-
if (_optionalChain([tx, 'access',
|
|
1095
|
+
if (_optionalChain([tx, 'access', _37 => _37.data, 'optionalAccess', _38 => _38.calldata]) && typeof tx.data.calldata === "string") {
|
|
1042
1096
|
tx.data.calldata = {
|
|
1043
1097
|
base64: tx.data.calldata,
|
|
1044
1098
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -1100,8 +1154,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1100
1154
|
return decodeLocalnetTransaction(transaction2);
|
|
1101
1155
|
}
|
|
1102
1156
|
const transaction = await publicClient.readContract({
|
|
1103
|
-
address: _optionalChain([client, 'access',
|
|
1104
|
-
abi: _optionalChain([client, 'access',
|
|
1157
|
+
address: _optionalChain([client, 'access', _39 => _39.chain, 'access', _40 => _40.consensusDataContract, 'optionalAccess', _41 => _41.address]),
|
|
1158
|
+
abi: _optionalChain([client, 'access', _42 => _42.chain, 'access', _43 => _43.consensusDataContract, 'optionalAccess', _44 => _44.abi]),
|
|
1105
1159
|
functionName: "getTransactionData",
|
|
1106
1160
|
args: [
|
|
1107
1161
|
hash,
|
|
@@ -1113,7 +1167,7 @@ var transactionActions = (client, publicClient) => ({
|
|
|
1113
1167
|
},
|
|
1114
1168
|
estimateTransactionGas: async (transactionParams) => {
|
|
1115
1169
|
const formattedParams = {
|
|
1116
|
-
from: transactionParams.from || _optionalChain([client, 'access',
|
|
1170
|
+
from: transactionParams.from || _optionalChain([client, 'access', _45 => _45.account, 'optionalAccess', _46 => _46.address]),
|
|
1117
1171
|
to: transactionParams.to,
|
|
1118
1172
|
data: transactionParams.data || "0x",
|
|
1119
1173
|
value: transactionParams.value ? `0x${transactionParams.value.toString(16)}` : "0x0"
|
|
@@ -1155,7 +1209,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
1155
1209
|
chainName: selectedNetwork.name,
|
|
1156
1210
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
1157
1211
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
1158
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
1212
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _47 => _47.blockExplorers, 'optionalAccess', _48 => _48.default, 'access', _49 => _49.url])]
|
|
1159
1213
|
};
|
|
1160
1214
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
1161
1215
|
if (currentChainId !== chainIdHex) {
|
|
@@ -1189,10 +1243,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1189
1243
|
}
|
|
1190
1244
|
const isFlask = async () => {
|
|
1191
1245
|
try {
|
|
1192
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
1246
|
+
const clientVersion = await _optionalChain([window, 'access', _50 => _50.ethereum, 'optionalAccess', _51 => _51.request, 'call', _52 => _52({
|
|
1193
1247
|
method: "web3_clientVersion"
|
|
1194
1248
|
})]);
|
|
1195
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
1249
|
+
return _optionalChain([clientVersion, 'optionalAccess', _53 => _53.includes, 'call', _54 => _54("flask")]);
|
|
1196
1250
|
} catch (error) {
|
|
1197
1251
|
console.error("Error detecting Flask:", error);
|
|
1198
1252
|
return false;
|
|
@@ -1200,7 +1254,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1200
1254
|
};
|
|
1201
1255
|
const installedSnaps = async () => {
|
|
1202
1256
|
try {
|
|
1203
|
-
return await _optionalChain([window, 'access',
|
|
1257
|
+
return await _optionalChain([window, 'access', _55 => _55.ethereum, 'optionalAccess', _56 => _56.request, 'call', _57 => _57({
|
|
1204
1258
|
method: "wallet_getSnaps"
|
|
1205
1259
|
})]);
|
|
1206
1260
|
} catch (error) {
|
|
@@ -1287,7 +1341,7 @@ function extractRevertReason(err) {
|
|
|
1287
1341
|
}
|
|
1288
1342
|
const revertError = err.walk((e) => e instanceof _viem.ContractFunctionRevertedError);
|
|
1289
1343
|
if (revertError instanceof _viem.ContractFunctionRevertedError) {
|
|
1290
|
-
if (_optionalChain([revertError, 'access',
|
|
1344
|
+
if (_optionalChain([revertError, 'access', _58 => _58.data, 'optionalAccess', _59 => _59.errorName])) {
|
|
1291
1345
|
return revertError.data.errorName;
|
|
1292
1346
|
}
|
|
1293
1347
|
return revertError.reason || "Unknown reason";
|
|
@@ -1375,7 +1429,7 @@ var stakingActions = (client, publicClient) => {
|
|
|
1375
1429
|
};
|
|
1376
1430
|
const getStakingAddress = () => {
|
|
1377
1431
|
const stakingConfig = client.chain.stakingContract;
|
|
1378
|
-
if (!_optionalChain([stakingConfig, 'optionalAccess',
|
|
1432
|
+
if (!_optionalChain([stakingConfig, 'optionalAccess', _60 => _60.address]) || stakingConfig.address === "0x0000000000000000000000000000000000000000") {
|
|
1379
1433
|
throw new Error("Staking is not supported on studio-based networks. Use testnet-asimov for staking operations.");
|
|
1380
1434
|
}
|
|
1381
1435
|
return stakingConfig.address;
|
|
@@ -1456,10 +1510,10 @@ var stakingActions = (client, publicClient) => {
|
|
|
1456
1510
|
return executeWrite({ to: getStakingAddress(), data });
|
|
1457
1511
|
},
|
|
1458
1512
|
validatorClaim: async (options) => {
|
|
1459
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
1513
|
+
if (!_optionalChain([options, 'optionalAccess', _61 => _61.validator]) && !client.account) {
|
|
1460
1514
|
throw new Error("Either provide validator address or initialize client with an account");
|
|
1461
1515
|
}
|
|
1462
|
-
const validatorAddress = _optionalChain([options, 'optionalAccess',
|
|
1516
|
+
const validatorAddress = _optionalChain([options, 'optionalAccess', _62 => _62.validator]) || client.account.address;
|
|
1463
1517
|
const data = _viem.encodeFunctionData.call(void 0, {
|
|
1464
1518
|
abi: _chunk5TKVNHAOcjs.STAKING_ABI,
|
|
1465
1519
|
functionName: "validatorClaim",
|
|
@@ -1800,29 +1854,43 @@ var stakingActions = (client, publicClient) => {
|
|
|
1800
1854
|
function chainActions(client) {
|
|
1801
1855
|
return {
|
|
1802
1856
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
1803
|
-
if (_optionalChain([client, 'access',
|
|
1857
|
+
if (_optionalChain([client, 'access', _63 => _63.chain, 'optionalAccess', _64 => _64.id]) === _chunk5TKVNHAOcjs.testnetAsimov.id) {
|
|
1804
1858
|
return;
|
|
1805
1859
|
}
|
|
1806
|
-
|
|
1860
|
+
const hasStaticConsensusContract = !!_optionalChain([client, 'access', _65 => _65.chain, 'access', _66 => _66.consensusMainContract, 'optionalAccess', _67 => _67.address]) && !!_optionalChain([client, 'access', _68 => _68.chain, 'access', _69 => _69.consensusMainContract, 'optionalAccess', _70 => _70.abi]);
|
|
1861
|
+
const isLocalOrStudioChain = _optionalChain([client, 'access', _71 => _71.chain, 'optionalAccess', _72 => _72.id]) === _chunk5TKVNHAOcjs.localnet.id || _optionalChain([client, 'access', _73 => _73.chain, 'optionalAccess', _74 => _74.id]) === _chunk5TKVNHAOcjs.studionet.id;
|
|
1862
|
+
if (!forceReset && hasStaticConsensusContract && !isLocalOrStudioChain) {
|
|
1807
1863
|
return;
|
|
1808
1864
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1865
|
+
try {
|
|
1866
|
+
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
1867
|
+
method: "POST",
|
|
1868
|
+
headers: {
|
|
1869
|
+
"Content-Type": "application/json"
|
|
1870
|
+
},
|
|
1871
|
+
body: JSON.stringify({
|
|
1872
|
+
jsonrpc: "2.0",
|
|
1873
|
+
id: Date.now(),
|
|
1874
|
+
method: "sim_getConsensusContract",
|
|
1875
|
+
params: ["ConsensusMain"]
|
|
1876
|
+
})
|
|
1877
|
+
});
|
|
1878
|
+
if (!contractsResponse.ok) {
|
|
1879
|
+
throw new Error("Failed to fetch ConsensusMain contract");
|
|
1880
|
+
}
|
|
1881
|
+
const consensusMainContract = await contractsResponse.json();
|
|
1882
|
+
if (_optionalChain([consensusMainContract, 'optionalAccess', _75 => _75.error]) || !_optionalChain([consensusMainContract, 'optionalAccess', _76 => _76.result, 'optionalAccess', _77 => _77.address]) || !_optionalChain([consensusMainContract, 'optionalAccess', _78 => _78.result, 'optionalAccess', _79 => _79.abi])) {
|
|
1883
|
+
throw new Error("ConsensusMain response did not include a valid contract");
|
|
1884
|
+
}
|
|
1885
|
+
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1886
|
+
client.chain.__consensusAbiFetchedFromRpc = true;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (hasStaticConsensusContract) {
|
|
1889
|
+
client.chain.__consensusAbiFetchedFromRpc = false;
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1823
1893
|
}
|
|
1824
|
-
const consensusMainContract = await contractsResponse.json();
|
|
1825
|
-
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1826
1894
|
}
|
|
1827
1895
|
};
|
|
1828
1896
|
}
|
package/dist/index.js
CHANGED
|
@@ -624,6 +624,7 @@ var contractActions = (client, publicClient) => {
|
|
|
624
624
|
leaderOnly = false,
|
|
625
625
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
626
626
|
} = args;
|
|
627
|
+
await client.initializeConsensusSmartContract();
|
|
627
628
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
628
629
|
const serializedData = serialize(data);
|
|
629
630
|
const senderAccount = account || client.account;
|
|
@@ -651,6 +652,7 @@ var contractActions = (client, publicClient) => {
|
|
|
651
652
|
leaderOnly = false,
|
|
652
653
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
653
654
|
} = args;
|
|
655
|
+
await client.initializeConsensusSmartContract();
|
|
654
656
|
const data = [
|
|
655
657
|
code,
|
|
656
658
|
encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
|
|
@@ -693,6 +695,50 @@ var validateAccount = (Account4) => {
|
|
|
693
695
|
}
|
|
694
696
|
return Account4;
|
|
695
697
|
};
|
|
698
|
+
var ADD_TRANSACTION_ABI_V5 = [
|
|
699
|
+
{
|
|
700
|
+
type: "function",
|
|
701
|
+
name: "addTransaction",
|
|
702
|
+
stateMutability: "nonpayable",
|
|
703
|
+
inputs: [
|
|
704
|
+
{ name: "_sender", type: "address" },
|
|
705
|
+
{ name: "_recipient", type: "address" },
|
|
706
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
707
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
708
|
+
{ name: "_txData", type: "bytes" }
|
|
709
|
+
],
|
|
710
|
+
outputs: []
|
|
711
|
+
}
|
|
712
|
+
];
|
|
713
|
+
var ADD_TRANSACTION_ABI_V6 = [
|
|
714
|
+
{
|
|
715
|
+
type: "function",
|
|
716
|
+
name: "addTransaction",
|
|
717
|
+
stateMutability: "nonpayable",
|
|
718
|
+
inputs: [
|
|
719
|
+
{ name: "_sender", type: "address" },
|
|
720
|
+
{ name: "_recipient", type: "address" },
|
|
721
|
+
{ name: "_numOfInitialValidators", type: "uint256" },
|
|
722
|
+
{ name: "_maxRotations", type: "uint256" },
|
|
723
|
+
{ name: "_txData", type: "bytes" },
|
|
724
|
+
{ name: "_validUntil", type: "uint256" }
|
|
725
|
+
],
|
|
726
|
+
outputs: []
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
var getAddTransactionInputCount = (abi) => {
|
|
730
|
+
if (!abi || !Array.isArray(abi)) {
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
const addTransactionFunction = abi.find((item) => {
|
|
734
|
+
if (!item || typeof item !== "object") {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const candidate = item;
|
|
738
|
+
return candidate.type === "function" && candidate.name === "addTransaction";
|
|
739
|
+
});
|
|
740
|
+
return Array.isArray(addTransactionFunction?.inputs) ? addTransactionFunction.inputs.length : 0;
|
|
741
|
+
};
|
|
696
742
|
var _encodeAddTransactionData = ({
|
|
697
743
|
client,
|
|
698
744
|
senderAccount,
|
|
@@ -701,16 +747,24 @@ var _encodeAddTransactionData = ({
|
|
|
701
747
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations
|
|
702
748
|
}) => {
|
|
703
749
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
750
|
+
const addTransactionArgs = [
|
|
751
|
+
validatedSenderAccount.address,
|
|
752
|
+
recipient,
|
|
753
|
+
client.chain.defaultNumberOfInitialValidators,
|
|
754
|
+
consensusMaxRotations,
|
|
755
|
+
data
|
|
756
|
+
];
|
|
757
|
+
if (getAddTransactionInputCount(client.chain.consensusMainContract?.abi) >= 6) {
|
|
758
|
+
return encodeFunctionData({
|
|
759
|
+
abi: ADD_TRANSACTION_ABI_V6,
|
|
760
|
+
functionName: "addTransaction",
|
|
761
|
+
args: [...addTransactionArgs, 0n]
|
|
762
|
+
});
|
|
763
|
+
}
|
|
704
764
|
return encodeFunctionData({
|
|
705
|
-
abi:
|
|
765
|
+
abi: ADD_TRANSACTION_ABI_V5,
|
|
706
766
|
functionName: "addTransaction",
|
|
707
|
-
args:
|
|
708
|
-
validatedSenderAccount.address,
|
|
709
|
-
recipient,
|
|
710
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
711
|
-
consensusMaxRotations,
|
|
712
|
-
data
|
|
713
|
-
]
|
|
767
|
+
args: addTransactionArgs
|
|
714
768
|
});
|
|
715
769
|
};
|
|
716
770
|
var _encodeSubmitAppealData = ({
|
|
@@ -1803,26 +1857,40 @@ function chainActions(client) {
|
|
|
1803
1857
|
if (client.chain?.id === testnetAsimov.id) {
|
|
1804
1858
|
return;
|
|
1805
1859
|
}
|
|
1806
|
-
|
|
1860
|
+
const hasStaticConsensusContract = !!client.chain.consensusMainContract?.address && !!client.chain.consensusMainContract?.abi;
|
|
1861
|
+
const isLocalOrStudioChain = client.chain?.id === localnet.id || client.chain?.id === studionet.id;
|
|
1862
|
+
if (!forceReset && hasStaticConsensusContract && !isLocalOrStudioChain) {
|
|
1807
1863
|
return;
|
|
1808
1864
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1865
|
+
try {
|
|
1866
|
+
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
1867
|
+
method: "POST",
|
|
1868
|
+
headers: {
|
|
1869
|
+
"Content-Type": "application/json"
|
|
1870
|
+
},
|
|
1871
|
+
body: JSON.stringify({
|
|
1872
|
+
jsonrpc: "2.0",
|
|
1873
|
+
id: Date.now(),
|
|
1874
|
+
method: "sim_getConsensusContract",
|
|
1875
|
+
params: ["ConsensusMain"]
|
|
1876
|
+
})
|
|
1877
|
+
});
|
|
1878
|
+
if (!contractsResponse.ok) {
|
|
1879
|
+
throw new Error("Failed to fetch ConsensusMain contract");
|
|
1880
|
+
}
|
|
1881
|
+
const consensusMainContract = await contractsResponse.json();
|
|
1882
|
+
if (consensusMainContract?.error || !consensusMainContract?.result?.address || !consensusMainContract?.result?.abi) {
|
|
1883
|
+
throw new Error("ConsensusMain response did not include a valid contract");
|
|
1884
|
+
}
|
|
1885
|
+
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1886
|
+
client.chain.__consensusAbiFetchedFromRpc = true;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
if (hasStaticConsensusContract) {
|
|
1889
|
+
client.chain.__consensusAbiFetchedFromRpc = false;
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1823
1893
|
}
|
|
1824
|
-
const consensusMainContract = await contractsResponse.json();
|
|
1825
|
-
client.chain.consensusMainContract = consensusMainContract.result;
|
|
1826
1894
|
}
|
|
1827
1895
|
};
|
|
1828
1896
|
}
|