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