Orange
Search…
Assess Reputation for Your dApp Users
An SDK to integrate Orange to your dApp
The "algorithm" and "AP" in method and variable names refer to "model" and "MP" respectively.
You can invoke the models of your choice available via Orange by sending invocation requests from your dApp to the system using the Orange Server SDK.
The general sequence in which you would call the methods to send an invocation request by specifying an model and a dataset is:
  1. 1.
    Call GetAlgorithmProviders and GetDataProviders to go through the available model and data providers.
  2. 2.
    Choose an MP and DP, and call GetAlgorithmMethods and GetDataMethods to fetch the method details on available models and datasets.
  3. 3.
    Choose an MP method and a DP method ensuring the schemas match, then call RequestOrangeScore to send an invocation request along with authorized and signed wallet information.
  4. 4.
    Call GetUserTask to fetch the invocation results, or the status of a task.
The results can be exported in the form of Verifiable Credentials. Refer to the verifiable credential docs here for more details on how that can be implemented.

SDK intro

The Orange server uses GraphQL for its interface design. You can use the methods defined below to perform actions such as fetching MP and DP schema details and sending calculation requests using a model-data pair for specific wallets and DIDs.
To use the SDK you need a DID for your dApp. You can get one by creating a wallet using ONTO app.

Initialization

Add this dependency in the go.mod file in your project.
1
github.com/orange-protocol/orange-sdk-go latest
Copied!

Schema definition

The major schemas defined for the interface are described below.
1
type AlgorithmProvider{
2
name:String!
3
type:String!
4
introduction:String!
5
did:String!
6
createTime:Int!
7
title:String!
8
provider:String!
9
invokeFrequency:Int!
10
apiState:Int!
11
author:String!
12
popularity:Int!
13
delay:Int!
14
icon:String!
15
}
16
17
type DataProvider {
18
name:String!
19
type:String!
20
introduction:String!
21
did:String!
22
createTime:Int!
23
title:String!
24
provider:String!
25
invokeFrequency:Int!
26
apiState:Int!
27
author:String!
28
popularity:Int!
29
delay:Int!
30
icon:String!
31
}
32
33
type ProviderMethod {
34
name:String!
35
paramSchema:String!
36
resultSchema:String!
37
}
38
39
type UserTasks {
40
taskId:String!
41
userDID:String!
42
apDID:String!
43
apName:String!
44
apMethod:String!
45
dpDID:String!
46
dpName:String!
47
dpMethod:String!
48
createTime:String!
49
updateTime:String!
50
taskStatus:String!
51
taskResult:String
52
resultFile:String
53
issueTxhash:String
54
}
55
56
input RequestOrangeScoreReq{
57
appdid:String!
58
data:RequestOrangeScoreData!
59
sig:String!
60
}
61
input RequestOrangeScoreData {
62
userdid:String!
63
apdid:String!
64
apmethod:String!
65
dpdid:String!
66
dpmethod:String!
67
overwriteOld:Boolean!
68
wallets:[UserWallet!]!
69
}
70
input UserWallet{
71
chain:String!
72
address:String!
73
pubkey:String!
74
sig:String!
75
}
76
77
# Currently defined queries
78
type Query {
79
getAllAlgorithmProviders:[AlgorithmProvider!]!
80
getAllDataProviders:[DataProvider!]!
81
getAlgorithmMethods(did:String!):[ProviderMethod!]!
82
getDataMethods(did:String!):[ProviderMethod!]!
83
getUserTask(key:String!,taskId:Int!):UserTasks
84
}
85
86
type Mutation {
87
requestOrangeScore(input:RequestOrangeScoreReq):Int!
88
}
89
Copied!

Interface methods

1. Fetch details for all available MPs

Returns the details of all the currently registered model providers.
Method: GetAlgorithmProviders
Parameters: none
Returns: []*AlgorithmProvider
1
type AlgorithmProvider struct {
2
Name string `json:"name"`
3
Type string `json:"type"`
4
Introduction string `json:"introduction"`
5
Did string `json:"did"`
6
CreateTime int64 `json:"createTime"`
7
Title string `json:"title"`
8
Provider string `json:"provider"`
9
InvokeFrequency int64 `json:"invokeFrequency"`
10
APIState int64 `json:"apiState"`
11
Author string `json:"author"`
12
Popularity int64 `json:"popularity"`
13
Delay int64 `json:"delay"`
14
Icon string `json:"icon"`
15
}
Copied!

2. Fetch available methods for an MP

Returns all the currently available models and the associated schemas as defined by an MP.
Method: GetAlgorithmMethods
Parameters
  • apdid- The DID of specified MP
Returns: []*ProviderMethod
1
type ProviderMethod struct {
2
Name string `json:"name"`
3
ParamSchema string `json:"paramSchema"`
4
ResultSchema string `json:"resultSchema"`
5
}
Copied!

3. Fetch details for all available DPs

Returns the details of all the currently registered data providers.
Method: GetDataProviders
Parameters: none
Returns: []*DataProvider
1
type DataProvider struct {
2
Name string `json:"name"`
3
Type string `json:"type"`
4
Introduction string `json:"introduction"`
5
Did string `json:"did"`
6
CreateTime int64 `json:"createTime"`
7
Title string `json:"title"`
8
Provider string `json:"provider"`
9
InvokeFrequency int64 `json:"invokeFrequency"`
10
APIState int64 `json:"apiState"`
11
Author string `json:"author"`
12
Popularity int64 `json:"popularity"`
13
Delay int64 `json:"delay"`
14
Icon string `json:"icon"`
15
}
Copied!

4. Fetch available data methods for a DP

Returns all the currently available datasets and the associated schemas as defined by a DP.
Method: GetDataMethods
Parameters
  • dpdid- The DID of specified DP
Returns: []*ProviderMethod
1
type ProviderMethod struct {
2
Name string `json:"name"`
3
ParamSchema string `json:"paramSchema"`
4
ResultSchema string `json:"resultSchema"`
5
}
Copied!

5. Send a request to run the model with selected data

Sends a request to generate the score or report for the specified wallet addresses using the specified model and dataset, or MP and DP method respectively. Returns a taskId.
Calculation requests are handled asynchronously. You can use the returned task ID to fetch the generated result. Please note that certain types of data or volume may take some time to fetch, and so the calculation may take up to an hour in certain extreme cases after a request is sent successfully.
Method: RequestOrangeScore
Parameters
  • *RequestOrangeScoreReq- defined below
1
type RequestOrangeScoreReq struct {
2
AppDid string `json:"appDid"` // DID of your dApp
3
Data RequestOrangeScoreData `json:"data"` // request data, specified as below
4
Sig string `json:"sig"` // signature: dApp's DID signed with its private key
5
}
6
7
type RequestOrangeScoreData struct {
8
Userdid string `json:"userDid"` // DID of the user
9
Apdid string `json:"apdid"` // DID of the MP
10
Apmethod string `json:"apmethod"` // MP method name
11
Dpdid string `json:"dpdid"` // DID of the DP
12
Dpmethod string `json:"dpmethod"` // DP method name
13
overwriteOld bool `json:"overwriteOld"` // whether override existing task
14
Wallets []*UserWallet `json:"wallets"` // user's wallet details, specified as below
15
16
}
17
type UserWallet struct {
18
Chain string `json:"chain"` // name of the chain
19
Address string `json:"address"` // linked wallet address
20
Pubkey string `json:"pubkey"` // wallet public key
21
Sig string `json:"sig"` // signature: user's DID signed with their private key
22
}
23
24
Copied!
Returns: int64

6. Fetch result/status for a task

Method: GetUserTask
Parameters
  • key- API key
  • taskId - task ID
Returns: *UserTasks
1
type UserTasks struct {
2
TaskID string `json:"taskId"`
3
UserDid string `json:"userDID"`
4
ApDid string `json:"apDID"`
5
ApName string `json:"apName"`
6
ApMethod string `json:"apMethod"`
7
DpDid string `json:"dpDID"`
8
DpName string `json:"dpName"`
9
DpMethod string `json:"dpMethod"`
10
CreateTime string `json:"createTime"`
11
UpdateTime string `json:"updateTime"`
12
TaskStatus string `json:"taskStatus"`
13
TaskResult *string `json:"taskResult"` // score points
14
ResultFile *string `json:"resultFile"` // credential file
15
IssueTxhash *string `json:"issueTxhash"` // transaction hash for the credential on ontology
16
}
Copied!

Sample invocation

Refer to the sample code below that invokes the GetAlgorithmProviders method.
1
func TestOrangeSDK_GetAlgorithmProviders(t *testing.T) {
2
sdk, err := NewOrangeSDK("http://localhost:8080/query")
3
assert.Nil(t, err)
4
aps, err := sdk.GetAlgorithmProviders()
5
assert.Nil(t, err)
6
assert.NotNil(t, aps)
7
assert.Greater(t, len(aps), 0)
8
}
Copied!