Skip to content

Commit d37af7d

Browse files
sekulicdaltafan
andauthored
Add GetTransactionsStream RPC (#345)
* RPC GetPaymentsStream This introduces a new feature to the ArkService API that allows clients to subscribe to payment events. Here's a breakdown of the changes: 1. **OpenAPI Specification (`service.swagger.json`):** - A new endpoint `/v1/payments` is added to the API, supporting a `GET` operation for streaming payment events. - New definitions `v1GetPaymentsStreamResponse`, `v1RoundPayment`, and `v1AsyncPayment` are added to describe the structure of the streaming responses. 2. **Protobuf Definition (`service.proto`):** - Added a new RPC method `GetPaymentsStream` that streams `GetPaymentsStreamResponse` messages. - Defined new message types: `GetPaymentsStreamRequest`, `GetPaymentsStreamResponse`, `RoundPayment`, and `AsyncPayment`. 3. **Generated Protobuf Code (`service.pb.go`, `service.pb.gw.go`, `service_grpc.pb.go`):** - The generated code is updated to include the new RPC method and message types. - The gateway code includes functions to handle HTTP requests and responses for the new streaming endpoint. 4. **Application Logic (`covenant.go`, `covenantless.go`):** - New payment events channels are introduced (`paymentEventsCh`). - Payment events are propagated to these channels when a round is finalized or an async payment is completed. - New event types `RoundPaymentEvent` and `AsyncPaymentEvent` are defined, implementing a `PaymentEvent` interface. 5. **gRPC Handlers (`arkservice.go`):** - Added logic to handle `GetPaymentsStream` requests and manage payment listeners. - A new goroutine is started to listen to payment events and forward them to active listeners. Overall, this patch extends the ArkService to support real-time streaming of payment events, allowing clients to receive updates on both round payments and async payments as they occur. * Move emit events in updateVtxoSet & Use generics and parsers (#1) * Move sending event to updateVtxoSet * Use generics and parsers * pr review refactor * pr review refactor * fix --------- Co-authored-by: Pietralberto Mazza <[email protected]>
1 parent 26bcbc8 commit d37af7d

File tree

10 files changed

+996
-206
lines changed

10 files changed

+996
-206
lines changed

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,37 @@
415415
]
416416
}
417417
},
418+
"/v1/transactions": {
419+
"get": {
420+
"operationId": "ArkService_GetTransactionsStream",
421+
"responses": {
422+
"200": {
423+
"description": "A successful response.(streaming responses)",
424+
"schema": {
425+
"type": "object",
426+
"properties": {
427+
"result": {
428+
"$ref": "#/definitions/v1GetTransactionsStreamResponse"
429+
},
430+
"error": {
431+
"$ref": "#/definitions/rpcStatus"
432+
}
433+
},
434+
"title": "Stream result of v1GetTransactionsStreamResponse"
435+
}
436+
},
437+
"default": {
438+
"description": "An unexpected error response.",
439+
"schema": {
440+
"$ref": "#/definitions/rpcStatus"
441+
}
442+
}
443+
},
444+
"tags": [
445+
"ArkService"
446+
]
447+
}
448+
},
418449
"/v1/vtxos/{address}": {
419450
"get": {
420451
"operationId": "ArkService_ListVtxos",
@@ -620,6 +651,17 @@
620651
}
621652
}
622653
},
654+
"v1GetTransactionsStreamResponse": {
655+
"type": "object",
656+
"properties": {
657+
"round": {
658+
"$ref": "#/definitions/v1RoundTransaction"
659+
},
660+
"redeem": {
661+
"$ref": "#/definitions/v1RedeemTransaction"
662+
}
663+
}
664+
},
623665
"v1Input": {
624666
"type": "object",
625667
"properties": {
@@ -727,6 +769,28 @@
727769
}
728770
}
729771
},
772+
"v1RedeemTransaction": {
773+
"type": "object",
774+
"properties": {
775+
"txid": {
776+
"type": "string"
777+
},
778+
"spentVtxos": {
779+
"type": "array",
780+
"items": {
781+
"type": "object",
782+
"$ref": "#/definitions/v1Outpoint"
783+
}
784+
},
785+
"spendableVtxos": {
786+
"type": "array",
787+
"items": {
788+
"type": "object",
789+
"$ref": "#/definitions/v1Vtxo"
790+
}
791+
}
792+
}
793+
},
730794
"v1RegisterInputsForNextRoundRequest": {
731795
"type": "object",
732796
"properties": {
@@ -896,6 +960,35 @@
896960
],
897961
"default": "ROUND_STAGE_UNSPECIFIED"
898962
},
963+
"v1RoundTransaction": {
964+
"type": "object",
965+
"properties": {
966+
"txid": {
967+
"type": "string"
968+
},
969+
"spentVtxos": {
970+
"type": "array",
971+
"items": {
972+
"type": "object",
973+
"$ref": "#/definitions/v1Outpoint"
974+
}
975+
},
976+
"spendableVtxos": {
977+
"type": "array",
978+
"items": {
979+
"type": "object",
980+
"$ref": "#/definitions/v1Vtxo"
981+
}
982+
},
983+
"claimedBoardingUtxos": {
984+
"type": "array",
985+
"items": {
986+
"type": "object",
987+
"$ref": "#/definitions/v1Outpoint"
988+
}
989+
}
990+
}
991+
},
899992
"v1SubmitSignedForfeitTxsRequest": {
900993
"type": "object",
901994
"properties": {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ service ArkService {
9292
get: "/v1/vtxos/{address}"
9393
};
9494
}
95+
rpc GetTransactionsStream(GetTransactionsStreamRequest) returns (stream GetTransactionsStreamResponse) {
96+
option (google.api.http) = {
97+
get: "/v1/transactions"
98+
};
99+
}
95100
}
96101

97102
message GetInfoRequest {}
@@ -321,3 +326,24 @@ message PendingPayment {
321326
string redeem_tx = 1;
322327
repeated string unconditional_forfeit_txs =2;
323328
}
329+
330+
message GetTransactionsStreamRequest {}
331+
message GetTransactionsStreamResponse {
332+
oneof tx {
333+
RoundTransaction round = 1;
334+
RedeemTransaction redeem = 2;
335+
}
336+
}
337+
338+
message RoundTransaction {
339+
string txid = 1;
340+
repeated Outpoint spent_vtxos = 2;
341+
repeated Vtxo spendable_vtxos = 3;
342+
repeated Outpoint claimed_boarding_utxos = 4;
343+
}
344+
345+
message RedeemTransaction {
346+
string txid = 1;
347+
repeated Outpoint spent_vtxos = 2;
348+
repeated Vtxo spendable_vtxos = 3;
349+
}

0 commit comments

Comments
 (0)