Navigation Menu

Skip to content
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

Simplify transaction builder 3 #1736

Merged
merged 16 commits into from Jan 25, 2023
Merged

Simplify transaction builder 3 #1736

merged 16 commits into from Jan 25, 2023

Conversation

davidyuk
Copy link
Member

based on the work done in #1730
closes #1727

This PR is supported by the Æternity Crypto Foundation

@davidyuk davidyuk force-pushed the feature/simplify-tx-types branch 5 times, most recently from 76fa5e3 to aa375e0 Compare January 17, 2023 14:51
@codecov
Copy link

codecov bot commented Jan 17, 2023

Codecov Report

Base: 82.99% // Head: 82.48% // Decreases project coverage by -0.52% ⚠️

Coverage data is based on head (aa375e0) compared to base (ec4d554).
Patch coverage: 85.61% of modified lines in pull request are covered.

❗ Current head aa375e0 differs from pull request most recent head d66c3ae. Consider uploading reports for the commit d66c3ae to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1736      +/-   ##
===========================================
- Coverage    82.99%   82.48%   -0.52%     
===========================================
  Files           84       85       +1     
  Lines         2947     2946       -1     
  Branches       563      573      +10     
===========================================
- Hits          2446     2430      -16     
- Misses         238      245       +7     
- Partials       263      271       +8     
Impacted Files Coverage Δ
src/tx/builder/field-types/encoded.ts 75.00% <ø> (ø)
src/tx/builder/field-types/short-u-int-const.ts 75.00% <0.00%> (ø)
src/tx/builder/field-types/ct-version.ts 70.00% <14.28%> (-30.00%) ⬇️
src/tx/builder/field-types/abi-version.ts 68.42% <53.84%> (-31.58%) ⬇️
src/tx/builder/field-types/nonce.ts 84.61% <84.61%> (ø)
src/tx/builder/index.ts 90.24% <84.61%> (+0.50%) ⬆️
src/tx/builder/field-types/ttl.ts 90.00% <90.00%> (ø)
src/tx/validator.ts 87.75% <97.43%> (-0.67%) ⬇️
src/AeSdkMethods.ts 84.21% <100.00%> (-0.41%) ⬇️
src/account/Generalized.ts 64.51% <100.00%> (-1.11%) ⬇️
... and 20 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

export * from './tx/builder';
export * from './tx/builder/helpers';
export * from './tx/builder/constants';
export * from './tx/builder/schema';
// TODO: move to constants
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidyuk you may have missed this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, it is definitely to be fixed later

): Promise<CtVersion | undefined> {
if (value != null) return value;
if (options.consensusProtocolVersion != null) return undefined;
if (Object.keys(ConsensusProtocolVersion).length === 2) return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could '2' be in the constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 means that ConsensusProtocolVersion have a single protocol version, e.g.

{
  'Iris': 5,
  '5': 'Iris',
}

In this case we don't need to find out the current protocol because it won't be compatible with sdk if it is different what we know.
It can be extracted only as KeysCountInEnumWithASlingleElement, but I would leave it as a TS quirck.

* @returns Deposit value Buffer.
*/
serialize(
value: Int | undefined,
options: Parameters<typeof coinAmount['serialize']>[1],
parameters: Parameters<typeof coinAmount['serialize']>[2],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have a type alias with a readable name for such type builds. Parameters<typeof coinAmount['serialize']>[2]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite verbose, but the base idea is just to copy the signature of the inherited method. I'm doing it frequently with different objects and their parts, so I'm not sure that adding intermediate types would be helpful in all cases, but I'm doing so in the most popular, like this:

export type BuildTxOptions <TxType extends Tag, OmitFields extends string> =
Omit<Parameters<typeof _buildTx<TxType>>[1], OmitFields>;

BREAKING CHANGE: sync `buildTx` accepts `denomination` in the first argument
```diff
-buildTx({ ... }, { denomination: AE_AMOUNT_FORMATS.AETTOS })
+buildTx({ ..., denomination: AE_AMOUNT_FORMATS.AETTOS })
```
BREAKING CHANGE: `TX_TTL` not exported anymore
Use `0` instead.
BREAKING CHANGE: AeSdk.buildTx accepts `tag` in options
Replace `aeSdk.buildTx(Tag.SpendTx, { ... })` with `aeSdk.buildTx({ ..., tag: Tag.SpendTx })`.
BREAKING CHANGE: TX_SCHEMA, TxParamsCommon, TxSchema, TxTypeSchemas not exported anymore
@davidyuk davidyuk added this to the v13 milestone Jan 24, 2023
@davidyuk davidyuk merged commit 72d0cd5 into develop Jan 25, 2023
@davidyuk davidyuk deleted the feature/simplify-tx-types branch January 25, 2023 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types discrepancy in transaction parameters(buildTx and unpackTx)
2 participants