Skip to content

Commit 11689c5

Browse files
show tx errors in get_block
1 parent 8b455a4 commit 11689c5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pc/rpc_client.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,21 @@ char *rpc::get_block::get_cmd()
21552155
return &ibuf_[0];
21562156
}
21572157

2158+
bool rpc::get_block::get_is_tx_err() const
2159+
{
2160+
return is_tx_err_;
2161+
}
2162+
2163+
uint64_t rpc::get_block::get_tx_fee() const
2164+
{
2165+
return fee_;
2166+
}
2167+
2168+
str rpc::get_block::get_tx_err() const
2169+
{
2170+
return tx_err_;
2171+
}
2172+
21582173
bool rpc::get_block::get_is_end() const
21592174
{
21602175
return is_end_;
@@ -2182,6 +2197,18 @@ void rpc::get_block::response( const jtree& jt )
21822197
}
21832198
}
21842199
if ( !found ) continue;
2200+
// get meta-data
2201+
is_tx_err_ = false;
2202+
fee_ = 0UL;
2203+
uint32_t mx = jt.find_val( it, "meta" );
2204+
if ( mx && jt.get_type( mx ) == jtree::e_obj ) {
2205+
fee_ = jt.get_uint( jt.find_val( mx, "fee" ) );
2206+
uint32_t ex = jt.find_val( mx, "err" );
2207+
if ( ex && jt.get_type( ex ) == jtree::e_obj ) {
2208+
is_tx_err_ = true;
2209+
tx_err_ = jt.get_str( jt.get_key( jt.get_first( ex ) ) );
2210+
}
2211+
}
21852212
// get transaction details
21862213
uint32_t ix = jt.find_val( ms, "instructions" );
21872214
str idata = jt.get_str( jt.find_val( jt.get_first( ix ), "data" ) );

pc/rpc_client.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,10 @@ namespace pc
850850
void set_program( pub_key * );
851851
void request( json_wtr& ) override;
852852
void response( const jtree& ) override;
853+
uint64_t get_fee() const;
854+
bool get_is_tx_err() const;
855+
str get_tx_err() const;
856+
uint64_t get_tx_fee() const;
853857
unsigned get_num_key() const;
854858
pub_key *get_key( unsigned i );
855859
char *get_cmd();
@@ -863,7 +867,10 @@ namespace pc
863867
pub_key *gkey_;
864868
key_vec_t kvec_;
865869
ins_vec_t ibuf_;
870+
uint64_t fee_;
871+
str tx_err_;
866872
bool is_end_;
873+
bool is_tx_err_;
867874
};
868875

869876
// set new component price

pcapps/pyth.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,12 @@ class get_block_print : public get_block
12461246
std::cout << cmd->conf_ << std::endl;
12471247
print( "pub_slot", 2 );
12481248
std::cout << cmd->pub_slot_ << std::endl;
1249+
print( "tx_fee", 2 );
1250+
std::cout << res->get_tx_fee() << std::endl;
1251+
if ( res->get_is_tx_err() ) {
1252+
print( "tx_error", 2 );
1253+
std::cout << res->get_tx_err().as_string() << std::endl;
1254+
}
12491255
std::cout << std::endl;
12501256
}
12511257
void on_response( rpc::get_block *res ) override {
@@ -1288,6 +1294,10 @@ class get_block_json : public get_block
12881294
wtr_.add_key( "price", cmd->price_ );
12891295
wtr_.add_key( "conf", cmd->conf_ );
12901296
wtr_.add_key( "pub_slot", cmd->pub_slot_ );
1297+
wtr_.add_key( "tx_fee", res->get_tx_fee() );
1298+
if ( res->get_is_tx_err() ) {
1299+
wtr_.add_key( "tx_error", res->get_tx_err() );
1300+
}
12911301
wtr_.pop();
12921302
}
12931303
void on_response( rpc::get_block *res ) override {

0 commit comments

Comments
 (0)