Reputation: 51
I am trying to call a function available in Corda RPC called startTrackedFlowDynamic
which accepts 2 arguments:
startTrackedFlowDynamic(logicType: Class<out FlowLogic<T>>, vararg args: Any?)
which is packaged in a JAR
The call to this function is made from a Javascript context (using GraalVM to achieve that), I want to call this function and pass the arguments to it obtained from a request object (say, coming from a REST API)
Example:
if the request contains an array [::InitiatorA, iouValue]
,
I would want to call startTrackedFlowDynamic like:
startTrackedFlowDynamic(::InitiatorA, iouValue)
if the request contains an array [::InitiatorB, abc, xyz]
I would want to call startTrackedFlowDynamic like:
startTrackedFlowDynamic(::InitiatorB, abc, xyz)
if the request contains an array [::InitiatorC]
I would want to call startTrackedFlowDynamic like:
startTrackedFlowDynamic(::InitiatorC)
TLDR: I would like to make it as a generic API instead of re-writing for every different Flow call. I want to be able to pass dynamic number of arguments coming from the request object to this function instead of hard coding a fixed number of arguments and having to update it when the number of argument changes
An example of the behaviour I want to replicate:
var func = function () {
console.log(arguments.length);
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
};
func.apply(null, ['::InitiatorA', 'abc', 'xyz'])
Any suggestions?
Upvotes: 4
Views: 1098
Reputation: 51
It seems to work with the following JavaScript syntax
var argsArray = ['::InitiatorA', 'abc', 'xyz']
startTrackedFlowDynamic(...argsArray)
Upvotes: 1