Skip to content

Commit 49b51d5

Browse files
committed
Fix return txid in history endpoint
1 parent 20aa611 commit 49b51d5

File tree

10 files changed

+98
-152
lines changed

10 files changed

+98
-152
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,10 @@
721721
"v1IndexerTxHistoryRecord": {
722722
"type": "object",
723723
"properties": {
724-
"boardingTxid": {
725-
"type": "string"
726-
},
727724
"commitmentTxid": {
728725
"type": "string"
729726
},
730-
"sweepTxid": {
731-
"type": "string"
732-
},
733-
"arkTxid": {
727+
"virtualTxid": {
734728
"type": "string"
735729
},
736730
"type": {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,14 @@ message IndexerChain {
187187

188188
message IndexerTxHistoryRecord {
189189
oneof key {
190-
string boarding_txid = 1;
191-
string commitment_txid = 2;
192-
string sweep_txid = 3;
193-
string ark_txid = 4;
190+
string commitment_txid = 1;
191+
string virtual_txid = 2;
194192
}
195-
IndexerTxType type = 5;
196-
uint64 amount = 6;
197-
int64 created_at = 7;
198-
int64 confirmed_at = 8;
199-
bool is_settled = 9;
193+
IndexerTxType type = 3;
194+
uint64 amount = 4;
195+
int64 created_at = 5;
196+
int64 confirmed_at = 6;
197+
bool is_settled = 7;
200198
}
201199

202200
enum IndexerTxType {

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

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

pkg/client-sdk/client/client.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,13 @@ const (
352352
)
353353

354354
type TxHistoryRecord struct {
355-
Txid string
356-
Type TxType
357-
Amount uint64
358-
CreatedAt int64
359-
ConfirmedAt int64
360-
IsSettled bool
355+
CommitmentTxid string
356+
VirtualTxid string
357+
Type TxType
358+
Amount uint64
359+
CreatedAt int64
360+
ConfirmedAt int64
361+
IsSettled bool
361362
}
362363

363364
type TransactionHistoryResponse struct {

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,13 @@ func (a *grpcClient) GetTransactionHistory(ctx context.Context, address string,
708708
history := make([]client.TxHistoryRecord, 0, len(resp.GetHistory()))
709709
for _, record := range resp.GetHistory() {
710710
history = append(history, client.TxHistoryRecord{
711-
Txid: getTxidFromHistoryRecord(record),
712-
Type: client.TxType(record.GetType()),
713-
Amount: record.GetAmount(),
714-
CreatedAt: record.GetCreatedAt(),
715-
ConfirmedAt: record.GetConfirmedAt(),
716-
IsSettled: record.GetIsSettled(),
711+
CommitmentTxid: record.GetCommitmentTxid(),
712+
VirtualTxid: record.GetVirtualTxid(),
713+
Type: client.TxType(record.GetType()),
714+
Amount: record.GetAmount(),
715+
CreatedAt: record.GetCreatedAt(),
716+
ConfirmedAt: record.GetConfirmedAt(),
717+
IsSettled: record.GetIsSettled(),
717718
})
718719
}
719720

@@ -727,21 +728,6 @@ func (a *grpcClient) GetTransactionHistory(ctx context.Context, address string,
727728
}, nil
728729
}
729730

730-
func getTxidFromHistoryRecord(record *arkv1.IndexerTxHistoryRecord) string {
731-
switch {
732-
case record.GetBoardingTxid() != "":
733-
return record.GetBoardingTxid()
734-
case record.GetCommitmentTxid() != "":
735-
return record.GetCommitmentTxid()
736-
case record.GetSweepTxid() != "":
737-
return record.GetSweepTxid()
738-
case record.GetArkTxid() != "":
739-
return record.GetArkTxid()
740-
default:
741-
return ""
742-
}
743-
}
744-
745731
func (a *grpcClient) GetVtxoChain(ctx context.Context, outpoint client.Outpoint, page client.PageRequest) (*client.VtxoChainResponse, error) {
746732
req := &arkv1.GetVtxoChainRequest{
747733
Outpoint: &arkv1.IndexerOutpoint{

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,18 +1196,6 @@ func (a *restClient) GetTransactionHistory(ctx context.Context, address string,
11961196
return nil, err
11971197
}
11981198

1199-
var txid string
1200-
switch {
1201-
case record.BoardingTxid != "":
1202-
txid = record.BoardingTxid
1203-
case record.CommitmentTxid != "":
1204-
txid = record.CommitmentTxid
1205-
case record.SweepTxid != "":
1206-
txid = record.SweepTxid
1207-
case record.ArkTxid != "":
1208-
txid = record.ArkTxid
1209-
}
1210-
12111199
// Use a zero value for TxType if Type is nil, otherwise use a numeric conversion
12121200
var txType client.TxType
12131201
if record.Type != nil {
@@ -1227,12 +1215,13 @@ func (a *restClient) GetTransactionHistory(ctx context.Context, address string,
12271215
}
12281216

12291217
history = append(history, client.TxHistoryRecord{
1230-
Txid: txid,
1231-
Type: txType,
1232-
Amount: amount,
1233-
CreatedAt: createdAt,
1234-
ConfirmedAt: confirmedAt,
1235-
IsSettled: record.IsSettled,
1218+
CommitmentTxid: record.CommitmentTxid,
1219+
VirtualTxid: record.VirtualTxid,
1220+
Type: txType,
1221+
Amount: amount,
1222+
CreatedAt: createdAt,
1223+
ConfirmedAt: confirmedAt,
1224+
IsSettled: record.IsSettled,
12361225
})
12371226
}
12381227

pkg/client-sdk/client/rest/service/models/v1_indexer_tx_history_record.go

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

server/internal/core/application/indexer.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,19 +411,22 @@ func vtxosToTxs(spendable, spent []domain.Vtxo) ([]TxHistoryRecord, error) {
411411
continue // settlement or change, ignore
412412
}
413413

414-
txid := vtxo.RoundTxid
414+
commitmentTxid := vtxo.RoundTxid
415+
virtualTxid := ""
415416
settled := !vtxo.IsPending()
416417
if vtxo.IsPending() {
417-
txid = vtxo.Txid
418+
virtualTxid = vtxo.Txid
419+
commitmentTxid = ""
418420
settled = vtxo.SpentBy != ""
419421
}
420422

421423
txs = append(txs, TxHistoryRecord{
422-
Txid: txid,
423-
Amount: vtxo.Amount - settleAmount - spentAmount,
424-
Type: TxReceived,
425-
CreatedAt: time.Unix(vtxo.CreatedAt, 0),
426-
Settled: settled,
424+
CommitmentTxid: commitmentTxid,
425+
VirtualTxid: virtualTxid,
426+
Amount: vtxo.Amount - settleAmount - spentAmount,
427+
Type: TxReceived,
428+
CreatedAt: time.Unix(vtxo.CreatedAt, 0),
429+
Settled: settled,
427430
})
428431
}
429432

@@ -455,17 +458,20 @@ func vtxosToTxs(spendable, spent []domain.Vtxo) ([]TxHistoryRecord, error) {
455458

456459
vtxo := getVtxo(resultedVtxos, vtxosBySpentBy[sb])
457460

458-
txid := vtxo.RoundTxid
461+
commitmentTxid := vtxo.RoundTxid
462+
virtualTxid := ""
459463
if vtxo.IsPending() {
460-
txid = vtxo.Txid
464+
virtualTxid = vtxo.Txid
465+
commitmentTxid = ""
461466
}
462467

463468
txs = append(txs, TxHistoryRecord{
464-
Txid: txid,
465-
Amount: spentAmount - resultedAmount,
466-
Type: TxSent,
467-
CreatedAt: time.Unix(vtxo.CreatedAt, 0),
468-
Settled: true,
469+
CommitmentTxid: commitmentTxid,
470+
VirtualTxid: virtualTxid,
471+
Amount: spentAmount - resultedAmount,
472+
Type: TxSent,
473+
CreatedAt: time.Unix(vtxo.CreatedAt, 0),
474+
Settled: true,
469475
})
470476

471477
}

server/internal/core/application/types.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ type TxHistoryResp struct {
223223
}
224224

225225
type TxHistoryRecord struct {
226-
Txid string
227-
Type TxType
228-
Amount uint64
229-
CreatedAt time.Time
230-
ConfirmedAt int64
231-
Settled bool
226+
CommitmentTxid string
227+
VirtualTxid string
228+
Type TxType
229+
Amount uint64
230+
CreatedAt time.Time
231+
ConfirmedAt int64
232+
Settled bool
232233
}
233234

234235
type Page struct {

0 commit comments

Comments
 (0)