@@ -744,6 +744,105 @@ bool init_price::get_is_done() const
744
744
return st_ == e_done;
745
745
}
746
746
747
+ // /////////////////////////////////////////////////////////////////////////
748
+ // set_min_pub_req
749
+
750
+ set_min_pub_req::set_min_pub_req ()
751
+ : st_( e_init_sent ),
752
+ cmt_( commitment::e_confirmed )
753
+ {
754
+ }
755
+
756
+ void set_min_pub_req::set_min_pub ( uint8_t min_pub )
757
+ {
758
+ req_->set_min_pub ( min_pub );
759
+ }
760
+
761
+ void set_min_pub_req::set_price ( price *px )
762
+ {
763
+ price_ = px;
764
+ }
765
+
766
+ void set_min_pub_req::set_commitment ( commitment cmt )
767
+ {
768
+ cmt_ = cmt;
769
+ }
770
+
771
+ bool set_min_pub_req::get_is_ready ()
772
+ {
773
+ manager *cptr = get_manager ();
774
+ if ( !cptr->get_mapping_pub_key () ) {
775
+ return set_err_msg ( " missing mapping key pairfile ["
776
+ + cptr->get_mapping_key_pair_file () + " ]" );
777
+ }
778
+ return cptr->has_status ( PC_PYTH_RPC_CONNECTED |
779
+ PC_PYTH_HAS_BLOCK_HASH |
780
+ PC_PYTH_HAS_MAPPING );
781
+ }
782
+
783
+ void set_min_pub_req::submit ()
784
+ {
785
+ manager *cptr = get_manager ();
786
+ key_pair *pkey = cptr->get_publish_key_pair ();
787
+ if ( !pkey ) {
788
+ on_error_sub ( " missing or invalid publish key [" +
789
+ cptr->get_publish_key_pair_file () + " ]" , this );
790
+ return ;
791
+ }
792
+ pub_key *gpub = cptr->get_program_pub_key ();
793
+ if ( !gpub ) {
794
+ on_error_sub ( " missing or invalid program public key [" +
795
+ cptr->get_program_pub_key_file () + " ]" , this );
796
+ return ;
797
+ }
798
+ pub_key *pub = price_->get_account ();
799
+ if ( !cptr->get_account_key_pair ( *pub, key_ ) ) {
800
+ std::string knm;
801
+ pub->enc_base58 ( knm );
802
+ on_error_sub ( " missing key pair for price acct [" + knm + " ]" , this );
803
+ return ;
804
+ }
805
+ req_->set_program ( gpub );
806
+ req_->set_publish ( pkey );
807
+ req_->set_account ( &key_ );
808
+ req_->set_sub ( this );
809
+ sig_->set_sub ( this );
810
+
811
+ // get recent block hash and submit request
812
+ st_ = e_init_sent;
813
+ req_->set_block_hash ( get_manager ()->get_recent_block_hash () );
814
+ get_rpc_client ()->send ( req_ );
815
+ }
816
+
817
+ void set_min_pub_req::on_response ( rpc::signature_subscribe *res )
818
+ {
819
+ if ( res->get_is_err () ) {
820
+ on_error_sub ( res->get_err_msg (), this );
821
+ st_ = e_error;
822
+ } else if ( st_ == e_init_sig ) {
823
+ st_ = e_done;
824
+ on_response_sub ( this );
825
+ }
826
+ }
827
+
828
+ void set_min_pub_req::on_response ( rpc::set_min_pub_rpc *res )
829
+ {
830
+ if ( res->get_is_err () ) {
831
+ on_error_sub ( res->get_err_msg (), this );
832
+ st_ = e_error;
833
+ } else if ( st_ == e_init_sent ) {
834
+ st_ = e_init_sig;
835
+ sig_->set_commitment ( cmt_ );
836
+ sig_->set_signature ( res->get_signature () );
837
+ get_rpc_client ()->send ( sig_ );
838
+ }
839
+ }
840
+
841
+ bool set_min_pub_req::get_is_done () const
842
+ {
843
+ return st_ == e_done;
844
+ }
845
+
747
846
// /////////////////////////////////////////////////////////////////////////
748
847
// add_publisher
749
848
0 commit comments