-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert interaction error to warning #421
Conversation
|
||
return new TransactionBuilder({ | ||
config: this.config!, | ||
sender: options.sender, | ||
receiver: options.receiver, | ||
dataParts: [data], | ||
dataParts: [Buffer.from(data).toString()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here might be an issue. Since dataParts
wants strings - but Buffer.from(data).toString()
is not necessarily a valid / utf8 string. Can we create the transaction without TransactionBuilder
? Or perhaps just set the data after creating it with the builder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Buffer.toString()
returns by default a utf8
string.
this.trueAsHex = utf8ToHex("true"); | ||
this.falseAsHex = utf8ToHex("false"); | ||
this.argSerializer = new ArgSerializer(); | ||
this.trueAsHex = this.argSerializer.valuesToStrings([new StringValue("true")])[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we don't have valueToString()
here. All good.
new BigUIntValue(options.initialSupply), | ||
new BigUIntValue(options.numDecimals), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be merged into the call of valuesToStrings()
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, done!
options.canFreeze ? this.trueAsHex : this.falseAsHex, | ||
utf8ToHex("canWipe"), | ||
this.argSerializer.valuesToStrings([new StringValue("canWipe")])[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, above and below, for easier reading, we can do this:
const args = [
new StringValue(options.tokenName),
new StringValue(options.tokenTicker),
new BigUIntValue(options.numDecimals),
new StringValue("canFreeze")
new BooleanValue(options.canFreeze)
... and so on
]
const dataParts = ["registerMetaESDT", ...this.argSerializer.valuesToStrings(args)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
...(options.addRoleNFTBurn ? [utf8ToHex("ESDTRoleNFTBurn")] : []), | ||
...(options.addRoleNFTAddQuantity ? [utf8ToHex("ESDTRoleNFTAddQuantity")] : []), | ||
...(options.addRoleESDTTransferRole ? [utf8ToHex("ESDTTransferRole")] : []), | ||
...this.argSerializer.valuesToStrings([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit hard to read, here / above / below. Previously, code was easier to read.
Maybe do the args trick as in the comment above?
Also:
if options.addRoleNFTCreate:
args.push(new StringValue("ESDTRoleNFTCreate"))
That is, ideally, we should only call valuesToStrings()
once per factory function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -146,7 +166,11 @@ export class SmartContractTransactionsFactory { | |||
const args = options.args || []; | |||
const metadata = new CodeMetadata(isUpgradeable, isReadable, isPayable, isPayableBySmartContract); | |||
|
|||
let parts = ["upgradeContract", byteArrayToHex(options.bytecode), metadata.toString()]; | |||
let parts = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here, keep byteArrayToHex
, as before (simpler)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the changes.
|
||
constructor(options: { config: Config; abi?: IAbi; tokenComputer: TokenComputer }) { | ||
this.config = options.config; | ||
this.abi = options.abi; | ||
this.tokenComputer = options.tokenComputer; | ||
this.dataArgsBuilder = new TokenTransfersDataBuilder(); | ||
this.argSerializer = new ArgSerializer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file, maybe the code, as it was, was all right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
dataParts.push( | ||
...[ | ||
options.publicKeys[i].hex(), | ||
this.argSerializer.valuesToStrings([new BytesValue(Buffer.from(options.signedMessages[i]))])[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call valuesToStrings()
only once per factory method (ideally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's only used once per method.
"unPause", | ||
this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)])[0], | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, without [0]
. We can reuse the same pattern as above / below, even if we only have one argument.
const dataParts = [
"unPause",
...this.argSerializer.valuesToStrings([
new StringValue(options.tokenIdentifier)
]),
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
]; | ||
const args = [new StringValue(options.tokenIdentifier), new AddressValue(options.user)]; | ||
|
||
options.addRoleNFTCreate ? args.push(new StringValue("ESDTRoleNFTCreate")) : args.push(...[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args.push(...[]);
can be replaced with a no-operation such as 0;
or null;
.
https://stackoverflow.com/questions/21634886/what-is-the-javascript-convention-for-no-operation
Or, maybe, if you still want a one-liner instead of multi-line if statement:
args.push(...(condition ? [42] : []))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced args.push(...[]);
with 0
.
const dataParts = ["unsetBurnRoleGlobally", utf8ToHex(options.tokenIdentifier)]; | ||
const dataParts = [ | ||
"unsetBurnRoleGlobally", | ||
this.argSerializer.valuesToStrings([new StringValue(options.tokenIdentifier)])[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably, use the same pattern as above / below, even if we have a single argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
new StringValue(options.tokenTicker), | ||
new BigUIntValue(options.numDecimals), | ||
new StringValue("canFreeze"), | ||
new StringValue(options.canFreeze ? this.trueAsString : this.falseAsString), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A private function such as boolToString()
might be useful. E.g.
new StringValue("canFreeze"),
new StringValue(boolToString(options.canFreeze)),
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, added.
const dataParts = ["setCheckCapOnReDelegateRewards", utf8ToHex("true")]; | ||
const dataParts = [ | ||
"setCheckCapOnReDelegateRewards", | ||
this.argSerializer.valuesToStrings([new StringValue("true")])[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably, without [0]
(e.g. reuse the same pattern as when having more arguments).
|
||
return new TransactionBuilder({ | ||
config: this.config!, | ||
sender: options.sender, | ||
receiver: options.receiver, | ||
dataParts: [data], | ||
dataParts: [Buffer.from(data).toString("utf8")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user intends to have the tx.data
as Buffer.from([10, 10])
:
> Buffer.from([10, 10]).toString("utf-8")
'\n\n'
>
In this case, however, the final tx.data
will be fine:
> Buffer.from([10, 10]).toString("base64")
'Cgo='
> Buffer.from("\n\n").toString("base64")
'Cgo='
>
But let's take the example when the user wants to send the byte 255
.
// What the user wants
> Buffer.from([255]).toString("base64")
'/w=='
// What the user gets
> Buffer.from(Buffer.from([255]).toString("utf-8")).toString("base64")
'77+9'
>
Reverted the error that was throwing when interaction was used without
withSender()
or withAddress.Zero()
.Now also the transactions factories use the
ArgSerializer
.TransferTransactionsFactory
has changed a bit, theTransactionComputer
is not needed anymore by the constructor.The
nonce
parameter is now optional when instantiating aToken
. The default value is0
.