genlayer-js 0.12.1 → 0.14.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 +14 -0
- package/README.md +30 -1
- package/dist/{index-TWCEN45Z.d.ts → index-CgHl4W-5.d.ts} +1 -1
- package/dist/{index-icLJcrDm.d.cts → index-IViMPpkl.d.cts} +1 -1
- package/dist/index.cjs +231 -96
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +229 -94
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/abi/calldata/encoder.ts +36 -0
- package/src/contracts/actions.ts +3 -40
- package/src/index.ts +6 -0
- package/src/transactions/actions.ts +15 -141
- package/src/transactions/decoders.ts +276 -0
package/dist/index.js
CHANGED
|
@@ -57,6 +57,7 @@ var calldata_exports = {};
|
|
|
57
57
|
__export(calldata_exports, {
|
|
58
58
|
decode: () => decode,
|
|
59
59
|
encode: () => encode,
|
|
60
|
+
makeCalldataObject: () => makeCalldataObject,
|
|
60
61
|
toString: () => toString
|
|
61
62
|
});
|
|
62
63
|
|
|
@@ -203,6 +204,32 @@ function encode(data) {
|
|
|
203
204
|
encodeImpl(arr, data);
|
|
204
205
|
return new Uint8Array(arr);
|
|
205
206
|
}
|
|
207
|
+
function makeCalldataObject(method, args, kwargs) {
|
|
208
|
+
let ret = {};
|
|
209
|
+
if (method) {
|
|
210
|
+
ret["method"] = method;
|
|
211
|
+
}
|
|
212
|
+
if (args && args.length > 0) {
|
|
213
|
+
ret["args"] = args;
|
|
214
|
+
}
|
|
215
|
+
if (kwargs) {
|
|
216
|
+
if (kwargs instanceof Map) {
|
|
217
|
+
if (kwargs.size > 0) {
|
|
218
|
+
ret["kwargs"] = kwargs;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
let hasVal = false;
|
|
222
|
+
for (const _k in kwargs) {
|
|
223
|
+
hasVal = true;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (hasVal) {
|
|
227
|
+
ret["kwargs"] = kwargs;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return ret;
|
|
232
|
+
}
|
|
206
233
|
|
|
207
234
|
// src/abi/calldata/decoder.ts
|
|
208
235
|
function readULeb128(data, index) {
|
|
@@ -381,32 +408,6 @@ function serialize(data) {
|
|
|
381
408
|
|
|
382
409
|
// src/contracts/actions.ts
|
|
383
410
|
import { fromHex, toHex as toHex2, zeroAddress, encodeFunctionData, parseEventLogs } from "viem";
|
|
384
|
-
function makeCalldataObject(method, args, kwargs) {
|
|
385
|
-
let ret = {};
|
|
386
|
-
if (method) {
|
|
387
|
-
ret["method"] = method;
|
|
388
|
-
}
|
|
389
|
-
if (args && args.length > 0) {
|
|
390
|
-
ret["args"] = args;
|
|
391
|
-
}
|
|
392
|
-
if (kwargs) {
|
|
393
|
-
if (kwargs instanceof Map) {
|
|
394
|
-
if (kwargs.size > 0) {
|
|
395
|
-
ret["kwargs"] = kwargs;
|
|
396
|
-
}
|
|
397
|
-
} else {
|
|
398
|
-
let hasVal = false;
|
|
399
|
-
for (const _k in kwargs) {
|
|
400
|
-
hasVal = true;
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
if (hasVal) {
|
|
404
|
-
ret["kwargs"] = kwargs;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return ret;
|
|
409
|
-
}
|
|
410
411
|
var contractActions = (client, publicClient) => {
|
|
411
412
|
return {
|
|
412
413
|
getContractSchema: async (address) => {
|
|
@@ -682,65 +683,51 @@ function resultToUserFriendlyJson(cd64) {
|
|
|
682
683
|
};
|
|
683
684
|
}
|
|
684
685
|
|
|
685
|
-
// src/transactions/
|
|
686
|
+
// src/transactions/decoders.ts
|
|
686
687
|
import { fromRlp, fromHex as fromHex2 } from "viem";
|
|
687
|
-
var
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
const transaction = await publicClient.readContract({
|
|
731
|
-
address: client.chain.consensusDataContract?.address,
|
|
732
|
-
abi: client.chain.consensusDataContract?.abi,
|
|
733
|
-
functionName: "getTransactionData",
|
|
734
|
-
args: [
|
|
735
|
-
hash,
|
|
736
|
-
Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3)
|
|
737
|
-
// unix seconds
|
|
738
|
-
]
|
|
739
|
-
});
|
|
740
|
-
return _decodeTransaction(transaction);
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
var _decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
688
|
+
var FIELDS_TO_REMOVE = [
|
|
689
|
+
"raw",
|
|
690
|
+
"contract_state",
|
|
691
|
+
"base64",
|
|
692
|
+
"consensus_history",
|
|
693
|
+
"tx_data",
|
|
694
|
+
"eq_blocks_outputs",
|
|
695
|
+
"r",
|
|
696
|
+
"s",
|
|
697
|
+
"v",
|
|
698
|
+
"created_timestamp",
|
|
699
|
+
"current_timestamp",
|
|
700
|
+
"tx_execution_hash",
|
|
701
|
+
"random_seed",
|
|
702
|
+
"states",
|
|
703
|
+
"contract_code",
|
|
704
|
+
"appeal_failed",
|
|
705
|
+
"appeal_leader_timeout",
|
|
706
|
+
"appeal_processing_time",
|
|
707
|
+
"appeal_undetermined",
|
|
708
|
+
"appealed",
|
|
709
|
+
"timestamp_appeal",
|
|
710
|
+
"config_rotation_rounds",
|
|
711
|
+
"rotation_count",
|
|
712
|
+
"queue_position",
|
|
713
|
+
"queue_type",
|
|
714
|
+
"leader_timeout_validators",
|
|
715
|
+
"triggered_by",
|
|
716
|
+
"num_of_initial_validators",
|
|
717
|
+
"timestamp_awaiting_finalization",
|
|
718
|
+
"last_vote_timestamp",
|
|
719
|
+
"read_state_block_range",
|
|
720
|
+
"tx_slot",
|
|
721
|
+
"blockHash",
|
|
722
|
+
"blockNumber",
|
|
723
|
+
"to",
|
|
724
|
+
"transactionIndex"
|
|
725
|
+
];
|
|
726
|
+
var FIELD_NAME_MAPPINGS = {
|
|
727
|
+
statusName: "status_name",
|
|
728
|
+
typeHex: "type"
|
|
729
|
+
};
|
|
730
|
+
var decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
744
731
|
if (!rlpEncodedAppData || rlpEncodedAppData === "0x" || rlpEncodedAppData.length <= 2) {
|
|
745
732
|
return null;
|
|
746
733
|
}
|
|
@@ -778,8 +765,8 @@ var _decodeInputData = (rlpEncodedAppData, recipient) => {
|
|
|
778
765
|
return null;
|
|
779
766
|
}
|
|
780
767
|
};
|
|
781
|
-
var
|
|
782
|
-
const txDataDecoded =
|
|
768
|
+
var decodeTransaction = (tx) => {
|
|
769
|
+
const txDataDecoded = decodeInputData(tx.txData, tx.recipient);
|
|
783
770
|
const decodedTx = {
|
|
784
771
|
...tx,
|
|
785
772
|
txData: tx.txData,
|
|
@@ -814,7 +801,78 @@ var _decodeTransaction = (tx) => {
|
|
|
814
801
|
};
|
|
815
802
|
return decodedTx;
|
|
816
803
|
};
|
|
817
|
-
var
|
|
804
|
+
var simplifyTransactionReceipt = (tx) => {
|
|
805
|
+
const simplifyObject = (obj, path = "") => {
|
|
806
|
+
if (obj === null || obj === void 0) return obj;
|
|
807
|
+
if (Array.isArray(obj)) {
|
|
808
|
+
return obj.map((item) => simplifyObject(item, path)).filter((item) => item !== void 0);
|
|
809
|
+
}
|
|
810
|
+
if (typeof obj === "object") {
|
|
811
|
+
const result = {};
|
|
812
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
813
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
814
|
+
if (FIELDS_TO_REMOVE.includes(key)) {
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (key === "node_config" && !path.includes("consensus_data")) {
|
|
818
|
+
continue;
|
|
819
|
+
}
|
|
820
|
+
if (key === "consensus_data" && typeof value === "object" && value !== null) {
|
|
821
|
+
const simplifiedConsensus = {};
|
|
822
|
+
if ("votes" in value) {
|
|
823
|
+
simplifiedConsensus.votes = value.votes;
|
|
824
|
+
}
|
|
825
|
+
if ("leader_receipt" in value && Array.isArray(value.leader_receipt)) {
|
|
826
|
+
simplifiedConsensus.leader_receipt = value.leader_receipt.map((receipt) => {
|
|
827
|
+
const simplifiedReceipt = {};
|
|
828
|
+
["execution_result", "genvm_result", "mode", "vote", "node_config"].forEach((field) => {
|
|
829
|
+
if (field in receipt) {
|
|
830
|
+
simplifiedReceipt[field] = receipt[field];
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
if (receipt.calldata && typeof receipt.calldata === "object" && "readable" in receipt.calldata) {
|
|
834
|
+
simplifiedReceipt.calldata = { readable: receipt.calldata.readable };
|
|
835
|
+
}
|
|
836
|
+
if (receipt.eq_outputs) {
|
|
837
|
+
simplifiedReceipt.eq_outputs = simplifyObject(receipt.eq_outputs, currentPath);
|
|
838
|
+
}
|
|
839
|
+
if (receipt.result) {
|
|
840
|
+
simplifiedReceipt.result = simplifyObject(receipt.result, currentPath);
|
|
841
|
+
}
|
|
842
|
+
return simplifiedReceipt;
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
if ("validators" in value && Array.isArray(value.validators)) {
|
|
846
|
+
const simplifiedValidators = value.validators.map((validator) => {
|
|
847
|
+
const simplifiedValidator = {};
|
|
848
|
+
["execution_result", "genvm_result", "mode", "vote", "node_config"].forEach((field) => {
|
|
849
|
+
if (field in validator) {
|
|
850
|
+
simplifiedValidator[field] = validator[field];
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return simplifiedValidator;
|
|
854
|
+
}).filter((validator) => Object.keys(validator).length > 0);
|
|
855
|
+
if (simplifiedValidators.length > 0) {
|
|
856
|
+
simplifiedConsensus.validators = simplifiedValidators;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
result[key] = simplifiedConsensus;
|
|
860
|
+
continue;
|
|
861
|
+
}
|
|
862
|
+
const simplifiedValue = simplifyObject(value, currentPath);
|
|
863
|
+
const shouldInclude = simplifiedValue !== void 0 && !(typeof simplifiedValue === "object" && simplifiedValue !== null && Object.keys(simplifiedValue).length === 0);
|
|
864
|
+
if (shouldInclude || simplifiedValue === 0) {
|
|
865
|
+
const mappedKey = FIELD_NAME_MAPPINGS[key] || key;
|
|
866
|
+
result[mappedKey] = simplifiedValue;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return result;
|
|
870
|
+
}
|
|
871
|
+
return obj;
|
|
872
|
+
};
|
|
873
|
+
return simplifyObject({ ...tx });
|
|
874
|
+
};
|
|
875
|
+
var decodeLocalnetTransaction = (tx) => {
|
|
818
876
|
if (!tx.data) return tx;
|
|
819
877
|
try {
|
|
820
878
|
const leaderReceipt = tx.consensus_data?.leader_receipt;
|
|
@@ -831,11 +889,20 @@ var _decodeLocalnetTransaction = (tx) => {
|
|
|
831
889
|
};
|
|
832
890
|
}
|
|
833
891
|
if (receipt.eq_outputs) {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
892
|
+
const decodedOutputs = {};
|
|
893
|
+
for (const [key, value] of Object.entries(receipt.eq_outputs)) {
|
|
894
|
+
if (typeof value === "object" && value !== null) {
|
|
895
|
+
decodedOutputs[key] = value;
|
|
896
|
+
} else {
|
|
897
|
+
try {
|
|
898
|
+
decodedOutputs[key] = resultToUserFriendlyJson(value);
|
|
899
|
+
} catch (e) {
|
|
900
|
+
console.warn(`Error decoding eq_output ${key}: ${e}`);
|
|
901
|
+
decodedOutputs[key] = value;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
receipt.eq_outputs = decodedOutputs;
|
|
839
906
|
}
|
|
840
907
|
});
|
|
841
908
|
}
|
|
@@ -846,11 +913,75 @@ var _decodeLocalnetTransaction = (tx) => {
|
|
|
846
913
|
};
|
|
847
914
|
}
|
|
848
915
|
} catch (e) {
|
|
849
|
-
console.error("Error in
|
|
916
|
+
console.error("Error in decodeLocalnetTransaction:", e);
|
|
850
917
|
}
|
|
851
918
|
return tx;
|
|
852
919
|
};
|
|
853
920
|
|
|
921
|
+
// src/transactions/actions.ts
|
|
922
|
+
var receiptActions = (client, publicClient) => ({
|
|
923
|
+
waitForTransactionReceipt: async ({
|
|
924
|
+
hash,
|
|
925
|
+
status = "ACCEPTED" /* ACCEPTED */,
|
|
926
|
+
interval = transactionsConfig.waitInterval,
|
|
927
|
+
retries = transactionsConfig.retries,
|
|
928
|
+
fullTransaction = false
|
|
929
|
+
}) => {
|
|
930
|
+
const transaction = await client.getTransaction({
|
|
931
|
+
hash
|
|
932
|
+
});
|
|
933
|
+
if (!transaction) {
|
|
934
|
+
throw new Error("Transaction not found");
|
|
935
|
+
}
|
|
936
|
+
const transactionStatusString = String(transaction.status);
|
|
937
|
+
const transactionStatusFinalized = transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
|
|
938
|
+
const requestedStatus = transactionsStatusNameToNumber[status];
|
|
939
|
+
if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
|
|
940
|
+
let finalTransaction = transaction;
|
|
941
|
+
if (client.chain.id === localnet.id) {
|
|
942
|
+
finalTransaction = decodeLocalnetTransaction(transaction);
|
|
943
|
+
}
|
|
944
|
+
if (!fullTransaction) {
|
|
945
|
+
return simplifyTransactionReceipt(finalTransaction);
|
|
946
|
+
}
|
|
947
|
+
return finalTransaction;
|
|
948
|
+
}
|
|
949
|
+
if (retries === 0) {
|
|
950
|
+
throw new Error("Transaction status is not " + status);
|
|
951
|
+
}
|
|
952
|
+
await sleep(interval);
|
|
953
|
+
return receiptActions(client, publicClient).waitForTransactionReceipt({
|
|
954
|
+
hash,
|
|
955
|
+
status,
|
|
956
|
+
interval,
|
|
957
|
+
retries: retries - 1,
|
|
958
|
+
fullTransaction
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
var transactionActions = (client, publicClient) => ({
|
|
963
|
+
getTransaction: async ({ hash }) => {
|
|
964
|
+
if (client.chain.id === localnet.id) {
|
|
965
|
+
const transaction2 = await client.getTransaction({ hash });
|
|
966
|
+
const localnetStatus = transaction2.status === "ACTIVATED" ? "PENDING" /* PENDING */ : transaction2.status;
|
|
967
|
+
transaction2.status = Number(transactionsStatusNameToNumber[localnetStatus]);
|
|
968
|
+
transaction2.statusName = localnetStatus;
|
|
969
|
+
return decodeLocalnetTransaction(transaction2);
|
|
970
|
+
}
|
|
971
|
+
const transaction = await publicClient.readContract({
|
|
972
|
+
address: client.chain.consensusDataContract?.address,
|
|
973
|
+
abi: client.chain.consensusDataContract?.abi,
|
|
974
|
+
functionName: "getTransactionData",
|
|
975
|
+
args: [
|
|
976
|
+
hash,
|
|
977
|
+
Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3)
|
|
978
|
+
// unix seconds
|
|
979
|
+
]
|
|
980
|
+
});
|
|
981
|
+
return decodeTransaction(transaction);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
|
|
854
985
|
// src/config/snapID.ts
|
|
855
986
|
var snapID = {
|
|
856
987
|
local: "local:http://localhost:8081",
|
|
@@ -1077,5 +1208,9 @@ export {
|
|
|
1077
1208
|
chains_exports as chains,
|
|
1078
1209
|
createAccount,
|
|
1079
1210
|
createClient,
|
|
1080
|
-
|
|
1211
|
+
decodeInputData,
|
|
1212
|
+
decodeLocalnetTransaction,
|
|
1213
|
+
decodeTransaction,
|
|
1214
|
+
generatePrivateKey,
|
|
1215
|
+
simplifyTransactionReceipt
|
|
1081
1216
|
};
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export {
|
|
2
|
+
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-IViMPpkl.cjs';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export {
|
|
2
|
+
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-CgHl4W-5.js';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.js';
|
package/package.json
CHANGED
|
@@ -140,3 +140,39 @@ export function encode(data: CalldataEncodable): Uint8Array {
|
|
|
140
140
|
encodeImpl(arr, data);
|
|
141
141
|
return new Uint8Array(arr);
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
// Constructs a calldata object for contract calls, omitting empty args/kwargs for compactness.
|
|
145
|
+
export function makeCalldataObject(
|
|
146
|
+
method: string | undefined,
|
|
147
|
+
args: CalldataEncodable[] | undefined,
|
|
148
|
+
kwargs: {[key: string]: CalldataEncodable} | Map<string, CalldataEncodable> | undefined,
|
|
149
|
+
): CalldataEncodable {
|
|
150
|
+
let ret: {[key: string]: CalldataEncodable} = {};
|
|
151
|
+
|
|
152
|
+
if (method) {
|
|
153
|
+
ret["method"] = method;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (args && args.length > 0) {
|
|
157
|
+
ret["args"] = args;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (kwargs) {
|
|
161
|
+
if (kwargs instanceof Map) {
|
|
162
|
+
if (kwargs.size > 0) {
|
|
163
|
+
ret["kwargs"] = kwargs;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
let hasVal = false;
|
|
167
|
+
for (const _k in kwargs) {
|
|
168
|
+
hasVal = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (hasVal) {
|
|
172
|
+
ret["kwargs"] = kwargs;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return ret;
|
|
178
|
+
}
|
package/src/contracts/actions.ts
CHANGED
|
@@ -12,43 +12,6 @@ import {
|
|
|
12
12
|
} from "@/types";
|
|
13
13
|
import {fromHex, toHex, zeroAddress, encodeFunctionData, PublicClient, parseEventLogs} from "viem";
|
|
14
14
|
|
|
15
|
-
function makeCalldataObject(
|
|
16
|
-
method: string | undefined,
|
|
17
|
-
args: CalldataEncodable[] | undefined,
|
|
18
|
-
kwargs: {[key: string]: CalldataEncodable} | Map<string, CalldataEncodable> | undefined,
|
|
19
|
-
): CalldataEncodable {
|
|
20
|
-
// this method omits args or kwargs if they are empty
|
|
21
|
-
// it reduces transaction size
|
|
22
|
-
let ret: {[key: string]: CalldataEncodable} = {};
|
|
23
|
-
|
|
24
|
-
if (method) {
|
|
25
|
-
ret["method"] = method;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (args && args.length > 0) {
|
|
29
|
-
ret["args"] = args;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (kwargs) {
|
|
33
|
-
if (kwargs instanceof Map) {
|
|
34
|
-
if (kwargs.size > 0) {
|
|
35
|
-
ret["kwargs"] = kwargs;
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
let hasVal = false;
|
|
39
|
-
for (const _k in kwargs) {
|
|
40
|
-
hasVal = true;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
if (hasVal) {
|
|
44
|
-
ret["kwargs"] = kwargs;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return ret;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
15
|
export const contractActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => {
|
|
53
16
|
return {
|
|
54
17
|
getContractSchema: async (address: Address): Promise<ContractSchema> => {
|
|
@@ -91,7 +54,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
91
54
|
transactionHashVariant = TransactionHashVariant.LATEST_NONFINAL,
|
|
92
55
|
} = args;
|
|
93
56
|
|
|
94
|
-
const encodedData = [calldata.encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
57
|
+
const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
95
58
|
const serializedData = serialize(encodedData);
|
|
96
59
|
|
|
97
60
|
const senderAddress = account?.address ?? client.account?.address;
|
|
@@ -135,7 +98,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
135
98
|
leaderOnly = false,
|
|
136
99
|
consensusMaxRotations = client.chain.defaultConsensusMaxRotations,
|
|
137
100
|
} = args;
|
|
138
|
-
const data = [calldata.encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
101
|
+
const data = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
139
102
|
const serializedData = serialize(data);
|
|
140
103
|
const senderAccount = account || client.account;
|
|
141
104
|
const encodedData = _encodeAddTransactionData({
|
|
@@ -171,7 +134,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
171
134
|
} = args;
|
|
172
135
|
const data = [
|
|
173
136
|
code,
|
|
174
|
-
calldata.encode(makeCalldataObject(undefined, constructorArgs, kwargs)),
|
|
137
|
+
calldata.encode(calldata.makeCalldataObject(undefined, constructorArgs, kwargs)),
|
|
175
138
|
leaderOnly,
|
|
176
139
|
];
|
|
177
140
|
const serializedData = serialize(data);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
export {createClient} from "./client/client";
|
|
3
3
|
export {createAccount, generatePrivateKey} from "./accounts/account";
|
|
4
|
+
export {
|
|
5
|
+
decodeInputData,
|
|
6
|
+
decodeTransaction,
|
|
7
|
+
simplifyTransactionReceipt,
|
|
8
|
+
decodeLocalnetTransaction
|
|
9
|
+
} from "./transactions/decoders";
|
|
4
10
|
export * as chains from "./chains";
|
|
5
11
|
export * as abi from "./abi";
|