/* eslint-disable */
// @ts-nocheck
/**
 *
 * This file is auto-generated. Do not edit manually: changes may be erased.
 * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
 * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
 * Aqua version: 0.10.1
 *
 */

import {
    v5_callFunction as callFunction$$,
    v5_registerService as registerService$$,
} from '@fluencelabs/js-client.api';
    


// Services



export function registerNumOp(...args) {
    registerService$$(
        args,
        {
    "defaultServiceId" : "op",
    "functions" : {
        "tag" : "labeledProduct",
        "fields" : {
            "identity" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "labeledProduct",
                    "fields" : {
                        "n" : {
                            "tag" : "scalar",
                            "name" : "u64"
                        }
                    }
                },
                "codomain" : {
                    "tag" : "unlabeledProduct",
                    "items" : [
                        {
                            "tag" : "scalar",
                            "name" : "i64"
                        }
                    ]
                }
            }
        }
    }
}
    );
}
      




export function registerLogger(...args) {
    registerService$$(
        args,
        {
    "defaultServiceId" : "logger",
    "functions" : {
        "tag" : "labeledProduct",
        "fields" : {
            "log" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "labeledProduct",
                    "fields" : {
                        "s" : {
                            "tag" : "array",
                            "type" : {
                                "tag" : "scalar",
                                "name" : "string"
                            }
                        }
                    }
                },
                "codomain" : {
                    "tag" : "nil"
                }
            },
            "logCall" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "labeledProduct",
                    "fields" : {
                        "s" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                },
                "codomain" : {
                    "tag" : "nil"
                }
            }
        }
    }
}
    );
}
      




export function registerQuorumChecker(...args) {
    registerService$$(
        args,
        {
    "defaultServiceId" : "quorum",
    "functions" : {
        "tag" : "labeledProduct",
        "fields" : {
            "check" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "labeledProduct",
                    "fields" : {
                        "results" : {
                            "tag" : "array",
                            "type" : {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        },
                        "minResults" : {
                            "tag" : "scalar",
                            "name" : "u32"
                        }
                    }
                },
                "codomain" : {
                    "tag" : "unlabeledProduct",
                    "items" : [
                        {
                            "tag" : "struct",
                            "name" : "QuorumResult",
                            "fields" : {
                                "error" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                },
                                "results" : {
                                    "tag" : "array",
                                    "type" : {
                                        "tag" : "struct",
                                        "name" : "EthResult",
                                        "fields" : {
                                            "error" : {
                                                "tag" : "scalar",
                                                "name" : "string"
                                            },
                                            "success" : {
                                                "tag" : "scalar",
                                                "name" : "bool"
                                            },
                                            "value" : {
                                                "tag" : "scalar",
                                                "name" : "string"
                                            }
                                        }
                                    }
                                },
                                "value" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
    );
}
      




export function registerEthCaller(...args) {
    registerService$$(
        args,
        {
    "functions" : {
        "tag" : "labeledProduct",
        "fields" : {
            "eth_call" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "labeledProduct",
                    "fields" : {
                        "uri" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "method" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "jsonArgs" : {
                            "tag" : "array",
                            "type" : {
                                "tag" : "scalar",
                                "name" : "string"
                            }
                        }
                    }
                },
                "codomain" : {
                    "tag" : "unlabeledProduct",
                    "items" : [
                        {
                            "tag" : "struct",
                            "name" : "EthResult",
                            "fields" : {
                                "error" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                },
                                "success" : {
                                    "tag" : "scalar",
                                    "name" : "bool"
                                },
                                "value" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
    );
}
      




export function registerCounter(...args) {
    registerService$$(
        args,
        {
    "defaultServiceId" : "counter",
    "functions" : {
        "tag" : "labeledProduct",
        "fields" : {
            "incrementAndReturn" : {
                "tag" : "arrow",
                "domain" : {
                    "tag" : "nil"
                },
                "codomain" : {
                    "tag" : "unlabeledProduct",
                    "items" : [
                        {
                            "tag" : "scalar",
                            "name" : "u32"
                        }
                    ]
                }
            }
        }
    }
}
    );
}
      
// Functions

export function roundRobinEth(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (seq
                             (seq
                              (seq
                               (seq
                                (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                                (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                               )
                               (call %init_peer_id% ("getDataSrv" "method") [] method)
                              )
                              (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                             )
                             (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                            )
                            (call %init_peer_id% ("getDataSrv" "counterServiceId") [] counterServiceId)
                           )
                           (call %init_peer_id% ("getDataSrv" "counterPeerId") [] counterPeerId)
                          )
                          (call -relay- ("op" "noop") [])
                         )
                         (xor
                          (call counterPeerId (counterServiceId "incrementAndReturn") [] requestNumber)
                          (seq
                           (call -relay- ("op" "noop") [])
                           (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                          )
                         )
                        )
                        (xor
                         (seq
                          (seq
                           (seq
                            (ap uris uris_to_functor)
                            (ap uris_to_functor.length uris_length)
                           )
                           (call %init_peer_id% ("math" "rem") [requestNumber uris_length] rem)
                          )
                          (call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
                         )
                         (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                        )
                       )
                       (xor
                        (call -relay- (serviceId "eth_call") [uris.$.[rem]! method jsonArgs] res)
                        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [res])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "roundRobinEth",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "counterServiceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "counterPeerId" : {
                    "tag" : "scalar",
                    "name" : "string"
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function empty(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                       (call %init_peer_id% ("json" "obj") ["error" "" "success" true "value" ""] EthResult_obj)
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [EthResult_obj])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "empty",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function quorumEth(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (seq
                             (seq
                              (seq
                               (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                               (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                              )
                              (call %init_peer_id% ("getDataSrv" "quorumNumber") [] quorumNumber)
                             )
                             (call %init_peer_id% ("getDataSrv" "timeout") [] timeout)
                            )
                            (call %init_peer_id% ("getDataSrv" "method") [] method)
                           )
                           (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                          )
                          (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                         )
                         (call %init_peer_id% ("getDataSrv" "quorumServiceId") [] quorumServiceId)
                        )
                        (call %init_peer_id% ("getDataSrv" "quorumPeerId") [] quorumPeerId)
                       )
                       (new $results
                        (seq
                         (seq
                          (seq
                           (xor
                            (par
                             (fold uris uri-0
                              (par
                               (seq
                                (seq
                                 (xor
                                  (call -relay- (serviceId "eth_call") [uri-0 method jsonArgs] res)
                                  (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                                 )
                                 (ap res $results)
                                )
                                (call %init_peer_id% ("op" "noop") [])
                               )
                               (next uri-0)
                              )
                              (never)
                             )
                             (null)
                            )
                            (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                           )
                           (par
                            (seq
                             (seq
                              (seq
                               (seq
                                (seq
                                 (seq
                                  (ap uris uris_to_functor)
                                  (ap uris_to_functor.length uris_length)
                                 )
                                 (call %init_peer_id% ("math" "sub") [uris_length 1] sub)
                                )
                                (new $results_test
                                 (seq
                                  (seq
                                   (seq
                                    (call %init_peer_id% ("math" "add") [sub 1] results_incr)
                                    (fold $results s
                                     (seq
                                      (seq
                                       (ap s $results_test)
                                       (canon %init_peer_id% $results_test  #results_iter_canon)
                                      )
                                      (xor
                                       (match #results_iter_canon.length results_incr
                                        (null)
                                       )
                                       (next s)
                                      )
                                     )
                                     (never)
                                    )
                                   )
                                   (canon %init_peer_id% $results_test  #results_result_canon)
                                  )
                                  (ap #results_result_canon results_gate)
                                 )
                                )
                               )
                               (ap uris uris_to_functor-0)
                              )
                              (ap uris_to_functor-0.length uris_length-0)
                             )
                             (call %init_peer_id% ("math" "sub") [uris_length-0 1] sub-0)
                            )
                            (call %init_peer_id% ("peer" "timeout") [timeout ""])
                           )
                          )
                          (call -relay- ("op" "noop") [])
                         )
                         (xor
                          (seq
                           (seq
                            (canon quorumPeerId $results  #results_canon)
                            (call quorumPeerId ("quorum" "check") [#results_canon quorumNumber] quorumResult)
                           )
                           (call -relay- ("op" "noop") [])
                          )
                          (seq
                           (call -relay- ("op" "noop") [])
                           (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                          )
                         )
                        )
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [quorumResult])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "quorumEth",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "quorumNumber" : {
                    "tag" : "scalar",
                    "name" : "u32"
                },
                "timeout" : {
                    "tag" : "scalar",
                    "name" : "u32"
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "quorumServiceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "quorumPeerId" : {
                    "tag" : "scalar",
                    "name" : "string"
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "QuorumResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "results" : {
                            "tag" : "array",
                            "type" : {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function randomLoadBalancing(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                            (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                           )
                           (call %init_peer_id% ("getDataSrv" "method") [] method)
                          )
                          (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                         )
                         (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                        )
                        (xor
                         (seq
                          (seq
                           (seq
                            (seq
                             (call %init_peer_id% ("peer" "timestamp_sec") [] timestamp_sec)
                             (call %init_peer_id% ("op" "identity") [timestamp_sec] time)
                            )
                            (call %init_peer_id% ("op" "array_length") [uris] array_length)
                           )
                           (call %init_peer_id% ("math" "rem") [time array_length] rem)
                          )
                          (call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
                         )
                         (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                        )
                       )
                       (xor
                        (call %init_peer_id% ("callbackSrv" "callFunc") [uris.$.[rem]! method jsonArgs serviceId] init_call_res0)
                        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [init_call_res0])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "randomLoadBalancing",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "callFunc" : {
                    "tag" : "arrow",
                    "domain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "array",
                                "type" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                }
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            }
                        ]
                    },
                    "codomain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function randomLoadBalancingEth(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                            (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                           )
                           (call %init_peer_id% ("getDataSrv" "method") [] method)
                          )
                          (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                         )
                         (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                        )
                        (xor
                         (seq
                          (seq
                           (seq
                            (seq
                             (call %init_peer_id% ("peer" "timestamp_sec") [] timestamp_sec)
                             (call %init_peer_id% ("op" "identity") [timestamp_sec] time)
                            )
                            (call %init_peer_id% ("op" "array_length") [uris] array_length)
                           )
                           (call %init_peer_id% ("math" "rem") [time array_length] rem)
                          )
                          (call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
                         )
                         (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                        )
                       )
                       (xor
                        (call -relay- (serviceId "eth_call") [uris.$.[rem]! method jsonArgs] res)
                        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [res])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "randomLoadBalancingEth",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function quorum(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (seq
                             (seq
                              (seq
                               (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                               (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                              )
                              (call %init_peer_id% ("getDataSrv" "quorumNumber") [] quorumNumber)
                             )
                             (call %init_peer_id% ("getDataSrv" "timeout") [] timeout)
                            )
                            (call %init_peer_id% ("getDataSrv" "method") [] method)
                           )
                           (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                          )
                          (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                         )
                         (call %init_peer_id% ("getDataSrv" "quorumServiceId") [] quorumServiceId)
                        )
                        (call %init_peer_id% ("getDataSrv" "quorumPeerId") [] quorumPeerId)
                       )
                       (new $results
                        (seq
                         (seq
                          (seq
                           (xor
                            (par
                             (fold uris uri-0
                              (par
                               (seq
                                (seq
                                 (xor
                                  (call %init_peer_id% ("callbackSrv" "callFunc") [uri-0 method jsonArgs serviceId] init_call_res0)
                                  (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                                 )
                                 (ap init_call_res0 $results)
                                )
                                (call %init_peer_id% ("op" "noop") [])
                               )
                               (next uri-0)
                              )
                              (never)
                             )
                             (null)
                            )
                            (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                           )
                           (par
                            (seq
                             (seq
                              (seq
                               (seq
                                (seq
                                 (seq
                                  (ap uris uris_to_functor)
                                  (ap uris_to_functor.length uris_length)
                                 )
                                 (call %init_peer_id% ("math" "sub") [uris_length 1] sub)
                                )
                                (new $results_test
                                 (seq
                                  (seq
                                   (seq
                                    (call %init_peer_id% ("math" "add") [sub 1] results_incr)
                                    (fold $results s
                                     (seq
                                      (seq
                                       (ap s $results_test)
                                       (canon %init_peer_id% $results_test  #results_iter_canon)
                                      )
                                      (xor
                                       (match #results_iter_canon.length results_incr
                                        (null)
                                       )
                                       (next s)
                                      )
                                     )
                                     (never)
                                    )
                                   )
                                   (canon %init_peer_id% $results_test  #results_result_canon)
                                  )
                                  (ap #results_result_canon results_gate)
                                 )
                                )
                               )
                               (ap uris uris_to_functor-0)
                              )
                              (ap uris_to_functor-0.length uris_length-0)
                             )
                             (call %init_peer_id% ("math" "sub") [uris_length-0 1] sub-0)
                            )
                            (call %init_peer_id% ("peer" "timeout") [timeout ""])
                           )
                          )
                          (call -relay- ("op" "noop") [])
                         )
                         (xor
                          (seq
                           (seq
                            (canon quorumPeerId $results  #results_canon)
                            (call quorumPeerId ("quorum" "check") [#results_canon quorumNumber] quorumResult)
                           )
                           (call -relay- ("op" "noop") [])
                          )
                          (seq
                           (call -relay- ("op" "noop") [])
                           (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                          )
                         )
                        )
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [quorumResult])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "quorum",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "quorumNumber" : {
                    "tag" : "scalar",
                    "name" : "u32"
                },
                "timeout" : {
                    "tag" : "scalar",
                    "name" : "u32"
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "quorumServiceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "quorumPeerId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "callFunc" : {
                    "tag" : "arrow",
                    "domain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "array",
                                "type" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                }
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            }
                        ]
                    },
                    "codomain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "QuorumResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "results" : {
                            "tag" : "array",
                            "type" : {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function roundRobin(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (seq
                            (seq
                             (seq
                              (seq
                               (seq
                                (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                                (call %init_peer_id% ("getDataSrv" "uris") [] uris)
                               )
                               (call %init_peer_id% ("getDataSrv" "method") [] method)
                              )
                              (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                             )
                             (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                            )
                            (call %init_peer_id% ("getDataSrv" "counterServiceId") [] counterServiceId)
                           )
                           (call %init_peer_id% ("getDataSrv" "counterPeerId") [] counterPeerId)
                          )
                          (call -relay- ("op" "noop") [])
                         )
                         (xor
                          (call counterPeerId (counterServiceId "incrementAndReturn") [] requestNumber)
                          (seq
                           (call -relay- ("op" "noop") [])
                           (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                          )
                         )
                        )
                        (xor
                         (seq
                          (seq
                           (seq
                            (ap uris uris_to_functor)
                            (ap uris_to_functor.length uris_length)
                           )
                           (call %init_peer_id% ("math" "rem") [requestNumber uris_length] rem)
                          )
                          (call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
                         )
                         (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                        )
                       )
                       (xor
                        (call %init_peer_id% ("callbackSrv" "callFunc") [uris.$.[rem]! method jsonArgs serviceId] init_call_res0)
                        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [init_call_res0])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "roundRobin",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uris" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "counterServiceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "counterPeerId" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "callFunc" : {
                    "tag" : "arrow",
                    "domain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            },
                            {
                                "tag" : "array",
                                "type" : {
                                    "tag" : "scalar",
                                    "name" : "string"
                                }
                            },
                            {
                                "tag" : "scalar",
                                "name" : "string"
                            }
                        ]
                    },
                    "codomain" : {
                        "tag" : "unlabeledProduct",
                        "items" : [
                            {
                                "tag" : "struct",
                                "name" : "EthResult",
                                "fields" : {
                                    "error" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    },
                                    "success" : {
                                        "tag" : "scalar",
                                        "name" : "bool"
                                    },
                                    "value" : {
                                        "tag" : "scalar",
                                        "name" : "string"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}


export function call(...args) {

    let script = `
                    (xor
                     (seq
                      (seq
                       (seq
                        (seq
                         (seq
                          (seq
                           (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
                           (call %init_peer_id% ("getDataSrv" "uri") [] uri)
                          )
                          (call %init_peer_id% ("getDataSrv" "method") [] method)
                         )
                         (call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
                        )
                        (call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
                       )
                       (xor
                        (call -relay- (serviceId "eth_call") [uri method jsonArgs] res)
                        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
                       )
                      )
                      (xor
                       (call %init_peer_id% ("callbackSrv" "response") [res])
                       (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
                      )
                     )
                     (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
                    )
    `
    return callFunction$$(
        args,
        {
    "functionName" : "call",
    "arrow" : {
        "tag" : "arrow",
        "domain" : {
            "tag" : "labeledProduct",
            "fields" : {
                "uri" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "method" : {
                    "tag" : "scalar",
                    "name" : "string"
                },
                "jsonArgs" : {
                    "tag" : "array",
                    "type" : {
                        "tag" : "scalar",
                        "name" : "string"
                    }
                },
                "serviceId" : {
                    "tag" : "scalar",
                    "name" : "string"
                }
            }
        },
        "codomain" : {
            "tag" : "unlabeledProduct",
            "items" : [
                {
                    "tag" : "struct",
                    "name" : "EthResult",
                    "fields" : {
                        "error" : {
                            "tag" : "scalar",
                            "name" : "string"
                        },
                        "success" : {
                            "tag" : "scalar",
                            "name" : "bool"
                        },
                        "value" : {
                            "tag" : "scalar",
                            "name" : "string"
                        }
                    }
                }
            ]
        }
    },
    "names" : {
        "relay" : "-relay-",
        "getDataSrv" : "getDataSrv",
        "callbackSrv" : "callbackSrv",
        "responseSrv" : "callbackSrv",
        "responseFnName" : "response",
        "errorHandlingSrv" : "errorHandlingSrv",
        "errorFnName" : "error"
    }
},
        script
    )
}

/* eslint-enable */