Skip to content

Commit 18eafa5

Browse files
committed
Merge remote-tracking branch origin/next-version into vtxo-chain-fix
2 parents 42d267d + c4f5911 commit 18eafa5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1194
-1106
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,11 @@
10781078
"spentBy": {
10791079
"type": "string"
10801080
},
1081-
"commitmentTxid": {
1082-
"type": "string"
1081+
"commitmentTxids": {
1082+
"type": "array",
1083+
"items": {
1084+
"type": "string"
1085+
}
10831086
}
10841087
}
10851088
},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,11 @@
872872
"type": "string",
873873
"format": "int64"
874874
},
875-
"commitmentTxid": {
876-
"type": "string"
875+
"commitmentTxids": {
876+
"type": "array",
877+
"items": {
878+
"type": "string"
879+
}
877880
},
878881
"preconfirmed": {
879882
"type": "boolean"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ message IndexerVtxo {
280280
bool is_redeemed = 8;
281281
bool is_spent = 9;
282282
string spent_by = 10;
283-
string commitment_txid = 11;
283+
repeated string commitment_txids = 11;
284284
}
285285

286286
message IndexerChain {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ message Vtxo {
2525
string script = 3;
2626
int64 created_at = 4;
2727
int64 expires_at = 5;
28-
string commitment_txid = 6;
28+
repeated string commitment_txids = 6;
2929
bool preconfirmed = 7;
3030
bool swept = 8;
3131
bool redeemed = 9;

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

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

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

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

pkg/client-sdk/client.go

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -975,30 +975,7 @@ func (a *covenantlessArkClient) GetTransactionHistory(
975975
return history, nil
976976
}
977977

978-
spendableVtxos, spentVtxos, err := a.ListVtxos(ctx)
979-
if err != nil {
980-
return nil, err
981-
}
982-
983-
boardingTxs, commitmentTxsToIgnore, err := a.getBoardingTxs(ctx)
984-
if err != nil {
985-
return nil, err
986-
}
987-
988-
offchainTxs, err := vtxosToTxHistory(
989-
spendableVtxos, spentVtxos, commitmentTxsToIgnore, a.indexer,
990-
)
991-
if err != nil {
992-
return nil, err
993-
}
994-
995-
history := append(boardingTxs, offchainTxs...)
996-
// Sort the slice by age
997-
sort.SliceStable(history, func(i, j int) bool {
998-
return history[i].CreatedAt.IsZero() || history[i].CreatedAt.After(history[j].CreatedAt)
999-
})
1000-
1001-
return history, nil
978+
return a.fetchTxHistory(ctx)
1002979
}
1003980

1004981
func (a *covenantlessArkClient) RegisterIntent(
@@ -1114,25 +1091,16 @@ func (a *covenantlessArkClient) listenForArkTxs(ctx context.Context) {
11141091

11151092
func (a *covenantlessArkClient) refreshDb(ctx context.Context) error {
11161093
// fetch new data
1117-
spendableVtxos, spentVtxos, err := a.ListVtxos(ctx)
1094+
history, err := a.fetchTxHistory(ctx)
11181095
if err != nil {
11191096
return err
11201097
}
1121-
1122-
boardingTxs, commitmentTxsToIgnore, err := a.getBoardingTxs(ctx)
1123-
if err != nil {
1124-
return err
1125-
}
1126-
1127-
offchainTxs, err := vtxosToTxHistory(
1128-
spendableVtxos, spentVtxos, commitmentTxsToIgnore, a.indexer,
1129-
)
1098+
spendableVtxos, spentVtxos, err := a.ListVtxos(ctx)
11301099
if err != nil {
11311100
return err
11321101
}
11331102

1134-
newTxs := append(offchainTxs, boardingTxs...)
1135-
if err := a.refreshTxDb(newTxs); err != nil {
1103+
if err := a.refreshTxDb(history); err != nil {
11361104
return err
11371105
}
11381106

@@ -3030,17 +2998,7 @@ func (a *covenantlessArkClient) handleCommitmentTx(
30302998

30312999
for _, vtxo := range commitmentTx.SpendableVtxos {
30323000
if _, ok := myPubkeys[vtxo.Script]; ok {
3033-
vtxosToAdd = append(vtxosToAdd, types.Vtxo{
3034-
VtxoKey: types.VtxoKey{
3035-
Txid: vtxo.Txid,
3036-
VOut: vtxo.VOut,
3037-
},
3038-
Script: vtxo.Script,
3039-
Amount: vtxo.Amount,
3040-
CommitmentTxid: vtxo.CommitmentTxid,
3041-
ExpiresAt: vtxo.ExpiresAt,
3042-
CreatedAt: time.Now(),
3043-
})
3001+
vtxosToAdd = append(vtxosToAdd, vtxo)
30443002
}
30453003
}
30463004

@@ -3333,3 +3291,41 @@ func (a *covenantlessArkClient) handleOptions(
33333291

33343292
return sessions, signerPubKeys, nil
33353293
}
3294+
3295+
func (a *covenantlessArkClient) fetchTxHistory(ctx context.Context) ([]types.Transaction, error) {
3296+
_, offchainAddrs, _, _, err := a.wallet.GetAddresses(ctx)
3297+
if err != nil {
3298+
return nil, err
3299+
}
3300+
3301+
indexedHistory := make(map[string]types.Transaction)
3302+
for _, addr := range offchainAddrs {
3303+
resp, err := a.indexer.GetTransactionHistory(ctx, addr.Address)
3304+
if err != nil {
3305+
return nil, err
3306+
}
3307+
for _, tx := range resp.History {
3308+
indexedHistory[tx.String()] = tx
3309+
}
3310+
}
3311+
3312+
boardingTxs, commitmentTxsToIgnore, err := a.getBoardingTxs(ctx)
3313+
if err != nil {
3314+
return nil, err
3315+
}
3316+
3317+
for txid := range commitmentTxsToIgnore {
3318+
delete(indexedHistory, txid)
3319+
}
3320+
3321+
allHistory := append([]types.Transaction{}, boardingTxs...)
3322+
for _, tx := range indexedHistory {
3323+
allHistory = append(allHistory, tx)
3324+
}
3325+
3326+
sort.SliceStable(allHistory, func(i, j int) bool {
3327+
return allHistory[i].CreatedAt.IsZero() || allHistory[i].CreatedAt.After(allHistory[j].CreatedAt)
3328+
})
3329+
3330+
return allHistory, nil
3331+
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ func (v vtxo) toVtxo() types.Vtxo {
116116
Txid: v.GetOutpoint().GetTxid(),
117117
VOut: v.GetOutpoint().GetVout(),
118118
},
119-
Script: v.GetScript(),
120-
Amount: v.GetAmount(),
121-
CommitmentTxid: v.GetCommitmentTxid(),
122-
CreatedAt: time.Unix(v.GetCreatedAt(), 0),
123-
ExpiresAt: time.Unix(v.GetExpiresAt(), 0),
124-
Preconfirmed: v.GetPreconfirmed(),
125-
Swept: v.GetSwept(),
126-
Redeemed: v.GetRedeemed(),
127-
Spent: v.GetSpent(),
128-
SpentBy: v.GetSpentBy(),
119+
Script: v.GetScript(),
120+
Amount: v.GetAmount(),
121+
CommitmentTxids: v.GetCommitmentTxids(),
122+
CreatedAt: time.Unix(v.GetCreatedAt(), 0),
123+
ExpiresAt: time.Unix(v.GetExpiresAt(), 0),
124+
Preconfirmed: v.GetPreconfirmed(),
125+
Swept: v.GetSwept(),
126+
Redeemed: v.GetRedeemed(),
127+
Spent: v.GetSpent(),
128+
SpentBy: v.GetSpentBy(),
129129
}
130130
}
131131

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,16 @@ func vtxosFromRest(restVtxos []*models.V1Vtxo) []types.Vtxo {
542542
Txid: v.Outpoint.Txid,
543543
VOut: uint32(v.Outpoint.Vout),
544544
},
545-
Script: v.Script,
546-
Amount: uint64(amount),
547-
CommitmentTxid: v.CommitmentTxid,
548-
ExpiresAt: expiresAt,
549-
CreatedAt: createdAt,
550-
Preconfirmed: v.Preconfirmed,
551-
Swept: v.Swept,
552-
Redeemed: v.Redeemed,
553-
Spent: v.Spent,
554-
SpentBy: v.SpentBy,
545+
Script: v.Script,
546+
Amount: uint64(amount),
547+
CommitmentTxids: v.CommitmentTxids,
548+
ExpiresAt: expiresAt,
549+
CreatedAt: createdAt,
550+
Preconfirmed: v.Preconfirmed,
551+
Swept: v.Swept,
552+
Redeemed: v.Redeemed,
553+
Spent: v.Spent,
554+
SpentBy: v.SpentBy,
555555
}
556556
}
557557
return vtxos

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

Lines changed: 2 additions & 2 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: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,21 @@ func (a *grpcClient) GetTransactionHistory(
375375
return nil, err
376376
}
377377

378-
history := make([]indexer.TxHistoryRecord, 0, len(resp.GetHistory()))
378+
history := make([]types.Transaction, 0, len(resp.GetHistory()))
379379
for _, record := range resp.GetHistory() {
380-
history = append(history, indexer.TxHistoryRecord{
381-
CommitmentTxid: record.GetCommitmentTxid(),
382-
ArkTxid: record.GetVirtualTxid(),
383-
Type: indexer.TxType(record.GetType()),
384-
Amount: record.GetAmount(),
385-
CreatedAt: record.GetCreatedAt(),
386-
IsSettled: record.GetIsSettled(),
387-
SettledBy: record.GetSettledBy(),
380+
txType := types.TxSent
381+
if record.GetType() == arkv1.IndexerTxType_INDEXER_TX_TYPE_RECEIVED {
382+
txType = types.TxReceived
383+
}
384+
history = append(history, types.Transaction{
385+
TransactionKey: types.TransactionKey{
386+
CommitmentTxid: record.GetCommitmentTxid(),
387+
ArkTxid: record.GetVirtualTxid(),
388+
},
389+
Type: txType,
390+
Amount: record.GetAmount(),
391+
CreatedAt: time.Unix(record.GetCreatedAt(), 0),
392+
Settled: record.GetIsSettled(),
388393
})
389394
}
390395

@@ -580,15 +585,15 @@ func newIndexerVtxo(vtxo *arkv1.IndexerVtxo) types.Vtxo {
580585
Txid: vtxo.GetOutpoint().GetTxid(),
581586
VOut: vtxo.GetOutpoint().GetVout(),
582587
},
583-
Script: vtxo.GetScript(),
584-
CommitmentTxid: vtxo.GetCommitmentTxid(),
585-
Amount: vtxo.GetAmount(),
586-
CreatedAt: time.Unix(vtxo.GetCreatedAt(), 0),
587-
ExpiresAt: time.Unix(vtxo.GetExpiresAt(), 0),
588-
Preconfirmed: vtxo.GetIsPreconfirmed(),
589-
Swept: vtxo.GetIsSwept(),
590-
Spent: vtxo.GetIsSpent(),
591-
Redeemed: vtxo.GetIsRedeemed(),
592-
SpentBy: vtxo.GetSpentBy(),
588+
Script: vtxo.GetScript(),
589+
CommitmentTxids: vtxo.GetCommitmentTxids(),
590+
Amount: vtxo.GetAmount(),
591+
CreatedAt: time.Unix(vtxo.GetCreatedAt(), 0),
592+
ExpiresAt: time.Unix(vtxo.GetExpiresAt(), 0),
593+
Preconfirmed: vtxo.GetIsPreconfirmed(),
594+
Swept: vtxo.GetIsSwept(),
595+
Spent: vtxo.GetIsSpent(),
596+
Redeemed: vtxo.GetIsRedeemed(),
597+
SpentBy: vtxo.GetSpentBy(),
593598
}
594599
}

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func (a *restClient) GetTransactionHistory(
368368
return nil, err
369369
}
370370

371-
history := make([]indexer.TxHistoryRecord, 0, len(resp.Payload.History))
371+
history := make([]types.Transaction, 0, len(resp.Payload.History))
372372
for _, record := range resp.Payload.History {
373373
amount, err := strconv.ParseUint(record.Amount, 10, 64)
374374
if err != nil {
@@ -380,29 +380,27 @@ func (a *restClient) GetTransactionHistory(
380380
}
381381

382382
// Use a zero value for TxType if Type is nil, otherwise use a numeric conversion
383-
var txType indexer.TxType
383+
var txType types.TxType
384384
if record.Type != nil {
385385
// Convert the string enum to a numeric value
386386
typeStr := string(*record.Type)
387387
switch typeStr {
388388
case "INDEXER_TX_TYPE_RECEIVED":
389-
txType = indexer.TxTypeReceived
389+
txType = types.TxReceived
390390
case "INDEXER_TX_TYPE_SENT":
391-
txType = indexer.TxTypeSent
392-
default:
393-
// Default to unspecified for unknown types
394-
txType = indexer.TxTypeUnspecified
391+
txType = types.TxSent
395392
}
396393
}
397394

398-
history = append(history, indexer.TxHistoryRecord{
399-
CommitmentTxid: record.CommitmentTxid,
400-
ArkTxid: record.VirtualTxid,
401-
Type: txType,
402-
Amount: amount,
403-
CreatedAt: createdAt,
404-
IsSettled: record.IsSettled,
405-
SettledBy: record.SettledBy,
395+
history = append(history, types.Transaction{
396+
TransactionKey: types.TransactionKey{
397+
CommitmentTxid: record.CommitmentTxid,
398+
ArkTxid: record.VirtualTxid,
399+
},
400+
Type: txType,
401+
Amount: amount,
402+
CreatedAt: time.Unix(createdAt, 0),
403+
Settled: record.IsSettled,
406404
})
407405
}
408406

@@ -700,15 +698,15 @@ func newIndexerVtxo(vtxo *models.V1IndexerVtxo) (*types.Vtxo, error) {
700698
Txid: vtxo.Outpoint.Txid,
701699
VOut: uint32(vtxo.Outpoint.Vout),
702700
},
703-
Script: vtxo.Script,
704-
CommitmentTxid: vtxo.CommitmentTxid,
705-
Amount: amount,
706-
CreatedAt: time.Unix(createdAt, 0),
707-
ExpiresAt: time.Unix(expiresAt, 0),
708-
Preconfirmed: vtxo.IsPreconfirmed,
709-
Swept: vtxo.IsSwept,
710-
Redeemed: vtxo.IsRedeemed,
711-
Spent: vtxo.IsSpent,
712-
SpentBy: vtxo.SpentBy,
701+
Script: vtxo.Script,
702+
CommitmentTxids: vtxo.CommitmentTxids,
703+
Amount: amount,
704+
CreatedAt: time.Unix(createdAt, 0),
705+
ExpiresAt: time.Unix(expiresAt, 0),
706+
Preconfirmed: vtxo.IsPreconfirmed,
707+
Swept: vtxo.IsSwept,
708+
Redeemed: vtxo.IsRedeemed,
709+
Spent: vtxo.IsSpent,
710+
SpentBy: vtxo.SpentBy,
713711
}, nil
714712
}

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

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

0 commit comments

Comments
 (0)