In this PR, we are implementing a sol::Connection class inspired by the web3.js sdk and organize the library into a consistent library in solana.h.
We have also moved the existing structs into separate files where each RPC call will be handled separately to avoid crowding one file.
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:
All RPC calls involving Accounts are in Account.h
All RPC calls involving transactions are in Transaction.h
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
[ ] All the existing examples and methods in solana.hpp by @mschneider have not been modified. We can start looking at migrating them to use the sol::Connection interface.
[ ] Implement all the HTTP RPC calls in connection.h
[ ] Add support for websocket to sol::Connection instance.
[ ] Support templated AccountInfo<T>
[ ] Support multiple concurrent connection instances.
sol::Connection
class inspired by theweb3.js
sdk and organize the library into a consistent library insolana.h
.The implemented API is illustrated in
examples/connection-example.cpp
. It looks like this:Implementing a new RPC method
Add it to
connection.h
and implement it in a separate file. Example:Account.h
Transaction.h
The added method will be used by the library user as:
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
solana.hpp
by @mschneider have not been modified. We can start looking at migrating them to use thesol::Connection
interface.connection.h
sol::Connection
instance.AccountInfo<T>