Skip to content

Commit df514b0

Browse files
crowdfunding continuity fixes
1 parent 23a6610 commit df514b0

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

docs/developers/tutorials/crowdfunding/crowdfunding-p2.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,25 @@ fn init(&self, target: BigUint, deadline: TimestampMillis) {
4747
self.target().set(target);
4848

4949
require!(
50-
deadline > self.blockchain().get_block_timestamp_millis(),
50+
deadline > self.get_current_time_millis(),
5151
"Deadline can't be in the past"
5252
);
5353
self.deadline().set(deadline);
5454
}
55+
56+
fn get_current_time_millis(&self) -> TimestampMillis {
57+
self.blockchain().get_block_timestamp_millis()
58+
}
5559
```
5660

5761
The `cf_token_id()` storage mapper will hold the token identifier for our crowdfunding campaign. We initialize it to `TokenId::egld()` in the `init` function, hardcoding it to EGLD for now. In Part 3, we'll make this configurable to support any token.
5862

5963
`TimestampMillis` is a type-safe wrapper for millisecond timestamps, providing better type safety than using raw `u64` values.
6064

65+
:::note Private functions
66+
Note that `get_current_time_millis()` is not annotated with `#[endpoint]` or `#[view]`. This makes it a **private helper function** that can only be called from within the contract, not from external transactions. Private functions are useful for organizing code and avoiding duplication, but they cannot be called directly by users or other contracts.
67+
:::
68+
6169
The deadline being a block timestamp can be expressed as a 64-bits unsigned integer `TimestampMillis`. The target, however, being a sum of EGLD cannot.
6270

6371
:::note
@@ -345,7 +353,7 @@ fn init(&self, target: BigUint, deadline: TimestampMillis) {
345353
self.target().set(target);
346354

347355
require!(
348-
deadline > self.blockchain().get_block_timestamp_millis(),
356+
deadline > self.get_current_time_millis(),
349357
"Deadline can't be in the past"
350358
);
351359
self.deadline().set(deadline);
@@ -460,7 +468,7 @@ We can now use the type **Status** just like we use the other types, so we can w
460468
```rust
461469
#[view]
462470
fn status(&self) -> Status {
463-
if self.blockchain().get_block_timestamp_millis() < self.deadline().get() {
471+
if self.get_current_time_millis() < self.deadline().get() {
464472
Status::FundingPeriod
465473
} else if self.get_current_funds() >= self.target().get() {
466474
Status::Successful

docs/developers/tutorials/crowdfunding/crowdfunding-p3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn get_current_time_millis(&self) -> TimestampMillis {
4141
}
4242
```
4343

44-
We've made several improvements:
44+
The key changes:
4545

4646
1. **New parameter**: `token_identifier: TokenId` is now the first parameter
4747
2. **Validation**: We validate that the token identifier is valid before storing it

0 commit comments

Comments
 (0)