@@ -44,7 +44,7 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
44
44
45
45
// defaults
46
46
public taskParameters : TaskParameters = { difficulty : 2 , numGenerations : 2 , numValidations : 2 } ;
47
- public protocol = "oracle-js- sdk/0.1.0 " ;
47
+ public protocol = "dria- oracle-sdk/0.x.x " ;
48
48
49
49
constructor (
50
50
readonly client : {
@@ -83,9 +83,24 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
83
83
84
84
/**
85
85
* Change the underlying default protocol.
86
+ *
87
+ * The protocol is a string that should fit a `bytes32` type in Solidity. It is used
88
+ * to identify the source of the request, and can be used within event filters.
89
+ *
90
+ * It should have to format `name/version`, e.g. `dria-oracle-sdk/0.x.x`.
86
91
* @param protocol protocol name
87
92
*/
88
93
withProtocol ( protocol : string ) {
94
+ // ensure `/` appears once
95
+ if ( protocol . split ( "/" ) . length !== 2 ) {
96
+ throw new Error ( "Invalid protocol format." ) ;
97
+ }
98
+
99
+ // ensure it fits bytes32
100
+ if ( Buffer . from ( protocol ) . length > 32 ) {
101
+ throw new Error ( "Protocol string is too long." ) ;
102
+ }
103
+
89
104
this . protocol = protocol ;
90
105
return this ;
91
106
}
@@ -225,8 +240,7 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
225
240
* @returns true if the task is completed, or `taskId` is 0
226
241
*/
227
242
async isCompleted ( taskId : bigint | number ) : Promise < boolean > {
228
- // 0 is always accepted
229
- // TODO: explain why
243
+ // 0 is always accepted; because `history_id: 0` may be used for chat messages
230
244
if ( BigInt ( taskId ) === 0n ) {
231
245
return true ;
232
246
}
@@ -252,9 +266,9 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
252
266
}
253
267
254
268
/**
255
- * Reads the request of a task.
269
+ * Returns the validations of all generation responses for a task.
256
270
* @param taskId task id
257
- * @returns task validations
271
+ * @returns array of task validations
258
272
*/
259
273
async getValidations ( taskId : bigint | number ) : Promise < readonly Prettify < TaskValidation > [ ] > {
260
274
if ( this . coordinator === undefined ) {
@@ -264,12 +278,11 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
264
278
}
265
279
266
280
/**
267
- * Read the validations of a task.
281
+ * Returns the generation responses for a task.
268
282
* @param taskId task id
269
- * @param idx index of the response, if not provided, the best & completed response is returned
270
- * @returns task response
283
+ * @returns array of task responses
271
284
*/
272
- async readResponses ( taskId : bigint | number ) : Promise < readonly Prettify < TaskResponse > [ ] > {
285
+ async getResponses ( taskId : bigint | number ) : Promise < readonly Prettify < TaskResponse > [ ] > {
273
286
if ( this . coordinator === undefined ) {
274
287
throw new Error ( "SDK not initialized." ) ;
275
288
}
@@ -306,6 +319,7 @@ export class Oracle<T extends Transport, C extends Chain, K = unknown> {
306
319
try {
307
320
return {
308
321
...validation ,
322
+ // here we assume the type like this, because validators are trusted
309
323
metadata : JSON . parse ( metadata ) as TaskValidationScores [ ] ,
310
324
} ;
311
325
} catch ( err ) {
0 commit comments