-
Notifications
You must be signed in to change notification settings - Fork 83
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
[framework]:add exist_new_events fun and subscriber_info fun #2680
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ module moveos_std::event_queue { | |
use std::string::String; | ||
use moveos_std::timestamp; | ||
use moveos_std::event; | ||
use moveos_std::object::{Self, Object, ObjectID}; | ||
use moveos_std::object::{Self, Object, ObjectID, borrow_object}; | ||
|
||
const EVENT_EXPIRE_TIME: u64 = 1000 * 60 * 60 * 24 * 31; // 31 days | ||
const REMOVE_EXPIRED_EVENT_BATCH_SIZE: u64 = 10; | ||
|
@@ -175,7 +175,38 @@ module moveos_std::event_queue { | |
let event_queue_obj = borrow_mut_queue<E>(queue_id); | ||
internal_remove_expired_events(event_queue_obj); | ||
} | ||
|
||
|
||
|
||
public fun subscriber_info<E: copy + drop + store>(subscriber_obj: &Object<Subscriber<E>>):(u64, u64, u64) { | ||
let subscriber = object::borrow(subscriber_obj); | ||
let subscriber_sequence_number = subscriber.sequence_number; | ||
// If the subscriber_obj is exsited, the queue must be existed | ||
let event_queue_obj = borrow_object<EventQueue<E>>(subscriber.queue_id); | ||
let head_sequence_number = object::borrow(event_queue_obj).head_sequence_number; | ||
let tail_sequence_number = object::borrow(event_queue_obj).tail_sequence_number; | ||
(subscriber_sequence_number, head_sequence_number, tail_sequence_number) | ||
} | ||
|
||
public fun exist_new_events<E: copy + drop + store>(subscriber_obj: &Object<Subscriber<E>>): bool { | ||
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. Unify to exists 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. Same as above |
||
let subscriber = object::borrow(subscriber_obj); | ||
let subscriber_sequence_number = subscriber.sequence_number; | ||
// If the subscriber_obj is exsited, the queue must be existed | ||
let event_queue_obj = borrow_object<EventQueue<E>>(subscriber.queue_id); | ||
let head_sequence_number = object::borrow(event_queue_obj).head_sequence_number; | ||
let tail_sequence_number = object::borrow(event_queue_obj).tail_sequence_number; | ||
if(head_sequence_number == tail_sequence_number){ | ||
return false | ||
}; | ||
if (subscriber_sequence_number >= head_sequence_number) { | ||
return false | ||
}; | ||
subscriber_sequence_number = if (tail_sequence_number > subscriber_sequence_number) { | ||
tail_sequence_number | ||
} else { | ||
subscriber_sequence_number | ||
}; | ||
return object::contains_field(event_queue_obj, subscriber_sequence_number) | ||
} | ||
fun internal_remove_expired_events<E: copy + drop + store>(event_queue_obj: &mut Object<EventQueue<E>>){ | ||
let head_sequence_number = object::borrow(event_queue_obj).head_sequence_number; | ||
let tail_sequence_number = object::borrow(event_queue_obj).tail_sequence_number; | ||
|
Oops, something went wrong.
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.
Is it easier to call by passing
object_id
instead ofsubscriber_obj
?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 arguments in the transaction are same, both are
ObjectID
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 think there is not much difference between the two