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

feat(jellyfish-transaction-builder): Extend createDeFiTx to allow for custom vins and vouts #1892

Closed
wants to merge 1 commit into from

Conversation

marktanrj
Copy link
Contributor

@marktanrj marktanrj commented Dec 1, 2022

What this PR does / why we need it:

@codeclimate
Copy link

codeclimate bot commented Dec 1, 2022

Code Climate has analyzed commit ae7b3e5 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@netlify
Copy link

netlify bot commented Dec 1, 2022

Deploy Preview for jellyfishsdk ready!

Name Link
🔨 Latest commit ae7b3e5
🔍 Latest deploy log https://app.netlify.com/sites/jellyfishsdk/deploys/6388159500c060000955f13f
😎 Deploy Preview https://deploy-preview-1892--jellyfishsdk.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Dec 1, 2022

Codecov Report

Base: 89.95% // Head: 91.24% // Increases project coverage by +1.29% 🎉

Coverage data is based on head (ae7b3e5) compared to base (256e3ef).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1892      +/-   ##
==========================================
+ Coverage   89.95%   91.24%   +1.29%     
==========================================
  Files         358      359       +1     
  Lines       10432    10464      +32     
  Branches     1317     1321       +4     
==========================================
+ Hits         9384     9548     +164     
+ Misses       1012      879     -133     
- Partials       36       37       +1     
Impacted Files Coverage Δ
...llyfish-transaction-builder/src/txn/txn_builder.ts 98.33% <100.00%> (+0.11%) ⬆️
packages/ocean-api-client/src/ApiResponse.ts 6.25% <0.00%> (-93.75%) ⬇️
packages/jellyfish-wallet-encrypted/src/hd_node.ts 12.12% <0.00%> (-87.88%) ⬇️
packages/jellyfish-wallet/src/wallet.ts 20.00% <0.00%> (-80.00%) ⬇️
packages/whale-api-client/src/api/blocks.ts 50.00% <0.00%> (-50.00%) ⬇️
packages/jellyfish-crypto/src/bech32.ts 79.16% <0.00%> (-20.84%) ⬇️
...jellyfish-transaction/src/script/dftx/dftx_pool.ts 80.00% <0.00%> (-20.00%) ⬇️
packages/whale-api-client/src/api/address.ts 88.88% <0.00%> (-11.12%) ⬇️
...pps/whale-api/src/module.api/address.controller.ts 96.15% <0.00%> (-1.93%) ⬇️
packages/jellyfish-testing/src/icxorderbook.ts 98.38% <0.00%> (-1.62%) ⬇️
... and 35 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.

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

Docker build preview for jellyfish/apps is ready!

Built with commit ec9a4f5

  • ghcr.io/jellyfishsdk/legacy-api:pr-1892
  • ghcr.io/jellyfishsdk/ocean-api:pr-1892
  • ghcr.io/jellyfishsdk/playground-api:pr-1892
  • ghcr.io/jellyfishsdk/status-api:pr-1892
  • ghcr.io/jellyfishsdk/whale-api:pr-1892

You can also get an immutable image with the commit hash

  • ghcr.io/jellyfishsdk/legacy-api:ec9a4f5dec6cb4d5e5ead5ed8a0327e4755ef580
  • ghcr.io/jellyfishsdk/ocean-api:ec9a4f5dec6cb4d5e5ead5ed8a0327e4755ef580
  • ghcr.io/jellyfishsdk/playground-api:ec9a4f5dec6cb4d5e5ead5ed8a0327e4755ef580
  • ghcr.io/jellyfishsdk/status-api:ec9a4f5dec6cb4d5e5ead5ed8a0327e4755ef580
  • ghcr.io/jellyfishsdk/whale-api:ec9a4f5dec6cb4d5e5ead5ed8a0327e4755ef580

Copy link
Contributor

@imkven imkven left a comment

Choose a reason for hiding this comment

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

LGTM.

*/
async createDeFiTx (
opDeFiTx: OP_DEFI_TX,
changeScript: Script,
outValue: BigNumber = new BigNumber('0')
outValue: BigNumber = new BigNumber('0'),
customVinVout: Array<{ vin: Vin, vout: Vout, prevout: Prevout }> = []
Copy link
Contributor

Choose a reason for hiding this comment

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

This overloader concept isn't really applicable and it doesn't gel well.

  • Given that can inject any Vin, the Vin can already be collected by await this.collectPrevouts(minFee) and included in vins, giving you an invalid Transaction due to duplicated Vins.
  • The assumption is with the Vin provided that you have the signing rights to it.
  • That {Vin, Vout, Prevout} comes in a Set, that's not true since only Vin is tied to Prevout. The amount Vin to Vout ratio is not exclusive. So an array won't make sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

We also have to ensure collectPrevout doesn't collect the Vin you need to sign in a special way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your setup requires:

  1. A custom "Prevouts Collector" implementation since you need control of the Vins
  2. Injection of Vout in a special order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense for the upstream implementation to just prepare their Transaction from scratch?

We change protected async sign to public sync sign to allow that. And anything else that is required we make it public or create an abstraction for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, a little lost 😓 correct me if I'm wrong:

  • I will implement a "Prevouts Collector" as a method in P2WPKHTxnBuilder class
  • then combine the outputs of it along with outputs of await this.collectPrevouts(minFee) so Vin and Vout can be placed in the correct order that doesn't have duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

prepare their Transaction from scratch

do you mean build the transaction from scratch with vin and vout and then sign it, all in the updatemasternode function in packages/jellyfish-transaction-builder/src/txn/txn_builder_masternode.ts?

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that's right. Since your requirements require vin and vout to be arranged in a certain way. Nobody else will probably need it. It is better to keep the custom logic there instead of bleeding it into an abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, that makes sense. I will do it this way since no other functions need it 👍

@marktanrj
Copy link
Contributor Author

I will build the updatemasternode transaction from scratch in #1894 in txn_builder_masternode.ts, no need for an abstraction with this PR

@marktanrj marktanrj closed this Dec 1, 2022
fuxingloh pushed a commit that referenced this pull request Jan 14, 2023
… builder (#1894)

<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
- updatemasternode transaction builder

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes part of #1842

#### Additional comments?:
- #1863 needed for typings
- <del> #1892 needed for createDeFiTx </del>

Co-authored-by: Isaac Yong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants