@@ -107,13 +107,15 @@ namespace pc
107107static hash sys_id = gen_sys_id();
108108
109109// generate json for sendTransaction
110- static void send_transaction ( json_wtr& msg, bincode& tx )
110+ static void send_transaction ( json_wtr& msg, bincode& tx, bool skipPreflight )
111111{
112112 msg.add_key ( " method" , " sendTransaction" );
113113 msg.add_key ( " params" , json_wtr::e_arr );
114114 msg.add_val_enc_base64 ( str ( tx.get_buf (), tx.size () ) );
115115 msg.add_val ( json_wtr::e_obj );
116116 msg.add_key ( " encoding" , " base64" );
117+ if ( skipPreflight )
118+ msg.add_key ( " skipPreflight" , json_wtr::jtrue () );
117119 msg.pop ();
118120 msg.pop ();
119121}
@@ -808,7 +810,7 @@ void rpc::transfer::request( json_wtr& msg )
808810 sig_.init_from_buf ( (const uint8_t *)(tx.get_buf () + sign_idx) );
809811
810812 // encode transaction and add to json params
811- send_transaction ( msg, tx );
813+ send_transaction ( msg, tx, false );
812814 bptr->dealloc ();
813815}
814816
@@ -1140,7 +1142,7 @@ void rpc::create_account::request( json_wtr& msg )
11401142 tx.sign ( acct_idx, tx_idx, *account_ );
11411143
11421144 // encode transaction and add to json params
1143- send_transaction ( msg, tx );
1145+ send_transaction ( msg, tx, false );
11441146 bptr->dealloc ();
11451147}
11461148
@@ -1240,7 +1242,7 @@ void rpc::add_product::request( json_wtr& msg )
12401242 tx.sign ( sym_idx, tx_idx, *akey_ );
12411243
12421244 // encode transaction and add to json params
1243- send_transaction ( msg, tx );
1245+ send_transaction ( msg, tx, false );
12441246 bptr->dealloc ();
12451247}
12461248
@@ -1344,7 +1346,7 @@ void rpc::upd_product::request( json_wtr& msg )
13441346 tx.sign ( sym_idx, tx_idx, *akey_ );
13451347
13461348 // encode transaction and add to json params
1347- send_transaction ( msg, tx );
1349+ send_transaction ( msg, tx, false );
13481350 bptr->dealloc ();
13491351}
13501352
@@ -1464,7 +1466,7 @@ void rpc::add_price::request( json_wtr& msg )
14641466 tx.sign ( prc_idx, tx_idx, *akey_ );
14651467
14661468 // encode transaction and add to json params
1467- send_transaction ( msg, tx );
1469+ send_transaction ( msg, tx, false );
14681470 bptr->dealloc ();
14691471}
14701472
@@ -1573,7 +1575,7 @@ void rpc::init_price::request( json_wtr& msg )
15731575 tx.sign ( prc_idx, tx_idx, *akey_ );
15741576
15751577 // encode transaction and add to json params
1576- send_transaction ( msg, tx );
1578+ send_transaction ( msg, tx, false );
15771579 bptr->dealloc ();
15781580}
15791581
@@ -1655,7 +1657,7 @@ void rpc::init_mapping::request( json_wtr& msg )
16551657 tx.sign ( map_idx, tx_idx, *mkey_ );
16561658
16571659 // encode transaction and add to json params
1658- send_transaction ( msg, tx );
1660+ send_transaction ( msg, tx, false );
16591661 bptr->dealloc ();
16601662}
16611663
@@ -1746,7 +1748,7 @@ void rpc::add_mapping::request( json_wtr& msg )
17461748 tx.sign ( acc_idx, tx_idx, *akey_ );
17471749
17481750 // encode transaction and add to json params
1749- send_transaction ( msg, tx );
1751+ send_transaction ( msg, tx, false );
17501752 bptr->dealloc ();
17511753}
17521754
@@ -1839,7 +1841,7 @@ void rpc::add_publisher::request( json_wtr& msg )
18391841 tx.sign ( sym_idx, tx_idx, *akey_ );
18401842
18411843 // encode transaction and add to json params
1842- send_transaction ( msg, tx );
1844+ send_transaction ( msg, tx, false );
18431845 bptr->dealloc ();
18441846}
18451847
@@ -1932,7 +1934,7 @@ void rpc::del_publisher::request( json_wtr& msg )
19321934 tx.sign ( sym_idx, tx_idx, *akey_ );
19331935
19341936 // encode transaction and add to json params
1935- send_transaction ( msg, tx );
1937+ send_transaction ( msg, tx, false );
19361938 bptr->dealloc ();
19371939}
19381940
@@ -2014,7 +2016,7 @@ void rpc::init_test::request( json_wtr& msg )
20142016 tx.sign ( prm_idx, tx_idx, *akey_ );
20152017
20162018 // encode transaction and add to json params
2017- send_transaction ( msg, tx );
2019+ send_transaction ( msg, tx, false );
20182020 bptr->dealloc ();
20192021}
20202022
@@ -2122,16 +2124,7 @@ void rpc::upd_test::request( json_wtr& msg )
21222124 tx.sign ( tst_idx, tx_idx, *tkey_ );
21232125
21242126 // encode transaction and add to json params
2125- msg.add_key ( " method" , " sendTransaction" );
2126- msg.add_key ( " params" , json_wtr::e_arr );
2127- char buf[4096 ];
2128- size_t buf_len = enc_base64 ( (const uint8_t *)tx.get_buf (),
2129- tx.size (), (uint8_t *)buf );
2130- msg.add_val ( str ( buf, buf_len ) );
2131- msg.add_val ( json_wtr::e_obj );
2132- msg.add_key ( " encoding" , " base64" );
2133- msg.pop ();
2134- msg.pop ();
2127+ send_transaction ( msg, tx, false );
21352128 bptr->dealloc ();
21362129}
21372130
@@ -2314,6 +2307,16 @@ void rpc::upd_price::set_price( int64_t px,
23142307 cmd_ = is_agg?e_cmd_agg_price:e_cmd_upd_price;
23152308}
23162309
2310+ signature *rpc::upd_price::get_signature ()
2311+ {
2312+ return &sig_;
2313+ }
2314+
2315+ str rpc::upd_price::get_ack_signature () const
2316+ {
2317+ return ack_sig_;
2318+ }
2319+
23172320class tx_wtr : public net_wtr
23182321{
23192322public:
@@ -2329,12 +2332,8 @@ class tx_wtr : public net_wtr
23292332 }
23302333};
23312334
2332- void rpc::upd_price::build ( net_wtr& wtr )
2335+ void rpc::upd_price::build_tx ( bincode& tx )
23332336{
2334- // construct binary transaction and add header
2335- bincode tx;
2336- ((tx_wtr&)wtr).init ( tx );
2337-
23382337 // signatures section
23392338 tx.add_len <1 >(); // one signature (publish)
23402339 size_t pub_idx = tx.reserve_sign ();
@@ -2376,5 +2375,36 @@ void rpc::upd_price::build( net_wtr& wtr )
23762375
23772376 // all accounts need to sign transaction
23782377 tx.sign ( pub_idx, tx_idx, *ckey_ );
2378+ sig_.init_from_buf ( (const uint8_t *)(tx.get_buf () + pub_idx) );
2379+ }
2380+
2381+ void rpc::upd_price::build ( net_wtr& wtr )
2382+ {
2383+ bincode tx;
2384+ ((tx_wtr&)wtr).init ( tx );
2385+ build_tx ( tx );
23792386 ((tx_wtr&)wtr).commit ( tx );
23802387}
2388+
2389+ void rpc::upd_price::request ( json_wtr& msg )
2390+ {
2391+ // construct binary transaction
2392+ net_buf *bptr = net_buf::alloc ();
2393+ bincode tx ( bptr->buf_ );
2394+ build_tx ( tx );
2395+
2396+ // encode transaction and add to json params
2397+ send_transaction ( msg, tx, true );
2398+ bptr->dealloc ();
2399+ }
2400+
2401+ void rpc::upd_price::response ( const jtree& jt )
2402+ {
2403+ if ( on_error ( jt, this ) )
2404+ return ;
2405+ uint32_t rtok = jt.find_val ( 1 , " result" );
2406+ if ( rtok == 0 )
2407+ return ;
2408+ ack_sig_ = jt.get_str ( rtok );
2409+ on_response ( this );
2410+ }
0 commit comments