Skip to content

Commit e81dfea

Browse files
committed
rectify ws_url not being written to storage
1 parent 020beb8 commit e81dfea

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

pkg/client-sdk/base_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ func (a *arkClient) init(
370370
BoardingExitDelay: common.RelativeLocktime{Type: boardingExitDelayType, Value: uint32(info.BoardingExitDelay)},
371371
BoardingDescriptorTemplate: info.BoardingDescriptorTemplate,
372372
ExplorerURL: explorerSvc.BaseUrl(),
373+
ExplorerWSURL: args.ExplorerWSURL,
373374
ForfeitAddress: info.ForfeitAddress,
374375
WithTransactionFeed: args.WithTransactionFeed,
375376
MarketHourStartTime: info.MarketHourStartTime,

pkg/client-sdk/client.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ func (a *covenantlessArkClient) getTransaction(ctx context.Context, txId string)
10481048
}
10491049

10501050
func (a *covenantlessArkClient) listenWebsocketBoardingTxns(ctx context.Context) {
1051-
// try to add existing boarding utxos if present
1051+
// try to add existing boarding utxos if present during initialization
10521052
_, boardingAddresses, _, err := a.wallet.GetAddresses(ctx)
10531053
if err == nil {
10541054
for _, boardingAddress := range boardingAddresses {
@@ -1060,7 +1060,7 @@ func (a *covenantlessArkClient) listenWebsocketBoardingTxns(ctx context.Context)
10601060

10611061
err = a.explorer.ListenAddresses(func(boaringUtxos, mempoolUtxos []explorer.WSUtxo) error {
10621062
if len(mempoolUtxos) > 0 {
1063-
newPendingBoardingTxs := make([]types.Transaction, 0)
1063+
newPendingBoardingTxs := make([]types.Transaction, len(mempoolUtxos))
10641064
createdAt := time.Now()
10651065

10661066
for _, u := range mempoolUtxos {
@@ -1090,6 +1090,8 @@ func (a *covenantlessArkClient) listenWebsocketBoardingTxns(ctx context.Context)
10901090
}
10911091
}
10921092

1093+
log.WithField("rbFTransactions", rbfTransactions).Debugf("replacing %d boarding transaction(s) with rbf transactions", len(rbfTransactions))
1094+
10931095
count, err := a.store.TransactionStore().RbfTransactions(ctx, rbfTransactions)
10941096
if err != nil {
10951097
log.WithError(err).Error("failed to update rbf boarding transactions")
@@ -1100,6 +1102,8 @@ func (a *covenantlessArkClient) listenWebsocketBoardingTxns(ctx context.Context)
11001102
continue
11011103
}
11021104

1105+
log.WithField("mempool_txid", u.Txid).Infof("new boarding transaction %s", u.Txid)
1106+
11031107
newPendingBoardingTxs = append(newPendingBoardingTxs, types.Transaction{
11041108
TransactionKey: types.TransactionKey{
11051109
BoardingTxid: u.Txid,
@@ -1130,6 +1134,30 @@ func (a *covenantlessArkClient) listenWebsocketBoardingTxns(ctx context.Context)
11301134
)
11311135
if err != nil {
11321136
log.WithError(err).Error("failed to update boarding transactions")
1137+
return err
1138+
}
1139+
// ensure that we add transactions that were not in memepool
1140+
// but were confirmed in the blockchain
1141+
if count != len(boaringUtxos) {
1142+
newPendingBoardingTxs := make([]types.Transaction, len(boaringUtxos))
1143+
for _, u := range boaringUtxos {
1144+
newPendingBoardingTxs = append(newPendingBoardingTxs, types.Transaction{
1145+
TransactionKey: types.TransactionKey{
1146+
BoardingTxid: u.Txid,
1147+
},
1148+
Amount: u.Value,
1149+
Type: types.TxReceived,
1150+
CreatedAt: time.Now(),
1151+
})
1152+
}
1153+
count, err = a.store.TransactionStore().AddTransactions(
1154+
ctx, newPendingBoardingTxs,
1155+
)
1156+
if err != nil {
1157+
log.WithError(err).Error("failed to add new boarding transactions")
1158+
return err
1159+
}
1160+
11331161
}
11341162
log.Debugf("confirmed %d boarding transaction(s)", count)
11351163
}

pkg/client-sdk/store/file/config_store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (s *configStore) AddData(ctx context.Context, data types.Config) error {
6464
Dust: fmt.Sprintf("%d", data.Dust),
6565
BoardingDescriptorTemplate: data.BoardingDescriptorTemplate,
6666
ExplorerURL: data.ExplorerURL,
67+
ExplorerWSURL: data.ExplorerWSURL,
6768
ForfeitAddress: data.ForfeitAddress,
6869
WithTransactionFeed: strconv.FormatBool(data.WithTransactionFeed),
6970
MarketHourStartTime: fmt.Sprintf("%d", data.MarketHourStartTime),

pkg/client-sdk/store/file/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type storeData struct {
2323
BoardingExitDelay string `json:"boarding_exit_delay"`
2424
BoardingDescriptorTemplate string `json:"boarding_descriptor_template"`
2525
ExplorerURL string `json:"explorer_url"`
26+
ExplorerWSURL string `json:"explorer_ws_url"`
2627
ForfeitAddress string `json:"forfeit_address"`
2728
WithTransactionFeed string `json:"with_transaction_feed"`
2829
MarketHourStartTime string `json:"market_hour_start_time"`
@@ -55,6 +56,7 @@ func (d storeData) decode() types.Config {
5556
buf, _ := hex.DecodeString(d.ServerPubKey)
5657
serverPubkey, _ := secp256k1.ParsePubKey(buf)
5758
explorerURL := d.ExplorerURL
59+
explorerWSURL := d.ExplorerWSURL
5860
nextStartTime, _ := strconv.Atoi(d.MarketHourStartTime)
5961
nextEndTime, _ := strconv.Atoi(d.MarketHourEndTime)
6062
period, _ := strconv.Atoi(d.MarketHourPeriod)
@@ -92,6 +94,7 @@ func (d storeData) decode() types.Config {
9294
BoardingExitDelay: common.RelativeLocktime{Type: boardingExitDelayType, Value: uint32(boardingExitDelay)},
9395
BoardingDescriptorTemplate: d.BoardingDescriptorTemplate,
9496
ExplorerURL: explorerURL,
97+
ExplorerWSURL: explorerWSURL,
9598
ForfeitAddress: d.ForfeitAddress,
9699
WithTransactionFeed: withTransactionFeed,
97100
MarketHourStartTime: int64(nextStartTime),
@@ -119,6 +122,7 @@ func (d storeData) asMap() map[string]string {
119122
"boarding_exit_delay": d.BoardingExitDelay,
120123
"boarding_descriptor_template": d.BoardingDescriptorTemplate,
121124
"explorer_url": d.ExplorerURL,
125+
"explorer_ws_url": d.ExplorerWSURL,
122126
"forfeit_address": d.ForfeitAddress,
123127
"with_transaction_feed": d.WithTransactionFeed,
124128
"market_hour_start_time": d.MarketHourStartTime,

0 commit comments

Comments
 (0)