Skip to content

Commit

Permalink
fix to errors on fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
barelooksrare committed Sep 26, 2024
1 parent 735c36e commit 5bf3c60
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/anchor_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,41 +885,39 @@ Error AnchorProgram::fetch_account(const String name, const Variant& account){

void AnchorProgram::fetch_account_callback(const Dictionary &rpc_result){
String name = pending_account_name;
pending_account_name = "";

Dictionary ref_struct = find_idl_account(name);

if(ref_struct.is_empty()){
emit_signal("account_fetched", Dictionary());
ERR_FAIL_EDMSG("Account name was not found in IDL.");
}

pending_account_name = "";
if(!rpc_result.has("result")){
emit_signal("account_fetched", Dictionary());
ERR_FAIL_COND_EDMSG(rpc_result.has("error"), String(rpc_result["result"]));
ERR_FAIL_EDMSG("Unexpected RPC responce, no result.");
ERR_FAIL_COND_EDMSG(rpc_result.has("error"), String(rpc_result["error"]));
ERR_FAIL_EDMSG("Unexpected RPC response, no result.");
}

Dictionary result_dict = rpc_result["result"];
Variant value;
if(!result_dict.has("value")){
emit_signal("account_fetched", Dictionary());
ERR_FAIL_EDMSG("Unexpected RPC responce, no value.");
ERR_FAIL_EDMSG("Unexpected RPC response, no value.");
}
value = result_dict["value"];
Variant value = result_dict["value"];
if(value.get_type() != Variant::DICTIONARY){
if(value.get_type() == Variant::NIL) {
emit_signal("account_fetched", Dictionary());
return;
}
emit_signal("account_fetched", Dictionary());
ERR_FAIL_COND_EDMSG(value.get_type() == Variant::NIL, "Account does not exist");
ERR_FAIL_EDMSG("Unexpected RPC responce, unknown value type.");
ERR_FAIL_EDMSG("Unexpected RPC response, unknown value type.");
}

Dictionary account_dict = value;

Array account_data_tuple = account_dict["data"];
String encoded_data = account_data_tuple[0];

PackedByteArray account_data = SolanaUtils::bs64_decode(encoded_data);

account_data = account_data.slice(8);

const Array fields = ((Dictionary)ref_struct["type"])["fields"];
Expand Down Expand Up @@ -959,23 +957,25 @@ Error AnchorProgram::fetch_all_accounts(const String name, const Array& addition

void AnchorProgram::fetch_all_accounts_callback(const Dictionary &rpc_result) {
String name = pending_accounts_name;
pending_accounts_name = "";

Dictionary ref_struct = find_idl_account(name);

if (ref_struct.is_empty()) {
emit_signal("accounts_fetched", Dictionary());
ERR_FAIL_EDMSG("Account name was not found in IDL.");
}
pending_accounts_name = "";

if (!rpc_result.has("result")) {
emit_signal("accounts_fetched", Dictionary());
ERR_FAIL_COND_EDMSG(rpc_result.has("error"), String(rpc_result["error"]));
ERR_FAIL_EDMSG("Unexpected RPC response, no result.");
}

if (rpc_result["result"].get_type() != Variant::ARRAY){
emit_signal("accounts_fetched", Dictionary());
ERR_FAIL_EDMSG("Unexpected RPC response, result is not an array.");
}

Array accounts = rpc_result["result"];
Dictionary result_accounts;
const Array fields = ((Dictionary)ref_struct["type"])["fields"];
Expand Down

0 comments on commit 5bf3c60

Please sign in to comment.