Skip to content

Commit

Permalink
Merge pull request #293 from Virus-Axel/feature/shdw_drive
Browse files Browse the repository at this point in the history
Feature/shdw drive
  • Loading branch information
Virus-Axel authored Oct 12, 2024
2 parents d8e8f30 + d8bdcc4 commit 2b845af
Show file tree
Hide file tree
Showing 13 changed files with 1,940 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
path = build-containers
url = [email protected]:godotengine/build-containers.git
branch = main
[submodule "GodotSolanaSDKDemoPackage"]
path = GodotSolanaSDKDemoPackage
url = [email protected]:ZenRepublic/GodotSolanaSDKDemoPackage.git
132 changes: 132 additions & 0 deletions include/honeycomb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#ifndef GODOT_SOLANA_SDK_HONEYCOMB_HPP
#define GODOT_SOLANA_SDK_HONEYCOMB_HPP

#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/classes/http_request.hpp>
#include "transaction.hpp"

namespace godot{

enum ResourceStorageEnum{
AccountState = 0,
LedgerState = 1,
};

class InitResourceInput: public Resource{
GDCLASS(InitResourceInput, Resource)
private:
String resource_name = "";
String symbol = "";
String uri = "";
int32_t decimals = 0;
ResourceStorageEnum storage = AccountState;
protected:
static void _bind_methods();
public:
void set_resource_name(const String& resource_name);
String get_resource_name();
void set_symbol(const String& symbol);
String get_symbol();
void set_uri(const String& uri);
String get_uri();
void set_decimals(int32_t decimals);
int32_t get_decimals();
void set_storage(int32_t storage);
int32_t get_storage();

Dictionary to_dict();
};


class UserInfoInput: public Resource{
GDCLASS(UserInfoInput, Resource)
private:
String username = "";
String real_name = "";
String bio = "";
String pfp = "";
protected:
static void _bind_methods();
public:
Dictionary to_dict();
};


class BasicTreeConfig : public Resource{
GDCLASS(BasicTreeConfig, Resource)
private:
int32_t num_assets = 0;
protected:
static void _bind_methods();
public:
};

class AdvancedTreeConfig : public Resource{
GDCLASS(AdvancedTreeConfig, Resource)
private:
int32_t max_depth = 0;
int32_t max_buffer_size = 0;
int32_t canopy_depth = 0;
protected:
static void _bind_methods();
public:
Dictionary to_dict();
};

class TreeSetupConfig : public Resource{
GDCLASS(TreeSetupConfig, Resource)
private:
Variant basic;
Variant advanced;
protected:
static void _bind_methods();
public:
Dictionary to_dict();
};

class HoneyComb: public Node{
GDCLASS(HoneyComb, Node)
private:
bool pending = false;
Node* child = nullptr;
HTTPRequest* api_request;
Transaction* result_tx;

String request;
String method_name;
Array args;

Array signers;
String query_fields = "";

String build();
void send_query();

void bind_method_from_ref(const String ref);
void add_arg(const String& name, const String& type_name, const Variant& value, bool optional = false);
void query_response_callback(int result, int response_code, const PackedStringArray& headers, const PackedByteArray& body);
void transaction_response_callback(const Dictionary& response);

static void bind_non_changing_methods();

protected:
HoneyComb();
static void _bind_methods();
~HoneyComb();
public:

Variant create_project(const Variant& authority, const String& name);
void create_user(const Variant& user_wallet_keypair);
void create_profile(const Variant& project, const Variant& payer);
void create_resource(const Variant& project, const Variant& authority, const String& name, const String& uri, const String& symbol, uint32_t decimals);
Variant createCreateNewResourceTransaction(const Variant& project, const Variant& authority, Variant params, String delegateAuthority = "", String payer = "", PackedStringArray lutAddresses = PackedStringArray(), int32_t computeUnitPrice = -1);
Variant createCreateNewResourceTreeTransaction(const Variant& project, const Variant& resource, const Variant& authority, Variant treeConfig, const Variant& delegateAuthority = "", const Variant& payer = "", PackedStringArray lutAddresses = PackedStringArray(), int32_t computeUnitPrice = -1);
Variant createMintResourceTransaction(const Variant& resource, const Variant& owner, const Variant& authority, int64_t amount, const Variant& delegateAuthority = "", const Variant& payer = "", PackedStringArray lutAddresses = PackedStringArray(), int32_t computeUnitPrice = -1);
Variant createBurnResourceTransaction(const Variant& resource, int64_t amount, const Variant& authority, const Variant& owner = "", const Variant& payer = "", const Variant& delegateAuthority = "", PackedStringArray lutAddresses = PackedStringArray(), int32_t computeUnitPrice = -1);
Variant createNewUserTransaction(const Variant& wallet, Variant info = Variant(nullptr), const Variant& payer = "", PackedStringArray lutAddresses = PackedStringArray(), int32_t computeUnitPrice = -1);
};

}

#endif
132 changes: 132 additions & 0 deletions include/shdwdrive.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#ifndef GODOT_SOLANA_SDK_SHDW_DRIVE_HPP
#define GODOT_SOLANA_SDK_SHDW_DRIVE_HPP

#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/classes/http_request.hpp>
#include "solana_client.hpp"
#include "transaction.hpp"

namespace godot{

class StorageAccountV2: public Resource{
GDCLASS(StorageAccountV2, Resource)
private:
bool immutable = false;
bool to_be_deleted = false;
uint32_t delete_request_epoch = 0;
uint64_t storage = 0;
Variant owner1;
uint32_t account_counter_seed = 0;
uint32_t creation_time = 0;
uint32_t creation_epoch = 0;
uint32_t last_fee_epoch = 0;
String identifier = "";

static PackedByteArray discriminator();

protected:
static void _bind_methods();
public:
void from_bytes(const PackedByteArray& bytes);
String get_identifier();
Dictionary to_dict();
};

class UserInfo: public Resource{
GDCLASS(UserInfo, Resource)
private:
uint32_t account_counter = 0;
uint32_t delete_counter = 0;
bool agreed_to_terms = false;
bool had_bad_scam_scan = false;

static PackedByteArray discriminator();

protected:
static void _bind_methods();

public:
uint32_t get_account_counter();
void from_bytes(const PackedByteArray& bytes);
};

class ShdwDrive : public Node {
GDCLASS(ShdwDrive, Node)
private:
static const std::string ID;

bool new_user = false;
Variant owner_keypair;
String storage_name;
uint64_t storage_size;
UserInfo* user_info = nullptr;
StorageAccountV2* storage_account = nullptr;
RpcSingleHttpRequestClient *api_request = nullptr;
HTTPRequest *upload_file_request = nullptr;

Array storage_list;
PackedStringArray storage_name_list;
PackedStringArray storage_key_list;

SolanaClient *create_storage_account_client = nullptr;
SolanaClient *fetch_user_info_client = nullptr;
SolanaClient *fetch_storage_account_client = nullptr;
SolanaClient *fetch_all_storage_accounts_client = nullptr;
Transaction *create_storage_account_transaction = nullptr;

static PackedByteArray initialize_accountv2_discriminator();
static PackedByteArray create_form_line(const String& line);
static PackedByteArray create_form_line(const PackedByteArray& content);
static String get_upload_message(const Variant& storage_account_key, const String& filename_hash);
static String get_filename_hash(const String& filename);

void get_all_storage_accounts(const Variant& owner_key);
void send_fetch_account_infos();

void fetch_userinfo_callback(const Dictionary& params);
void fetch_storage_account_callback(const Dictionary& params);
void upload_file_callback(int result, int response_code, const PackedStringArray& headers, const PackedByteArray& body);

uint64_t human_size_to_bytes(const String& human_size);

Variant get_uploader();

protected:
static void _bind_methods();
public:
ShdwDrive();
void _process(double delta) override;

Array get_cached_storage_accounts();

Variant fetch_user_info(const Variant address);
Variant fetch_storage_account(const Variant address);
Variant create_storage_account(const Variant& owner_keypair, const String& name, const Variant& size);

Variant fetch_storage_key_by_name_callback(const String& storage_name);
Variant fetch_storage_key_by_name(const Variant& owner_keypair, const String& storage_name);

void send_create_storage_tx();
void send_create_storage_tx_signed();

void create_store_api_response(const Dictionary& response);
void get_multiple_accounts_callback(const Dictionary& response);

static Variant new_user_info_pubkey(const Variant& base_keypair);
static Variant new_stake_account_pubkey(const Variant& storage_account);
static Variant new_storage_config_pubkey();
static Variant new_storage_account_pubkey(const Variant& owner_key, uint64_t account_seed);

Variant initialize_account(const Variant& owner_keypair, const String name, uint64_t storage);
void upload_file_to_storage(const String& filename, const Variant& storage_owner_keypair, const Variant& storage_account);

static Variant get_pid();

~ShdwDrive();
};

} // godot


#endif
2 changes: 1 addition & 1 deletion include/solana_client/solana_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class SolanaClient : public Node {
Callable ws_callback;
Callable rpc_callback = callable_mp(this, &SolanaClient::response_callback);


String ws_from_http(const String& http_url);
String get_real_url();
uint32_t get_real_http_port();
Expand Down Expand Up @@ -162,6 +161,7 @@ class SolanaClient : public Node {
*
* @param url
*/

void set_url_override(const String& url);

/**
Expand Down
2 changes: 2 additions & 0 deletions include/transaction/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Message: public Resource{ // Message
TypedArray<CompiledInstruction> compiled_instructions;
Array signers;

bool is_versioned_transaction = false;

Array address_lookup_tables;

TypedArray<AccountMeta> merged_metas;
Expand Down
2 changes: 1 addition & 1 deletion include/transaction/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Transaction : public Node {
Error sign();
void send();
Variant sign_and_send();
Error partially_sign(const Variant& latest_blockhash);
Error partially_sign(const Array& array);

void create_signed_with_payer(Array instructions, Variant payer, Array signers, Variant latest_blockhash);

Expand Down
Loading

0 comments on commit 2b845af

Please sign in to comment.