Skip to content

Commit

Permalink
fix: require --ticket-creation-time in sns pay (#159)
Browse files Browse the repository at this point in the history
* ticket_creation_time

* changelog
  • Loading branch information
lwshang authored Feb 14, 2023
1 parent 62d33ae commit 81272c9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Changed

- Require `--ticket-creation-time` in `quill sns pay`. (#159)

## [0.3.3] - 2023-02-09

### Changed
Expand Down
3 changes: 2 additions & 1 deletion docs/cli-reference/sns/quill-sns-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Second, the sale canister is notified that the transfer has been made.
The basic syntax for running `quill sns pay` commands is:

```bash
quill sns pay --amount-icp-e8s <AMOUNT_ICP_E8S> --ticket-id <TICKET_ID> [option]
quill sns pay --amount-icp-e8s <AMOUNT_ICP_E8S> --ticket-creation-time <TICKET_CREATION_TIME> --ticket-id <TICKET_ID> [option]
```

## Flags
Expand All @@ -29,6 +29,7 @@ quill sns pay --amount-icp-e8s <AMOUNT_ICP_E8S> --ticket-id <TICKET_ID> [option]
|-------------------------------------------------|---------------------------------------|
| `--amount-icp-e8s <AMOUNT>` | The amount of ICP to transfer. |
| `--subaccount <SUBACCOUNT>` | Pay from this subaccount. |
| `--ticket-creation-time <TICKET_CREATION_TIME>` | The creation_time of the sale ticket. |
| `--ticket-id` | The ticket_id of the sale ticket. |

## Remarks
Expand Down
10 changes: 8 additions & 2 deletions src/commands/sns/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use candid::Encode;
use clap::Parser;
use ic_base_types::PrincipalId;
use ic_sns_swap::pb::v1::RefreshBuyerTokensRequest;
use icp_ledger::{AccountIdentifier, Memo, SendArgs, Subaccount, Tokens};
use icp_ledger::{AccountIdentifier, Memo, SendArgs, Subaccount, TimeStamp, Tokens};

use crate::lib::ParsedSubaccount;
use crate::lib::{
Expand All @@ -28,6 +28,10 @@ pub struct PayOpts {
#[clap(long)]
subaccount: Option<ParsedSubaccount>,

/// The creation_time of the sale ticket. This should be the same as the "creation_time" of the sale ticket.
#[clap(long, required_unless_present("notify-only"))]
ticket_creation_time: Option<u64>,

/// The tocket_id of the sale ticket. This should be the same as the "ticket_id" of the sale ticket.
#[clap(long, required_unless_present("notify-only"))]
ticket_id: Option<u64>,
Expand All @@ -51,7 +55,9 @@ pub fn exec(
AccountIdentifier::new(sns_canister_ids.swap_canister_id.into(), Some(subaccount));
let request = SendArgs {
amount: Tokens::from_e8s(opts.amount_icp_e8s.unwrap()),
created_at_time: None,
created_at_time: Some(TimeStamp::from_nanos_since_unix_epoch(
opts.ticket_creation_time.unwrap(),
)),
from_subaccount: opts.subaccount.map(|x| x.0),
fee: Tokens::from_e8s(10_000),
memo: Memo(opts.ticket_id.unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/sns-pay.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"$QUILL" sns pay --amount-icp-e8s 100000 --subaccount e000d80101 --ticket-id 100 --canister-ids-file ./sns_canister_ids.json --pem-file - | "$QUILL" send --dry-run -
"$QUILL" sns pay --amount-icp-e8s 100000 --subaccount e000d80101 --ticket-creation-time 1676321340000 --ticket-id 100 --canister-ids-file ./sns_canister_ids.json --pem-file - | "$QUILL" send --dry-run -
4 changes: 3 additions & 1 deletion tests/outputs/sns-pay.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Sending message with
fee = record { e8s = 10_000 : nat64 };
memo = 100 : nat64;
from_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";
created_at_time = null;
created_at_time = opt record {
timestamp_nanos = 1_676_321_340_000 : nat64;
};
amount = record { e8s = 100_000 : nat64 };
},
)
Expand Down

0 comments on commit 81272c9

Please sign in to comment.