@@ -107,13 +107,15 @@ namespace pc
107
107
static hash sys_id = gen_sys_id();
108
108
109
109
// 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 )
111
111
{
112
112
msg.add_key ( " method" , " sendTransaction" );
113
113
msg.add_key ( " params" , json_wtr::e_arr );
114
114
msg.add_val_enc_base64 ( str ( tx.get_buf (), tx.size () ) );
115
115
msg.add_val ( json_wtr::e_obj );
116
116
msg.add_key ( " encoding" , " base64" );
117
+ if ( skipPreflight )
118
+ msg.add_key ( " skipPreflight" , json_wtr::jtrue () );
117
119
msg.pop ();
118
120
msg.pop ();
119
121
}
@@ -808,7 +810,7 @@ void rpc::transfer::request( json_wtr& msg )
808
810
sig_.init_from_buf ( (const uint8_t *)(tx.get_buf () + sign_idx) );
809
811
810
812
// encode transaction and add to json params
811
- send_transaction ( msg, tx );
813
+ send_transaction ( msg, tx, false );
812
814
bptr->dealloc ();
813
815
}
814
816
@@ -1140,7 +1142,7 @@ void rpc::create_account::request( json_wtr& msg )
1140
1142
tx.sign ( acct_idx, tx_idx, *account_ );
1141
1143
1142
1144
// encode transaction and add to json params
1143
- send_transaction ( msg, tx );
1145
+ send_transaction ( msg, tx, false );
1144
1146
bptr->dealloc ();
1145
1147
}
1146
1148
@@ -1240,7 +1242,7 @@ void rpc::add_product::request( json_wtr& msg )
1240
1242
tx.sign ( sym_idx, tx_idx, *akey_ );
1241
1243
1242
1244
// encode transaction and add to json params
1243
- send_transaction ( msg, tx );
1245
+ send_transaction ( msg, tx, false );
1244
1246
bptr->dealloc ();
1245
1247
}
1246
1248
@@ -1344,7 +1346,7 @@ void rpc::upd_product::request( json_wtr& msg )
1344
1346
tx.sign ( sym_idx, tx_idx, *akey_ );
1345
1347
1346
1348
// encode transaction and add to json params
1347
- send_transaction ( msg, tx );
1349
+ send_transaction ( msg, tx, false );
1348
1350
bptr->dealloc ();
1349
1351
}
1350
1352
@@ -1464,7 +1466,7 @@ void rpc::add_price::request( json_wtr& msg )
1464
1466
tx.sign ( prc_idx, tx_idx, *akey_ );
1465
1467
1466
1468
// encode transaction and add to json params
1467
- send_transaction ( msg, tx );
1469
+ send_transaction ( msg, tx, false );
1468
1470
bptr->dealloc ();
1469
1471
}
1470
1472
@@ -1573,7 +1575,7 @@ void rpc::init_price::request( json_wtr& msg )
1573
1575
tx.sign ( prc_idx, tx_idx, *akey_ );
1574
1576
1575
1577
// encode transaction and add to json params
1576
- send_transaction ( msg, tx );
1578
+ send_transaction ( msg, tx, false );
1577
1579
bptr->dealloc ();
1578
1580
}
1579
1581
@@ -1655,7 +1657,7 @@ void rpc::init_mapping::request( json_wtr& msg )
1655
1657
tx.sign ( map_idx, tx_idx, *mkey_ );
1656
1658
1657
1659
// encode transaction and add to json params
1658
- send_transaction ( msg, tx );
1660
+ send_transaction ( msg, tx, false );
1659
1661
bptr->dealloc ();
1660
1662
}
1661
1663
@@ -1746,7 +1748,7 @@ void rpc::add_mapping::request( json_wtr& msg )
1746
1748
tx.sign ( acc_idx, tx_idx, *akey_ );
1747
1749
1748
1750
// encode transaction and add to json params
1749
- send_transaction ( msg, tx );
1751
+ send_transaction ( msg, tx, false );
1750
1752
bptr->dealloc ();
1751
1753
}
1752
1754
@@ -1839,7 +1841,7 @@ void rpc::add_publisher::request( json_wtr& msg )
1839
1841
tx.sign ( sym_idx, tx_idx, *akey_ );
1840
1842
1841
1843
// encode transaction and add to json params
1842
- send_transaction ( msg, tx );
1844
+ send_transaction ( msg, tx, false );
1843
1845
bptr->dealloc ();
1844
1846
}
1845
1847
@@ -1932,7 +1934,7 @@ void rpc::del_publisher::request( json_wtr& msg )
1932
1934
tx.sign ( sym_idx, tx_idx, *akey_ );
1933
1935
1934
1936
// encode transaction and add to json params
1935
- send_transaction ( msg, tx );
1937
+ send_transaction ( msg, tx, false );
1936
1938
bptr->dealloc ();
1937
1939
}
1938
1940
@@ -2014,7 +2016,7 @@ void rpc::init_test::request( json_wtr& msg )
2014
2016
tx.sign ( prm_idx, tx_idx, *akey_ );
2015
2017
2016
2018
// encode transaction and add to json params
2017
- send_transaction ( msg, tx );
2019
+ send_transaction ( msg, tx, false );
2018
2020
bptr->dealloc ();
2019
2021
}
2020
2022
@@ -2122,16 +2124,7 @@ void rpc::upd_test::request( json_wtr& msg )
2122
2124
tx.sign ( tst_idx, tx_idx, *tkey_ );
2123
2125
2124
2126
// 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 );
2135
2128
bptr->dealloc ();
2136
2129
}
2137
2130
@@ -2314,6 +2307,16 @@ void rpc::upd_price::set_price( int64_t px,
2314
2307
cmd_ = is_agg?e_cmd_agg_price:e_cmd_upd_price;
2315
2308
}
2316
2309
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
+
2317
2320
class tx_wtr : public net_wtr
2318
2321
{
2319
2322
public:
@@ -2329,12 +2332,8 @@ class tx_wtr : public net_wtr
2329
2332
}
2330
2333
};
2331
2334
2332
- void rpc::upd_price::build ( net_wtr& wtr )
2335
+ void rpc::upd_price::build_tx ( bincode& tx )
2333
2336
{
2334
- // construct binary transaction and add header
2335
- bincode tx;
2336
- ((tx_wtr&)wtr).init ( tx );
2337
-
2338
2337
// signatures section
2339
2338
tx.add_len <1 >(); // one signature (publish)
2340
2339
size_t pub_idx = tx.reserve_sign ();
@@ -2376,5 +2375,36 @@ void rpc::upd_price::build( net_wtr& wtr )
2376
2375
2377
2376
// all accounts need to sign transaction
2378
2377
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 );
2379
2386
((tx_wtr&)wtr).commit ( tx );
2380
2387
}
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