@@ -8,7 +8,7 @@ mod state;
88use async_graphql:: ComplexObject ;
99use gol_challenge:: { game:: Puzzle , GolChallengeAbi , Operation } ;
1010use linera_sdk:: {
11- linera_base_types:: { AccountOwner , ChainId , DataBlobHash , Timestamp , WithContractAbi } ,
11+ linera_base_types:: { AccountOwner , DataBlobHash , Timestamp , WithContractAbi } ,
1212 views:: { RootView , View } ,
1313 Contract , ContractRuntime ,
1414} ;
@@ -22,12 +22,6 @@ pub struct GolChallengeContract {
2222
2323linera_sdk:: contract!( GolChallengeContract ) ;
2424
25- #[ derive( Clone , Debug , Serialize , Deserialize ) ]
26- pub struct Parameters {
27- /// Where to report puzzles for scoring.
28- scoring_chain_id : ChainId ,
29- }
30-
3125impl WithContractAbi for GolChallengeContract {
3226 type Abi = GolChallengeAbi ;
3327}
@@ -45,7 +39,7 @@ pub struct Message {
4539impl Contract for GolChallengeContract {
4640 type Message = Message ;
4741 type InstantiationArgument = ( ) ;
48- type Parameters = Parameters ;
42+ type Parameters = ( ) ;
4943 type EventValue = ( ) ;
5044
5145 async fn load ( runtime : ContractRuntime < Self > ) -> Self {
@@ -68,6 +62,7 @@ impl Contract for GolChallengeContract {
6862 puzzle_id,
6963 board,
7064 owner,
65+ scoring_chain_id,
7166 } => {
7267 let owner = owner. unwrap_or_else ( || {
7368 self . runtime
@@ -88,18 +83,19 @@ impl Contract for GolChallengeContract {
8883 . insert ( & puzzle_id, solution)
8984 . expect ( "Store solution" ) ;
9085
91- let Parameters { scoring_chain_id } = self . runtime . application_parameters ( ) ;
92- let message = Message {
93- puzzle_id,
94- timestamp,
95- owner,
96- } ;
97- self . runtime
98- . prepare_message ( message)
99- . send_to ( scoring_chain_id) ;
86+ if let Some ( scoring_chain_id) = scoring_chain_id {
87+ let message = Message {
88+ puzzle_id,
89+ timestamp,
90+ owner,
91+ } ;
92+ self . runtime
93+ . prepare_message ( message)
94+ . send_to ( scoring_chain_id) ;
95+ }
10096 }
10197 Operation :: RegisterPuzzle { puzzle_id } => {
102- self . assert_scoring_chain ( " Puzzles are only registered on the scoring chain." ) ;
98+ // Puzzles are only registered on a scoring chain.
10399 self . state . registered_puzzles . insert ( & puzzle_id) . unwrap ( ) ;
104100 }
105101 }
@@ -112,35 +108,30 @@ impl Contract for GolChallengeContract {
112108 timestamp,
113109 owner,
114110 } = message;
115- self . assert_scoring_chain ( "Messages are sent to the scoring chain." ) ;
116111 let is_registered = self
117112 . state
118113 . registered_puzzles
119114 . contains ( & puzzle_id)
120115 . await
121116 . unwrap ( ) ;
122- assert ! ( is_registered, "Puzzle must be registered" ) ;
123- let map = self
124- . state
125- . reported_solutions
126- . load_entry_mut ( & owner)
127- . await
128- . unwrap ( ) ;
129- map. insert ( & puzzle_id, timestamp) . unwrap ( ) ;
117+ if is_registered {
118+ let map = self
119+ . state
120+ . reported_solutions
121+ . load_entry_mut ( & owner)
122+ . await
123+ . unwrap ( ) ;
124+ map. insert ( & puzzle_id, timestamp) . unwrap ( ) ;
125+ } else {
126+ log:: trace!( "Ignoring unregistered puzzle" ) ;
127+ }
130128 }
131129
132130 async fn store ( mut self ) {
133131 self . state . save ( ) . await . expect ( "Failed to save state" ) ;
134132 }
135133}
136134
137- impl GolChallengeContract {
138- fn assert_scoring_chain ( & mut self , error : & str ) {
139- let Parameters { scoring_chain_id } = self . runtime . application_parameters ( ) ;
140- assert_eq ! ( self . runtime. chain_id( ) , scoring_chain_id, "{}" , error) ;
141- }
142- }
143-
144135/// This implementation is only nonempty in the service.
145136#[ ComplexObject ]
146137impl GolChallengeState { }
0 commit comments