@@ -1055,234 +1055,6 @@ bool del_publisher::get_is_done() const
10551055 return st_ == e_done;
10561056}
10571057
1058- // /////////////////////////////////////////////////////////////////////////
1059- // init_test
1060-
1061- init_test::init_test ()
1062- : st_( e_create_sent )
1063- {
1064- }
1065-
1066- void init_test::set_lamports ( uint64_t lamports )
1067- {
1068- creq_->set_lamports ( lamports );
1069- }
1070-
1071- key_pair *init_test::get_account ()
1072- {
1073- return &tkey_;
1074- }
1075-
1076- void init_test::submit ()
1077- {
1078- // get keys
1079- manager *sptr = get_manager ();
1080- key_pair *pkey = sptr->get_publish_key_pair ();
1081- if ( !pkey ) {
1082- on_error_sub ( " missing or invalid publish key [" +
1083- sptr->get_publish_key_pair_file (), this );
1084- return ;
1085- }
1086- pub_key *gpub = sptr->get_program_pub_key ();
1087- if ( !gpub ) {
1088- on_error_sub ( " missing or invalid program public key [" +
1089- sptr->get_program_pub_key_file () + " ]" , this );
1090- return ;
1091- }
1092- manager *cptr = get_manager ();
1093- if ( !cptr->create_account_key_pair ( tkey_ ) ) {
1094- on_error_sub ( " failed to create new test key_pair" , this );
1095- return ;
1096- }
1097-
1098- creq_->set_sub ( this );
1099- creq_->set_sender ( pkey );
1100- creq_->set_account ( &tkey_ );
1101- creq_->set_owner ( gpub );
1102- creq_->set_space ( sizeof ( pc_price_t ) );
1103-
1104- ireq_->set_sub ( this );
1105- ireq_->set_publish ( pkey );
1106- ireq_->set_account ( &tkey_ );
1107- ireq_->set_program ( gpub );
1108-
1109- sig_->set_sub ( this );
1110- sig_->set_commitment ( commitment::e_finalized );
1111-
1112- // get recent block hash and submit request
1113- st_ = e_create_sent;
1114- creq_->set_block_hash ( cptr->get_recent_block_hash () );
1115- get_rpc_client ()->send ( creq_ );
1116- }
1117-
1118- void init_test::on_response ( rpc::create_account *res )
1119- {
1120- if ( res->get_is_err () ) {
1121- on_error_sub ( res->get_err_msg (), this );
1122- st_ = e_error;
1123- } else if ( st_ == e_create_sent ) {
1124- // subscribe to signature completion
1125- st_ = e_create_sig;
1126- sig_->set_commitment ( commitment::e_finalized );
1127- sig_->set_signature ( res->get_signature () );
1128- get_rpc_client ()->send ( sig_ );
1129- }
1130- }
1131-
1132- void init_test::on_response ( rpc::signature_subscribe *res )
1133- {
1134- if ( res->get_is_err () ) {
1135- on_error_sub ( res->get_err_msg (), this );
1136- st_ = e_error;
1137- } else if ( st_ == e_create_sig ) {
1138- st_ = e_init_sent;
1139- ireq_->set_block_hash ( get_manager ()->get_recent_block_hash () );
1140- get_rpc_client ()->send ( ireq_ );
1141- } else if ( st_ == e_init_sig ) {
1142- st_ = e_done;
1143- on_response_sub ( this );
1144- }
1145- }
1146-
1147- void init_test::on_response ( rpc::init_test *res )
1148- {
1149- if ( res->get_is_err () ) {
1150- on_error_sub ( res->get_err_msg (), this );
1151- st_ = e_error;
1152- } else if ( st_ == e_init_sent ) {
1153- st_ = e_init_sig;
1154- sig_->set_signature ( res->get_signature () );
1155- get_rpc_client ()->send ( sig_ );
1156- }
1157- }
1158-
1159- bool init_test::get_is_done () const
1160- {
1161- return st_ == e_done;
1162- }
1163-
1164- // /////////////////////////////////////////////////////////////////////////
1165- // upd_test
1166-
1167- void upd_test::set_test_key ( const std::string& tkey )
1168- {
1169- tpub_.init_from_text ( tkey );
1170- }
1171-
1172- bool upd_test::init_from_file ( const std::string& file )
1173- {
1174- mem_map mf;
1175- mf.set_file ( file );
1176- if ( !mf.init () ) {
1177- return set_err_msg ( " failed to read file[" + file + " ]" );
1178- }
1179- jtree pt;
1180- pt.parse ( mf.data (), mf.size () );
1181- if ( !pt.is_valid () ) {
1182- return set_err_msg ( " failed to parse file[" + file + " ]" );
1183- }
1184- ureq_->set_expo ( pt.get_int ( pt.find_val ( 1 , " exponent" ) ) );
1185- unsigned i=0 , qt =pt.find_val ( 1 , " quotes" );
1186- for ( uint32_t it = pt.get_first ( qt ); it; it = pt.get_next ( it ) ) {
1187- int64_t px = pt.get_int ( pt.find_val ( it, " price" ) );
1188- uint64_t conf = pt.get_uint ( pt.find_val ( it, " conf" ) );
1189- int64_t sdiff = pt.get_int ( pt.find_val ( it, " slot_diff" ) );
1190- ureq_->set_price ( i++, px, conf, sdiff );
1191- }
1192- ureq_->set_num ( i );
1193- return true ;
1194- }
1195-
1196- bool upd_test::get_is_done () const
1197- {
1198- return st_ == e_done;
1199- }
1200-
1201- void upd_test::submit ()
1202- {
1203- // get keys
1204- manager *sptr = get_manager ();
1205- key_pair *pkey = sptr->get_publish_key_pair ();
1206- if ( !pkey ) {
1207- on_error_sub ( " missing or invalid publish key [" +
1208- sptr->get_publish_key_pair_file (), this );
1209- return ;
1210- }
1211- pub_key *gpub = sptr->get_program_pub_key ();
1212- if ( !gpub ) {
1213- on_error_sub ( " missing or invalid program public key [" +
1214- sptr->get_program_pub_key_file () + " ]" , this );
1215- return ;
1216- }
1217- manager *cptr = get_manager ();
1218- if ( !cptr->get_account_key_pair ( tpub_, tkey_ ) ) {
1219- on_error_sub ( " failed to find test key_pair" , this );
1220- return ;
1221- }
1222-
1223- ureq_->set_sub ( this );
1224- ureq_->set_publish ( pkey );
1225- ureq_->set_account ( &tkey_ );
1226- ureq_->set_program ( gpub );
1227-
1228- areq_->set_sub ( this );
1229- areq_->set_account ( &tpub_ );
1230- areq_->set_commitment ( commitment::e_confirmed );
1231- get_rpc_client ()->send ( areq_ );
1232-
1233- // get recent block hash and submit request
1234- st_ = e_upd_sent;
1235- ureq_->set_block_hash ( cptr->get_recent_block_hash () );
1236- get_rpc_client ()->send ( ureq_ );
1237- }
1238-
1239- void upd_test::on_response ( rpc::upd_test *res )
1240- {
1241- if ( res->get_is_err () ) {
1242- on_error_sub ( res->get_err_msg (), this );
1243- st_ = e_error;
1244- }
1245- }
1246-
1247- void upd_test::on_response ( rpc::account_subscribe *res )
1248- {
1249- if ( res->get_is_err () ) {
1250- on_error_sub ( res->get_err_msg (), this );
1251- st_ = e_error;
1252- return ;
1253- }
1254- manager *cptr = get_manager ();
1255- pc_price_t *tptr;
1256- if ( sizeof ( pc_price_t ) != res->get_data_ref ( tptr ) ||
1257- tptr->magic_ != PC_MAGIC ||
1258- tptr->type_ != PC_ACCTYPE_TEST ) {
1259- cptr->set_err_msg ( " invalid or corrupt test account" );
1260- st_ = e_error;
1261- return ;
1262- }
1263- if ( tptr->ver_ != PC_VERSION ) {
1264- cptr->set_err_msg ( " invalid test account version=" +
1265- std::to_string ( tptr->ver_ ) );
1266- st_ = e_error;
1267- return ;
1268- }
1269- json_wtr jw;
1270- jw.add_val ( json_wtr::e_obj );
1271- jw.add_key ( " exponent" , (int64_t )tptr->expo_ );
1272- jw.add_key ( " price" , tptr->agg_ .price_ );
1273- jw.add_key ( " conf" , tptr->agg_ .conf_ );
1274- jw.pop ();
1275- net_buf *hd, *tl;
1276- jw.detach ( hd, tl );
1277- while ( hd ) {
1278- net_buf *nxt = hd->next_ ;
1279- std::cout.write ( hd->buf_ , hd->size_ );
1280- hd = nxt;
1281- }
1282- std::cout << std::endl;
1283- st_ = e_done;
1284- }
1285-
12861058// /////////////////////////////////////////////////////////////////////////
12871059// get_minimum_balance_rent_exemption
12881060
0 commit comments