mschneider / solcpp

A fast Solana and Mango Markets C++ SDK
Other
40 stars 13 forks source link

Create a consistent Connection interface and organize structs into individual files. #5

Closed bdhobare closed 2 years ago

bdhobare commented 2 years ago

The implemented API is illustrated in examples/connection-example.cpp. It looks like this:

#include "solana.h"

// Example: getAccountInfo RPC method

const auto rpc_url = "...";
const auto pubKey = "..";
sol::Connection connection = sol::Connection{rpc_url, "finalized"};
auto key  = sol::PublicKey::fromBase58(pubKey);
std::optional<sol::AccountInfo> info = connection.getAccountInfo(key);
if (!info.has_value()){
    std::cout << "Account doesn't exist.\n";
    return;
}
std::cout << "Account Owner: " << info.value().owner.toBase58() << std::endl;

Implementing a new RPC method

Add it to connection.h and implement it in a separate file. Example:

The added method will be used by the library user as:

auto response = connection.getXXYY(request);

WebSockets

This PR starts with the HTTP RPC methods(only getAccountInfo is implemented here) to get feedback and websockets implementation will be added in follow up PRs.

Next Steps