Skip to content

Commit 241d3e1

Browse files
louisingeraltafan
andauthored
Add Subscription API to Indexer (#599)
* add subscribe API * workaround v6 * refactor subscriptions APIs * delete indexer permisssions * permissions.go: revert * hotfix service_test.go * Simplify * Add topics (scripts) to GetSubscriptionResponse message * Fix shutdown and logging * Fixes --------- Co-authored-by: altafan <[email protected]>
1 parent 7b49c03 commit 241d3e1

29 files changed

+3560
-554
lines changed

api-spec/openapi/swagger/ark/v1/indexer.swagger.json

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,109 @@
478478
]
479479
}
480480
},
481+
"/v1/script/subscribe": {
482+
"post": {
483+
"operationId": "IndexerService_SubscribeForScripts",
484+
"responses": {
485+
"200": {
486+
"description": "A successful response.",
487+
"schema": {
488+
"$ref": "#/definitions/v1SubscribeForScriptsResponse"
489+
}
490+
},
491+
"default": {
492+
"description": "An unexpected error response.",
493+
"schema": {
494+
"$ref": "#/definitions/rpcStatus"
495+
}
496+
}
497+
},
498+
"parameters": [
499+
{
500+
"name": "body",
501+
"in": "body",
502+
"required": true,
503+
"schema": {
504+
"$ref": "#/definitions/v1SubscribeForScriptsRequest"
505+
}
506+
}
507+
],
508+
"tags": [
509+
"IndexerService"
510+
]
511+
}
512+
},
513+
"/v1/script/subscription/{subscriptionId}": {
514+
"get": {
515+
"operationId": "IndexerService_GetSubscription",
516+
"responses": {
517+
"200": {
518+
"description": "A successful response.(streaming responses)",
519+
"schema": {
520+
"type": "object",
521+
"properties": {
522+
"result": {
523+
"$ref": "#/definitions/v1GetSubscriptionResponse"
524+
},
525+
"error": {
526+
"$ref": "#/definitions/rpcStatus"
527+
}
528+
},
529+
"title": "Stream result of v1GetSubscriptionResponse"
530+
}
531+
},
532+
"default": {
533+
"description": "An unexpected error response.",
534+
"schema": {
535+
"$ref": "#/definitions/rpcStatus"
536+
}
537+
}
538+
},
539+
"parameters": [
540+
{
541+
"name": "subscriptionId",
542+
"in": "path",
543+
"required": true,
544+
"type": "string"
545+
}
546+
],
547+
"tags": [
548+
"IndexerService"
549+
]
550+
}
551+
},
552+
"/v1/script/unsubscribe": {
553+
"post": {
554+
"operationId": "IndexerService_UnsubscribeForScripts",
555+
"responses": {
556+
"200": {
557+
"description": "A successful response.",
558+
"schema": {
559+
"$ref": "#/definitions/v1UnsubscribeForScriptsResponse"
560+
}
561+
},
562+
"default": {
563+
"description": "An unexpected error response.",
564+
"schema": {
565+
"$ref": "#/definitions/rpcStatus"
566+
}
567+
}
568+
},
569+
"parameters": [
570+
{
571+
"name": "body",
572+
"in": "body",
573+
"required": true,
574+
"schema": {
575+
"$ref": "#/definitions/v1UnsubscribeForScriptsRequest"
576+
}
577+
}
578+
],
579+
"tags": [
580+
"IndexerService"
581+
]
582+
}
583+
},
481584
"/v1/virtualTx/{txids}": {
482585
"get": {
483586
"operationId": "IndexerService_GetVirtualTxs",
@@ -687,6 +790,34 @@
687790
}
688791
}
689792
},
793+
"v1GetSubscriptionResponse": {
794+
"type": "object",
795+
"properties": {
796+
"txid": {
797+
"type": "string"
798+
},
799+
"scripts": {
800+
"type": "array",
801+
"items": {
802+
"type": "string"
803+
}
804+
},
805+
"newVtxos": {
806+
"type": "array",
807+
"items": {
808+
"type": "object",
809+
"$ref": "#/definitions/v1IndexerVtxo"
810+
}
811+
},
812+
"spentVtxos": {
813+
"type": "array",
814+
"items": {
815+
"type": "object",
816+
"$ref": "#/definitions/v1IndexerVtxo"
817+
}
818+
}
819+
}
820+
},
690821
"v1GetSweptCommitmentTxResponse": {
691822
"type": "object",
692823
"properties": {
@@ -1003,6 +1134,47 @@
10031134
"type": "string"
10041135
}
10051136
}
1137+
},
1138+
"v1SubscribeForScriptsRequest": {
1139+
"type": "object",
1140+
"properties": {
1141+
"scripts": {
1142+
"type": "array",
1143+
"items": {
1144+
"type": "string"
1145+
}
1146+
},
1147+
"subscriptionId": {
1148+
"type": "string",
1149+
"title": "if set, update an existing subscription"
1150+
}
1151+
}
1152+
},
1153+
"v1SubscribeForScriptsResponse": {
1154+
"type": "object",
1155+
"properties": {
1156+
"subscriptionId": {
1157+
"type": "string"
1158+
}
1159+
}
1160+
},
1161+
"v1UnsubscribeForScriptsRequest": {
1162+
"type": "object",
1163+
"properties": {
1164+
"subscriptionId": {
1165+
"type": "string"
1166+
},
1167+
"scripts": {
1168+
"type": "array",
1169+
"items": {
1170+
"type": "string"
1171+
},
1172+
"title": "if empty, unsubscribe all scripts"
1173+
}
1174+
}
1175+
},
1176+
"v1UnsubscribeForScriptsResponse": {
1177+
"type": "object"
10061178
}
10071179
}
10081180
}

api-spec/protobuf/ark/v1/indexer.proto

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ service IndexerService {
6565
get: "/v1/commitmentTx/{txid}/swept"
6666
};
6767
}
68+
rpc SubscribeForScripts(SubscribeForScriptsRequest) returns (SubscribeForScriptsResponse) {
69+
option (google.api.http) = {
70+
post: "/v1/script/subscribe"
71+
body: "*"
72+
};
73+
};
74+
rpc UnsubscribeForScripts(UnsubscribeForScriptsRequest) returns (UnsubscribeForScriptsResponse) {
75+
option (google.api.http) = {
76+
post: "/v1/script/unsubscribe"
77+
body: "*"
78+
};
79+
};
80+
rpc GetSubscription(GetSubscriptionRequest) returns (stream GetSubscriptionResponse) {
81+
option (google.api.http) = {
82+
get: "/v1/script/subscription/{subscription_id}"
83+
};
84+
};
6885
}
6986

7087
message GetCommitmentTxRequest {
@@ -183,15 +200,6 @@ message GetSweptCommitmentTxResponse {
183200
repeated string swept_by = 1;
184201
}
185202

186-
message SubscribeForAddressesRequest {
187-
repeated string addresses = 1;
188-
}
189-
message SubscribeForAddressesResponse {
190-
string address = 1;
191-
repeated IndexerVtxo new_vtxos = 2;
192-
repeated IndexerVtxo spent_vtxos = 3;
193-
}
194-
195203
message IndexerBatch {
196204
uint64 total_output_amount = 1;
197205
int32 total_output_vtxos = 2;
@@ -268,4 +276,33 @@ message IndexerPageResponse {
268276
int32 current = 1;
269277
int32 next = 2;
270278
int32 total = 3;
279+
}
280+
281+
message SubscribeForScriptsRequest {
282+
repeated string scripts = 1;
283+
// if set, update an existing subscription
284+
string subscription_id = 2;
285+
}
286+
287+
message SubscribeForScriptsResponse {
288+
string subscription_id = 1;
289+
}
290+
291+
message UnsubscribeForScriptsRequest {
292+
string subscription_id = 1;
293+
// if empty, unsubscribe all scripts
294+
repeated string scripts = 2;
295+
}
296+
297+
message UnsubscribeForScriptsResponse {}
298+
299+
message GetSubscriptionRequest {
300+
string subscription_id = 1;
301+
}
302+
303+
message GetSubscriptionResponse {
304+
string txid = 1;
305+
repeated string scripts = 2;
306+
repeated IndexerVtxo new_vtxos = 3;
307+
repeated IndexerVtxo spent_vtxos = 4;
271308
}

0 commit comments

Comments
 (0)