Skip to content

Commit b04cc58

Browse files
committed
feat: add name blocks to ic-message
1 parent 505bd34 commit b04cc58

File tree

17 files changed

+382
-96
lines changed

17 files changed

+382
-96
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ ic-cdk-timers = "0.8"
4949
ic-stable-structures = "0.6"
5050
icrc-ledger-types = "0.1"
5151
ic_cose_types = "0.3"
52+
ic-certification = "2.6"
5253
getrandom = { version = "0.2", features = ["custom"] }
5354
rand = { version = "0.8", features = ["getrandom"] }

src/ic_message/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ ic-cdk = { workspace = true }
2525
ic-stable-structures = { workspace = true }
2626
icrc-ledger-types = { workspace = true }
2727
ic_cose_types = { workspace = true }
28+
ic-certification = { workspace = true }

src/ic_message/ic_message.did

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
type ArchivedBlocks = record {
2+
args : vec GetBlocksRequest;
3+
callback : func (vec GetBlocksRequest) -> (GetBlocksResult) query;
4+
};
5+
type BlockWithId = record { id : nat; block : ICRC3Value };
16
type CanisterKind = variant { Cose; Channel; Profile };
27
type CanisterStatusResponse = record {
38
status : CanisterStatusType;
@@ -27,6 +32,7 @@ type ChannelInfo = record {
2732
created_at : nat64;
2833
created_by : principal;
2934
canister : principal;
35+
image : text;
3036
latest_message_at : nat32;
3137
latest_message_by : principal;
3238
my_setting : ChannelSetting;
@@ -46,6 +52,7 @@ type CreateChannelInput = record {
4652
paid : nat64;
4753
description : text;
4854
created_by : principal;
55+
image : text;
4956
};
5057
type DefiniteCanisterSettings = record {
5158
freezing_threshold : nat;
@@ -56,6 +63,27 @@ type DefiniteCanisterSettings = record {
5663
memory_allocation : nat;
5764
compute_allocation : nat;
5865
};
66+
type GetArchivesArgs = record { from : opt principal };
67+
type GetBlocksRequest = record { start : nat; length : nat };
68+
type GetBlocksResult = record {
69+
log_length : nat;
70+
blocks : vec BlockWithId;
71+
archived_blocks : vec ArchivedBlocks;
72+
};
73+
type ICRC3ArchiveInfo = record {
74+
end : nat;
75+
canister_id : principal;
76+
start : nat;
77+
};
78+
type ICRC3DataCertificate = record { certificate : blob; hash_tree : blob };
79+
type ICRC3Value = variant {
80+
Int : int;
81+
Map : vec record { text; ICRC3Value };
82+
Nat : nat;
83+
Blob : blob;
84+
Text : text;
85+
Array : vec ICRC3Value;
86+
};
5987
type InitArgs = record { managers : vec principal; name : text };
6088
type LogVisibility = variant { controllers; public };
6189
type Price = record {
@@ -91,6 +119,7 @@ type StateInfo = record {
91119
incoming_total : nat;
92120
channel_canisters : vec principal;
93121
};
122+
type SupportedBlockType = record { url : text; block_type : text };
94123
type UpdatePriceInput = record {
95124
name_l1 : opt nat64;
96125
name_l2 : opt nat64;
@@ -121,6 +150,10 @@ service : (opt ChainArgs) -> {
121150
get_canister_status : () -> (Result_4) query;
122151
get_state : () -> (Result_5) query;
123152
get_user : (opt principal) -> (Result_3) query;
153+
icrc3_get_archives : (GetArchivesArgs) -> (vec ICRC3ArchiveInfo) query;
154+
icrc3_get_blocks : (vec GetBlocksRequest) -> (GetBlocksResult) query;
155+
icrc3_get_tip_certificate : () -> (opt ICRC3DataCertificate) query;
156+
icrc3_supported_block_types : () -> (vec SupportedBlockType) query;
124157
register_username : (text) -> (Result_3);
125158
save_channel_kek : (ChannelKEKInput) -> (Result);
126159
search_username : (text) -> (Result_6) query;

src/ic_message/src/api_query.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ use candid::Principal;
22
use ic_cdk::api::management_canister::main::{
33
canister_status, CanisterIdRecord, CanisterStatusResponse,
44
};
5-
use ic_cose_types::format_error;
5+
use ic_cose_types::{format_error, to_cbor_bytes};
66
use ic_message_types::profile::UserInfo;
7+
use icrc_ledger_types::icrc3::{
8+
archive::{GetArchivesArgs, GetArchivesResult},
9+
blocks::{GetBlocksRequest, GetBlocksResult, ICRC3DataCertificate, SupportedBlockType},
10+
};
11+
use serde_bytes::ByteBuf;
712
use std::collections::BTreeSet;
813

914
use crate::{is_authenticated, store, types};
@@ -36,6 +41,35 @@ async fn get_canister_status() -> Result<CanisterStatusResponse, String> {
3641
Ok(res)
3742
}
3843

44+
#[ic_cdk::query]
45+
pub fn icrc3_supported_block_types() -> Vec<SupportedBlockType> {
46+
vec![SupportedBlockType {
47+
block_type: "ic-message".to_string(),
48+
url: "https://github.com/ldclabs/ic-panda/tree/main/src/ic_message".to_string(),
49+
}]
50+
}
51+
52+
#[ic_cdk::query]
53+
pub fn icrc3_get_tip_certificate() -> Option<ICRC3DataCertificate> {
54+
let certificate = ByteBuf::from(ic_cdk::api::data_certificate()?);
55+
let hash_tree = store::state::with(|s| s.hash_tree());
56+
let buf = to_cbor_bytes(&hash_tree);
57+
Some(ICRC3DataCertificate {
58+
certificate,
59+
hash_tree: ByteBuf::from(buf),
60+
})
61+
}
62+
63+
#[ic_cdk::query]
64+
pub fn icrc3_get_archives(_args: GetArchivesArgs) -> GetArchivesResult {
65+
vec![] // TODO: implement
66+
}
67+
68+
#[ic_cdk::query]
69+
pub fn icrc3_get_blocks(args: Vec<GetBlocksRequest>) -> GetBlocksResult {
70+
store::user::get_blocks(args)
71+
}
72+
3973
#[ic_cdk::query]
4074
fn search_username(prefix: String) -> Result<Vec<String>, String> {
4175
Ok(store::user::search_username(prefix))

src/ic_message/src/api_update.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ic_cose_types::validate_key;
1+
use ic_cose_types::{validate_key, MILLISECONDS};
22
use ic_message_types::{
33
channel::{ChannelInfo, ChannelKEKInput, CreateChannelInput},
44
profile::UserInfo,
@@ -18,7 +18,8 @@ async fn register_username(username: String) -> Result<UserInfo, String> {
1818
}
1919

2020
let caller = ic_cdk::caller();
21-
store::user::register_username(caller, username).await
21+
let now_ms = ic_cdk::api::time() / MILLISECONDS;
22+
store::user::register_username(caller, username, now_ms).await
2223
}
2324

2425
#[ic_cdk::update(guard = "is_authenticated")]

src/ic_message/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use ic_message_types::{
66
channel::{ChannelInfo, CreateChannelInput},
77
profile::UserInfo,
88
};
9+
use icrc_ledger_types::icrc3::{
10+
archive::{GetArchivesArgs, GetArchivesResult},
11+
blocks::{GetBlocksRequest, GetBlocksResult, ICRC3DataCertificate, SupportedBlockType},
12+
};
913
use icrc_ledger_types::{
1014
icrc1::{
1115
account::Account,

0 commit comments

Comments
 (0)