4

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?

1
  • I'd suggest using in example console.log instead of alert - it's less annoying Commented Nov 16, 2018 at 12:44

1 Answer 1

1

It seems to work with the following JavaScript syntax

var argsArray = ['::InitiatorA', 'abc', 'xyz']
startTrackedFlowDynamic(...argsArray)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.