Skip to content

Commit 6919e7e

Browse files
committed
add filtering based on account type to getProgramAccounts
1 parent 9353f91 commit 6919e7e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

pc/net_socket.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,12 @@ void json_wtr::add_key_verbatim( str key, str val )
14711471
add( val );
14721472
}
14731473

1474+
void json_wtr::add_key_enc_base58( str key, str val )
1475+
{
1476+
add_key_only( key );
1477+
add_enc_base58( val );
1478+
}
1479+
14741480
void json_wtr::add_key( str key, type_t t )
14751481
{
14761482
add_key_only( key );

pc/net_socket.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ namespace pc
446446
void add_key( str key, jtrue );
447447
void add_key( str key, jfalse );
448448
void add_key_verbatim( str key, str );
449+
void add_key_enc_base58( str key, str val );
449450

450451
// add array value
451452
void add_val( str val );

pc/rpc_client.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ bool rpc::account_subscribe::notify( const jtree& jt )
630630

631631
rpc::program_subscribe::program_subscribe()
632632
: account_update{}
633+
, pgm_{ nullptr }
633634
{
634635
}
635636

@@ -686,7 +687,9 @@ bool rpc::program_subscribe::notify( const jtree& jt )
686687
// get_program_accounts
687688

688689
rpc::get_program_accounts::get_program_accounts()
689-
: pgm_{ nullptr }
690+
: account_update{}
691+
, pgm_{ nullptr }
692+
, acct_type_{ 0 }
690693
{
691694
}
692695

@@ -695,6 +698,11 @@ void rpc::get_program_accounts::set_program( pub_key *pkey )
695698
pgm_ = pkey;
696699
}
697700

701+
void rpc::get_program_accounts::set_account_type( uint32_t const acct_type )
702+
{
703+
acct_type_ = acct_type;
704+
}
705+
698706
void rpc::get_program_accounts::request( json_wtr& msg )
699707
{
700708
msg.add_key( "method", "getProgramAccounts" );
@@ -703,6 +711,17 @@ void rpc::get_program_accounts::request( json_wtr& msg )
703711
msg.add_val( json_wtr::e_obj );
704712
msg.add_key( "encoding", "base64+zstd" );
705713
msg.add_key( "commitment", commitment_to_str( cmt_ ) );
714+
if ( acct_type_ ) {
715+
msg.add_key( "filters", json_wtr::e_arr );
716+
msg.add_val( json_wtr::e_obj );
717+
msg.add_key( "memcmp", json_wtr::e_obj );
718+
msg.add_key( "offset", offsetof( pc_acc_t, type_ ) );
719+
msg.add_key_enc_base58(
720+
"bytes", str( ( char* )&acct_type_, sizeof( acct_type_ ) ) );
721+
msg.pop();
722+
msg.pop();
723+
msg.pop();
724+
}
706725
msg.add_key( "withContext", json_wtr::jtrue{} );
707726
msg.pop();
708727
msg.pop();

pc/rpc_client.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ namespace pc
378378
public:
379379
// parameters
380380
void set_program( pub_key * );
381+
void set_account_type( uint32_t );
381382

382383
get_program_accounts();
383384
void request( json_wtr& ) override;
@@ -387,6 +388,7 @@ namespace pc
387388

388389
private:
389390
pub_key *pgm_;
391+
uint32_t acct_type_;
390392
};
391393

392394
// get all (pyth) transactions in a slot

0 commit comments

Comments
 (0)