Skip to content

Commit

Permalink
Merge pull request #166 from Virus-Axel/feature/anchor_program_node
Browse files Browse the repository at this point in the history
Add AnchorProgram interface
  • Loading branch information
Virus-Axel authored Jan 28, 2024
2 parents 893771b + 464b9d6 commit 9bedc88
Show file tree
Hide file tree
Showing 6 changed files with 809 additions and 0 deletions.
74 changes: 74 additions & 0 deletions include/anchor_program.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef SOLANA_SDK_ANCHOR_PROGRAM
#define SOLANA_SDK_ANCHOR_PROGRAM

#include <godot_cpp/variant/variant.hpp>
#include <godot_cpp/classes/node.hpp>

namespace godot{

class AnchorProgram : public Node{
GDCLASS(AnchorProgram, Node)
private:
Variant idl;
String pid;
bool try_from_pid = false;
Variant json_file;
bool try_from_json_file = false;
Array instructions;

static bool is_typed_primitive(const Dictionary &dict);
static PackedByteArray serialize_typed_primitive(const Dictionary &dict);
Variant idl_address(const Variant& pid);
bool load_from_pid(const String& pid);

bool is_int(const Variant &var);
bool is_float(const Variant &var);
bool check_type(const Variant& expected_type, const Variant& value);
bool validate_instruction_arguments(const String &instruction_name, const Array &arguments);
void register_instruction_builders();
PackedByteArray discriminator_by_name(const String &name);
Dictionary find_idl_instruction(const String &name);
Dictionary find_idl_account(const String &name);

Variant deserialize_variant(const PackedByteArray& bytes, const Variant& type, int &consumed_bytes);

bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;

protected:
static void _bind_methods();

public:
static PackedByteArray serialize_variant(const Variant &var);

void set_idl(const Dictionary& idl);
Dictionary get_idl();
void set_try_from_pid(const bool try_from_pid);
bool get_try_from_pid();
void set_try_from_json_file(const bool try_from_json_file);
bool get_try_from_json_file();

void set_pid(const String& try_from_pid);
String get_pid();
void set_json_file(const Variant& try_from_json_file);
Variant get_json_file();

static Dictionary f32(float val);
static Dictionary f64(double val);
static Dictionary s8(int val);
static Dictionary s16(int val);
static Dictionary s32(int32_t val);
static Dictionary s64(int64_t val);
static Dictionary u8(unsigned int val);
static Dictionary u16(unsigned int val);
static Dictionary u32(uint32_t val);
static Dictionary u64(uint64_t val);

Variant build_instruction(String name, Array accounts, Variant arguments);
Dictionary fetch_account(const String name, const Variant &account);
};

}

#endif
2 changes: 2 additions & 0 deletions include/pubkey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Pubkey : public Resource {
static Variant new_pda(const PackedStringArray seeds, const Variant &program_id);
static Variant new_pda_bytes(const Array seeds, const Variant &program_id);

static bool is_pubkey(const Variant &object);

bool create_program_address(const PackedStringArray seeds, const Variant &program_id);
bool create_program_address_bytes(const Array seeds, const Variant &program_id);
bool get_associated_token_address(const Variant &wallet_address, const Variant &token_mint_address);
Expand Down
Loading

0 comments on commit 9bedc88

Please sign in to comment.