14: Implement JSON-RPC call
This commit is contained in:
@@ -392,6 +392,52 @@ public class SolanaBlockChainImpl implements SolanaBlockChain {
|
||||
return Set.copyOf(accountInfos);
|
||||
}
|
||||
|
||||
private String createGetProgramAccountsBody(
|
||||
ΩSolanaProgramIdΩ programId,
|
||||
Set<SolanaProgramAccountMemcmpFilter> filters
|
||||
) throws IOException {
|
||||
StringBuilder filtersJson = new StringBuilder();
|
||||
|
||||
boolean first = true;
|
||||
for (SolanaProgramAccountMemcmpFilter filter : filters) {
|
||||
if (!first) {
|
||||
filtersJson.append(",");
|
||||
}
|
||||
|
||||
filtersJson.append("""
|
||||
{
|
||||
"memcmp": {
|
||||
"offset": %d,
|
||||
"bytes": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(
|
||||
filter.offset(),
|
||||
filter.bytes()
|
||||
));
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
return """
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "getProgramAccounts",
|
||||
"params": [
|
||||
"%s",
|
||||
{
|
||||
"commitment": "finalized",
|
||||
"encoding": "base64",
|
||||
"filters": [
|
||||
%s
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(programId, filtersJson);
|
||||
}
|
||||
|
||||
private synchronized HttpResponse<String> sendThrottled(HttpRequest request) throws IOException, InterruptedException {
|
||||
waitBeforeRemoteCall();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user