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: support private policy #5

Merged
merged 6 commits into from
Oct 16, 2024
Merged

feat: support private policy #5

merged 6 commits into from
Oct 16, 2024

Conversation

BarryTong98
Copy link
Collaborator

@BarryTong98 BarryTong98 commented Oct 15, 2024

support private policy for IsSponsorable & SendRawTransaction


constructor(
userUrl: string | FetchRequest,
sponsorUrl: string | FetchRequest,
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if a user:

  1. just want to use the user api?
  2. just want to use the sponsor api and private policy?
  3. will use both of them.
    But now, I have to input two URL. I think we can improve so that user just need input necessary one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make the sponsorUrl optional, so that private policy UUID can only be sent if the user provides this URL. Add a comment explaining the purpose of sponsorUrl and Options.

src/paymasterclient.ts Outdated Show resolved Hide resolved
@BarryTong98 BarryTong98 force-pushed the feat-private-policy branch 3 times, most recently from 1150f05 to 2f69254 Compare October 16, 2024 08:46
if (policyUUID) {
const newConnection = this._getConnection()
newConnection.setHeader("X-MegaFuel-Policy-Uuid", policyUUID)
const sponsorProviderWithHeader = new ethers.JsonRpcProvider(
Copy link
Collaborator

Choose a reason for hiding this comment

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

sponsorProviderWithHeader the name sponsor is not proper here.

if no new header to set here, can we not do new ethers.JsonRpcProvider, but reuse the current one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sponsorProviderWithHeader the name sponsor is not proper here. ------> rename to provider

if no new header to set here, can we not do new ethers.JsonRpcProvider, but reuse the current one.
------------>
image

if (policyUUID)
if policyUUID is undefined, null, or an empty string. In any of these cases, the program will skip the if block and directly execute: return await this.send('pm_isSponsorable', [tx])
This way, we didn't create a new ethers.JsonRpcProvider in cases where we don't need to set a header.

src/paymasterclient.ts Outdated Show resolved Hide resolved
@BarryTong98 BarryTong98 merged commit 4e4c610 into main Oct 16, 2024
1 check passed
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.

3 participants