Skip to content

Commit 3aeef5f

Browse files
committed
remove on-chain messages, use offchain messages instead
1 parent d2b3cc7 commit 3aeef5f

File tree

2 files changed

+6
-71
lines changed

2 files changed

+6
-71
lines changed

examples/demo.ts

-13
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,10 @@ async function interact(appMeta: AppMeta, signer: Ed25519Keypair, user: Ed25519K
561561
description: '新的 description',
562562
threshold: 2,
563563
});
564-
// new message
565-
await club.newMessage(signer, clubId, 0, 'hello, world!', MessageType.RAW);
566-
await club.newMessage(signer, clubId, 0, '你好,世界!😁', MessageType.RAW);
567564
// create channel
568565
await club.addClubChannel(signer, clubId, '中文');
569566
// update channel name
570567
await club.updateClubChannelName(signer, clubId, 0, '默认');
571-
// new message
572-
await club.newMessage(signer, clubId, 1, 'hello, world!', MessageType.XOR);
573-
await club.newMessage(signer, clubId, 1, '你好,世界!😁', MessageType.XOR);
574-
// delete message
575-
await club.deleteMessage(signer, clubId, 0, 0);
576568
// delete channel
577569
await club.deleteClubChannel(signer, clubId, 1);
578570
}
@@ -598,11 +590,6 @@ async function queries(appMeta: AppMeta) {
598590
// get one club info
599591
const clubInfo = await club.getClubInfoById(clubId);
600592
console.log('clubInfo', JSON.stringify(clubInfo, null, 2));
601-
// get club channel msgs
602-
const msgs = await club.getClubChannelMsgs(clubId, 0, 0, 3);
603-
console.log('msgs', JSON.stringify(msgs, null, 2));
604-
const msgs2 = await club.getClubChannelMsgs(clubId, 1, 0, 3);
605-
console.log('msgs2', JSON.stringify(msgs2, null, 2));
606593
}
607594

608595
async function main() {

sources/club.move

+6-58
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,23 @@ module club::club {
33
use std::string::{utf8, String};
44
use std::type_name;
55
use std::vector;
6-
use sui::clock::{Clock, timestamp_ms};
76
use sui::coin::{Self, Coin};
87
use sui::event::emit;
98
use sui::object::{Self, UID, new, ID};
109
use sui::sui;
1110
use sui::table::{Self, Table};
12-
use sui::table_vec::{Self, TableVec};
1311
use sui::transfer::{share_object, public_transfer};
1412
use sui::tx_context::{Self, TxContext, sender};
1513
use sui::vec_set::{Self, VecSet, keys};
1614

1715
// errors
1816
const ERR_NOT_AUTHORIZED: u64 = 1;
19-
const ERR_MESSAGE_NOT_FOUND: u64 = 2;
20-
const ERR_MESSAGE_DELETED: u64 = 3;
21-
const ERR_INVALID_CLUB_NAME: u64 = 4;
22-
const ERR_INVALID_CHANNEL_NAME: u64 = 5;
23-
const ERR_ADMIN_ALREADY_EXISTS: u64 = 6;
24-
const ERR_ADMIN_NOT_FOUND: u64 = 7;
25-
const ERR_CHANNEL_NOT_FOUND: u64 = 8;
26-
const ERR_INVALID_FEE: u64 = 9;
17+
const ERR_INVALID_CLUB_NAME: u64 = 2;
18+
const ERR_INVALID_CHANNEL_NAME: u64 = 3;
19+
const ERR_ADMIN_ALREADY_EXISTS: u64 = 4;
20+
const ERR_ADMIN_NOT_FOUND: u64 = 5;
21+
const ERR_CHANNEL_NOT_FOUND: u64 = 6;
22+
const ERR_INVALID_FEE: u64 = 7;
2723

2824
// constants
2925
const VERSION: u64 = 0;
@@ -57,14 +53,6 @@ module club::club {
5753
struct Channel has store {
5854
name: String,
5955
deleted: bool,
60-
messages: TableVec<Message>,
61-
}
62-
63-
struct Message has copy, drop, store {
64-
sender: address,
65-
content: vector<u8>,
66-
timestamp: u64,
67-
deleted: bool,
6856
}
6957

7058
// ====== Events ======
@@ -139,7 +127,6 @@ module club::club {
139127
let default_channel = Channel {
140128
name: default_channel_name_str,
141129
deleted: false,
142-
messages: table_vec::empty(ctx),
143130
};
144131
let index = table::length(&club_global.clubs);
145132
let type_name = type_name::into_string(type_name::get<T>());
@@ -274,7 +261,6 @@ module club::club {
274261
let channel = Channel {
275262
name: utf8(name),
276263
deleted: false,
277-
messages: table_vec::empty(ctx),
278264
};
279265
vector::push_back(&mut club.channels, channel);
280266
}
@@ -303,42 +289,4 @@ module club::club {
303289
let channel = vector::borrow_mut(&mut club.channels, channel_index);
304290
channel.name = utf8(name);
305291
}
306-
307-
entry public fun new_message(
308-
clock: &Clock,
309-
_club_global: &Global,
310-
club: &mut Club,
311-
channel_index: u64,
312-
content: vector<u8>,
313-
ctx: &mut TxContext,
314-
) {
315-
assert!(channel_index < vector::length(&club.channels), ERR_CHANNEL_NOT_FOUND);
316-
let channel = vector::borrow_mut(&mut club.channels, channel_index);
317-
let sender = tx_context::sender(ctx);
318-
let message = Message {
319-
sender,
320-
content,
321-
timestamp: timestamp_ms(clock),
322-
deleted: false,
323-
};
324-
table_vec::push_back(&mut channel.messages, message);
325-
}
326-
327-
entry public fun delete_message(
328-
_club_global: &Global,
329-
club: &mut Club,
330-
channel_index: u64,
331-
message_index: u64,
332-
ctx: &mut TxContext,
333-
) {
334-
let sender = tx_context::sender(ctx);
335-
assert!(channel_index < vector::length(&club.channels), ERR_CHANNEL_NOT_FOUND);
336-
let channel = vector::borrow_mut(&mut club.channels, channel_index);
337-
assert!(message_index < table_vec::length(&channel.messages), ERR_MESSAGE_NOT_FOUND);
338-
let message = table_vec::borrow_mut(&mut channel.messages, message_index);
339-
assert!(message.sender == sender, ERR_NOT_AUTHORIZED);
340-
assert!(!message.deleted, ERR_MESSAGE_DELETED);
341-
message.content = vector::empty();
342-
message.deleted = true;
343-
}
344292
}

0 commit comments

Comments
 (0)