stdrpc icon indicating copy to clipboard operation
stdrpc copied to clipboard

Batch Requests

Open ch4ot1c opened this issue 6 years ago • 2 comments

https://bitcoin.stackexchange.com/a/38492

Allow input like:

[{"jsonrpc":"2.0","method":"x","params":"y","id":1545344929685}, {"jsonrpc":"2.0","method":"a","params":"b","id":1545344929686}]

From https://www.jsonrpc.org/specification#batch:

rpc call Batch:

--> [
        {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
        {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
        {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
        {"foo": "boo"},
        {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
        {"jsonrpc": "2.0", "method": "get_data", "id": "9"} 
    ]
<-- [
        {"jsonrpc": "2.0", "result": 7, "id": "1"},
        {"jsonrpc": "2.0", "result": 19, "id": "2"},
        {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null},
        {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "5"},
        {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}
    ]

ch4ot1c avatar Dec 20 '18 22:12 ch4ot1c

@ch4ot1c What kinda API would work for this?

something like?

const [ result1, result2 ] = await rpc.$batch()
.rpcCall1(arg)
.rpcCall2(arg)
.$exec();

montyanderson avatar Jan 06 '19 14:01 montyanderson

Looks good

ch4ot1c avatar Feb 19 '19 22:02 ch4ot1c