Skip to content

Commit 966e9e6

Browse files
committed
moving files
1 parent 54ffa56 commit 966e9e6

File tree

108 files changed

+2995
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2995
-0
lines changed

src/icrc3_canisters/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ICRC-3 Rust Implementation
2+
3+
This repository contains a Rust implementation of the ICRC-3 standard for the Internet Computer (ICP). ICRC-3 defines a generic value type for interoperable token transactions and ledger interactions.
4+
5+
## Project Structure
6+
7+
### Backend canisters
8+
9+
All the backend canisters are included in the folder [`backend/canisters`](backend/canisters/). This includes
10+
11+
- [`icrc3`](backend/canisters/icrc3/): The core logic for the archive creation, blocks archiving.
12+
- [`icrc3_archive`](backend/canisters/icrc3_archive/): The archive canister that stores archived blocks.
13+
14+
## Local development instructions
15+
16+
### Clone this repository
17+
18+
```sh
19+
git clone "ADD LINK HERE"
20+
```
21+
22+
(Or from the Origyn internal Gitlab url, from which this Github repo is automatically mirrored)
23+
24+
### Install the dependencies
25+
26+
First, ensure that you have [`cargo`](https://doc.rust-lang.org/cargo/getting-started/installation.html) and [`ic-wasm`](https://github.com/dfinity/ic-wasm) installed, as well as [`wasmtime`](https://wasmtime.dev).
27+
Then from the repository's root folder:
28+
29+
```sh
30+
npm install
31+
```
32+
33+
## Technical documentation
34+
35+
- Developers documentation still :construction: WIP (See code comments for now. Documentation will be automatically generated and published at a later time)
36+
37+
## DevOps documentation
38+
39+
- :construction: WIP on Origyn's internal Gitlab wiki
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5+
6+
## Versions
7+
8+
### [unreleased]
9+
10+
### [1.0.0] - 2025-02-18
11+
12+
#### Description
13+
This marks the initial release of the archive canister, which is designed to work alongside the ICRC-3 core canister.
14+
The archive canister **stores historical transactions**, enabling scalability by allowing the ICRC-3 core canister to **spawn new archives** as needed.
15+
This architecture ensures efficient transaction storage and retrieval while maintaining performance.
16+
17+
#### Added
18+
- **Transaction Archiving**: Stores historical transactions offloaded from the core ICRC-3 canister.
19+
- **Efficient Querying**: Provides methods to retrieve stored transactions efficiently.
20+
- **Metadata Management**: Supports fetching archive metadata for monitoring and indexing.
21+
- **Data Integrity**: Ensures consistency between the core canister and its archives.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "bity-ic-icrc3-archive-api"
3+
version = "0.1.0"
4+
description = "bity icrc3 archive api"
5+
edition = "2021"
6+
license = "MIT"
7+
repository = "https://github.com/BitySA/dfinity-rust-libraries"
8+
keywords = ["dfinity", "internet-computer", "ic", "canister", "subcanister"]
9+
authors = ["Bity Team", "Gautier Wojda <[email protected]>", "Freddie Hands <[email protected]>", "Victoria Horbunova <[email protected]>", "Dustin Becker <[email protected]>"]
10+
documentation = "https://docs.rs/bity-ic-icrc3-archive-api"
11+
12+
[features]
13+
inttest = []
14+
15+
[dependencies]
16+
bity-ic-types = { workspace = true }
17+
candid = { workspace = true }
18+
icrc-ledger-types = { workspace = true }
19+
serde = { workspace = true, features = ["derive"] }
20+
serde_bytes = { workspace = true }
21+
ic-stable-structures = { workspace = true }
22+
sha2 = { workspace = true }
23+
hex = { workspace = true }
24+
serde_cbor = { workspace = true }
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
type ArchiveConfig = record {
2+
max_blocks_per_response : nat64;
3+
block_offset : nat64;
4+
max_memory_size_bytes : nat;
5+
};
6+
type ArchivedBlocks = record {
7+
args : vec GetBlocksRequest;
8+
callback : func (vec GetBlocksRequest) -> (GetBlocksResult) query;
9+
};
10+
type Args = variant { Upgrade : UpgradeArgs; Init : InitArgs };
11+
type BlockType = variant { ICRC1; Default };
12+
type BlockWithId = record { id : nat; block : ICRC3Value };
13+
type BuildVersion = record { major : nat32; minor : nat32; patch : nat32 };
14+
type GetBlocksRequest = record { start : nat; length : nat };
15+
type GetBlocksResult = record {
16+
log_length : nat;
17+
blocks : vec BlockWithId;
18+
archived_blocks : vec ArchivedBlocks;
19+
};
20+
type ICRC3Value = variant {
21+
Int : int;
22+
Map : vec record { text; ICRC3Value };
23+
Nat : nat;
24+
Blob : blob;
25+
Text : text;
26+
Array : vec ICRC3Value;
27+
};
28+
type InitArgs = record {
29+
master_canister_id : principal;
30+
test_mode : bool;
31+
block_type : BlockType;
32+
archive_config : ArchiveConfig;
33+
authorized_principals : vec principal;
34+
version : BuildVersion;
35+
commit_hash : text;
36+
};
37+
type Response = variant { Error : text; Success };
38+
type UpgradeArgs = record {
39+
block_type : BlockType;
40+
version : BuildVersion;
41+
commit_hash : text;
42+
};
43+
service : (Args) -> {
44+
get_version : (null) -> (BuildVersion) query;
45+
icrc3_get_blocks : (vec GetBlocksRequest) -> (GetBlocksResult) query;
46+
insert_blocks : (vec blob) -> (Response);
47+
remaining_capacity : (null) -> (nat) query;
48+
total_transactions : (null) -> (nat64) query;
49+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub mod lifecycle;
2+
pub mod queries;
3+
pub mod types;
4+
pub mod updates;
5+
6+
pub use lifecycle::*;
7+
pub use queries::*;
8+
pub use types::*;
9+
pub use updates::*;
10+
11+
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::archive_config::ArchiveConfig;
2+
use crate::lifecycle::BlockType;
3+
4+
use bity_ic_types::BuildVersion;
5+
use candid::{CandidType, Principal};
6+
use serde::{Deserialize, Serialize};
7+
8+
#[derive(Deserialize, Serialize, CandidType, Debug, Clone)]
9+
pub struct InitArgs {
10+
pub test_mode: bool,
11+
pub version: BuildVersion,
12+
pub commit_hash: String,
13+
pub authorized_principals: Vec<Principal>,
14+
pub archive_config: ArchiveConfig,
15+
pub master_canister_id: Principal,
16+
pub block_type: BlockType,
17+
}
18+
19+
impl Default for InitArgs {
20+
fn default() -> Self {
21+
Self {
22+
test_mode: false,
23+
version: BuildVersion::default(),
24+
commit_hash: String::new(),
25+
authorized_principals: Vec::new(),
26+
archive_config: ArchiveConfig::default(),
27+
master_canister_id: Principal::anonymous(),
28+
block_type: BlockType::Default,
29+
}
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use candid::CandidType;
2+
use init::InitArgs;
3+
use post_upgrade::UpgradeArgs;
4+
use serde::{Deserialize, Serialize};
5+
6+
pub mod init;
7+
pub mod post_upgrade;
8+
9+
#[derive(Deserialize, Serialize, CandidType, Debug, Clone)]
10+
pub enum BlockType {
11+
Default,
12+
ICRC1,
13+
// TODO: add other block types
14+
}
15+
16+
#[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
17+
pub enum Args {
18+
Init(InitArgs),
19+
Upgrade(UpgradeArgs),
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use bity_ic_types::BuildVersion;
2+
use candid::CandidType;
3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::lifecycle::BlockType;
6+
7+
#[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
8+
pub struct UpgradeArgs {
9+
pub version: BuildVersion,
10+
pub commit_hash: String,
11+
pub block_type: BlockType,
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use bity_ic_types::BuildVersion;
2+
3+
pub type Args = ();
4+
pub type Response = BuildVersion;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use icrc_ledger_types::icrc3::blocks::{GetBlocksRequest, GetBlocksResult};
2+
3+
pub type Args = Vec<GetBlocksRequest>;
4+
pub type Response = GetBlocksResult;

0 commit comments

Comments
 (0)