evm-contracts-tools 0.0.86 → 0.0.87

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.
@@ -489,7 +489,8 @@ async function
489
489
  _contract) {
490
490
  let
491
491
  _contract_object_get,
492
- _contract_get_args;
492
+ _contract_get_args,
493
+ _msg;
493
494
  const
494
495
  _contract_type =
495
496
  typeof(
@@ -723,7 +724,13 @@ async function
723
724
  _fee_priority =
724
725
  Number(
725
726
  _fee_priority);
726
- return _fee_priority;
727
+ const
728
+ _output = [
729
+ _price_gas,
730
+ _gas_fee,
731
+ _fee_priority
732
+ ];
733
+ return _output;
727
734
  }
728
735
 
729
736
  function
@@ -905,6 +912,209 @@ async function
905
912
  return _method;
906
913
  }
907
914
 
915
+ function
916
+ _price_gas_max_check(
917
+ _price_gas_max) {
918
+ let
919
+ _price_gas_max_get,
920
+ _msg;
921
+ const
922
+ _default =
923
+ 100000000;
924
+ _price_gas_max_get =
925
+ false;
926
+ const
927
+ _price_gas_max_type =
928
+ typeof(
929
+ _price_gas_max);
930
+ if ( _price_gas_max_type === "undefined" ) {
931
+ _msg =
932
+ "Maximum gas price variable undefined, " +
933
+ `setting default. (${_default}).`;
934
+ _msg_info(
935
+ _msg);
936
+ _price_gas_max_get =
937
+ true;
938
+ }
939
+ else if ( _price_gas_max_type === "string" ) {
940
+ if ( _price_gas_max.length < 1 ) {
941
+ _msg =
942
+ "Maximum gas price variable is an empty string, " +
943
+ `setting default. (${_default}).`;
944
+ _msg_info(
945
+ _msg);
946
+ _price_gas_max_get =
947
+ true;
948
+ }
949
+ }
950
+ else if ( _price_gas_max_type === "object" ) {
951
+ _price_gas_max_keys =
952
+ Object.keys(
953
+ _price_gas_max);
954
+ if ( _price_gas_max_keys.length < 1 ) {
955
+ _msg =
956
+ "Maximum gas price variable is an empty object, " +
957
+ `setting default. (${_default}).`;
958
+ _msg_info(
959
+ _msg);
960
+ _price_gas_max_get =
961
+ true;
962
+ }
963
+ else {
964
+ _msg =
965
+ "Maximum gas price variable is an " +
966
+ "object but it should be a positive integer.";
967
+ _msg_error(
968
+ _msg,
969
+ 0);
970
+ throw _msg;
971
+ }
972
+ }
973
+ else if ( _price_gas_max_type === "number" ) {
974
+ true;
975
+ }
976
+ else {
977
+ _msg =
978
+ "Maximum gas price variable has type " +
979
+ `'${_price_gas_max_type}' but it should be` +
980
+ "a positive integer.";
981
+ _msg_error(
982
+ _msg,
983
+ 0);
984
+ throw _msg;
985
+ }
986
+ if ( _price_gas_max_get ) {
987
+ _price_gas_max =
988
+ _default;
989
+ }
990
+ if ( _price_gas_max_get < 1 ) {
991
+ _msg =
992
+ "Maximum gas price variable should be " +
993
+ "a positive integer, but has value " +
994
+ `'${_price_gas_max}'`;
995
+ _msg_error(
996
+ _msg,
997
+ 0);
998
+ }
999
+ return _price_gas_max;
1000
+ }
1001
+
1002
+ function
1003
+ _eip_1559_check(
1004
+ _eip_1559) {
1005
+ let
1006
+ _eip_1559_get,
1007
+ _msg;
1008
+ const
1009
+ _default =
1010
+ true;
1011
+ _eip_1559_get =
1012
+ false;
1013
+ const
1014
+ _eip_1559_type =
1015
+ typeof(
1016
+ _eip_1559);
1017
+ if ( _eip_1559_type === "undefined" ) {
1018
+ _msg =
1019
+ "EIP-1559 switch setting undefined, " +
1020
+ `setting default. (${_default})`;
1021
+ _msg_info(
1022
+ _msg);
1023
+ _eip_1559_get =
1024
+ true;
1025
+ }
1026
+ else if ( _eip_1559_type === "string" ) {
1027
+ if ( _eip_1559_max.length < 1 ) {
1028
+ _msg =
1029
+ "EIP-1559 switch setting is an empty string, " +
1030
+ `setting default. (${_default}).`;
1031
+ _msg_info(
1032
+ _msg);
1033
+ _eip_1559_get =
1034
+ true;
1035
+ }
1036
+ else {
1037
+ if ( _eip_1559 === "true" ) {
1038
+ _eip_1559 =
1039
+ true;
1040
+ }
1041
+ if ( _eip_1559 === "false" ) {
1042
+ _eip_1559 =
1043
+ false;
1044
+ }
1045
+ else {
1046
+ _msg =
1047
+ "EIP-1559 switch setting is a non-boolean string, " +
1048
+ "but it should be a boolean " +
1049
+ `(current value: ${_eip_1559}).`;
1050
+ _msg_error(
1051
+ _msg,
1052
+ 0);
1053
+ throw _msg;
1054
+ }
1055
+ }
1056
+ }
1057
+ else if ( _eip_1559_type === "object" ) {
1058
+ _eip_1559_keys =
1059
+ Object.keys(
1060
+ _eip_1559);
1061
+ if ( _eip_1559_keys.length < 1 ) {
1062
+ _msg =
1063
+ "EIP-1559 switch setting is an empty object, " +
1064
+ `setting default. (${_default}).`;
1065
+ _msg_info(
1066
+ _msg);
1067
+ _eip_1559_get =
1068
+ true;
1069
+ }
1070
+ else {
1071
+ _msg =
1072
+ "EIP-1559 switch setting is an " +
1073
+ "object but it should be a boolean. " +
1074
+ `(current value: ${_eip_1559}).`;
1075
+ _msg_error(
1076
+ _msg,
1077
+ 0);
1078
+ throw _msg;
1079
+ }
1080
+ }
1081
+ else if ( _eip_1559_type === "number" ) {
1082
+ if ( _eip_1559 === 0 ) {
1083
+ _eip_1559 =
1084
+ false;
1085
+ }
1086
+ if ( _eip_1559 === 1 ) {
1087
+ _eip_1559 =
1088
+ true;
1089
+ }
1090
+ else {
1091
+ _msg =
1092
+ "EIP-1559 switch setting is an " +
1093
+ "object but it should be a boolean " +
1094
+ `(current value: ${_eip_1559}).`;
1095
+ _msg_error(
1096
+ _msg,
1097
+ 0);
1098
+ throw _msg;
1099
+ }
1100
+ }
1101
+ else {
1102
+ _msg =
1103
+ "EIP-1559 switch setting has type " +
1104
+ `'${_eip_1559_type}' but it should be` +
1105
+ "a boolean.";
1106
+ _msg_error(
1107
+ _msg,
1108
+ 0);
1109
+ throw _msg;
1110
+ }
1111
+ if ( _eip_1559_get ) {
1112
+ _eip_1559 =
1113
+ _default;
1114
+ }
1115
+ return _eip_1559;
1116
+ }
1117
+
908
1118
  async function
909
1119
  _call_price_gas_manual(
910
1120
  _price_feasible_retries_max,
@@ -914,6 +1124,10 @@ async function
914
1124
  _price_gas,
915
1125
  _gas_fee,
916
1126
  _fee_priority,
1127
+ _price_gas_max,
1128
+ _eip_1559,
1129
+ _msg_value,
1130
+ _contract,
917
1131
  _method,
918
1132
  _method_args,
919
1133
  _tx) {
@@ -921,8 +1135,24 @@ async function
921
1135
  _gas_limit,
922
1136
  _msg,
923
1137
  _price_feasible_retries,
924
- _price_gas_max,
925
1138
  _price_gas_transaction_get_args;
1139
+ try {
1140
+ _price_gas_max =
1141
+ _price_gas_max_check(
1142
+ _price_gas_max);
1143
+ }
1144
+ catch(
1145
+ _error) {
1146
+ _msg =
1147
+ "Error running '_price_gas_max_check' " +
1148
+ `with argument '${_price_gas_max}'.`;
1149
+ _msg_error(
1150
+ _msg,
1151
+ 0);
1152
+ _echo2(
1153
+ _error);
1154
+ throw _error;
1155
+ }
926
1156
  const
927
1157
  _price_gas_type =
928
1158
  typeof(
@@ -969,10 +1199,9 @@ async function
969
1199
  0);
970
1200
  throw _msg;
971
1201
  }
972
- _price_gas_transaction_get_selection_mode =
973
- _price_gas;
974
- _price_gas_max =
975
- 100000000;
1202
+ const
1203
+ _price_gas_transaction_get_selection_mode =
1204
+ _price_gas;
976
1205
  try {
977
1206
  _tx = await
978
1207
  _method.populateTransaction.apply(
@@ -1148,7 +1377,23 @@ async function
1148
1377
  _msg_error(
1149
1378
  _msg,
1150
1379
  0);
1151
- throw _error;
1380
+ const
1381
+ _code =
1382
+ _error[
1383
+ "info"][
1384
+ "error"][
1385
+ "code"];
1386
+ if ( _code === -32000 ) {
1387
+ _msg =
1388
+ _error[
1389
+ "info"][
1390
+ "error"][
1391
+ "message"];
1392
+ throw _msg;
1393
+ }
1394
+ else {
1395
+ throw _error;
1396
+ }
1152
1397
  }
1153
1398
  return _tx;
1154
1399
  }
@@ -1243,7 +1488,9 @@ async function
1243
1488
  _verbose,
1244
1489
  _retries_max,
1245
1490
  _contract,
1246
- _method) {
1491
+ _method,
1492
+ _price_gas_max,
1493
+ _eip_1559) {
1247
1494
  let
1248
1495
  _amount,
1249
1496
  _call_price_gas_manual_args,
@@ -1252,17 +1499,27 @@ async function
1252
1499
  _fee_priority,
1253
1500
  _gas_fee,
1254
1501
  _msg,
1255
- _eip_1559,
1256
1502
  _price_feasible_retries_max,
1257
- _price_gas_max,
1258
1503
  _price_gas_transaction_get_args,
1259
1504
  _price_gas_transaction_get_retries_max,
1260
1505
  _price_gas_transaction_get_selection_mode,
1261
1506
  _send_opts,
1262
1507
  _receipt,
1263
1508
  _tx;
1264
- _eip_1559 =
1265
- true;
1509
+ try {
1510
+ _eip_1559 =
1511
+ _eip_1559_check(
1512
+ _eip_1559);
1513
+ }
1514
+ catch(
1515
+ _error) {
1516
+ _msg =
1517
+ "Error running '_eip_1559_check'.";
1518
+ _msg_error(
1519
+ _msg,
1520
+ 0);
1521
+ throw _msg;
1522
+ }
1266
1523
  _send_opts =
1267
1524
  {};
1268
1525
  _measure_unit =
@@ -1302,7 +1559,7 @@ async function
1302
1559
  }
1303
1560
  _msg_value =
1304
1561
  _msg_value_check(
1305
- _value);
1562
+ _msg_value);
1306
1563
  _call_timeout =
1307
1564
  _call_timeout_check(
1308
1565
  _call_timeout);
@@ -1372,6 +1629,10 @@ async function
1372
1629
  _price_gas,
1373
1630
  _gas_fee,
1374
1631
  _fee_priority,
1632
+ _price_gas_max,
1633
+ _eip_1559,
1634
+ _msg_value,
1635
+ _contract,
1375
1636
  _method,
1376
1637
  _method_args,
1377
1638
  _tx
@@ -1561,6 +1822,43 @@ function
1561
1822
  return _retries_max;
1562
1823
  }
1563
1824
 
1825
+ function
1826
+ _receipt_tx_cost_get(
1827
+ _receipt,
1828
+ _measure_unit) {
1829
+ const
1830
+ _tx_cost =
1831
+ _receipt[
1832
+ "gasUsed"] *
1833
+ _receipt[
1834
+ "gasPrice"];
1835
+ return _tx_cost;
1836
+ }
1837
+
1838
+ function
1839
+ _receipt_display(
1840
+ _receipt,
1841
+ _measure_unit) {
1842
+ _msg =
1843
+ `Transaction hash: '${_receipt.hash}'.`;
1844
+ _msg_info(
1845
+ _msg);
1846
+ const
1847
+ _tx_cost =
1848
+ _receipt_tx_cost_get(
1849
+ _receipt,
1850
+ _measure_unit);
1851
+ if ( _measure_unit == "ether" ) {
1852
+ _tx_cost =
1853
+ _wei_to_ether(
1854
+ _tx_cost);
1855
+ }
1856
+ _msg =
1857
+ `Transaction cost: '${_tx_cost}'.`;
1858
+ _msg_info(
1859
+ _msg);
1860
+ }
1861
+
1564
1862
  async function
1565
1863
  _contract_run(
1566
1864
  _retries_max,
@@ -1584,6 +1882,7 @@ async function
1584
1882
  _method) {
1585
1883
  let
1586
1884
  _attempt,
1885
+ _hash_type,
1587
1886
  _msg,
1588
1887
  _receipt,
1589
1888
  _receipt_type,
@@ -1724,86 +2023,104 @@ async function
1724
2023
  1;
1725
2024
  while ( _attempt <= _retries_max ) {
1726
2025
  try {
1727
- [ _tx,
1728
- _receipt,
1729
- _method,
1730
- _contract ] =
1731
- await _contract_call_dynamic.apply(
1732
- null,
1733
- _contract_call_dynamic_args);
1734
- _receipt_type =
1735
- typeof(
1736
- _receipt);
1737
- if ( _receipt_type == "undefined" ) {
1738
- _msg_error_transaction_undefined(
1739
- _attempt);
1740
- _msg =
1741
- "No receipt, transaction may have failed.";
1742
- throw _msg;
2026
+ try {
2027
+ [ _tx,
2028
+ _receipt,
2029
+ _method,
2030
+ _contract ] =
2031
+ await _contract_call_dynamic.apply(
2032
+ null,
2033
+ _contract_call_dynamic_args);
1743
2034
  }
1744
- else if ( _receipt_type != "undefined" ) {
2035
+ catch (
2036
+ _error) {
1745
2037
  _msg =
1746
- `Transaction no. '${_tx.nonce}'.`;
1747
- _msg_info(
1748
- _msg);
1749
- if ( _verbose == "y" ) {
1750
- _msg =
1751
- "Transaction response:";
1752
- _msg_info(
1753
- _msg);
1754
- _echo(
1755
- _tx);
1756
- _msg =
1757
- "Transaction receipt:";
1758
- _msg_info(
1759
- _msg);
1760
- _echo(
2038
+ "Error running '_evm_contract_call_dynamic'. " +
2039
+ "Arguments unsatized, not showing.";
2040
+ _msg_error(
2041
+ _msg,
2042
+ 0);
2043
+ _echo2(
2044
+ _error);
2045
+ throw _error;
2046
+ }
2047
+ try {
2048
+ _receipt_type =
2049
+ typeof(
1761
2050
  _receipt);
2051
+ if ( _receipt_type === "undefined" ) {
2052
+ _msg_error_transaction_undefined(
2053
+ _attempt);
2054
+ _msg =
2055
+ "No receipt, transaction may have failed.";
2056
+ throw _msg;
1762
2057
  }
1763
- if ( _receipt.hash != undefined ) {
1764
- _receipt_tx_cost_get(
1765
- _receipt,
1766
- _measure_unit);
1767
- _receipt_display(
1768
- _receipt,
1769
- _measure_unit);
2058
+ else if ( _receipt_type !== "undefined" ) {
1770
2059
  _msg =
1771
- `Transaction hash: '${_receipt.hash}'.`;
2060
+ `Transaction no. '${_tx.nonce}'.`;
1772
2061
  _msg_info(
1773
2062
  _msg);
1774
- _tx_cost =
1775
- _receipt[
1776
- "gasUsed"] *
1777
- _receipt[
1778
- "gasPrice"];
1779
- if ( _measure_unit == "ether" ) {
1780
- _tx_cost =
1781
- _wei_to_ether(
1782
- _tx_cost);
2063
+ if ( _verbose == "y" ) {
2064
+ _msg =
2065
+ "Transaction response:";
2066
+ _msg_info(
2067
+ _msg);
2068
+ _echo(
2069
+ _tx);
2070
+ _msg =
2071
+ "Transaction receipt:";
2072
+ _msg_info(
2073
+ _msg);
2074
+ _echo(
2075
+ _receipt);
2076
+ }
2077
+ _hash_type =
2078
+ typeof(
2079
+ _receipt.hash);
2080
+ if ( _hash_type !== "undefined" ) {
2081
+ _receipt_display(
2082
+ _receipt,
2083
+ _measure_unit);
2084
+ break;
2085
+ }
2086
+ else if ( _hash_type === "undefined" ) {
2087
+ _msg_error_transaction_failed(
2088
+ _attempt);
2089
+ _msg =
2090
+ "Transaction hash undefined.";
2091
+ _msg_error(
2092
+ _msg,
2093
+ 0);
2094
+ throw _msg;
2095
+ }
2096
+ else {
2097
+ _msg_error_transaction_failed(
2098
+ _attempt);
2099
+ _msg =
2100
+ "Unknown transaction error.";
2101
+ _msg_error(
2102
+ _msg,
2103
+ 0);
2104
+ throw _msg;
1783
2105
  }
1784
- _msg =
1785
- `Transaction cost: '${_tx_cost}'.`;
1786
- _msg_info(
1787
- _msg);
1788
- break;
1789
- }
1790
- else if ( _receipt.hash == undefined ) {
1791
- _msg_error_transaction_failed(
1792
- _attempt);
1793
- _msg =
1794
- "Transaction hash undefined.";
1795
- throw _msg;
1796
- }
1797
- else {
1798
- _msg_error_transaction_failed(
1799
- _attempt);
1800
- _msg =
1801
- "Unknown transaction error.";
1802
- throw _msg;
1803
2106
  }
1804
2107
  }
1805
- } catch (
2108
+ catch (
1806
2109
  _error) {
2110
+ _msg =
2111
+ "Error processing receipt with value:";
2112
+ _msg_error(
2113
+ _msg,
2114
+ 0);
2115
+ _echo2(
2116
+ _receipt);
2117
+ _echo2(
2118
+ _error);
2119
+ throw _error;
2120
+ }
2121
+ }
2122
+ catch (
2123
+ _error) {
1807
2124
  _error_display(
1808
2125
  _error);
1809
2126
  _msg =
@@ -1816,7 +2133,7 @@ async function
1816
2133
  _attempt + 1;
1817
2134
  }
1818
2135
  }
1819
- if ( _attempt > _retries_max ) {
2136
+ if ( _retries_max < _attempt ) {
1820
2137
  _msg =
1821
2138
  "Maximum number of retries reached.";
1822
2139
  throw _msg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  { "name": "evm-contracts-tools",
2
2
  "version":
3
- "0.0.86",
3
+ "0.0.87",
4
4
  "description":
5
5
  "JavaScript programs and libraries to enable seamless development of native computer applications designed to interact with Ethereum Virtual Machine-compatible networks.",
6
6
  "funding": {