This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Implement the new sale payment flow for the ticketing system #33
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b498166
Update swap.did
lwshang 96d3b22
send get_open_ticket
lwshang eab8d78
handle response after send
lwshang cbd7b81
send new-sale-ticket
lwshang 126183d
handle new-ssale-ticket response
lwshang 05fe971
typo
lwshang 9adc993
update swap.did
lwshang eced27e
combine into get-sale-ticket
lwshang 323b18d
Merge branch 'master' into lwshang/sdk-921
lwshang 3acd073
fmt
lwshang 7d7f9b8
mark todo with jira ticket
lwshang 87f6c0c
doc help
lwshang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use candid::Encode; | ||
use clap::Parser; | ||
|
||
use crate::{ | ||
commands::transfer::HexSubaccount, | ||
lib::{ | ||
signing::{sign_ingress_with_request_status_query, IngressWithRequestId}, | ||
AnyhowResult, TargetCanister, | ||
}, | ||
SnsCanisterIds, | ||
}; | ||
|
||
/// Get the sale ticket of the caller. If there is no open ticket yet, create a new ticket with specified arguments. | ||
#[derive(Parser)] | ||
pub struct GetSaleTicketOpts { | ||
/// The amount of ICP tokens in e8s. | ||
#[clap(long)] | ||
amount_icp_e8s: u64, | ||
|
||
/// The subaccount of the account to create sale ticket. For example: e000d80101 | ||
#[clap(long)] | ||
subaccount: Option<HexSubaccount>, | ||
} | ||
|
||
// TODO: SDK-954 - use ic_sns_swap when it is available | ||
#[derive(candid::CandidType, candid::Deserialize)] | ||
struct NewSaleTicketRequest { | ||
amount_icp_e8s: u64, | ||
subaccount: Option<[u8; 32]>, | ||
} | ||
|
||
#[derive(candid::CandidType, candid::Deserialize)] | ||
struct GetOpenTicketArg {} | ||
|
||
pub fn exec( | ||
pem: &str, | ||
sns_canister_ids: &SnsCanisterIds, | ||
opts: GetSaleTicketOpts, | ||
) -> AnyhowResult<Vec<IngressWithRequestId>> { | ||
let req1 = sign_ingress_with_request_status_query( | ||
pem, | ||
"get_open_ticket", | ||
Encode!(&GetOpenTicketArg {})?, | ||
TargetCanister::Swap(sns_canister_ids.swap_canister_id.get().0), | ||
)?; | ||
|
||
let message = NewSaleTicketRequest { | ||
amount_icp_e8s: opts.amount_icp_e8s, | ||
subaccount: opts.subaccount.map(|sub| sub.0), | ||
}; | ||
let req2 = sign_ingress_with_request_status_query( | ||
pem, | ||
"new_sale_ticket", | ||
Encode!(&message)?, | ||
TargetCanister::Swap(sns_canister_ids.swap_canister_id.get().0), | ||
)?; | ||
Comment on lines
+51
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like
I think (1) is the best option right now but less than ideal. Lets see how he responds on Monday. |
||
Ok(vec![req1, req2]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${CARGO_TARGET_DIR:-../target}/debug/sns-quill --canister-ids-file ./canister_ids.json --pem-file - get-sale-ticket --amount-icp-e8s 100000 --subaccount e000d80101 | ${CARGO_TARGET_DIR:-../target}/debug/sns-quill send --dry-run - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Sending message with | ||
|
||
Call type: update | ||
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae | ||
Canister id: rkp4c-7iaaa-aaaaa-aaaca-cai | ||
Method name: get_open_ticket | ||
Arguments: (record {}) | ||
Sending message with | ||
|
||
Call type: update | ||
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae | ||
Canister id: rkp4c-7iaaa-aaaaa-aaaca-cai | ||
Method name: new_sale_ticket | ||
Arguments: ( | ||
record { | ||
subaccount = opt blob "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\e0\00\d8\01\01"; | ||
amount_icp_e8s = 100_000 : nat64; | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.