Skip to content

Commit

Permalink
Download transfers starting from latest block header (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak authored Jun 14, 2019
1 parent 804a109 commit 047c9b5
Show file tree
Hide file tree
Showing 40 changed files with 4,018 additions and 88 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ run:
skip-dirs:
- static
skip-files:
- bindata.go
- .*_mock.go
- jail/doc.go

Expand Down
50 changes: 40 additions & 10 deletions api/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/big"
"path"
"sync"
"time"

Expand Down Expand Up @@ -474,7 +475,19 @@ func (b *StatusBackend) Logout() error {
default:
return err
}

if b.statusNode.Config().WalletConfig.Enabled {
wallet, err := b.statusNode.WalletService()
switch err {
case node.ErrServiceUnknown:
case nil:
err = wallet.StopReactor()
if err != nil {
return err
}
default:
return err
}
}
b.AccountManager().Logout()

return nil
Expand All @@ -497,7 +510,6 @@ func (b *StatusBackend) reSelectAccount() error {
default:
return err
}

return nil
}

Expand Down Expand Up @@ -539,20 +551,38 @@ func (b *StatusBackend) SelectAccount(walletAddress, chatAddress, password strin
return err
}
}
return b.startWallet(password)
}

return nil
func (b *StatusBackend) startWallet(password string) error {
if !b.statusNode.Config().WalletConfig.Enabled {
return nil
}
wallet, err := b.statusNode.WalletService()
if err != nil {
return err
}
account, err := b.accountManager.SelectedWalletAccount()
if err != nil {
return err
}
path := path.Join(b.statusNode.Config().DataDir, fmt.Sprintf("wallet-%x.sql", account.Address))
return wallet.StartReactor(path, password,
b.statusNode.RPCClient().Ethclient(),
[]common.Address{account.Address},
new(big.Int).SetUint64(b.statusNode.Config().NetworkID))
}

// SendDataNotification sends data push notifications to users.
// dataPayloadJSON is a JSON string that looks like this:
// {
// "data": {
// "msg-v2": {
// "from": "0x2cea3bd5", // hash of sender (first 10 characters/4 bytes of sha3 hash)
// "to": "0xb1f89744", // hash of recipient (first 10 characters/4 bytes of sha3 hash)
// "id": "0x872653ad", // message ID hash (first 10 characters/4 bytes of sha3 hash)
// }
// }
// "data": {
// "msg-v2": {
// "from": "0x2cea3bd5", // hash of sender (first 10 characters/4 bytes of sha3 hash)
// "to": "0xb1f89744", // hash of recipient (first 10 characters/4 bytes of sha3 hash)
// "id": "0x872653ad", // message ID hash (first 10 characters/4 bytes of sha3 hash)
// }
// }
// }
func (b *StatusBackend) SendDataNotification(dataPayloadJSON string, tokens ...string) error {
log.Debug("sending data push notification")
Expand Down
16 changes: 16 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/status-im/status-go/services/personal"
"github.com/status-im/status-go/services/shhext"
"github.com/status-im/status-go/services/status"
"github.com/status-im/status-go/services/wallet"
"github.com/status-im/status-go/static"
"github.com/status-im/status-go/timesource"
whisper "github.com/status-im/whisper/whisperv6"
Expand All @@ -45,6 +46,7 @@ var (
ErrStatusServiceRegistrationFailure = errors.New("failed to register the Status service")
ErrPeerServiceRegistrationFailure = errors.New("failed to register the Peer service")
ErrIncentivisationServiceRegistrationFailure = errors.New("failed to register the Incentivisation service")
ErrWalletServiceRegistrationFailure = errors.New("failed to register the Wallet service")
)

// All general log messages in this package should be routed through this logger.
Expand Down Expand Up @@ -118,6 +120,10 @@ func MakeNode(config *params.NodeConfig, db *leveldb.DB) (*node.Node, error) {
return nil, fmt.Errorf("%v: %v", ErrPeerServiceRegistrationFailure, err)
}

if err := activateWalletService(stack, config.WalletConfig); err != nil {
return nil, fmt.Errorf("%v: %v", ErrWalletServiceRegistrationFailure, err)
}

return stack, nil
}

Expand Down Expand Up @@ -269,6 +275,16 @@ func activatePeerService(stack *node.Node) error {
})
}

func activateWalletService(stack *node.Node, config params.WalletConfig) error {
if !config.Enabled {
logger.Info("service.Wallet is disabled")
return nil
}
return stack.Register(func(*node.ServiceContext) (node.Service, error) {
return wallet.NewService(), nil
})
}

func registerMailServer(whisperService *whisper.Whisper, config *params.WhisperConfig) (err error) {
var mailServer mailserver.WMailServer
whisperService.RegisterServer(&mailServer)
Expand Down
12 changes: 12 additions & 0 deletions node/status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/status-im/status-go/services/peer"
"github.com/status-im/status-go/services/shhext"
"github.com/status-im/status-go/services/status"
"github.com/status-im/status-go/services/wallet"
)

// tickerResolution is the delta to check blockchain sync progress.
Expand Down Expand Up @@ -590,6 +591,17 @@ func (n *StatusNode) ShhExtService() (s *shhext.Service, err error) {
return
}

// WalletService returns wallet.Service instance if it is started.
func (n *StatusNode) WalletService() (s *wallet.Service, err error) {
n.mu.RLock()
defer n.mu.RUnlock()
err = n.gethService(&s)
if err == node.ErrServiceUnknown {
err = ErrServiceUnknown
}
return
}

// AccountManager exposes reference to node's accounts manager
func (n *StatusNode) AccountManager() (*accounts.Manager, error) {
n.mu.RLock()
Expand Down
12 changes: 10 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,12 @@ type NodeConfig struct {
// IncentivisationConfig extra configuration for incentivisation service
IncentivisationConfig IncentivisationConfig `json:"IncentivisationConfig," validate:"structonly"`

// ShhextConfig keeps configuration for service running under shhext namespace.
// ShhextConfig extra configuration for service running under shhext namespace.
ShhextConfig ShhextConfig `json:"ShhextConfig," validate:"structonly"`

// WalletConfig extra configuration for wallet.Service.
WalletConfig WalletConfig

// SwarmConfig extra configuration for Swarm and ENS
SwarmConfig SwarmConfig `json:"SwarmConfig," validate:"structonly"`

Expand All @@ -358,6 +361,11 @@ type NodeConfig struct {
MailServerRegistryAddress string
}

// WalletConfig extra configuration for wallet.Service.
type WalletConfig struct {
Enabled bool
}

// ShhextConfig defines options used by shhext service.
type ShhextConfig struct {
PFSEnabled bool
Expand Down Expand Up @@ -523,7 +531,7 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
HTTPPort: 8545,
HTTPVirtualHosts: []string{"localhost"},
ListenAddr: ":0",
APIModules: "eth,net,web3,peer",
APIModules: "eth,net,web3,peer,wallet",
MaxPeers: 25,
MaxPendingPeers: 0,
IPCFile: "geth.ipc",
Expand Down
9 changes: 9 additions & 0 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/params"
Expand Down Expand Up @@ -74,6 +75,14 @@ func NewClient(client *gethrpc.Client, upstream params.UpstreamRPCConfig) (*Clie
return &c, nil
}

// Ethclient returns ethclient.Client with upstream or local client.
func (c *Client) Ethclient() *ethclient.Client {
if c.upstreamEnabled {
return ethclient.NewClient(c.upstream)
}
return ethclient.NewClient(c.local)
}

// UpdateUpstreamURL changes the upstream RPC client URL, if the upstream is enabled.
func (c *Client) UpdateUpstreamURL(url string) error {
if c.upstream == nil {
Expand Down
Loading

0 comments on commit 047c9b5

Please sign in to comment.