feat: Support incremental mode:
- Support incremental mode in heromodels - Updated the example to refelct the changes - Updated the tests to reflect the changes
This commit is contained in:
@@ -10,9 +10,9 @@ fn main() {
|
||||
// --- PART 1: ACCOUNTS AND ASSETS ---
|
||||
println!("=== ACCOUNTS AND ASSETS ===\n");
|
||||
|
||||
// Create a new account
|
||||
// Create a new account with auto-generated ID
|
||||
let mut account = Account::new(
|
||||
1, // id
|
||||
None, // id (auto-generated)
|
||||
"Main ETH Wallet", // name
|
||||
1001, // user_id
|
||||
"My primary Ethereum wallet", // description
|
||||
@@ -28,8 +28,9 @@ fn main() {
|
||||
println!("");
|
||||
|
||||
// Create some assets
|
||||
// Asset with auto-generated ID
|
||||
let eth_asset = Asset::new(
|
||||
101, // id
|
||||
None, // id (auto-generated)
|
||||
"Ethereum", // name
|
||||
"Native ETH cryptocurrency", // description
|
||||
1.5, // amount
|
||||
@@ -38,8 +39,9 @@ fn main() {
|
||||
18, // decimals
|
||||
);
|
||||
|
||||
// Assets with explicit IDs
|
||||
let usdc_asset = Asset::new(
|
||||
102, // id
|
||||
Some(102), // id
|
||||
"USDC", // name
|
||||
"USD Stablecoin on Ethereum", // description
|
||||
1000.0, // amount
|
||||
@@ -49,7 +51,7 @@ fn main() {
|
||||
);
|
||||
|
||||
let nft_asset = Asset::new(
|
||||
103, // id
|
||||
Some(103), // id
|
||||
"CryptoPunk #1234", // name
|
||||
"Rare digital collectible", // description
|
||||
1.0, // amount
|
||||
@@ -95,9 +97,9 @@ fn main() {
|
||||
// --- PART 2: MARKETPLACE LISTINGS ---
|
||||
println!("\n=== MARKETPLACE LISTINGS ===\n");
|
||||
|
||||
// Create a fixed price listing
|
||||
// Create a fixed price listing with auto-generated ID
|
||||
let mut fixed_price_listing = Listing::new(
|
||||
201, // id
|
||||
None, // id (auto-generated)
|
||||
"1000 USDC for Sale", // title
|
||||
"Selling 1000 USDC tokens at fixed price", // description
|
||||
"102", // asset_id (referencing the USDC asset)
|
||||
@@ -131,9 +133,9 @@ fn main() {
|
||||
Err(e) => println!("Error completing sale: {}", e),
|
||||
}
|
||||
|
||||
// Create an auction listing for the NFT
|
||||
// Create an auction listing for the NFT with explicit ID
|
||||
let mut auction_listing = Listing::new(
|
||||
202, // id
|
||||
Some(202), // id (explicit)
|
||||
"CryptoPunk #1234 Auction", // title
|
||||
"Rare CryptoPunk NFT for auction", // description
|
||||
"103", // asset_id (referencing the NFT asset)
|
||||
@@ -176,7 +178,7 @@ fn main() {
|
||||
|
||||
// Add bids to the auction
|
||||
println!("Adding Bids to Auction:");
|
||||
|
||||
|
||||
// Using clone() to avoid ownership issues with match expressions
|
||||
match auction_listing.clone().add_bid(bid1) {
|
||||
Ok(updated_listing) => {
|
||||
@@ -185,7 +187,7 @@ fn main() {
|
||||
},
|
||||
Err(e) => println!("Error adding bid: {}", e),
|
||||
}
|
||||
|
||||
|
||||
match auction_listing.clone().add_bid(bid2) {
|
||||
Ok(updated_listing) => {
|
||||
auction_listing = updated_listing;
|
||||
@@ -193,7 +195,7 @@ fn main() {
|
||||
},
|
||||
Err(e) => println!("Error adding bid: {}", e),
|
||||
}
|
||||
|
||||
|
||||
match auction_listing.clone().add_bid(bid3) {
|
||||
Ok(updated_listing) => {
|
||||
auction_listing = updated_listing;
|
||||
@@ -204,14 +206,14 @@ fn main() {
|
||||
|
||||
println!("\nCurrent Auction Status:");
|
||||
println!("Current Price: {} {}", auction_listing.price, auction_listing.currency);
|
||||
|
||||
|
||||
if let Some(highest_bid) = auction_listing.highest_bid() {
|
||||
println!("Highest Bid: {} {} from User {}",
|
||||
highest_bid.amount,
|
||||
highest_bid.currency,
|
||||
println!("Highest Bid: {} {} from User {}",
|
||||
highest_bid.amount,
|
||||
highest_bid.currency,
|
||||
highest_bid.bidder_id);
|
||||
}
|
||||
|
||||
|
||||
println!("Total Bids: {}", auction_listing.bids.len());
|
||||
println!("");
|
||||
|
||||
@@ -224,13 +226,13 @@ fn main() {
|
||||
println!("Winner: User {}", auction_listing.buyer_id.as_ref().unwrap());
|
||||
println!("Winning Bid: {} {}", auction_listing.sale_price.as_ref().unwrap(), auction_listing.currency);
|
||||
println!("");
|
||||
|
||||
|
||||
println!("Final Bid Statuses:");
|
||||
for bid in &auction_listing.bids {
|
||||
println!("- User {}: {} {} (Status: {:?})",
|
||||
bid.bidder_id,
|
||||
bid.amount,
|
||||
bid.currency,
|
||||
println!("- User {}: {} {} (Status: {:?})",
|
||||
bid.bidder_id,
|
||||
bid.amount,
|
||||
bid.currency,
|
||||
bid.status);
|
||||
}
|
||||
println!("");
|
||||
@@ -238,9 +240,9 @@ fn main() {
|
||||
Err(e) => println!("Error completing auction: {}", e),
|
||||
}
|
||||
|
||||
// Create an exchange listing
|
||||
// Create an exchange listing with auto-generated ID
|
||||
let exchange_listing = Listing::new(
|
||||
203, // id
|
||||
None, // id (auto-generated)
|
||||
"ETH for BTC Exchange", // title
|
||||
"Looking to exchange ETH for BTC", // description
|
||||
"101", // asset_id (referencing the ETH asset)
|
||||
@@ -262,9 +264,9 @@ fn main() {
|
||||
// --- PART 3: DEMONSTRATING EDGE CASES ---
|
||||
println!("\n=== EDGE CASES AND VALIDATIONS ===\n");
|
||||
|
||||
// Create a new auction listing for edge case testing
|
||||
// Create a new auction listing for edge case testing with explicit ID
|
||||
let test_auction = Listing::new(
|
||||
205, // id
|
||||
Some(205), // id (explicit)
|
||||
"Test Auction", // title
|
||||
"For testing edge cases", // description
|
||||
"101", // asset_id
|
||||
@@ -277,7 +279,7 @@ fn main() {
|
||||
vec![], // tags
|
||||
None::<String>, // image_url
|
||||
);
|
||||
|
||||
|
||||
// Try to add a bid that's too low
|
||||
let low_bid = Bid::new(
|
||||
test_auction.base_data.id.to_string(), // listing_id
|
||||
@@ -285,7 +287,7 @@ fn main() {
|
||||
5.0, // amount (lower than starting price)
|
||||
"ETH", // currency
|
||||
);
|
||||
|
||||
|
||||
println!("Attempting to add a bid that's too low (5.0 ETH):");
|
||||
match test_auction.add_bid(low_bid) {
|
||||
Ok(_) => println!("Bid accepted (This shouldn't happen)"),
|
||||
@@ -301,9 +303,9 @@ fn main() {
|
||||
}
|
||||
println!("");
|
||||
|
||||
// Create a listing that will expire
|
||||
// Create a listing that will expire with auto-generated ID
|
||||
let mut expiring_listing = Listing::new(
|
||||
204, // id
|
||||
None, // id (auto-generated)
|
||||
"About to Expire", // title
|
||||
"This listing will expire immediately", // description
|
||||
"101", // asset_id
|
||||
@@ -316,10 +318,10 @@ fn main() {
|
||||
vec![], // tags
|
||||
None::<String>, // image_url
|
||||
);
|
||||
|
||||
|
||||
println!("Created Expiring Listing: '{}' (ID: {})", expiring_listing.title, expiring_listing.base_data.id);
|
||||
println!("Initial Status: {:?}", expiring_listing.status);
|
||||
|
||||
|
||||
// Check expiration
|
||||
expiring_listing = expiring_listing.check_expiration();
|
||||
println!("After Checking Expiration: {:?}", expiring_listing.status);
|
||||
|
Reference in New Issue
Block a user