Skip to content
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 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions frameworks/moveos-stdlib/sources/event_queue.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Collaborator

@baichuan3 baichuan3 Sep 24, 2024

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 of subscriber_obj ?

Copy link
Contributor

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

Copy link
Collaborator Author

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

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unify to exists

Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
Expand Down
Loading