1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! Typed contract interfaces.
//!
//! This module provides the [`Contract`] trait for creating type-safe contract
//! clients using the `#[near_kit::contract]` proc macro.
//!
//! # Why Typed Contracts?
//!
//! Without typed contracts, method names and arguments are stringly-typed:
//!
//! ```rust,no_run
//! # use near_kit::*;
//! # async fn example(near: &Near) -> Result<(), Error> {
//! // Typos compile fine but fail at runtime
//! let count: u64 = near.view("counter.near", "get_counnt").await?; // typo!
//! # Ok(())
//! # }
//! ```
//!
//! With typed contracts, the compiler catches errors:
//!
//! ```ignore
//! let counter = near.contract::<Counter>("counter.near");
//! let count = counter.get_count().await?; // Compile-time checked!
//! ```
//!
//! # Defining a Contract Interface
//!
//! Use the `#[near_kit::contract]` macro on a trait:
//!
//! ```ignore
//! use near_kit::*;
//! use serde::Serialize;
//!
//! #[near_kit::contract]
//! pub trait Counter {
//! // View method: &self, no #[call] attribute
//! fn get_count(&self) -> u64;
//!
//! // Change method: &mut self + #[call] attribute
//! #[call]
//! fn increment(&mut self);
//!
//! // Change method with arguments
//! #[call]
//! fn add(&mut self, args: AddArgs);
//!
//! // Payable method (can receive NEAR deposit)
//! #[call(payable)]
//! fn donate(&mut self);
//! }
//!
//! #[derive(Serialize)]
//! pub struct AddArgs {
//! pub value: u64,
//! }
//! ```
//!
//! # Using a Typed Contract
//!
//! ```ignore
//! async fn example(near: &Near) -> Result<(), Error> {
//! let counter = near.contract::<Counter>("counter.testnet");
//!
//! // View calls
//! let count = counter.get_count().await?;
//!
//! // Change calls
//! counter.increment().await?;
//! counter.add(AddArgs { value: 5 }).await?;
//!
//! // Payable calls with deposit
//! counter.donate().deposit(NearToken::near(1)).await?;
//!
//! // Override gas
//! counter.add(AddArgs { value: 10 }).gas(Gas::tgas(50)).await?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Serialization Formats
//!
//! By default, arguments are serialized as JSON. For Borsh serialization:
//!
//! ```ignore
//! #[near_kit::contract(borsh)]
//! pub trait MyContract {
//! fn my_method(&self, args: MyArgs) -> u64;
//! }
//! ```
use crateNear;
use crateAccountId;
/// Marker trait for typed contract interfaces.
///
/// This trait is automatically implemented by the `#[near_kit::contract]` macro
/// for each contract trait you define. It provides the associated `Client` type
/// that is used by [`Near::contract`](crate::Near::contract).
///
/// # Example
///
/// The macro generates an implementation like this:
///
/// ```ignore
/// impl Contract for dyn MyContract {
/// type Client<'a> = MyContractClient<'a>;
/// }
/// ```
/// Trait for contract client constructors.
///
/// This trait is implemented by the generated client structs to enable
/// construction via [`Near::contract`](crate::Near::contract).