-
Notifications
You must be signed in to change notification settings - Fork 65
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
hub: Add an endpoint to create a scheduled payment #3231
Conversation
…ransaction is done
…he type of "v" in vrs to number
This is ready for a draft review, I'm currently not planning any significant changes, only the things listed in TODO. |
}); | ||
|
||
it('does not persist a scheduled payment when something goes wrong with on chain call', async function () { | ||
forceSchedulePaymentOnChainTimeout = true; |
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.
Maybe this should be reset to false
in a beforeEach
in case any tests get added after this?
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.
Sounds good. Will change
// can poll the record to see when it's mined (creation_block_number attribute will be set). | ||
await this.workerClient.addJob('scheduled-payment-on-chain-creation-waiter', { | ||
scheduledPaymentId: scheduledPayment.id, | ||
}); |
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 profile purchase code uses a “job ticket” pattern for a slow/chain operation; the endpoint returns a newly-created ticket that the consumer can poll at /api/job-tickets/:id
to track progress. Would it make sense to use that pattern here?
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 thought about it. I think it's easier to just query for the scheduled payments. If creation_block_number
is present on the record, it will mean the job finished successfully. In this case job ticket pattern sounds a bit roundabout
}); | ||
} | ||
} | ||
} |
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.
Is it worth having a couple of tests for this task?
@@ -435,3 +435,15 @@ function sortSignaturesAsBytes( | |||
return [contractSignature, ownerSignature]; | |||
} | |||
} | |||
|
|||
export function signatureToVRS(rawSignature: 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.
is this essentially the same as ethSignSignatureToRSVForSafe()
in this module?
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.
It looks like it. However, there is one diference, in the recovery identifier (v
):
signatureToVRS
uses parseInt(value)
while ethSignSignatureToRSVForSafe
uses parseInt(value, 16)
So for example, let's have:
signature = 0x21fbf0696d5e0aa2ef41a2b4ffb623bcaf070461d61cf7251c74161f82fec3a4370854bc0a34b3ab487c1bc021cd318c734c51ae29374f2beb0e6f2dd49b4bf41c
v
is the last 2 bytes and that is 1c
signatureToVRS
:
parseInt("1c")
=> 1
ethSignSignatureToRSVForSafe
:
parseInt("1c", 16)
=> 28
Judging by this article it looks like the v
can be either either 27 (0x1b) or 28 (0x1c). That makes me think ethSignSignatureToRSVForSafe
is the correct implementation and we should use it instead of signatureToVRS
(and get rid of this one).
However I'm not sure how this even worked then, given the parsing might be wrong. 🙇♂️ Judging by this comment ethereum/go-ethereum#19751 (comment), v
can also be 0 or 1 and this is the reason both implementations that we have are working.
} | ||
|
||
export function strip0x(s: string) { | ||
return Web3.utils.isHexStrict(s) ? s.substr(2) : s; |
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.
using s.replace(/^0x/, '')
is simpler and it's idempotent--you can run it as many times as you want and it will always return the correct thing.
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.
Agree! Will change it
From what I understand for now the development in the hub is only related to the crank work which is regarding scheduling the payment and triggering the execution of the scheduled payment. I don't think we plan to use the hub to pull any type of transactions, such as creating safe and enabling modules that will not be handled by the hub/crank. CMIIW |
@jurgenwerk @FadhlanR so i'm confused them about about this function in the SDK: https://github.com/cardstack/cardstack/blob/main/packages/cardpay-sdk/sdk/scheduled-payment-module.ts#L672. This function uses To be clear is this PR about establishing the schedule for the payments or to execute a specific payment that is part of the schedule? |
Closing because the approach changed, and it will be split into 2 PRs - one for the SDK/CLI and one for the hub. |
Ticket: CS-4373
It goes like this:
creation_block_number
). This way the client can poll the scheduled payment and whencreation_block_number
gets written by the background job, it means the scheduled payment has been added in both blockchain and the crank - the client can then show it as "added successfully", otherwise it will be "pending".TODO:
payAt
gets set correctly)