neo3/neo_contract/mod.rs
1//! # Neo Contract Module (v0.1.8)
2//!
3//! Comprehensive interfaces for interacting with Neo N3 smart contracts and tokens.
4//!
5//! ## Overview
6//!
7//! The neo_contract module provides a robust set of interfaces for interacting with
8//! various types of smart contracts on the Neo N3 blockchain. This module abstracts
9//! away the complexity of contract calls and state management, providing easy-to-use
10//! APIs for developers.
11//!
12//! ## Key Features
13//!
14//! - **System Contracts**: Built-in interfaces for Neo N3 system contracts:
15//! - NEO Token contract
16//! - GAS Token contract
17//! - Policy contract
18//! - RoleManagement contract
19//! - ContractManagement contract
20//!
21//! - **Token Standards**:
22//! - NEP-17 fungible token standard (similar to Ethereum's ERC-20)
23//! - NEP-11 non-fungible token standard (similar to Ethereum's ERC-721)
24//!
25//! - **Advanced Contract Interactions**:
26//! - Neo Name Service (NNS) domain resolution
27//! - Neo URI parsing and validation
28//! - Contract iterator support for handling large result sets
29//!
30//! - **Famous Contract Integrations**:
31//! - Flamingo Finance DeFi ecosystem
32//! - NeoburgerNeo (bNEO) staking contract
33//! - GrandShare voting and proposals
34//! - NeoCompound yield aggregator
35//!
36//! - **Developer Tools**:
37//! - Contract deployment helpers
38//! - ABI and manifest handling utilities
39//! - Contract invocation result parsing
40//!
41//! ## Examples
42//!
43//! ### Working with Standard Contracts
44//!
45//! ```ignore
46//! use neo3::neo_contract::{NeoToken, GasToken, PolicyContract};
47//! use neo3::neo_protocol::{Account, AccountTrait};
48//! use neo3::neo_clients::{HttpProvider, RpcClient};
49//! use std::str::FromStr;
50//!
51//! async fn contract_examples() -> Result<(), Box<dyn std::error::Error>> {
52//! // Set up a client connection
53//! let provider = HttpProvider::new("https://testnet1.neo.org:443").unwrap();
54//! let client = RpcClient::new(provider);
55//!
56//! // Create accounts for testing
57//! let sender = Account::create()?;
58//! let recipient = Account::from_address("NUVPACTpQvd2HHmBgFjJJRWwVXJiR3uAEh")?;
59//!
60//! // 1. Working with the NEO token contract
61//! let neo_token = NeoToken::new(&client);
62//!
63//! // Get token information
64//! let symbol = neo_token.symbol().await?;
65//! let decimals = neo_token.decimals().await?;
66//! let total_supply = neo_token.total_supply().await?;
67//!
68//! println!("NEO Token: Symbol={}, Decimals={}, Total Supply={}",
69//! symbol, decimals, total_supply);
70//!
71//! // Check account balance
72//! let balance = neo_token.balance_of(&sender.get_script_hash()).await?;
73//! println!("NEO Balance: {}", balance);
74//!
75//! // Get voting data
76//! let candidates = neo_token.get_all_candidates().await?;
77//! println!("Current NEO committee candidates: {}", candidates.len());
78//!
79//! // 2. Working with the GAS token contract
80//! let gas_token = GasToken::new(&client);
81//!
82//! // Transfer GAS (requires sender to have GAS)
83//! if gas_token.balance_of(&sender.get_script_hash()).await? > 0 {
84//! let tx_hash = gas_token.transfer(
85//! &sender,
86//! &recipient.get_script_hash(),
87//! 1_00000000, // 1 GAS
88//! None, // No data
89//! ).await?;
90//!
91//! println!("GAS transfer transaction: {}", tx_hash);
92//! }
93//!
94//! // 3. Working with the Policy contract
95//! let policy = PolicyContract::new(&client);
96//!
97//! // Get network policies
98//! let exec_fee_factor = policy.get_exec_fee_factor().await?;
99//! let storage_price = policy.get_storage_price().await?;
100//!
101//! println!("Network Policies:");
102//! println!(" Execution Fee Factor: {}", exec_fee_factor);
103//! println!(" Storage Price: {}", storage_price);
104//!
105//! // 4. Working with a custom NEP-17 token
106//! let token_hash = ScriptHash::from_str("0xd2a4cff31913016155e38e474a2c06d08be276cf")?;
107//! let custom_token = FungibleTokenContract::new(token_hash, &client);
108//!
109//! let custom_symbol = custom_token.symbol().await?;
110//! let custom_balance = custom_token.balance_of(&sender.get_script_hash()).await?;
111//!
112//! println!("{} Balance: {}", custom_symbol, custom_balance);
113//!
114//! // 5. Using the Neo Name Service
115//! let nns = NameService::new(&client);
116//!
117//! // Resolve a domain name to a script hash
118//! let domain = "example.neo";
119//! if let Ok(resolved_address) = nns.resolve(domain).await {
120//! println!("Domain {} resolves to: {}", domain, resolved_address);
121//! } else {
122//! println!("Domain {} is not registered", domain);
123//! }
124//!
125//! Ok(())
126//! }
127//! ```
128//!
129//! ### Deploying a Smart Contract
130//!
131//! ```ignore
132//! use neo3::neo_contract::ContractManagement;
133//! use neo3::ContractState;
134//! use neo3::neo_protocol::{Account, AccountTrait};
135//! use neo3::neo_types::{ContractManifest, NefFile};
136//! use neo3::neo_clients::{HttpProvider, RpcClient};
137//! use std::fs;
138//!
139//! async fn deploy_contract_example() -> Result<(), Box<dyn std::error::Error>> {
140//! // Set up a client connection
141//! let provider = HttpProvider::new("https://testnet1.neo.org:443").unwrap();
142//! let client = RpcClient::new(provider);
143//!
144//! // Create or load an account with GAS for deployment
145//! let account = Account::from_wif("KwVEKk78X65fDrJ3VgqHLcpPpbQVfJLjXrkFUCozHQBJ5nT2xwP8")?;
146//!
147//! // Load contract files (NEF and manifest)
148//! let nef_bytes = fs::read("path/to/contract.nef")?;
149//! let manifest_json = fs::read_to_string("path/to/contract.manifest.json")?;
150//!
151//! // Parse contract files
152//! let nef = NefFile::from_bytes(&nef_bytes)?;
153//! let manifest = ContractManifest::from_json(&manifest_json)?;
154//!
155//! // Create contract management instance
156//! let contract_mgmt = ContractManagement::new(&client);
157//!
158//! // Deploy the contract
159//! println!("Deploying contract...");
160//! let result = contract_mgmt.deploy(
161//! &nef,
162//! &manifest,
163//! None, // No deployment data
164//! &account,
165//! ).await?;
166//!
167//! // Get the contract hash
168//! let contract_hash = result.script_hash;
169//! println!("Contract deployed successfully!");
170//! println!("Contract hash: {}", contract_hash);
171//!
172//! // Get detailed contract information
173//! let contract_state: ContractState = contract_mgmt.get_contract(&contract_hash).await?;
174//! println!("Contract ID: {}", contract_state.id);
175//! println!("Contract update counter: {}", contract_state.update_counter);
176//!
177//! Ok(())
178//! }
179//! ```
180
181pub use contract_error::*;
182pub use contract_management::*;
183pub use famous::*;
184pub use fungible_token_contract::*;
185pub use gas_token::*;
186pub use iterator::*;
187pub use name_service::*;
188pub use neo_token::*;
189pub use neo_uri::*;
190pub use nft_contract::*;
191pub use policy_contract::*;
192pub use role_management::*;
193pub use traits::*;
194
195mod contract_error;
196mod contract_management;
197mod famous;
198mod fungible_token_contract;
199mod gas_token;
200mod iterator;
201mod name_service;
202mod neo_token;
203mod neo_uri;
204mod nft_contract;
205mod policy_contract;
206mod role_management;
207mod traits;
208
209#[cfg(test)]
210mod tests;