Service

Service模块允许在IRIS Hub中定义、绑定、调用服务。了解更多iService内容

可用命令

名称 描述
define 定义一个新的服务
definition 查询服务定义
bind 绑定一个服务
binding 查询服务绑定
bindings 查询服务绑定列表
set-withdraw-addr 设置服务提供者的提取地址
withdraw-addr 查询服务提供者的提取地址
update-binding 更新一个存在的服务绑定
disable 禁用一个可用的服务绑定
enable 启用一个不可用的服务绑定
refund-deposit 退还一个服务绑定的所有押金
call 发起服务调用
request 通过请求ID查询服务请求
requests 通过服务绑定或请求上下文查询服务请求列表
respond 响应服务请求
response 通过请求ID查询服务响应
responses 通过请求上下文ID和批次计数器查询服务响应列表
request-context 查询请求上下文
update 更新请求上下文
pause 暂停一个正在进行的请求上下文
start 启动一个暂停的请求上下文
kill 终止请求上下文
fees 查询服务提供者的收益
withdraw-fees 提取服务提供者的收益
schema 通过 schema 名称查询系统 schema
params 查询当前服务参数值

iris tx service define

定义一个新的服务。

iris tx service define [flags]

标志:

名称,速记 默认 描述 必须
--name 服务名称
--description 服务的描述
--author-description 服务创建者的描述
--tags 服务的标签列表
--schemas 服务接口schemas的内容或文件路径

定义一个新的服务

iris tx service define \
    --name=<service name> \
    --description=<service description> \
    --author-description=<author description> \
    --tags=tag1,tag2 --schemas=<schemas content or path/to/schemas.json> \
    --chain-id=irishub \
    --from=<key-name> \
    --fees=0.3iris

Schemas内容示例

{
    "input": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "BioIdentify service input body",
        "description": "BioIdentify service input body specification",
        "type": "object",
        "properties": {
            "id": {
                "description": "id",
                "type": "string"
            },
            "name": {
                "description": "name",
                "type": "string"
            },
            "data": {
                "description": "data",
                "type": "string"
            }
        },
        "required": [
            "id",
            "data"
        ]
    },
    "output": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "BioIdentify service output body",
        "description": "BioIdentify service output body specification",
        "type": "object",
        "properties": {
            "data": {
                "description": "result data",
                "type": "string"
            }
        },
        "required": [
            "data"
        ]
    }
}

iris query service definition

查询服务定义。

iris query service definition [service-name] [flags]

查询一个服务定义

查询指定服务定义的详细信息。

iris query service definition <service name>

iris tx service bind

绑定一个服务。

iris tx service bind [flags]

标志:

名称,速记 默认 描述 必须
--service-name 服务名称
--deposit 服务绑定的押金
--pricing 服务定价内容或文件路径,是一个Irishub Service Pricing JSON Schema实例
--qos 最小响应时间
--options 非功能性需求选项
--provider 服务提供者地址

绑定一个存在的服务定义

抵押deposit应该满足最小抵押数量需求,最小抵押数量为price * MinDepositMultipleMinDeposit中的最大值(MinDepositMultiple以及MinDeposit是可治理参数)。

iris tx service bind \
    --service-name=<service name> \
    --deposit=10000iris \
    --pricing=<pricing content or path/to/pricing.json> \
    --qos=50 \
    --options=<non-functional requirements options content or path/to/options.json> \
    --chain-id=irishub \
    --from=<key-name> \
    --fees=0.3iris

Pricing内容示例

{
    "price": "1iris"
}

iris query service binding

查询服务绑定。

iris query service binding [service-name] [provider] [flags]

iris query service bindings

查询服务绑定列表。

iris query service bindings [service-name] [flags]

查询服务绑定列表

iris query service bindings <service name> <owner address>

iris tx service update-binding

更新服务绑定。

iris tx service update-binding [service-name] [provider-address] [flags]

标志:

名称,速记 默认 描述 必须
--deposit 增加的绑定押金,为空则不更新
--pricing 服务定价内容或文件路径,是一个Irishub Service Pricing JSON Schema实例,为空则不更新
--qos 最小响应时间,为0则不更新
--options 非功能性需求选项

更新一个存在的服务绑定

更新服务绑定,追加 10 IRIS 的抵押。

iris tx service update-binding <service-name> <provider-address> \
    --deposit=10iris \
    --options=<non-functional requirements options content or path/to/options.json> \
    --pricing='{"price":"1iris"}' \
    --qos=50 \
    --chain-id=<chain-id> \
    --from=<key name> \
    --fees=0.3iris

iris tx service set-withdraw-addr

设置服务提供者的提取地址。

iris tx service set-withdraw-addr [withdrawal-address] [flags]

iris query service withdraw-addr

查询服务提供者的提取地址。

iris query service withdraw-addr [provider] [flags]

iris tx service disable

禁用一个可用的服务绑定。

iris tx service disable [service-name] [provider-address] [flags]

iris tx service enable

启用一个不可用的服务绑定。

iris tx service enable [service-name] [provider-address] [flags]

标志:

名称,速记 默认 描述 必须
--deposit 启用绑定增加的押金

启用一个不可用的服务绑定

启用一个不可用的服务绑定,追加 10 IRIS 的抵押。

iris tx service enable <service name> <provider-address> --chain-id=irishub --from=<key-name> --fees=0.3iris --deposit=10iris

iris tx service refund-deposit

从一个服务绑定中退还所有的押金。

iris tx service refund-deposit [service-name] [provider-address] [flags]

取回所有押金

取回抵押之前,必须先禁用服务绑定。

iris tx service refund-deposit <service name>  <provider-address> --chain-id=irishub --from=<key-name> --fees=0.3iris

iris tx service call

发起服务调用。

iris tx service call [flags]

标志:

名称,速记 默认 描述 必须
--service-name 服务名称
--providers 服务提供者列表
--service-fee-cap 愿意为单个请求支付的最大服务费用
--data 请求输入的内容或文件路径,是一个Input JSON Schema实例
--timeout 请求超时
--repeated false 请求是否为重复性的(irishub-v1.0.0中暂时禁用,将在后续版本中激活)
--frequency 重复性请求的请求频率;默认为timeout
--total 重复性请求的请求总数,-1表示无限制

发起一个服务调用请求

iris tx service call \
    --service-name=<service name>
    --providers=<provider list> \
    --service-fee-cap=1iris \
    --data=<request input or path/to/input.json> \
    --timeout=100 \
    --repeated \
    --frequency=150 \
    --total=100 \
    --chain-id=irishub \
    --from=<key name> \
    --fees=0.3iris

请求输入示例

{
    "header": {
        ...
    },
    "body": {
        "id": "1",
        "name": "irisnet",
        "data": "facedata"
    }
}

iris query service request

通过请求ID查询服务请求。

iris query service request [request-id] [flags]

查询一个服务请求

iris query service request <request-id>

提示

你可以通过两种方式获取request-id通过rpc接口查询request_id 和 [iris query service requests](#iris query service requests)。

通过rpc接口查询request_id

通过rpc接口区块高度查询block_results,在end_block_events找到new_batch_request_provider,将结果进行base64解码,获取request_id

curl -X POST -d '{"jsonrpc":"2.0","id":1,"method":"block_results","params":["10604"]}' http://localhost:26657

iris query service requests

通过服务绑定或请请求上下文ID查询服务请求列表。

iris query service requests [service-name] [provider] | [request-context-id] [batch-counter] [flags]

查询服务绑定的活跃请求

iris query service requests <service name> <provider>

通过请求上下文ID和批次计数器查询服务请求列表

iris query service requests <request-context-id> <batch-counter>

iris tx service respond

响应服务请求。

iris tx service respond [flags]

标志:

名称,速记 默认 描述 必须
--request-id 欲响应请求的ID
--result 响应结果的内容或文件路径,是一个Irishub Service Result JSON Schema实例
--data 响应输出的内容或文件路径,是一个Output JSON Schema实例

响应一个服务请求

iris tx service respond \
    --request-id=<request-id> \
    --result=<response result or path/to/result.json> \
    --data=<response output or path/to/output.json>
    --chain-id=irishub \
    --from=<key-name> \
    --fees=0.3iris

提示

你可以通过两种方式获取request-id通过rpc接口查询request_id 和 [iris query service requests](#iris query service requests)。

响应结果示例

{
    "code": 200,
    "message": ""
}

响应输出示例

{
    "header": {
        ...
    },
    "body": {
        "data": "userdata"
    }
}

iris query service response

通过请求ID查询服务响应。

iris query service response [request-id] [flags]

查询一个服务响应

iris query service response [request-id] [flags]

提示

你可以通过两种方式获取request-id通过rpc接口查询request_id 和 [iris query service requests](#iris query service requests)。

iris query service responses

通过请求上下文ID以及批次计数器查询服务响应列表。

iris query service responses [request-context-id] [batch-counter] [flags]

根据指定的请求上下文ID以及批次计数器查询服务响应

iris query service responses <request-context-id> <batch-counter>

iris query service request-context

查询请求上下文。

iris query service request-context [request-context-id] [flags]

查询一个请求上下文

iris query service request-context <request-context-id>

提示

你可以从调用服务的结果中获取request-context-id

iris tx service update

更新请求上下文。

iris tx service update [request-context-id] [flags]

标志:

名称,速记 默认 描述 必须
--providers 服务提供者列表,为空则不更新
--service-fee-cap 愿意为单个请求支付的最大服务费用,为空则不更新
--timeout 请求超时,为0则不更新
--frequency 请求频率,为0则不更新
--total 请求总数,为0则不更新

更新一个请求上下文

iris tx service update <request-context-id> \
    --providers=<provider list> \
    --service-fee-cap=1iris \
    --timeout=0 \
    --frequency=150 \
    --total=100 \
    --chain-id=irishub \
    --from=<key name> \
    --fees=0.3iris

iris tx service pause

暂停一个正在进行的请求上下文。

iris tx service pause [request-context-id] [flags]

暂停一个正在进行的请求上下文

iris tx service pause <request-context-id>

iris tx service start

启动一个暂停的请求上下文。

iris tx service start [request-context-id] [flags]

iris tx service kill

终止请求上下文。

iris tx service kill [request-context-id] [flags]

终止一个请求上下文

iris tx service kill <request-context-id>

iris query service fees

查询服务提供者的收益。

iris query service fees [provider] [flags]

iris tx service withdraw-fees

提取服务提供者的收益。

iris tx service withdraw-fees [flags]

iris query service schema

通过 schema 名称查询系统 schema。有效的 schema 名称为 pricing(服务定价)和 result(响应结果)。

iris query service schema [schema-name] [flags]

查询服务定价 schema

iris query service schema pricing

查询响应结果 schema

iris query service schema result

iris query service params

查询当前服务参数值。

iris query service params [flags]