use neo_devpack::prelude::*;
use neo_devpack::NeoVMSyscall;
pub struct SimpleStorage {
pub value: NeoInteger,
pub name: NeoString,
}
impl Default for SimpleStorage {
fn default() -> Self {
Self {
value: NeoInteger::zero(),
name: NeoString::from_str("default"),
}
}
}
impl SimpleStorage {
pub fn load(_context: &NeoStorageContext) -> Self {
Self::default()
}
pub fn save(&self, _context: &NeoStorageContext) -> NeoResult<()> {
Ok(())
}
}
pub struct SimpleContract {
storage: SimpleStorage,
}
impl SimpleContract {
pub fn new() -> Self {
Self {
storage: SimpleStorage::default(),
}
}
pub fn get_value(&self) -> NeoResult<NeoInteger> {
Ok(self.storage.value.clone())
}
pub fn set_value(&mut self, value: NeoInteger) -> NeoResult<()> {
self.storage.value = value;
Ok(())
}
pub fn get_name(&self) -> NeoResult<NeoString> {
Ok(self.storage.name.clone())
}
pub fn set_name(&mut self, name: NeoString) -> NeoResult<()> {
self.storage.name = name;
Ok(())
}
pub fn add(&self, a: NeoInteger, b: NeoInteger) -> NeoResult<NeoInteger> {
Ok(a + b)
}
pub fn multiply(&self, a: NeoInteger, b: NeoInteger) -> NeoResult<NeoInteger> {
Ok(a * b)
}
}
impl Default for SimpleContract {
fn default() -> Self {
Self::new()
}
}
fn main() {
println!("Simple Neo N3 Contract Example");
let mut contract = SimpleContract::new();
println!(
"Initial value: {}",
contract.get_value().unwrap().as_i32_saturating()
);
println!("Initial name: {}", contract.get_name().unwrap().as_str());
contract.set_value(NeoInteger::new(42)).unwrap();
contract.set_name(NeoString::from_str("Hello Neo")).unwrap();
println!(
"New value: {}",
contract.get_value().unwrap().as_i32_saturating()
);
println!("New name: {}", contract.get_name().unwrap().as_str());
let result = contract
.add(NeoInteger::new(10), NeoInteger::new(20))
.unwrap();
println!("10 + 20 = {}", result.as_i32_saturating());
let result = contract
.multiply(NeoInteger::new(5), NeoInteger::new(6))
.unwrap();
println!("5 * 6 = {}", result.as_i32_saturating());
let context = NeoStorageContext::new(1);
let storage = SimpleStorage::load(&context);
storage.save(&context).unwrap();
println!("Storage operations completed successfully!");
let time = NeoVMSyscall::get_time().unwrap();
println!("Current time: {}", time.as_i32_saturating());
let witness = NeoVMSyscall::check_witness(&NeoByteString::from_slice(b"test")).unwrap();
println!("Witness check: {}", witness.as_bool());
println!("All tests passed successfully!");
}