Skip to content

Commit 18a007e

Browse files
committed
Add tx info to GetSubscription stream message
1 parent aaf52b1 commit 18a007e

File tree

9 files changed

+483
-203
lines changed

9 files changed

+483
-203
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,15 @@
793793
"type": "object",
794794
"$ref": "#/definitions/v1IndexerVtxo"
795795
}
796+
},
797+
"tx": {
798+
"type": "string"
799+
},
800+
"checkpointTxs": {
801+
"type": "object",
802+
"additionalProperties": {
803+
"$ref": "#/definitions/v1IndexerTxData"
804+
}
796805
}
797806
}
798807
},
@@ -1006,6 +1015,17 @@
10061015
}
10071016
}
10081017
},
1018+
"v1IndexerTxData": {
1019+
"type": "object",
1020+
"properties": {
1021+
"txid": {
1022+
"type": "string"
1023+
},
1024+
"tx": {
1025+
"type": "string"
1026+
}
1027+
}
1028+
},
10091029
"v1IndexerTxHistoryRecord": {
10101030
"type": "object",
10111031
"properties": {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,11 @@ message GetSubscriptionResponse {
355355
repeated string scripts = 2;
356356
repeated IndexerVtxo new_vtxos = 3;
357357
repeated IndexerVtxo spent_vtxos = 4;
358+
string tx = 5;
359+
map<string, IndexerTxData> checkpoint_txs = 6;
360+
}
361+
362+
message IndexerTxData {
363+
string txid = 1;
364+
string tx = 2;
358365
}

api-spec/protobuf/gen/ark/v1/indexer.pb.go

Lines changed: 291 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client-sdk/indexer/grpc/client.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,24 @@ func (a *grpcClient) GetSubscription(ctx context.Context, subscriptionId string)
525525
return
526526
}
527527

528+
var checkpointTxs map[string]indexer.TxData
529+
if len(resp.GetCheckpointTxs()) > 0 {
530+
checkpointTxs = make(map[string]indexer.TxData)
531+
for k, v := range resp.GetCheckpointTxs() {
532+
checkpointTxs[k] = indexer.TxData{
533+
Txid: v.GetTxid(),
534+
Tx: v.GetTx(),
535+
}
536+
}
537+
}
538+
528539
eventsCh <- &indexer.ScriptEvent{
529-
Txid: resp.GetTxid(),
530-
Scripts: resp.GetScripts(),
531-
NewVtxos: newIndexerVtxos(resp.GetNewVtxos()),
532-
SpentVtxos: newIndexerVtxos(resp.GetSpentVtxos()),
540+
Txid: resp.GetTxid(),
541+
Tx: resp.GetTx(),
542+
Scripts: resp.GetScripts(),
543+
NewVtxos: newIndexerVtxos(resp.GetNewVtxos()),
544+
SpentVtxos: newIndexerVtxos(resp.GetSpentVtxos()),
545+
CheckpointTxs: checkpointTxs,
533546
}
534547
}
535548
}()

pkg/client-sdk/indexer/rest/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,17 @@ func (a *restClient) GetSubscription(ctx context.Context, subscriptionId string)
555555
return
556556
}
557557

558+
var checkpointTxs map[string]indexer.TxData
559+
if len(resp.Result.CheckpointTxs) > 0 {
560+
checkpointTxs = make(map[string]indexer.TxData)
561+
for k, v := range resp.Result.CheckpointTxs {
562+
checkpointTxs[k] = indexer.TxData{
563+
Txid: v.Txid,
564+
Tx: v.Tx,
565+
}
566+
}
567+
}
568+
558569
eventsCh <- &indexer.ScriptEvent{
559570
Txid: resp.Result.Txid,
560571
Scripts: resp.Result.Scripts,

pkg/client-sdk/indexer/rest/service/models/v1_get_subscription_response.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client-sdk/indexer/rest/service/models/v1_indexer_tx_data.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client-sdk/indexer/service.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,19 @@ type VirtualTxsResponse struct {
7272
Page *PageResponse
7373
}
7474

75+
type TxData struct {
76+
Txid string
77+
Tx string
78+
}
79+
7580
type ScriptEvent struct {
76-
Txid string
77-
Scripts []string
78-
NewVtxos []types.Vtxo
79-
SpentVtxos []types.Vtxo
80-
Err error
81+
Txid string
82+
Tx string
83+
Scripts []string
84+
NewVtxos []types.Vtxo
85+
SpentVtxos []types.Vtxo
86+
CheckpointTxs map[string]TxData
87+
Err error
8188
}
8289

8390
type PageRequest struct {

server/internal/interface/grpc/handlers/indexer.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,16 @@ func (h *indexerService) listenToTxEvents() {
496496
vtxoScript := toP2TR(vtxo.PubKey)
497497
allSpentVtxos[vtxoScript] = append(allSpentVtxos[vtxoScript], newIndexerVtxo(vtxo))
498498
}
499-
499+
var checkpointTxs map[string]*arkv1.IndexerTxData
500+
if len(event.CheckpointTxs) > 0 {
501+
checkpointTxs = make(map[string]*arkv1.IndexerTxData)
502+
for k, v := range event.CheckpointTxs {
503+
checkpointTxs[k] = &arkv1.IndexerTxData{
504+
Txid: v.Txid,
505+
Tx: v.Tx,
506+
}
507+
}
508+
}
500509
for _, l := range h.scriptSubsHandler.listeners {
501510
spendableVtxos := make([]*arkv1.IndexerVtxo, 0)
502511
spentVtxos := make([]*arkv1.IndexerVtxo, 0)
@@ -515,10 +524,12 @@ func (h *indexerService) listenToTxEvents() {
515524
if len(spendableVtxos) > 0 || len(spentVtxos) > 0 {
516525
go func() {
517526
l.ch <- &arkv1.GetSubscriptionResponse{
518-
Txid: event.Txid,
519-
Scripts: involvedScripts,
520-
NewVtxos: spendableVtxos,
521-
SpentVtxos: spentVtxos,
527+
Txid: event.Txid,
528+
Scripts: involvedScripts,
529+
NewVtxos: spendableVtxos,
530+
SpentVtxos: spentVtxos,
531+
Tx: event.Tx,
532+
CheckpointTxs: checkpointTxs,
522533
}
523534
}()
524535
}

0 commit comments

Comments
 (0)