Skip to content

Commit

Permalink
cgo: Allow getting addrs when not synced
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Feb 8, 2025
1 parent 82ed8a8 commit cf394fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
19 changes: 1 addition & 18 deletions cgo/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ func currentReceiveAddress(cName *C.char) *C.char {
return errCResponse("wallet with name %q is not loaded", goString(cName))
}

// Don't return an address if not synced!
synced, _ := w.IsSynced(w.ctx)
if !synced {
return errCResponseWithCode(ErrCodeNotSynced, "currentReceiveAddress requested on an unsynced wallet")
}

addr, err := w.CurrentAddress(udb.DefaultAccountNum)
if err != nil {
return errCResponse("w.CurrentAddress error: %v", err)
Expand All @@ -39,12 +33,6 @@ func newExternalAddress(cName *C.char) *C.char {
return errCResponse("wallet with name %q is not loaded", goString(cName))
}

// Don't return an address if not synced!
synced, _ := w.IsSynced(w.ctx)
if !synced {
return errCResponseWithCode(ErrCodeNotSynced, "newExternalAddress requested on an unsynced wallet")
}

_, err := w.NewExternalAddress(w.ctx, udb.DefaultAccountNum)
if err != nil {
return errCResponse("w.NewExternalAddress error: %v", err)
Expand Down Expand Up @@ -155,14 +143,9 @@ func addresses(cName, cNUsed, cNUnused *C.char) *C.char {

res := &AddressesRes{
Used: used,
Unused: []string{},
Unused: unused,
Index: index,
}
// Avoid returning unused addresses if we are not synced.
synced, _ := w.IsSynced(w.ctx)
if synced {
res.Unused = unused
}

b, err := json.Marshal(res)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion cgo/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,26 @@ func listTransactions(cName, cFrom, cCount *C.char) *C.char {
if err != nil {
return errCResponse("unable to get transactions: %v", err)
}
_, blockHeight := w.MainWallet().MainChainTip(w.ctx)
ltRes := make([]*ListTransactionRes, len(res))
for i, ltw := range res {
// Use earliest of receive time or block time if the transaction is mined.
receiveTime := ltw.TimeReceived
if ltw.BlockTime < ltw.TimeReceived {
if ltw.BlockTime != 0 && ltw.BlockTime < ltw.TimeReceived {
receiveTime = ltw.BlockTime
}

height := 0
if ltw.Confirmations > 0 {
height = blockHeight - ltw.Confirmations - 1

Check failure on line 177 in cgo/transactions.go

View workflow job for this annotation

GitHub Actions / Go CI (1.22)

invalid operation: blockHeight - ltw.Confirmations (mismatched types int32 and int64)

Check failure on line 177 in cgo/transactions.go

View workflow job for this annotation

GitHub Actions / Go CI (1.23)

invalid operation: blockHeight - ltw.Confirmations (mismatched types int32 and int64)
}

lt := &ListTransactionRes{
Address: ltw.Address,
Amount: ltw.Amount,
Category: ltw.Category,
Confirmations: ltw.Confirmations,
Height: height,

Check failure on line 185 in cgo/transactions.go

View workflow job for this annotation

GitHub Actions / Go CI (1.22)

cannot use height (variable of type int) as int64 value in struct literal

Check failure on line 185 in cgo/transactions.go

View workflow job for this annotation

GitHub Actions / Go CI (1.23)

cannot use height (variable of type int) as int64 value in struct literal
Fee: ltw.Fee,
Time: receiveTime,
TxID: ltw.TxID,
Expand Down
1 change: 1 addition & 0 deletions cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type ListTransactionRes struct {
Amount float64 `json:"amount"`
Category string `json:"category"`
Confirmations int64 `json:"confirmations"`
Height int64 `json:"height"`
Fee *float64 `json:"fee,omitempty"`
Time int64 `json:"time"`
TxID string `json:"txid"`
Expand Down

0 comments on commit cf394fc

Please sign in to comment.