Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgo: Use int64 for birthday time. #6

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions asset/dcr/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ func (w *Wallet) StartSync(ctx context.Context, ntfns *spv.Notifications, connec
// IsSyncing returns true if the wallet is catching up to the mainchain's best
// block.
func (w *Wallet) IsSyncing(ctx context.Context) bool {
if w.IsSynced(ctx) {
synced, _ := w.IsSynced(ctx)
if synced {
return false
}
return w.IsSyncingOrSynced()
}

// IsSynced returns true if the wallet has synced up to the best block on the
// mainchain.
func (w *Wallet) IsSynced(ctx context.Context) bool {
func (w *Wallet) IsSynced(ctx context.Context) (bool, int32) {
if w.syncer != nil {
synced, _ := w.syncer.Synced(ctx)
return synced
return w.syncer.Synced(ctx)
}
return false
return false, 0
}

// RescanProgressFromHeight rescans for relevant transactions in all blocks in
Expand Down
9 changes: 6 additions & 3 deletions cgo/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func currentReceiveAddress(cName *C.char) *C.char {
}

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

Expand All @@ -37,7 +38,8 @@ func newExternalAddress(cName *C.char) *C.char {
}

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

Expand Down Expand Up @@ -95,7 +97,8 @@ func addresses(cName *C.char) *C.char {
}

// w.AddressesByAccount does not include the current address.
if w.IsSynced(w.ctx) {
synced, _ := w.IsSynced(w.ctx)
if synced {
addr, err := w.CurrentAddress(udb.DefaultAccountNum)
if err != nil {
return errCResponse("w.CurrentAddress error: %v", err)
Expand Down
22 changes: 17 additions & 5 deletions cgo/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func syncWallet(cName, cPeers *C.char) *C.char {
w.log.Infof("Fetching cfilters from %d to %d.", startCFiltersHeight, endCFiltersHeight)
},
FetchMissingCFiltersFinished: func() {
w.syncStatusMtx.Lock()
w.cfiltersHeight = w.targetHeight
w.syncStatusMtx.Unlock()
w.log.Info("Finished fetching missing cfilters.")
},
FetchHeadersStarted: func() {
Expand All @@ -77,6 +80,9 @@ func syncWallet(cName, cPeers *C.char) *C.char {
w.log.Infof("Fetching headers to %d.", lastHeaderHeight)
},
FetchHeadersFinished: func() {
w.syncStatusMtx.Lock()
w.headersHeight = w.targetHeight
w.syncStatusMtx.Unlock()
w.log.Info("Fetching headers finished.")
},
DiscoverAddressesStarted: func() {
Expand Down Expand Up @@ -109,6 +115,9 @@ func syncWallet(cName, cPeers *C.char) *C.char {
w.log.Infof("Rescanned through block %d.", rescannedThrough)
},
RescanFinished: func() {
w.syncStatusMtx.Lock()
w.rescanHeight = w.targetHeight
w.syncStatusMtx.Unlock()
w.log.Info("Rescan finished.")
},
}
Expand All @@ -129,14 +138,13 @@ func syncWalletStatus(cName *C.char) *C.char {
var ssc, cfh, hh, rh, np = w.syncStatusCode, w.cfiltersHeight, w.headersHeight, w.rescanHeight, w.numPeers
w.syncStatusMtx.RUnlock()

_, targetHeight := w.MainWallet().MainChainTip(w.ctx)

// Sometimes it appears we miss a notification during start up. This is
// a bandaid to put us as synced in that case.
//
// TODO: Figure out why we would miss a notification.
synced, targetHeight := w.IsSynced(w.ctx)
w.syncStatusMtx.Lock()
if ssc != SSCComplete && w.IsSynced(w.ctx) && !w.rescanning {
if ssc != SSCComplete && synced && !w.rescanning {
ssc = SSCComplete
w.syncStatusCode = ssc
}
Expand Down Expand Up @@ -174,7 +182,8 @@ func rescanFromHeight(cName, cHeight *C.char) *C.char {
if !exists {
return errCResponse("wallet with name %q does not exist", name)
}
if !w.IsSynced(w.ctx) {
synced, _ := w.IsSynced(w.ctx)
if !synced {
return errCResponseWithCode(ErrCodeNotSynced, "rescanFromHeight requested on an unsynced wallet")
}
w.syncStatusMtx.Lock()
Expand Down Expand Up @@ -231,11 +240,14 @@ func birthState(cName *C.char) *C.char {
if err != nil {
return errCResponse("wallet.BirthState error: %v", err)
}
if bs == nil {
return errCResponse("birth state is nil for wallet %q", goString(cName))
}

bsRes := &BirthdayState{
Hash: bs.Hash.String(),
Height: bs.Height,
Time: bs.Time,
Time: bs.Time.Unix(),
SetFromHeight: bs.SetFromHeight,
SetFromTime: bs.SetFromTime,
}
Expand Down
11 changes: 5 additions & 6 deletions cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "C"
import (
"encoding/json"
"fmt"
"time"

wallettypes "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
)
Expand Down Expand Up @@ -140,9 +139,9 @@ type ListTransactionRes struct {
}

type BirthdayState struct {
Hash string `json:"hash"`
Height uint32 `json:"height"`
Time time.Time `json:"time"`
SetFromHeight bool `json:"setfromheight"`
SetFromTime bool `json:"setfromtime"`
Hash string `json:"hash"`
Height uint32 `json:"height"`
Time int64 `json:"time"`
SetFromHeight bool `json:"setfromheight"`
SetFromTime bool `json:"setfromtime"`
}
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/decred/libwallet

require (
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164
decred.org/dcrwallet/v4 v4.1.1
decred.org/dcrwallet/v4 v4.1.2
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/decred/dcrd/addrmgr/v2 v2.0.4
github.com/decred/dcrd/chaincfg/chainhash v1.0.4
Expand All @@ -15,7 +15,7 @@ require (
github.com/decred/slog v1.2.0
github.com/jrick/logrotate v1.0.0
github.com/kevinburke/nacl v0.0.0-20210405173606-cd9060f5f776
golang.org/x/crypto v0.23.0
golang.org/x/crypto v0.24.0
)

require (
Expand All @@ -26,15 +26,17 @@ require (
github.com/decred/base58 v1.0.5 // indirect
github.com/decred/dcrd/blockchain/stake/v5 v5.0.1 // indirect
github.com/decred/dcrd/blockchain/standalone/v2 v2.2.1 // indirect
github.com/decred/dcrd/container/lru v1.0.0 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/crypto/rand v1.0.0 // indirect
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
github.com/decred/dcrd/database/v3 v3.0.2 // indirect
github.com/decred/dcrd/dcrec v1.0.1 // indirect
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/decred/dcrd/dcrjson/v4 v4.1.0 // indirect
github.com/decred/dcrd/gcs/v4 v4.1.0 // indirect
github.com/decred/dcrd/mixing v0.3.0 // indirect
github.com/decred/dcrd/mixing v0.4.0 // indirect
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0 // indirect
github.com/decred/go-socks v1.1.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
Expand All @@ -45,7 +47,7 @@ require (
go.etcd.io/bbolt v1.3.8 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)

Expand Down
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ decred.org/cspp/v2 v2.2.0 h1:VSOUC1w0Wo+QOGS0r1XO6TLnO16X67KuvpDmRRYyr08=
decred.org/cspp/v2 v2.2.0/go.mod h1:9nO3bfvCheOPIFZw5f6sRQ42CjBFB5RKSaJ9Iq6G4MA=
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164 h1:ImD+Zui9lnZhVYacX0x9ki1M95hTYxwASl2PvVoAc2M=
decred.org/dcrdex v0.0.0-20240415203145-79c4689fd164/go.mod h1:rvIXDCS3B3gbu8b0tKDvNU664nC+/zVl3ivs6AeA2V8=
decred.org/dcrwallet/v4 v4.1.1 h1:imwPBboytp1PH6V8q7/JLTHiKgj/Scq9a3I1WmnJv0Y=
decred.org/dcrwallet/v4 v4.1.1/go.mod h1:WxerkRcUGVreJsAI0ptCBPUujPUmWncbdYbme8Kl5r0=
decred.org/dcrwallet/v4 v4.1.2 h1:NESPkLLpLXwrsWRmeDSLM/O5NaSMFSyjQrG+9m0iuzk=
decred.org/dcrwallet/v4 v4.1.2/go.mod h1:Ivu6THxbdMLGxKTa/eJT7vDr2awmKok7gEh82oCxs/s=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
Expand All @@ -30,8 +30,12 @@ github.com/decred/dcrd/chaincfg/v3 v3.2.1 h1:x9zKJaU24WAKbxAR1UyFKHlM3oJgP0H9Lod
github.com/decred/dcrd/chaincfg/v3 v3.2.1/go.mod h1:SDCWDtY7BLj0leXc9FuoA1YjSVKyCIBVAyxwZn6+sXc=
github.com/decred/dcrd/connmgr/v3 v3.1.2 h1:+xNopie2L3YYwwkz51k0h/pASATOBzHtl2O8eodGg04=
github.com/decred/dcrd/connmgr/v3 v3.1.2/go.mod h1:tdbErFiNOuy/sHrX2mwaOk+r1HLs3EBz2EGxsocMPe4=
github.com/decred/dcrd/container/lru v1.0.0 h1:7foQymtbu18aQWYiY9RnNIeE+kvpiN+fiBQ3+viyJjI=
github.com/decred/dcrd/container/lru v1.0.0/go.mod h1:vlPwj0l+IzAHhQSsbgQnJgO5Cte78+yI065V+Mc5PRQ=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/crypto/rand v1.0.0 h1:Ah9Asl36OZt09sGSMbJZuL1HfwGdlC38q/ZUeLDVKRg=
github.com/decred/dcrd/crypto/rand v1.0.0/go.mod h1:coa7BbxSTiKH6esi257plGfMFYuGL4MTbQlLYnOdzpE=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
github.com/decred/dcrd/database/v3 v3.0.2 h1:rgP7XNZemTs8ZC7bnTKO8JO79Woj5nq+yQYmB9ry7yM=
Expand All @@ -50,8 +54,8 @@ github.com/decred/dcrd/gcs/v4 v4.1.0 h1:tpW7JW53yJZlgNwl/n2NL1b8NxHaIPRUyNuLMkB/
github.com/decred/dcrd/gcs/v4 v4.1.0/go.mod h1:nPTbGM/I3Ihe5KFvUmxZEqQP/jDZQjQ63+WEi/f4lqU=
github.com/decred/dcrd/hdkeychain/v3 v3.1.2 h1:x25WuuE7zM/20EynuVMyOhL0K8BwGBBsexGq8xTiHFA=
github.com/decred/dcrd/hdkeychain/v3 v3.1.2/go.mod h1:FnNJmZ7jqUDeAo6/c/xkQi5cuxh3EWtJeMmW6/Z8lcc=
github.com/decred/dcrd/mixing v0.3.0 h1:eUHpTdwTqXUllnn1ZYLfxucW/2UOkMmx4CyztipTJ9g=
github.com/decred/dcrd/mixing v0.3.0/go.mod h1:W3K7yJKmoI03G2U5Yw+HSRNe6lLBegi63ZR6fFLnM9c=
github.com/decred/dcrd/mixing v0.4.0 h1:XblHAND4Vt5owVUvjPorDg30eWT53DpCZs6VF7U1t6U=
github.com/decred/dcrd/mixing v0.4.0/go.mod h1:ySvVwTZyVz5YvevA6YjPrB6pJEwTm7IkHohTfaiHh2c=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0 h1:l0DnCcILTNrpy8APF3FLN312ChpkQaAuW30aC/RgBaw=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0/go.mod h1:j+kkRPXPJB5S9VFOsx8SQLcU7PTFkPKRc1aCHN4ENzA=
github.com/decred/dcrd/txscript/v4 v4.1.1 h1:R4M2+jMujgQA91899SkL0cW66d6DC76Gx+1W1oEHjc0=
Expand Down Expand Up @@ -87,15 +91,15 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Loading