Skip to content

Commit 4ce42ad

Browse files
committed
update
1 parent b4880e9 commit 4ce42ad

File tree

14 files changed

+337
-23
lines changed

14 files changed

+337
-23
lines changed

Cargo.lock

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

src/canister_client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ tracing = { workspace = true }
1818
anyhow = { workspace = true }
1919

2020
bity-ic-types = "0.1.2"
21+
22+
# bity-ic-types = { path = "../types" }

src/icrc3/src/interface.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ impl ICRC3Interface for ICRC3 {
207207
}
208208
};
209209

210+
trace(format!(
211+
"checked_transaction as ICRC3Value: {:?}",
212+
transaction.tx()
213+
));
214+
210215
if !self
211216
.icrc3_config
212217
.supported_blocks
@@ -220,14 +225,14 @@ impl ICRC3Interface for ICRC3 {
220225

221226
// Check if transaction already exists in ledger
222227
for (i, existing_tx) in self.ledger.iter().enumerate() {
223-
if let ICRC3Value::Map(ref existing_map) = existing_tx {
224-
if let Some(tx) = existing_map.get("tx") {
225-
if tx.clone().hash().as_slice() == transaction_hash.as_slice() {
226-
return Err(Icrc3Error::DuplicateTransaction {
227-
duplicate_of: self.next_index - i as u64 - 1,
228-
});
229-
}
230-
}
228+
let mut existing_tx_clone = existing_tx.clone();
229+
if let ICRC3Value::Map(ref mut existing_map) = existing_tx_clone {
230+
existing_map.remove("phash");
231+
}
232+
if existing_tx_clone.clone().hash().as_slice() == transaction_hash.as_slice() {
233+
return Err(Icrc3Error::DuplicateTransaction {
234+
duplicate_of: self.next_index - i as u64 - 1,
235+
});
231236
}
232237
}
233238
self.ledger.push_back(checked_transaction.clone());
@@ -313,14 +318,14 @@ impl ICRC3Interface for ICRC3 {
313318

314319
// Check if transaction already exists in ledger
315320
for (i, existing_tx) in self.ledger.iter().enumerate() {
316-
if let ICRC3Value::Map(ref existing_map) = existing_tx {
317-
if let Some(tx) = existing_map.get("tx") {
318-
if tx.clone().hash().as_slice() == transaction_hash.as_slice() {
319-
return Err(Icrc3Error::DuplicateTransaction {
320-
duplicate_of: self.next_index - i as u64 - 1,
321-
});
322-
}
323-
}
321+
let mut existing_tx_clone = existing_tx.clone();
322+
if let ICRC3Value::Map(ref mut existing_map) = existing_tx_clone {
323+
existing_map.remove("phash");
324+
}
325+
if existing_tx_clone.clone().hash().as_slice() == transaction_hash.as_slice() {
326+
return Err(Icrc3Error::DuplicateTransaction {
327+
duplicate_of: self.next_index - i as u64 - 1,
328+
});
324329
}
325330
}
326331

@@ -345,7 +350,7 @@ impl ICRC3Interface for ICRC3 {
345350

346351
let basic_transaction = GlobalTransaction::new(transaction_as_icrc3);
347352

348-
let mut icrc3_transaction = ICRC3Value::from(basic_transaction);
353+
let icrc3_transaction = ICRC3Value::from(basic_transaction);
349354

350355
let transaction_hash = transaction.tx().hash().to_vec();
351356

@@ -371,12 +376,13 @@ impl ICRC3Interface for ICRC3 {
371376
));
372377
}
373378

374-
self.last_phash = Some(ByteBuf::from(icrc3_transaction.clone().hash().to_vec()));
375-
376379
// Add block to blockchain
377380
let block =
378381
DefaultBlock::from_transaction(self.blockchain.last_hash, icrc3_transaction, timestamp);
379382

383+
let block_hash = DefaultBlock::block_hash(&block.clone().encode());
384+
self.last_phash = Some(ByteBuf::from(block_hash.into_bytes()));
385+
380386
return match self.blockchain.add_block(block) {
381387
Ok(index) => {
382388
self.next_index = index + 1;
-333 Bytes
Binary file not shown.

src/icrc3_archive_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ serde_cbor = { workspace = true }
2424
minicbor = { workspace = true }
2525

2626
bity-ic-types = "0.1.2"
27+
2728
# bity-ic-types = { path = "../types" }

src/icrc3_canisters/canisters/icrc3_example/impl/src/updates/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod prepare_transaction;
77

88
pub use add_created_transaction::*;
99
pub use add_random_transaction::*;
10-
pub use add_same_transactions::*;
10+
// pub use add_same_transactions::*;
1111
pub use add_transactions_with_async::*;
1212
pub use commit_prepared_transaction::*;
1313
pub use prepare_transaction::*;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::borrow::Cow;
33
pub fn trace<'a>(msg: impl Into<Cow<'a, str>>) {
44
let msg: Cow<'a, str> = msg.into();
55

6-
unsafe {
7-
ic0::debug_print(msg.as_bytes());
8-
}
6+
ic0::debug_print(msg.as_bytes());
97
ic_cdk::println!("{}", msg);
108
}

src/icrc3_canisters/integration_testing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ lazy_static = "1.4.0"
1313
# icrc3_index_api = { path = "../canisters/icrc3_index/api" }
1414
serde_bytes = { workspace = true}
1515
icrc-ledger-types = { workspace = true }
16+
hex = { workspace = true }
1617

1718
arbitrary = { version = "1.4.1", features = ["derive"] }
1819

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod test_insert_transaction;
22
pub mod test_migration;
33
pub mod test_predefined_blocks;
4+
pub mod test_icrc3_hashing;

0 commit comments

Comments
 (0)