1- use crate :: { PdaLinkNode , PdaNode , PdaSeedValueNode } ;
1+ use crate :: { AccountValueNode , ArgumentValueNode , PdaLinkNode , PdaNode , PdaSeedValueNode } ;
22use codama_nodes_derive:: { node, node_union} ;
33
44#[ node]
55pub struct PdaValueNode {
66 // Children.
77 pub pda : PdaValue ,
88 pub seeds : Vec < PdaSeedValueNode > ,
9+ #[ serde( skip_serializing_if = "crate::is_default" ) ]
10+ pub program_id : Box < Option < PdaProgramIdValueNode > > ,
11+ }
12+
13+ #[ node_union]
14+ pub enum PdaProgramIdValueNode {
15+ Account ( AccountValueNode ) ,
16+ Argument ( ArgumentValueNode ) ,
917}
1018
1119impl From < PdaValueNode > for crate :: Node {
@@ -22,6 +30,19 @@ impl PdaValueNode {
2230 Self {
2331 pda : pda. into ( ) ,
2432 seeds,
33+ program_id : Box :: new ( None ) ,
34+ }
35+ }
36+
37+ pub fn new_with_program_id < T , U > ( pda : T , seeds : Vec < PdaSeedValueNode > , program_id : U ) -> Self
38+ where
39+ T : Into < PdaValue > ,
40+ U : Into < PdaProgramIdValueNode > ,
41+ {
42+ Self {
43+ pda : pda. into ( ) ,
44+ seeds,
45+ program_id : Box :: new ( Some ( program_id. into ( ) ) ) ,
2546 }
2647 }
2748}
@@ -105,4 +126,18 @@ mod tests {
105126 let node: PdaValueNode = serde_json:: from_str ( json) . unwrap ( ) ;
106127 assert_eq ! ( node, PdaValueNode :: new( PdaLinkNode :: new( "myPda" ) , vec![ ] ) ) ;
107128 }
129+
130+ #[ test]
131+ fn to_json_with_program_id ( ) {
132+ let node = PdaValueNode :: new_with_program_id (
133+ PdaValue :: Linked ( PdaLinkNode :: new ( "myPda" ) ) ,
134+ vec ! [ ] ,
135+ AccountValueNode :: new ( "myProgramAccount" ) ,
136+ ) ;
137+ let json = serde_json:: to_string ( & node) . unwrap ( ) ;
138+ assert_eq ! (
139+ json,
140+ r#"{"kind":"pdaValueNode","pda":{"kind":"pdaLinkNode","name":"myPda"},"seeds":[],"programId":{"kind":"accountValueNode","name":"myProgramAccount"}}"#
141+ ) ;
142+ }
108143}
0 commit comments