Skip to content

Commit 8d434f5

Browse files
committed
update icrc3
1 parent 597e351 commit 8d434f5

File tree

8 files changed

+45
-4
lines changed

8 files changed

+45
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/icrc3/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bity-ic-icrc3"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
license = "MIT"
66
description = "bity icrc3 library"

src/icrc3/src/config.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ pub struct ICRC3Properties {
6666
pub max_transactions_to_purge: u128,
6767
}
6868

69+
impl ICRC3Properties {
70+
pub fn new(
71+
tx_window: Duration,
72+
max_transactions_in_window: u128,
73+
max_memory_size_bytes: u128,
74+
max_blocks_per_response: u128,
75+
initial_cycles: u128,
76+
reserved_cycles: u128,
77+
max_transactions_to_purge: u128,
78+
) -> Self {
79+
Self {
80+
tx_window,
81+
max_transactions_in_window,
82+
max_memory_size_bytes,
83+
max_blocks_per_response,
84+
initial_cycles,
85+
reserved_cycles,
86+
max_transactions_to_purge,
87+
}
88+
}
89+
}
90+
6991
impl Default for ICRC3Properties {
7092
fn default() -> Self {
7193
ICRC3Properties {

src/icrc3/src/interface.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ impl<T: TransactionType> ICRC3Interface<T> for ICRC3 {
134134
}
135135
};
136136

137+
if !self
138+
.icrc3_config
139+
.supported_blocks
140+
.iter()
141+
.any(|b| b.block_type == transaction.block_type())
142+
{
143+
return Err(Icrc3Error::Icrc3Error("Unsupported block type".to_string()));
144+
}
145+
137146
let transaction_hash = transaction.hash();
138147

139148
checked_transaction = ICRC3Value::Map(match checked_transaction {

src/icrc3/src/transaction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub trait TransactionType: Sized + Clone + Into<ICRC3Value> {
5757

5858
/// Computes and returns the hash of the transaction.
5959
fn hash(&self) -> Hash;
60+
61+
fn block_type(&self) -> String;
6062
}
6163

6264
/// Enum representing different kinds of transactions supported by the system.

src/icrc3_canisters/canisters/icrc3_example/impl/src/state.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl FakeTransaction {
110110
let now = ic_cdk::api::time();
111111
Self {
112112
phash: format!("phash_{}", now),
113-
btype: format!("btype_{}", now),
113+
btype: "btype_test".to_string(),
114114
timestamp: now,
115115
sender: Principal::anonymous(),
116116
recipient: Principal::anonymous(),
@@ -136,6 +136,10 @@ impl TransactionType for FakeTransaction {
136136
hasher.update(self.recipient.as_slice());
137137
hasher.finalize().into()
138138
}
139+
140+
fn block_type(&self) -> String {
141+
self.btype.clone()
142+
}
139143
}
140144

141145
impl From<FakeTransaction> for ICRC3Value {

src/icrc3_canisters/integration_testing/src/icrc3_suite/setup/setup.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bity_ic_icrc3::config::{ICRC3Config, ICRC3Properties};
44
use bity_ic_types::{BuildVersion, CanisterId};
55
use candid::Principal;
66
use icrc3_example_api::Args;
7+
use icrc_ledger_types::icrc3::blocks::SupportedBlockType;
78
use pocket_ic::{PocketIc, PocketIcBuilder};
89
use std::time::Duration;
910

@@ -61,7 +62,10 @@ impl TestEnvBuilder {
6162
commit_hash: "".to_string(),
6263
authorized_principals: vec![self.controller],
6364
icrc3_config: ICRC3Config {
64-
supported_blocks: vec![],
65+
supported_blocks: vec![SupportedBlockType {
66+
block_type: "btype_test".to_string(),
67+
url: "https://github.com/dfinity/ICRC/blob/main/ICRCs/ICRC-3/README.md#supported-block-types".to_string(),
68+
}],
6569
constants,
6670
},
6771
});
-1.87 KB
Binary file not shown.

0 commit comments

Comments
 (0)