tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
414 stars 271 forks source link

TransactionBuilder should not modify original params, please make a clone first #449

Closed alienzhangyw closed 8 months ago

alienzhangyw commented 9 months ago

For example, I want to call or send a contract method with a parameter of address array.

const addressArr = ['T...', 'T...', 'T...']; // some base58 address
const params = [param1, param2, addressArr, ...] // all the params
const result = await contract.function_name(...params).call(); // call some method with this array
// during building the transaction data, all base58 addresses are transformed into hex addresses
console.log(addressArr); // now all address items in the array are turned into '0x' hex address

This makes bugs or inconveniences if I have to use these arrays later. Please consider to make a deep clone of the method params, donnot directly modify the original objects or arrays.

start940315 commented 8 months ago

Consider the params could be too complex to manipulate, we will not copy it first. You can use some copy functions to pass the parameters to TransactionBuilder. Both lodash cloneDeep and tronweb deepCopyJson in src/lib/TransactionBuilder/helper.ts is useful for you.