@layerzerolabs/framework-solana-anchor-trait 0.2.87 → 0.2.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/generation.rs +8 -2
- package/src/lib.rs +13 -7
- package/tests/snapshots/snapshots__tests__snapshot_all_defaults.snap +7 -4
- package/tests/snapshots/snapshots__tests__snapshot_full_override.snap +4 -4
- package/tests/snapshots/snapshots__tests__snapshot_handler_override.snap +7 -4
- package/tests/snapshots/snapshots__tests__snapshot_mixed_overrides.snap +7 -4
- package/tests/snapshots/snapshots__tests__snapshot_with_extend_macro.snap +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/framework-solana-anchor-trait",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.89",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"rustfmt.toml"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@layerzerolabs/
|
|
18
|
-
"@layerzerolabs/
|
|
19
|
-
"@layerzerolabs/
|
|
20
|
-
"@layerzerolabs/
|
|
17
|
+
"@layerzerolabs/tsup-configuration": "0.2.89",
|
|
18
|
+
"@layerzerolabs/build-utils-solana": "0.2.89",
|
|
19
|
+
"@layerzerolabs/typescript-configuration": "0.2.89",
|
|
20
|
+
"@layerzerolabs/vm-tooling-solana": "0.2.89"
|
|
21
21
|
},
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "restricted",
|
package/src/generation.rs
CHANGED
|
@@ -44,6 +44,12 @@ pub struct DefaultImpl<Ctx> {
|
|
|
44
44
|
/// 1. The concrete struct + impl — emitted as-is via [`to_definition`](Self::to_definition).
|
|
45
45
|
/// 2. A `macro_rules!` rule — built by decomposing the struct into attrs/fields and replacing the
|
|
46
46
|
/// name with `$name` via [`to_extend_rule`](Self::to_extend_rule).
|
|
47
|
+
///
|
|
48
|
+
/// The struct may carry at most a single `'info` lifetime parameter. Extra
|
|
49
|
+
/// type or const generics are rejected at expansion time — the entrypoint
|
|
50
|
+
/// and extend-rule codegen paths reduce the type to a bare ident, so any
|
|
51
|
+
/// non-`'info` generics would be silently dropped and produce malformed
|
|
52
|
+
/// output.
|
|
47
53
|
pub struct DefaultAccounts {
|
|
48
54
|
/// Complete struct definition including attributes, name, generics, and fields.
|
|
49
55
|
pub struct_type: ItemStruct,
|
|
@@ -187,12 +193,12 @@ fn generate_instruction<Ix: InstructionSet>(
|
|
|
187
193
|
// Emit the entrypoint function, with or without a params argument.
|
|
188
194
|
let entrypoints = match &spec.params_type {
|
|
189
195
|
Some(params_type) => quote! {
|
|
190
|
-
pub fn #entry_fn_ident #fn_generics (#ctx_decl, params: #params_type) -> Result<#return_type> {
|
|
196
|
+
pub fn #entry_fn_ident #fn_generics (#ctx_decl, params: #params_type) -> ::anchor_lang::Result<#return_type> {
|
|
191
197
|
#dispatch(#ref_token ctx, ¶ms)
|
|
192
198
|
}
|
|
193
199
|
},
|
|
194
200
|
None => quote! {
|
|
195
|
-
pub fn #entry_fn_ident #fn_generics (#ctx_decl) -> Result<#return_type> {
|
|
201
|
+
pub fn #entry_fn_ident #fn_generics (#ctx_decl) -> ::anchor_lang::Result<#return_type> {
|
|
196
202
|
#dispatch(#ref_token ctx)
|
|
197
203
|
}
|
|
198
204
|
},
|
package/src/lib.rs
CHANGED
|
@@ -55,10 +55,13 @@ pub trait InstructionSet: Copy + Ord + 'static {
|
|
|
55
55
|
/// Declares all instructions in one place, generating a named enum
|
|
56
56
|
/// implementing [`InstructionSet`].
|
|
57
57
|
///
|
|
58
|
-
/// Each `Variant => mod_name` pair maps an enum variant to
|
|
59
|
-
///
|
|
60
|
-
///
|
|
61
|
-
///
|
|
58
|
+
/// Each `Variant => mod_name` pair maps an enum variant to a module whose
|
|
59
|
+
/// `spec()` function provides the codegen descriptor. Each `mod_name` must
|
|
60
|
+
/// be unique — two variants on the same module emit colliding entrypoints.
|
|
61
|
+
///
|
|
62
|
+
/// Appending `(ctx)` after `mod_name` routes to `mod_name::spec(&ctx)`
|
|
63
|
+
/// with the [`CodegenContext`] reference; omitting it calls `spec()` with
|
|
64
|
+
/// no arguments. The marker token is discarded — `ctx` is convention.
|
|
62
65
|
///
|
|
63
66
|
/// Callers are responsible for declaring their own `mod` items before
|
|
64
67
|
/// invoking this macro.
|
|
@@ -81,7 +84,10 @@ pub trait InstructionSet: Copy + Ord + 'static {
|
|
|
81
84
|
/// ```
|
|
82
85
|
#[macro_export]
|
|
83
86
|
macro_rules! declare_instructions {
|
|
84
|
-
// Helper: dispatch spec call
|
|
87
|
+
// Helper: dispatch spec call. The marker token (conventionally `ctx`) is a
|
|
88
|
+
// routing sigil — it picks the ctx-passing branch but is otherwise
|
|
89
|
+
// discarded, so any ident inside the parens produces equivalent generated
|
|
90
|
+
// code. Without the marker, `spec()` is called with no arguments.
|
|
85
91
|
(@spec_call $ctx:ident, $mod_name:ident ( $marker:ident )) => {
|
|
86
92
|
$mod_name::spec(&$ctx)
|
|
87
93
|
};
|
|
@@ -95,7 +101,7 @@ macro_rules! declare_instructions {
|
|
|
95
101
|
$( $variant, )+
|
|
96
102
|
}
|
|
97
103
|
|
|
98
|
-
impl ::
|
|
104
|
+
impl $crate::InstructionSet for $name {
|
|
99
105
|
type Ctx = $ctx;
|
|
100
106
|
|
|
101
107
|
fn all() -> &'static [Self] {
|
|
@@ -118,7 +124,7 @@ macro_rules! declare_instructions {
|
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
fn spec(self, ctx: &$ctx) -> ::
|
|
127
|
+
fn spec(self, ctx: &$ctx) -> $crate::InstructionSpec<$ctx> {
|
|
122
128
|
match self {
|
|
123
129
|
$( Self::$variant => $crate::declare_instructions!(@spec_call ctx, $mod_name $( ( $ctx_marker ) )? ), )+
|
|
124
130
|
}
|
|
@@ -41,22 +41,25 @@ pub mod my_program {
|
|
|
41
41
|
Ok(())
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
pub fn set_peer(
|
|
44
|
+
pub fn set_peer(
|
|
45
|
+
mut ctx: Context<StdSetPeer>,
|
|
46
|
+
params: SetPeerParams,
|
|
47
|
+
) -> ::anchor_lang::Result<()> {
|
|
45
48
|
StdSetPeer::apply(&mut ctx, ¶ms)
|
|
46
49
|
}
|
|
47
50
|
pub fn get_peer(
|
|
48
51
|
ctx: Context<StdGetPeer>,
|
|
49
52
|
params: GetPeerParams,
|
|
50
|
-
) -> Result<[u8; 32]> {
|
|
53
|
+
) -> ::anchor_lang::Result<[u8; 32]> {
|
|
51
54
|
StdGetPeer::apply(&ctx, ¶ms)
|
|
52
55
|
}
|
|
53
56
|
pub fn lz_receive(
|
|
54
57
|
mut ctx: Context<MyReceive>,
|
|
55
58
|
params: LzReceiveParams,
|
|
56
|
-
) -> Result<()> {
|
|
59
|
+
) -> ::anchor_lang::Result<()> {
|
|
57
60
|
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
58
61
|
}
|
|
59
|
-
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
62
|
+
pub fn token(ctx: Context<StdToken>) -> ::anchor_lang::Result<Pubkey> {
|
|
60
63
|
StdToken::apply(&ctx)
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -54,22 +54,22 @@ pub mod my_program {
|
|
|
54
54
|
pub fn set_peer(
|
|
55
55
|
mut ctx: Context<MyCustomAccounts>,
|
|
56
56
|
params: SetPeerParams,
|
|
57
|
-
) -> Result<()> {
|
|
57
|
+
) -> ::anchor_lang::Result<()> {
|
|
58
58
|
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
59
59
|
}
|
|
60
60
|
pub fn get_peer(
|
|
61
61
|
ctx: Context<StdGetPeer>,
|
|
62
62
|
params: GetPeerParams,
|
|
63
|
-
) -> Result<[u8; 32]> {
|
|
63
|
+
) -> ::anchor_lang::Result<[u8; 32]> {
|
|
64
64
|
StdGetPeer::apply(&ctx, ¶ms)
|
|
65
65
|
}
|
|
66
66
|
pub fn lz_receive(
|
|
67
67
|
mut ctx: Context<MyReceive>,
|
|
68
68
|
params: LzReceiveParams,
|
|
69
|
-
) -> Result<()> {
|
|
69
|
+
) -> ::anchor_lang::Result<()> {
|
|
70
70
|
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
71
71
|
}
|
|
72
|
-
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
72
|
+
pub fn token(ctx: Context<StdToken>) -> ::anchor_lang::Result<Pubkey> {
|
|
73
73
|
StdToken::apply(&ctx)
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -51,22 +51,25 @@ pub mod my_program {
|
|
|
51
51
|
Ok(())
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
pub fn set_peer(
|
|
54
|
+
pub fn set_peer(
|
|
55
|
+
mut ctx: Context<StdSetPeer>,
|
|
56
|
+
params: SetPeerParams,
|
|
57
|
+
) -> ::anchor_lang::Result<()> {
|
|
55
58
|
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
56
59
|
}
|
|
57
60
|
pub fn get_peer(
|
|
58
61
|
ctx: Context<StdGetPeer>,
|
|
59
62
|
params: GetPeerParams,
|
|
60
|
-
) -> Result<[u8; 32]> {
|
|
63
|
+
) -> ::anchor_lang::Result<[u8; 32]> {
|
|
61
64
|
StdGetPeer::apply(&ctx, ¶ms)
|
|
62
65
|
}
|
|
63
66
|
pub fn lz_receive(
|
|
64
67
|
mut ctx: Context<MyReceive>,
|
|
65
68
|
params: LzReceiveParams,
|
|
66
|
-
) -> Result<()> {
|
|
69
|
+
) -> ::anchor_lang::Result<()> {
|
|
67
70
|
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
68
71
|
}
|
|
69
|
-
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
72
|
+
pub fn token(ctx: Context<StdToken>) -> ::anchor_lang::Result<Pubkey> {
|
|
70
73
|
StdToken::apply(&ctx)
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -67,22 +67,25 @@ pub mod my_program {
|
|
|
67
67
|
Ok(())
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
pub fn set_peer(
|
|
70
|
+
pub fn set_peer(
|
|
71
|
+
mut ctx: Context<StdSetPeer>,
|
|
72
|
+
params: SetPeerParams,
|
|
73
|
+
) -> ::anchor_lang::Result<()> {
|
|
71
74
|
__test_instruction__set_peer_handler::set_peer(&mut ctx, ¶ms)
|
|
72
75
|
}
|
|
73
76
|
pub fn get_peer(
|
|
74
77
|
ctx: Context<MyCustomGetPeer>,
|
|
75
78
|
params: GetPeerParams,
|
|
76
|
-
) -> Result<[u8; 32]> {
|
|
79
|
+
) -> ::anchor_lang::Result<[u8; 32]> {
|
|
77
80
|
__test_instruction__get_peer_handler::get_peer(&ctx, ¶ms)
|
|
78
81
|
}
|
|
79
82
|
pub fn lz_receive(
|
|
80
83
|
mut ctx: Context<MyReceive>,
|
|
81
84
|
params: LzReceiveParams,
|
|
82
|
-
) -> Result<()> {
|
|
85
|
+
) -> ::anchor_lang::Result<()> {
|
|
83
86
|
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
84
87
|
}
|
|
85
|
-
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
88
|
+
pub fn token(ctx: Context<StdToken>) -> ::anchor_lang::Result<Pubkey> {
|
|
86
89
|
StdToken::apply(&ctx)
|
|
87
90
|
}
|
|
88
91
|
}
|
|
@@ -61,22 +61,25 @@ pub mod my_program {
|
|
|
61
61
|
Ok(())
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
pub fn set_peer(
|
|
64
|
+
pub fn set_peer(
|
|
65
|
+
mut ctx: Context<StdSetPeer>,
|
|
66
|
+
params: SetPeerParams,
|
|
67
|
+
) -> ::anchor_lang::Result<()> {
|
|
65
68
|
StdSetPeer::apply(&mut ctx, ¶ms)
|
|
66
69
|
}
|
|
67
70
|
pub fn get_peer(
|
|
68
71
|
ctx: Context<StdGetPeer>,
|
|
69
72
|
params: GetPeerParams,
|
|
70
|
-
) -> Result<[u8; 32]> {
|
|
73
|
+
) -> ::anchor_lang::Result<[u8; 32]> {
|
|
71
74
|
StdGetPeer::apply(&ctx, ¶ms)
|
|
72
75
|
}
|
|
73
76
|
pub fn lz_receive(
|
|
74
77
|
mut ctx: Context<MyReceive>,
|
|
75
78
|
params: LzReceiveParams,
|
|
76
|
-
) -> Result<()> {
|
|
79
|
+
) -> ::anchor_lang::Result<()> {
|
|
77
80
|
__test_instruction__lz_receive_handler::lz_receive(&mut ctx, ¶ms)
|
|
78
81
|
}
|
|
79
|
-
pub fn token(ctx: Context<StdToken>) -> Result<Pubkey> {
|
|
82
|
+
pub fn token(ctx: Context<StdToken>) -> ::anchor_lang::Result<Pubkey> {
|
|
80
83
|
StdToken::apply(&ctx)
|
|
81
84
|
}
|
|
82
85
|
}
|