-
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
(small breaking change) Merge v13's "TransactionNext" into the existing "Transaction" class #396
Conversation
public version: number; | ||
|
||
/** | ||
* The options field, useful for describing different settings available for transactions. | ||
*/ | ||
public options: number; |
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.
Breaking change.
return feeForMove; | ||
} | ||
computeBytesForSigning(transaction: ITransaction): Uint8Array { | ||
// TODO: do some checks for the transaction e.g. sender, chain ID etc. |
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 not forget about this.
src/transaction.ts
Outdated
/** | ||
* The address of the sender. | ||
*/ | ||
public sender: string; | ||
|
||
/** | ||
* The address of the receiver. | ||
*/ | ||
public receiver: 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 that i think about, maybe in the js doc should be mentioned that the bech32
representation of an address should be provided. (optional)
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.
/** | ||
* The address of the guardian. | ||
*/ | ||
public guardian: 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.
same comment as 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.
Fixed.
src/transaction.ts
Outdated
public constructor({ | ||
nonce, | ||
value, | ||
sender, | ||
receiver, | ||
senderUsername, | ||
receiverUsername, | ||
gasPrice, | ||
gasLimit, | ||
data, | ||
chainID, | ||
version, | ||
options, | ||
guardian, | ||
signature, | ||
guardianSignature, | ||
}: { | ||
nonce?: INonce | bigint; | ||
value?: ITransactionValue | bigint; | ||
sender?: IAddress | string; | ||
receiver?: IAddress | string; | ||
senderUsername?: string; | ||
receiverUsername?: string; | ||
gasPrice?: IGasPrice | bigint; | ||
gasLimit?: IGasLimit | bigint; | ||
data?: ITransactionPayload | Uint8Array; | ||
chainID?: IChainID | string; | ||
version?: ITransactionVersion | number; | ||
options?: ITransactionOptions | number; | ||
guardian?: IAddress | string; | ||
signature?: Uint8Array; | ||
guardianSignature?: Uint8Array; | ||
}) { |
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.
perhaps change the constructor as bellow? to be aligned with the transaction factories.
constructor(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.
src/transaction.ts
Outdated
sender?: IAddress | string; | ||
receiver?: IAddress | 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.
shouldn't we have mandatory fields on the constructor? Like sender, receiver, gas limit and chain?
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, fixed. Reverted, and now we have the same required fields as in PY (as in JS v12, as well): sender, receiver, chain ID and gas limit.
src/smartcontracts/smartContract.ts
Outdated
@@ -127,7 +127,7 @@ export class SmartContract implements ISmartContract { | |||
const bytecode = Buffer.from(code.toString(), 'hex'); | |||
const metadataAsJson = this.getMetadataPropertiesAsObject(codeMetadata); | |||
|
|||
const nextTx = scNextTransactionFactory.createTransactionForDeploy({ | |||
const transaction = scNextTransactionFactory.createTransactionForDeploy({ |
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.
also rename scNextTransactionFactory
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.
|
||
public plainObjectToTransaction(object: IPlainTransactionObject): Transaction { | ||
const transaction = new Transaction({ | ||
nonce: Number(object.nonce), |
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.
this can be BigInt
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. Fixed.
} | ||
} | ||
private addressAsBech32(address: IAddress | string): string { | ||
return typeof address === "string" ? address : address.bech32(); |
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 hope people pass the correct string representation of the address. If people pass the address as a hex string
this will not work as expected.
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. In the specs, we have transaction.sender
, transaction.receiver
as strings.
afad158
The existing
Transaction
class has been adjusted to match the specs.TransactionNext
of v13 has been incorporated intoTransaction
.Breaking (but small) change on
tx.version
andtx.options
Before (v12):
Now (v13):
However, in practice, dApps should not be affected by this. The fields
version
andoptions
were marked as deprecated for a long time. This change does NOT affect the following (since they rely on the not-changedsetVersion
andsetOptions
):There, version & options are mutated like this (example):
These functions,
setVersion
andsetOptions
, remain available (legacy).