Skip to content

Commit a30d4c9

Browse files
committed
publish new package with encoded icrc3 with minicbor
1 parent 583dc9e commit a30d4c9

File tree

13 files changed

+59
-41
lines changed

13 files changed

+59
-41
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ time = { version = "0.3.36", features = [
7373
async-trait = "0.1.86"
7474
enum_dispatch = "0.3.13"
7575
typetag = "0.2.18"
76-
minicbor = { version = "0.25.1", features = ["alloc", "derive"] }
76+
minicbor = { version = "1.0.0", features = ["alloc", "derive"] }
7777
canfund = "0.8.2"
7878
ic-asset-certification = "3.0.3"
7979
ic-http-certification = "3.0.3"
@@ -95,6 +95,6 @@ bity-ic-stable-memory = "0.1.0"
9595
bity-ic-types = "0.1.0"
9696
bity-ic-utils = "0.1.0"
9797
bity-ic-subcanister-manager = "0.2.4"
98-
bity-ic-icrc3-archive-api = "0.1.0"
99-
bity-ic-icrc3-archive-c2c-client = "0.1.0"
100-
bity-ic-icrc3 = "0.1.5"
98+
bity-ic-icrc3-archive-api = "0.2.0"
99+
bity-ic-icrc3-archive-c2c-client = "0.2.0"
100+
bity-ic-icrc3 = "0.2.4"

src/icrc3/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bity-ic-icrc3"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
edition = "2021"
55
license = "MIT"
66
description = "bity icrc3 library"
@@ -24,7 +24,6 @@ serde_cbor = { workspace = true }
2424
canfund = { workspace = true }
2525
ic-certification = { workspace = true }
2626
leb128 = { workspace = true }
27-
minicbor = { workspace = true }
2827
ic-stable-structures = { workspace = true }
2928
syn = { workspace = true }
3029
ic0 = { workspace = true }

src/icrc3/src/blockchain/archive_canister.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl ArchiveCanister {
4343
}
4444

4545
let res = retry_async(
46-
|| bity_ic_icrc3_archive_c2c_client::insert_blocks(self.canister_id(), &blocks),
46+
|| bity_ic_icrc3_archive_c2c_client::insert_blocks(self.canister_id(), blocks.clone()),
4747
3,
4848
)
4949
.await;
10.2 KB
Binary file not shown.

src/icrc3_canisters/canisters/icrc3_archive/api/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bity-ic-icrc3-archive-api"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "bity icrc3 archive api"
55
edition = "2021"
66
license = "MIT"
@@ -21,4 +21,5 @@ serde_bytes = { workspace = true }
2121
ic-stable-structures = { workspace = true }
2222
sha2 = { workspace = true }
2323
hex = { workspace = true }
24-
serde_cbor = { workspace = true }
24+
serde_cbor = { workspace = true }
25+
minicbor = { workspace = true }

src/icrc3_canisters/canisters/icrc3_archive/api/can.did

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Args = variant { Upgrade : UpgradeArgs; Init : InitArgs };
1111
type BlockType = variant { ICRC1; Default };
1212
type BlockWithId = record { id : nat; block : ICRC3Value };
1313
type BuildVersion = record { major : nat32; minor : nat32; patch : nat32 };
14+
type EncodedBlock = record { block : blob };
1415
type GetBlocksRequest = record { start : nat; length : nat };
1516
type GetBlocksResult = record {
1617
log_length : nat;
@@ -43,7 +44,7 @@ type UpgradeArgs = record {
4344
service : (Args) -> {
4445
get_version : (null) -> (BuildVersion) query;
4546
icrc3_get_blocks : (vec GetBlocksRequest) -> (GetBlocksResult) query;
46-
insert_blocks : (vec blob) -> (Response);
47+
insert_blocks : (vec EncodedBlock) -> (Response);
4748
remaining_capacity : (null) -> (nat) query;
4849
total_transactions : (null) -> (nat64) query;
4950
}

src/icrc3_canisters/canisters/icrc3_archive/api/src/types/defaultblock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ impl Block for DefaultBlock {
6262

6363
fn block_hash(encoded: &EncodedBlock) -> HashOf<EncodedBlock> {
6464
let mut state = sha256::Sha256::new();
65-
state.write(&serde_cbor::ser::to_vec_packed(encoded).unwrap());
65+
let mut buffer = Vec::new();
66+
minicbor::encode(encoded, &mut buffer).expect("failed to encode EncodedBlock");
67+
state.write(&buffer);
6668
HashOf::new(state.finish())
6769
}
6870

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
use candid::CandidType;
22
use ic_stable_structures::{storable::Bound, Storable};
3+
use minicbor::{Decode, Encode};
34
use serde::{Deserialize, Serialize};
4-
use serde_bytes::ByteBuf;
55
use std::borrow::Cow;
66

77
#[derive(
8-
Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, CandidType, Deserialize, Serialize,
8+
Clone,
9+
Eq,
10+
PartialEq,
11+
Ord,
12+
PartialOrd,
13+
Hash,
14+
Debug,
15+
Encode,
16+
Decode,
17+
CandidType,
18+
Serialize,
19+
Deserialize,
920
)]
10-
#[serde(transparent)]
11-
pub struct EncodedBlock(pub ByteBuf);
12-
21+
#[cbor(map)]
22+
pub struct EncodedBlock {
23+
#[n(0)]
24+
pub block: Vec<u8>,
25+
}
1326
impl Storable for EncodedBlock {
1427
fn to_bytes(&self) -> Cow<[u8]> {
15-
Cow::Borrowed(self.0.as_slice())
28+
let mut buffer = Vec::new();
29+
minicbor::encode(self, &mut buffer).expect("failed to encode EncodedBlock");
30+
Cow::Owned(buffer)
1631
}
1732

1833
fn from_bytes(bytes: Cow<[u8]>) -> Self {
19-
Self(ByteBuf::from(bytes.into_owned()))
34+
minicbor::decode(&bytes).expect("failed to decode EncodedBlock")
2035
}
2136

2237
const BOUND: Bound = Bound::Unbounded;
@@ -30,18 +45,18 @@ impl From<Vec<u8>> for EncodedBlock {
3045

3146
impl EncodedBlock {
3247
pub fn from_vec(bytes: Vec<u8>) -> Self {
33-
Self(ByteBuf::from(bytes))
48+
Self { block: bytes }
3449
}
3550

3651
pub fn into_vec(self) -> Vec<u8> {
37-
self.0.to_vec()
52+
self.block
3853
}
3954

4055
pub fn as_slice(&self) -> &[u8] {
41-
&self.0
56+
&self.block
4257
}
4358

4459
pub fn size_bytes(&self) -> usize {
45-
self.0.len()
60+
self.block.len()
4661
}
4762
}

src/icrc3_canisters/canisters/icrc3_archive/c2c_client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ bity-ic-canister-client = { workspace = true }
1616
bity-ic-icrc3-archive-api = { workspace = true }
1717
ic-cdk = { workspace = true }
1818
candid = { workspace = true }
19-
bity-ic-types = { workspace = true }
19+
bity-ic-types = { workspace = true }

0 commit comments

Comments
 (0)