@@ -11,7 +11,6 @@ use ergo_lib::{
1111 ergo_box:: { box_value:: BoxValue , ErgoBox , NonMandatoryRegisterId } ,
1212 token:: Token ,
1313 } ,
14- ergotree_ir:: mir:: constant:: Constant ,
1514 ergotree_ir:: serialization:: SigmaSerializable ,
1615 wallet:: {
1716 box_selector:: { BoxSelection , BoxSelector , BoxSelectorError , SimpleBoxSelector } ,
@@ -24,13 +23,13 @@ use log::{error, info};
2423use std:: convert:: TryInto ;
2524
2625use crate :: {
27- box_kind:: { make_pool_box_candidate, BallotBox , BallotBoxWrapper , PoolBox , PoolBoxWrapper } ,
26+ box_kind:: { make_pool_box_candidate, BallotBox , PoolBox , PoolBoxWrapper , VoteBallotBoxWrapper } ,
2827 cli_commands:: ergo_explorer_transaction_link,
2928 contracts:: pool:: PoolContract ,
3029 contracts:: pool:: PoolContractInputs ,
3130 node_interface:: { current_block_height, get_wallet_status, sign_and_submit_transaction} ,
32- oracle_config:: { OracleConfig , ORACLE_CONFIG } ,
33- oracle_state:: { BallotBoxesSource , OraclePool , PoolBoxSource , StageError , UpdateBoxSource } ,
31+ oracle_config:: { CastBallotBoxVoteParameters , OracleConfig , ORACLE_CONFIG } ,
32+ oracle_state:: { OraclePool , PoolBoxSource , StageError , UpdateBoxSource , VoteBallotBoxesSource } ,
3433 wallet:: WalletDataSource ,
3534} ;
3635use derive_more:: From ;
@@ -190,7 +189,7 @@ fn display_update_diff(
190189#[ allow( clippy:: too_many_arguments) ]
191190fn build_update_pool_box_tx (
192191 pool_box_source : & dyn PoolBoxSource ,
193- ballot_boxes : & dyn BallotBoxesSource ,
192+ ballot_boxes : & dyn VoteBallotBoxesSource ,
194193 wallet : & dyn WalletDataSource ,
195194 update_box : & dyn UpdateBoxSource ,
196195 new_pool_contract : PoolContract ,
@@ -201,13 +200,18 @@ fn build_update_pool_box_tx(
201200 let update_box = update_box. get_update_box ( ) ?;
202201 let min_votes = update_box. min_votes ( ) ;
203202 let old_pool_box = pool_box_source. get_pool_box ( ) ?;
204- let pool_box_hash = Constant :: from ( blake2b256_hash (
203+ let pool_box_hash = blake2b256_hash (
205204 & new_pool_contract
206205 . ergo_tree ( )
207206 . sigma_serialize_bytes ( )
208207 . unwrap ( ) ,
209- ) ) ;
208+ ) ;
210209 let reward_tokens = new_reward_tokens. unwrap_or_else ( || old_pool_box. reward_token ( ) ) ;
210+ let vote_parameters = CastBallotBoxVoteParameters {
211+ pool_box_address_hash : pool_box_hash,
212+ reward_token_id : reward_tokens. token_id . clone ( ) ,
213+ reward_token_quantity : * reward_tokens. amount . as_u64 ( ) as u32 , // TODO: Change vote parameters to i64
214+ } ;
211215 // Find ballot boxes that are voting for the new pool hash
212216 let mut sorted_ballot_boxes = ballot_boxes. get_ballot_boxes ( ) ?;
213217 // Sort in descending order of ballot token amounts. If two boxes have the same amount of ballot tokens, also compare box value, in case some boxes were incorrectly created below minStorageRent
@@ -224,28 +228,10 @@ fn build_update_pool_box_tx(
224228 sorted_ballot_boxes. reverse ( ) ;
225229
226230 let mut votes_cast = 0 ;
227- let vote_ballot_boxes: Vec < BallotBoxWrapper > = ballot_boxes
231+ let vote_ballot_boxes: Vec < VoteBallotBoxWrapper > = ballot_boxes
228232 . get_ballot_boxes ( ) ?
229233 . into_iter ( )
230- . filter ( |ballot_box| {
231- let ballot_box = ballot_box. get_box ( ) ;
232- ballot_box
233- . additional_registers
234- . get ( NonMandatoryRegisterId :: R5 )
235- == Some ( & update_box. get_box ( ) . creation_info ( ) . 0 . into ( ) )
236- && ballot_box
237- . additional_registers
238- . get ( NonMandatoryRegisterId :: R6 )
239- == Some ( & pool_box_hash)
240- && ballot_box
241- . additional_registers
242- . get ( NonMandatoryRegisterId :: R7 )
243- == Some ( & reward_tokens. token_id . clone ( ) . into ( ) )
244- && ballot_box
245- . additional_registers
246- . get ( NonMandatoryRegisterId :: R8 )
247- == Some ( & ( * reward_tokens. amount . as_u64 ( ) as i64 ) . into ( ) )
248- } )
234+ . filter ( |ballot_box| * ballot_box. vote_parameters ( ) == vote_parameters)
249235 . scan ( & mut votes_cast, |votes_cast, ballot_box| {
250236 * * votes_cast += * ballot_box. ballot_token ( ) . amount . as_u64 ( ) ;
251237 Some ( ballot_box)
@@ -378,8 +364,8 @@ mod tests {
378364
379365 use crate :: {
380366 box_kind:: {
381- make_local_ballot_box_candidate, make_pool_box_candidate, BallotBoxWrapper ,
382- PoolBoxWrapper , PoolBoxWrapperInputs , UpdateBoxWrapper , UpdateBoxWrapperInputs ,
367+ make_local_ballot_box_candidate, make_pool_box_candidate, PoolBoxWrapper ,
368+ PoolBoxWrapperInputs , UpdateBoxWrapper , UpdateBoxWrapperInputs , VoteBallotBoxWrapper ,
383369 } ,
384370 contracts:: {
385371 ballot:: { BallotContract , BallotContractInputs } ,
@@ -496,11 +482,7 @@ mod tests {
496482 let secret = DlogProverInput :: random ( ) ;
497483 let ballot_box_parameters = BallotBoxWrapperParameters {
498484 contract_parameters : ballot_contract_parameters. clone ( ) ,
499- vote_parameters : Some ( crate :: oracle_config:: CastBallotBoxVoteParameters {
500- pool_box_address_hash : base16:: encode_lower ( & pool_box_hash) ,
501- reward_token_id : new_reward_tokens. token_id . clone ( ) ,
502- reward_token_quantity : * new_reward_tokens. amount . as_u64 ( ) as u32 ,
503- } ) ,
485+ vote_parameters : None ,
504486 ballot_token_owner_address : AddressEncoder :: new (
505487 ballot_contract_parameters. p2s . network ( ) ,
506488 )
@@ -526,7 +508,7 @@ mod tests {
526508 ErgoBox :: from_box_candidate ( & ballot_box_candidate, force_any_val :: < TxId > ( ) , 0 )
527509 . unwrap ( ) ;
528510 ballot_boxes. push (
529- BallotBoxWrapper :: new (
511+ VoteBallotBoxWrapper :: new (
530512 ballot_box,
531513 crate :: box_kind:: BallotBoxWrapperInputs {
532514 parameters : & ballot_box_parameters,
@@ -594,7 +576,6 @@ mod tests {
594576 change_address,
595577 )
596578 . unwrap ( ) ;
597- println ! ( "{}" , serde_json:: to_string( & update_tx. spending_tx) . unwrap( ) ) ;
598579
599580 wallet. sign_transaction ( update_tx, & ctx, None ) . unwrap ( ) ;
600581 }
0 commit comments