-
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
Implemented the Transaction class #366
Conversation
src/transaction.ts
Outdated
tx.applySignature(transaction.signature); | ||
} | ||
|
||
if (transaction.guardianSignature) { |
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.
The checks for transaction.signature
and transaction.guardianSignature
are not symmetric.
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, they were not. Fixed.
@@ -458,3 +492,215 @@ export class TransactionHash extends Hash { | |||
} | |||
} | |||
|
|||
/** | |||
* An abstraction for creating, signing and broadcasting transactions. | |||
* Will replace the {@link Transaction} class in the future. |
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, this is the one according to sdk-specs 👍
src/transaction.ts
Outdated
this.gasLimit = gasLimit; | ||
this.data = data || new Uint8Array(); | ||
this.chainID = chainID; | ||
this.version = version || TRANSACTION_OPTIONS_DEFAULT; |
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.
Version vs. options.
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.
Fixed
receiver: Address.fromBech32(transaction.receiver), | ||
gasLimit: new BigNumber(transaction.gasLimit).toNumber(), | ||
chainID: transaction.chainID, | ||
value: new BigNumber(transaction.value).toFixed(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.
Correct 👍
src/transaction.ts
Outdated
constructor() {} | ||
|
||
computeTransactionFee(transaction: ITransactionNext, networkConfig: INetworkConfig): BigNumber{ | ||
let moveBalanceGas = new BigNumber( |
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.
When possible, we should use const
instead of let
(optional, can also be done in other PR).
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 with const
where possible.
src/transaction.ts
Outdated
.update(buffer) | ||
.digest("hex"); | ||
|
||
return new Uint8Array(Buffer.from(hash, "hex")); |
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.
Generally speaking, the following:
return new Uint8Array(Buffer.from(hash, "hex"))
Can be replaced by:
return Buffer.from(hash, "hex")
(optional, shorter)
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, replaced it.
src/transaction.ts
Outdated
chainID: transaction.chainID, | ||
version: transaction.version, | ||
options: transaction.options == 0 ? undefined : transaction.options, | ||
guardian: transaction.guardian == "" ? undefined : transaction.guardian, |
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.
Check can also be: transaction.guardian ? undefined : transaction.guardian
, so that it handles null
values, as well. CC: @CiprianDraghici, makes sense? I think for options
, as well. Since setters are public.
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.
Check is now:
transaction.guardian ? transaction.guardian : undefined
Same for options
.
src/transaction.ts
Outdated
receiverUsername: transaction.receiverUsername ? Buffer.from(transaction.receiverUsername).toString("base64") : undefined, | ||
gasPrice: Number(transaction.gasPrice), | ||
gasLimit: Number(transaction.gasLimit), | ||
data: transaction.data.length == 0 ? undefined : Buffer.from(transaction.data).toString("base64"), |
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.
Since the setter is public, here we can also protect against a null / undefined data
field.
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!
MinGasLimit: number; | ||
GasPerDataByte: number; | ||
GasPriceModifier: number; | ||
ChainID: string; | ||
|
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 I see that at some point we have to have consistent naming for public fields. Here, uppercase. For TransactionNext
, the first letter is lowercase.
All right for now, no need to rename the fields of NetworkConfig
in v13.
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.
Not really sure what you mean. The TransactionComputer
uses the same INetworkConfig
interface as the Transaction
class where the first letter is uppercase.
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.
But I do agree that we need to stay consistent with the naming.
Implemented the new
Transaction
class as described in the specs.