Skip to content

Commit

Permalink
Release v4.2.0 (#252)
Browse files Browse the repository at this point in the history
* fix when decode result os array and has one value

* update dependencies version

* Update transactionBuilder.js

When trying to get estimated energy via constantContract, it returnes very small (wrong) value, because call_value variable is not passed in args. This update will fix it.
Why actually call_valu, fee_limit, token_id and call_token_value are not included in current version? Whats the reason?

* Update transactionBuilder.js

* add the name key when the contract call method has only one return value

* fix karma conf

* Optimize the `TriggerConstantContract` method

* Update changelog

* Optimize the `TriggerConstantContract` method (#246)

* Optimize the `TriggerConstantContract` method

* Update changelog

* fix code formatting

* add the name key when the `send()` method has only one return value

* add the `struct` name props when decoding abi

* fix `triggerSmartContractWithFuncABIV2` test

* Update README.md

Co-authored-by: summertanh <[email protected]>
Co-authored-by: vzin <[email protected]>
  • Loading branch information
3 people authored May 16, 2022
1 parent e995911 commit 15543c6
Show file tree
Hide file tree
Showing 9 changed files with 6,267 additions and 5,711 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,30 @@ In order to contribute you can

## Recent History

__4.2.0__
- Add the name key when the `call()` and `send()` methods has only one return value
- Optimize the `TriggerConstantContract()` method
- Update `axios` to version 0.26.1
- Update `karma` to version 6.3.17
- Update `puppeteer` to version 13.5.1

__4.1.0__
- add `encodeParamsV2ByABI` and `decodeParamsV2ByABI` functions in `tronWeb.utils.abi` lib
- support abi v2 for `triggerSmartContract`, `createSmartContract`, `call` and `send` method
- update `validator` to version 13.7.0
- update `axios` t0 version 0.24.0
- update discord group link
- Add `encodeParamsV2ByABI` and `decodeParamsV2ByABI` functions in `tronWeb.utils.abi` lib
- Support abi v2 for `triggerSmartContract`, `createSmartContract`, `call` and `send` methods
- Update `validator` to version 13.7.0
- Update `axios` to version 0.24.0
- Update discord group link

__4.0.1__
- set _isConstant as true for call method
- ignore max feeLimit check
- change git repository url
- Set _isConstant as true for call method
- Ignore max feeLimit check
- Change git repository url

__4.0.0__
- support `broadcastHex` method
- ignore fullnode version check when calling `createToken` method
- update dependencies version
- add strict mode for `pkToAddress` method
- Support `broadcastHex` method
- Ignore fullnode version check when calling `createToken` method
- Update dependencies version
- Add strict mode for `pkToAddress` method

__3.2.7__
- Add options `rawParameter` that format of the parameters method and args when creating or triggering a contract
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const basePlugins = [
'source-map-support'
];

const files = globby.sync([ 'test/**/*.test.js' ]);
const files = globby.sync([ 'test/**/*.test.js', '!test/**/abi.test.js' ]);

module.exports = function (config) {
config.set({
Expand Down
1,148 changes: 774 additions & 374 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tronweb",
"version": "4.1.0",
"version": "4.2.0",
"description": "JavaScript SDK that encapsulates the TRON HTTP API",
"main": "dist/TronWeb.node.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"axios": "^0.24.0",
"axios": "^0.26.1",
"bignumber.js": "^9.0.1",
"elliptic": "^6.5.4",
"ethers": "^5.4.4",
Expand All @@ -42,6 +42,7 @@
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.2",
"babel-plugin-istanbul": "^6.1.1",
"babel-plugin-source-map-support": "^2.1.3",
"chai": "^4.1.2",
"chalk": "^2.4.1",
Expand All @@ -50,7 +51,7 @@
"istanbul": "^0.4.5",
"istanbul-instrumenter-loader": "^3.0.1",
"jsonwebtoken": "^8.5.1",
"karma": "^6.3.3",
"karma": "^6.3.17",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^2.0.3",
"karma-coverage-istanbul-reporter": "^3.0.3",
Expand All @@ -62,7 +63,7 @@
"karma-webpack": "4.0.0-rc.6",
"matchdep": "^2.0.0",
"mocha": "^5.2.0",
"puppeteer": "^10.0.0",
"puppeteer": "^13.5.1",
"rimraf": "^3.0.2",
"source-map-support": "^0.5.19",
"webpack": "^4.46.0",
Expand Down
6 changes: 4 additions & 2 deletions src/lib/contract/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ export default class Method {

let output = decodeOutput(this.abi, '0x' + transaction.constant_result[0]);

if (output.length === 1)
if (output.length === 1 && Object.keys(output).length === 1) {
output = output[0];
}

return callback(null, output);
} catch (ex) {
Expand Down Expand Up @@ -278,8 +279,9 @@ export default class Method {

let decoded = decodeOutput(this.abi, '0x' + output.contractResult[0]);

if (decoded.length === 1)
if (decoded.length === 1 && Object.keys(decoded).length === 1) {
decoded = decoded[0];
}

if (options.keepTxID) {
return callback(null, [signedTransaction.txID, decoded]);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/transactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,14 +884,14 @@ export default class TransactionBuilder {
args.parameter = parameters;
}

args.call_value = parseInt(callValue)
if (utils.isNotNullOrUndefined(tokenValue))
args.call_token_value = parseInt(tokenValue)
if (utils.isNotNullOrUndefined(tokenId))
args.token_id = parseInt(tokenId)

if (!options._isConstant) {
args.call_value = parseInt(callValue)
args.fee_limit = parseInt(feeLimit)
if (utils.isNotNullOrUndefined(tokenValue))
args.call_token_value = parseInt(tokenValue)
if (utils.isNotNullOrUndefined(tokenId))
args.token_id = parseInt(tokenId)
}

if (options.permissionId) {
Expand Down
11 changes: 7 additions & 4 deletions src/utils/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ export function decodeParamsV2ByABI(funABI, data) {
};

const buildFullTypeNameDefinition = (typeDef) => {
const name = typeDef.name ? ` ${typeDef.name}` : '';
if (typeDef && typeDef.type.indexOf('tuple') === 0 && typeDef.components) {
const innerTypes = typeDef.components.map((innerType) => { return buildFullTypeNameDefinition(innerType) });
return `tuple(${innerTypes.join(',')})${extractSize(typeDef.type)}`;
return `tuple(${innerTypes.join(',')})${extractSize(typeDef.type)}${name}`;
}
const name = typeDef.name ? ` ${typeDef.name}` : '';
if (/trcToken/.test(typeDef.type))
return typeDef.type.replace(/trcToken/, 'uint256') + name;

Expand All @@ -233,11 +233,14 @@ export function decodeParamsV2ByABI(funABI, data) {
convertAddresses(result[i])
if(name) convertAddresses(result[name])
}
else if (type.indexOf('tuple') === 0)
else if (type.indexOf('tuple') === 0) {
if (extractSize(type)) {
const dimension = extractArrayDim(type);
mapTuple(output.components, result[i], dimension);
} else decodeResult(output.components, result[i]);

if(name) result[name] = result[i];
}
});
};

Expand All @@ -248,7 +251,7 @@ export function decodeParamsV2ByABI(funABI, data) {
for (let i = 0; i < funABI.outputs.length; i++) {
const type = funABI.outputs[i].type;
const name = funABI.outputs[i].name ? ` ${funABI.outputs[i].name}` : '';
outputTypes.push(type.indexOf('tuple') === 0 ? buildFullTypeNameDefinition(funABI.outputs[i]) : type+name);
outputTypes.push(type.indexOf('tuple') === 0 ? buildFullTypeNameDefinition(funABI.outputs[i]) : type + name);
}
convertTypeNames(outputTypes);

Expand Down
2 changes: 1 addition & 1 deletion test/lib/transactionBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ describe('TronWeb.transactionBuilder', function () {
.contract(abi, transaction.contract_address)
let check = await deployed.test().call();

assert.ok(equals(check, outputValues[0]));
assert.ok(equals(check[0], outputValues[0]));
});

it('should create or trigger a smart contract with funcABIV2 (V2 input test send )', async function () {
Expand Down
Loading

0 comments on commit 15543c6

Please sign in to comment.