tronscan-node-client
tronscan-node-client copied to clipboard
Syntax error in src/utils/tronWeb.js
When we try to require
@tronscan/client/src/utils/tronWeb.js, we get syntax errors on Node.js. It turns out that the same file can't contain ES6 export
statements and CommonJS require
statements, or various build tools will break.
We are currently using patch-package to patch @tronscan/[email protected]
. Here is the diff we are using:
diff --git a/node_modules/@tronscan/client/src/utils/tronWeb.js b/node_modules/@tronscan/client/src/utils/tronWeb.js
index 6b1bc38..3f48a11 100644
--- a/node_modules/@tronscan/client/src/utils/tronWeb.js
+++ b/node_modules/@tronscan/client/src/utils/tronWeb.js
@@ -25,7 +25,7 @@ const {
const fromHexString = hexString =>
new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
-export function transactionJsonToProtoBuf(transaction) {
+function transactionJsonToProtoBuf(transaction) {
const rawData = transaction["raw_data"];
const contractJson = rawData.contract[0];
const transactionObj = contractJsonToProtobuf(contractJson);
@@ -52,7 +52,7 @@ export function transactionJsonToProtoBuf(transaction) {
return transactionObj;
}
-export function contractJsonToProtobuf(contract) {
+function contractJsonToProtobuf(contract) {
const value = contract.parameter.value;
switch (contract.type) {
@@ -365,3 +365,8 @@ export function contractJsonToProtobuf(contract) {
}
}
+
+module.exports = {
+ transactionJsonToProtoBuf,
+ contractJsonToProtobuf
+};
Of course, we would love to get this fix upstream.
This issue body was partially generated by patch-package.