Skip to content
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: add creation of onchain notes #587

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions miden-lib/src/accounts/faucets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MAX_MAX_SUPPLY: u64 = (1 << 63) - 1;
const MAX_DECIMALS: u8 = 12;

/// Creates a new faucet account with basic fungible faucet interface,
/// specified authentication scheme, and provided meta data (token symbol, decimals, max supply).
/// specified authentication scheme, account storage type, and provided meta data (token symbol, decimals, max supply).
///
/// The basic faucet interface exposes two procedures:
/// - `distribute`, which mints an assets and create a note for the provided recipient.
Expand All @@ -36,6 +36,7 @@ pub fn create_basic_fungible_faucet(
decimals: u8,
max_supply: Felt,
auth_scheme: AuthScheme,
account_storage_type: AccountStorageType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: I would probably move account_storage_type up to be before auth_scheme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed!

) -> Result<(Account, Word), AccountError> {
// Atm we only have RpoFalcon512 as authentication scheme and this is also the default in the
// faucet contract, so we can just use the public key as storage slot 0.
Expand Down Expand Up @@ -85,7 +86,7 @@ pub fn create_basic_fungible_faucet(
let account_seed = AccountId::get_account_seed(
init_seed,
AccountType::FungibleFaucet,
AccountStorageType::OffChain,
account_storage_type,
account_code.root(),
account_storage.root(),
)?;
Expand Down
5 changes: 3 additions & 2 deletions miden-lib/src/accounts/wallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{AuthScheme, TransactionKernel};
// BASIC WALLET
// ================================================================================================

/// Creates a new account with basic wallet interface and the specified authentication scheme.
/// Creates a new account with basic wallet interface, the specified authentication scheme and the account storage type.
/// Basic wallets can be specified to have either mutable or immutable code.
///
/// The basic wallet interface exposes two procedures:
Expand All @@ -30,6 +30,7 @@ pub fn create_basic_wallet(
init_seed: [u8; 32],
auth_scheme: AuthScheme,
account_type: AccountType,
account_storage_type: AccountStorageType,
) -> Result<(Account, Word), AccountError> {
if matches!(account_type, AccountType::FungibleFaucet | AccountType::NonFungibleFaucet) {
return Err(AccountError::AccountIdInvalidFieldElement(
Expand Down Expand Up @@ -68,7 +69,7 @@ pub fn create_basic_wallet(
let account_seed = AccountId::get_account_seed(
init_seed,
account_type,
AccountStorageType::OffChain,
account_storage_type,
account_code.root(),
account_storage.root(),
)?;
Expand Down
17 changes: 12 additions & 5 deletions miden-tx/tests/integration/scripts/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use miden_lib::{
};
use miden_objects::{
accounts::{
Account, AccountCode, AccountId, AccountStorage, SlotItem, StorageSlot,
Account, AccountCode, AccountId, AccountStorage, AccountStorageType, SlotItem, StorageSlot,
ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN,
},
assembly::{ModuleAst, ProgramAst},
Expand Down Expand Up @@ -244,10 +244,17 @@ fn faucet_contract_creation() {
let token_symbol_string = "POL";
let token_symbol = TokenSymbol::try_from(token_symbol_string).unwrap();
let decimals = 2u8;

let (faucet_account, _) =
create_basic_fungible_faucet(init_seed, token_symbol, decimals, max_supply, auth_scheme)
.unwrap();
let storage_type = AccountStorageType::OffChain;

let (faucet_account, _) = create_basic_fungible_faucet(
init_seed,
token_symbol,
decimals,
max_supply,
auth_scheme,
storage_type,
)
.unwrap();

// check that max_supply (slot 1) is 123
assert_eq!(
Expand Down
8 changes: 5 additions & 3 deletions miden-tx/tests/integration/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn prove_send_asset_via_wallet() {
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn wallet_creation() {
use miden_objects::accounts::{AccountType, ACCOUNT_ID_SENDER};
use miden_objects::accounts::{AccountStorageType, AccountType, ACCOUNT_ID_SENDER};

// we need a Falcon Public Key to create the wallet account
let seed = [0_u8; 32];
Expand All @@ -207,9 +207,11 @@ fn wallet_creation() {
204, 149, 90, 166, 68, 100, 73, 106, 168, 125, 237, 138, 16,
];

let account_type = AccountType::RegularAccountImmutableCode;
let storage_type = AccountStorageType::OffChain;

let (wallet, _) =
create_basic_wallet(init_seed, auth_scheme, AccountType::RegularAccountImmutableCode)
.unwrap();
create_basic_wallet(init_seed, auth_scheme, account_type, storage_type).unwrap();

// sender_account_id not relevant here, just to create a default account code
let sender_account_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap();
Expand Down
Loading