Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25e8ca4
commit b61bf22
Showing
4 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package snowblossom.client; | ||
|
||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Error; | ||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; | ||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; | ||
import com.thetransactioncompany.jsonrpc2.server.RequestHandler; | ||
import com.thetransactioncompany.jsonrpc2.server.MessageContext; | ||
|
||
import net.minidev.json.JSONObject; | ||
|
||
|
||
public abstract class JsonRequestHandler implements RequestHandler | ||
{ | ||
public abstract String[] handledRequests(); | ||
|
||
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) | ||
{ | ||
try | ||
{ | ||
JSONObject reply = processRequest(req, ctx); | ||
|
||
return new JSONRPC2Response(reply, req.getID()); | ||
} | ||
catch(Throwable t) | ||
{ | ||
return new JSONRPC2Response(new JSONRPC2Error(500, t.toString()), req.getID()); | ||
|
||
} | ||
|
||
} | ||
|
||
protected abstract JSONObject processRequest(JSONRPC2Request req, MessageContext ctx) throws Exception; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package snowblossom.client; | ||
|
||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Request; | ||
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response; | ||
import com.thetransactioncompany.jsonrpc2.server.RequestHandler; | ||
import com.thetransactioncompany.jsonrpc2.server.MessageContext; | ||
|
||
import net.minidev.json.JSONObject; | ||
|
||
import snowblossom.proto.*; | ||
import snowblossom.lib.*; | ||
|
||
public class RpcServerHandler | ||
{ | ||
private SnowBlossomClient client; | ||
|
||
public RpcServerHandler(SnowBlossomClient client) | ||
{ | ||
this.client = client; | ||
} | ||
|
||
public void registerHandlers(JsonRpcServer json_server) | ||
{ | ||
json_server.register(new GetFreshHandler()); | ||
|
||
} | ||
|
||
public class GetFreshHandler extends JsonRequestHandler | ||
{ | ||
public String[] handledRequests() | ||
{ | ||
return new String[]{"getfresh"}; | ||
} | ||
|
||
@Override | ||
protected JSONObject processRequest(JSONRPC2Request req, MessageContext ctx) | ||
throws Exception | ||
{ | ||
boolean mark_used = false; | ||
boolean generate_now = false; | ||
if (req.getNamedParams().containsKey("mark_used")) | ||
{ | ||
mark_used = (boolean) req.getNamedParams().get("mark_used"); | ||
} | ||
if (req.getNamedParams().containsKey("generate_now")) | ||
{ | ||
generate_now = (boolean) req.getNamedParams().get("generate_now"); | ||
} | ||
JSONObject reply = new JSONObject(); | ||
reply.put("mark_used", mark_used); | ||
reply.put("generate_now", generate_now); | ||
|
||
AddressSpecHash spec_hash = client.getPurse().getUnusedAddress(mark_used, generate_now); | ||
String address = AddressUtil.getAddressString(client.getParams().getAddressPrefix(), spec_hash); | ||
reply.put("address", address); | ||
|
||
return reply; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters