-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat introduced icp nonces for context contract #1031
Open
alenmestrov
wants to merge
28
commits into
feat--add-near-calls-nonce
Choose a base branch
from
feat--icp-nonces
base: feat--add-near-calls-nonce
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
945be8f
fix: remove timestamp from contracts
frdomovic bbd07ee
fix: tests 2
frdomovic 964fa46
fix: removed prints in mock contract, optimized proxy contract deploy…
alenmestrov 9bbc038
feat: introduced nonces in icp context contract
alenmestrov 545b72d
fix: lint
alenmestrov 39e5c26
fix: check the transfer result before doing cross contract call
alenmestrov 2fa86ac
fix: resolved PR comments
alenmestrov d3d22a7
fix:lint
alenmestrov fcd5b3a
fix: reverted back grouping of members and nonces
alenmestrov 14db1bb
fix: lint
alenmestrov bc99546
fix: resolved PR comments
alenmestrov 244aab0
simplify nonce validation
miraclx 0182e26
prevent spurious proxy deployment for existing context
miraclx 647192c
pulled latest changes
alenmestrov f440214
fix: removed mock_ledger from Cargo
alenmestrov dcac961
fix: lint
alenmestrov d73e5e5
merged feat--add-near-calls-nonce
alenmestrov af88a83
fix: removed mock_ledger build process
alenmestrov ba80769
feat: added automated script for devnet deployment
alenmestrov a5f839d
fix: resolved issue with NEAR nonce
alenmestrov 42a9528
feat: added container_ids.json file to gitignore
alenmestrov df5b56f
fix: check if canister_ids.json file exists before trying to delete it
alenmestrov 84ff731
fix: fixed getting proxy contract wasm content
alenmestrov f99d909
fix: fixed fetching nonce encoding
alenmestrov 95d0d1d
fix: updated script for devnet deployment, adjusted initial context c…
alenmestrov 5fb103d
feat: implemented endpoint for fetching proxy contract ID
alenmestrov 5ee39c9
fix: lint
alenmestrov 8912db4
fix: cleaned deployment script and created test recipient account
alenmestrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ dist/ | |
pocket-ic | ||
|
||
!**/res/*.did | ||
**/canister_ids.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,125 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Build the contract | ||
./build.sh | ||
# Function to generate a new identity and return its principal | ||
generate_identity() { | ||
local name=$1 | ||
dfx identity new "$name" --storage-mode=plaintext || true | ||
dfx identity use "$name" | ||
dfx identity get-principal | ||
} | ||
|
||
# Function to get account ID from principal | ||
get_account_id() { | ||
local principal=$1 | ||
dfx ledger account-id --of-principal "$principal" | ||
} | ||
|
||
# Generate minting account | ||
dfx identity new minting --storage-mode=plaintext || true | ||
dfx identity use minting | ||
MINTING_PRINCIPAL=$(dfx identity get-principal) | ||
MINTING_ACCOUNT=$(get_account_id "$MINTING_PRINCIPAL") | ||
|
||
# Generate initial account | ||
dfx identity new initial --storage-mode=plaintext || true | ||
dfx identity use initial | ||
INITIAL_PRINCIPAL=$(dfx identity get-principal) | ||
INITIAL_ACCOUNT=$(get_account_id "$INITIAL_PRINCIPAL") | ||
|
||
# Generate archive controller account | ||
dfx identity new archive --storage-mode=plaintext || true | ||
dfx identity use archive | ||
ARCHIVE_PRINCIPAL=$(dfx identity get-principal) | ||
|
||
# Stop the replica | ||
# Switch back to default identity | ||
dfx identity use default | ||
|
||
# Stop dfx and clean up all state | ||
dfx stop | ||
rm -rf .dfx | ||
rm -rf ~/.config/dfx/replica-configuration/ | ||
rm -rf ~/.cache/dfinity/ | ||
# Remove canister_ids.json if it exists | ||
if [ -f "canister_ids.json" ]; then | ||
rm canister_ids.json | ||
fi | ||
|
||
# Start dfx with clean state | ||
dfx start --clean --background | ||
|
||
# Define canister IDs | ||
CONTEXT_ID="br5f7-7uaaa-aaaaa-qaaca-cai" | ||
LEDGER_ID="be2us-64aaa-aaaaa-qaabq-cai" | ||
|
||
# Create canisters | ||
echo "Creating canisters..." | ||
dfx canister create context_contract --specified-id "$CONTEXT_ID" | ||
dfx canister create ledger --specified-id "$LEDGER_ID" | ||
|
||
# Build contracts | ||
echo "Building contracts..." | ||
cd "$(dirname $0)" | ||
./build.sh | ||
cd ../context-proxy | ||
./build.sh | ||
cd ../context-config | ||
|
||
# Prepare ledger initialization argument | ||
LEDGER_INIT_ARG="(variant { Init = record { | ||
minting_account = \"${MINTING_ACCOUNT}\"; | ||
initial_values = vec { | ||
record { \"${INITIAL_ACCOUNT}\"; record { e8s = 100_000_000_000 } } | ||
}; | ||
send_whitelist = vec {}; | ||
transfer_fee = opt record { e8s = 10_000 }; | ||
token_symbol = opt \"LICP\"; | ||
token_name = opt \"Local Internet Computer Protocol Token\"; | ||
archive_options = opt record { | ||
trigger_threshold = 2000; | ||
num_blocks_to_archive = 1000; | ||
controller_id = principal \"${ARCHIVE_PRINCIPAL}\" | ||
}; | ||
} })" | ||
|
||
# Build and install canisters | ||
dfx build | ||
dfx canister install context_contract --mode=install | ||
dfx canister install ledger --mode=install --argument "$LEDGER_INIT_ARG" | ||
|
||
# Get the directory where the script is located | ||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
|
||
# Build path relative to the script location | ||
WASM_FILE="${SCRIPT_DIR}/../context-proxy/res/calimero_context_proxy_icp.wasm" | ||
|
||
# Verify file exists | ||
if [ ! -f "$WASM_FILE" ]; then | ||
echo "Error: WASM file not found at: $WASM_FILE" | ||
exit 1 | ||
fi | ||
|
||
# Then modify the script to use a consistent reading method | ||
WASM_CONTENTS=$(xxd -p "$WASM_FILE" | tr -d '\n' | sed 's/\(..\)/\\\1/g') | ||
|
||
TEMP_CMD=$(mktemp) | ||
echo "( | ||
blob \"${WASM_CONTENTS}\", | ||
principal \"${LEDGER_ID}\" | ||
)" > "$TEMP_CMD" | ||
|
||
# Execute the command using the temporary file | ||
dfx canister call context_contract set_proxy_code --argument-file "$TEMP_CMD" | ||
|
||
# Start the replica | ||
dfx start --background | ||
# Clean up | ||
rm "$TEMP_CMD" | ||
|
||
# Deploy the contract | ||
dfx deploy | ||
# Print all relevant information at the end | ||
echo -e "\n=== Deployment Summary ===" | ||
echo "Context Contract ID: ${CONTEXT_ID}" | ||
echo "Ledger Contract ID: ${LEDGER_ID}" | ||
echo -e "\nAccount Information:" | ||
echo "Minting Account: ${MINTING_ACCOUNT}" | ||
echo "Initial Account: ${INITIAL_ACCOUNT}" | ||
echo "Archive Principal: ${ARCHIVE_PRINCIPAL}" | ||
echo -e "\nDeployment completed successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ crate-type = ["cdylib"] | |
candid = "0.10" | ||
ic-cdk = "0.16" | ||
ic-cdk-macros = "0.16" | ||
ic-ledger-types = "0.14.0" |
7 changes: 6 additions & 1 deletion
7
contracts/icp/context-proxy/mock/external/res/calimero_mock_external_icp.did
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
service : { get_calls : () -> (vec blob) query; test_method : (blob) -> (blob) } | ||
service : (principal) -> { | ||
clear_state : () -> (); | ||
get_calls : () -> (vec blob) query; | ||
test_method : (blob) -> (blob); | ||
test_method_no_transfer : (blob) -> (blob); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,76 @@ | ||
use std::cell::RefCell; | ||
|
||
use candid::Principal; | ||
use ic_ledger_types::{AccountIdentifier, Memo, Subaccount, Tokens, TransferArgs, TransferError}; | ||
|
||
thread_local! { | ||
static CALLS: RefCell<Vec<Vec<u8>>> = RefCell::new(Vec::new()); | ||
static LEDGER_ID: RefCell<Option<Principal>> = RefCell::new(None); | ||
} | ||
|
||
#[ic_cdk::init] | ||
fn init(ledger_id: Principal) { | ||
LEDGER_ID.with(|id| { | ||
*id.borrow_mut() = Some(ledger_id); | ||
}); | ||
} | ||
|
||
#[ic_cdk::update] | ||
fn test_method(args: Vec<u8>) -> Vec<u8> { | ||
async fn test_method(args: Vec<u8>) -> Vec<u8> { | ||
let self_id = ic_cdk::id(); | ||
let caller = ic_cdk::caller(); | ||
|
||
let ledger_id = LEDGER_ID.with(|id| id.borrow().expect("Ledger ID not initialized")); | ||
|
||
// Prepare transfer args to move the approved tokens | ||
let transfer_args = TransferArgs { | ||
memo: Memo(0), | ||
amount: Tokens::from_e8s(100_000_000), // Example amount, in practice this would be parsed from args | ||
fee: Tokens::from_e8s(10_000), | ||
from_subaccount: Some(Subaccount::from(caller)), | ||
to: AccountIdentifier::new(&self_id, &Subaccount([0; 32])), | ||
created_at_time: None, | ||
}; | ||
|
||
// Execute the transfer with proper type annotations | ||
let transfer_result: Result<(Result<u64, TransferError>,), _> = | ||
ic_cdk::call(ledger_id, "transfer", (transfer_args,)).await; | ||
|
||
match transfer_result { | ||
Ok((Ok(_block_height),)) => { | ||
// Transfer successful, record the call | ||
CALLS.with(|calls| { | ||
calls.borrow_mut().push(args.clone()); | ||
}); | ||
args // Return the same args back | ||
} | ||
Ok((Err(transfer_error),)) => { | ||
ic_cdk::trap(&format!("Transfer failed: {:?}", transfer_error)); | ||
} | ||
Err(e) => { | ||
ic_cdk::trap(&format!("Call to ledger failed: {:?}", e)); | ||
} | ||
} | ||
} | ||
|
||
#[ic_cdk::update] | ||
async fn test_method_no_transfer(args: Vec<u8>) -> Vec<u8> { | ||
// Simply record the call and return | ||
CALLS.with(|calls| { | ||
calls.borrow_mut().push(args.clone()); | ||
args // Return the same args back | ||
}) | ||
}); | ||
args | ||
} | ||
|
||
#[ic_cdk::query] | ||
fn get_calls() -> Vec<Vec<u8>> { | ||
CALLS.with(|calls| calls.borrow().clone()) | ||
} | ||
|
||
// Clear state (useful for testing) | ||
#[ic_cdk::update] | ||
fn clear_state() { | ||
CALLS.with(|calls| calls.borrow_mut().clear()); | ||
} | ||
|
||
ic_cdk::export_candid!(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
contracts/icp/context-proxy/mock/ledger/res/calimero_mock_ledger_icp.did
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
icrc2
'stransfer_from
? or does this work too