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

[apps] grow registration #3150

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
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
Binary file added apps/grow_bitcoin/released/8/package.rpd
Binary file not shown.
85 changes: 85 additions & 0 deletions apps/grow_bitcoin/sources/grow_registration.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module grow_bitcoin::grow_registration {

use std::signer::address_of;
use std::string::String;
use std::vector;
use std::vector::length;
use grow_bitcoin::grow_point_v3::{PointBox, timestamp, value};
use app_admin::admin::AdminCap;
use moveos_std::object;
use moveos_std::table;
use moveos_std::object::{ObjectID, to_shared, Object};
use moveos_std::table::Table;


const ErrorInvalidVoteTime: u64 = 1;

struct Registration has key, store{
project_id: String,
register_point_box: Table<ObjectID, bool>,
user_info: Table<address, UserInfo>,
start_time: u64,
end_time: u64,
}

struct UserInfo has store, drop{
register_info: String,
amount: u256
}

public entry fun create_registration(project_id: String, start_time: u64, end_time: u64, _admin: &mut Object<AdminCap>) {
let registration = Registration {
project_id,
register_point_box: table::new(),
user_info: table::new(),
start_time,
end_time
};
to_shared(object::new_with_id(project_id, registration));
}

public entry fun update_registration_time(registration_obj: &mut Object<Registration>, start_time: u64, end_time: u64, _admin: &mut Object<AdminCap>) {
let registration = object::borrow_mut(registration_obj);
registration.start_time = start_time;
registration.end_time = end_time;
}

public entry fun register_batch(signer: &signer, registration_obj: &mut Object<Registration>, point_box_objs: vector<ObjectID>, register_info: String) {
let i = 0;
while (i < length(&point_box_objs)) {
let point_box_id = *vector::borrow(&point_box_objs, i);
let point_box = object::borrow_mut_object<PointBox>(signer, point_box_id);
register(signer, registration_obj, point_box, register_info);
i = i + 1;
}
}

public entry fun register(signer: &signer, registration_obj: &mut Object<Registration>, point_box_obj: &mut Object<PointBox>, register_info: String) {
let registration = object::borrow_mut(registration_obj);
let vote_time = timestamp(point_box_obj);
assert!(vote_time >= registration.start_time && vote_time <= registration.end_time, ErrorInvalidVoteTime);
let user_info = table::borrow_mut_with_default(&mut registration.user_info, address_of(signer), UserInfo{
register_info,
amount: 0
});
user_info.amount = user_info.amount + value(point_box_obj);
table::add(&mut registration.register_point_box, object::id(point_box_obj), true);
}

public entry fun update_register_info(signer: &signer, registration_obj: &mut Object<Registration>, register_info: String) {
let registration = object::borrow_mut(registration_obj);
let user_info = table::borrow_mut(&mut registration.user_info, address_of(signer));
user_info.register_info = register_info
}

public fun get_user_info(registration_obj: &Object<Registration>, account: address): (String, u256) {
let registration = object::borrow(registration_obj);
if(table::contains(&registration.user_info, account)){
let user_info = table::borrow(&registration.user_info, account);
(user_info.register_info, user_info.amount)
}else{
(std::string::utf8(b""), 0u256)
}
}
}

Loading