Skip to content

Commit

Permalink
Merge pull request #49 from SiaFoundation/nate/refactor-wallet-store
Browse files Browse the repository at this point in the history
Refactor wallet store
  • Loading branch information
lukechampine authored Feb 16, 2024
2 parents aa48178 + c39cf30 commit acf6fae
Show file tree
Hide file tree
Showing 14 changed files with 1,364 additions and 501 deletions.
9 changes: 3 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"go.sia.tech/core/types"
"go.sia.tech/walletd/wallet"
)

// A GatewayPeer is a currently-connected peer.
Expand All @@ -30,12 +31,8 @@ type TxpoolTransactionsResponse struct {
V2Transactions []types.V2Transaction `json:"v2transactions"`
}

// WalletBalanceResponse is the response type for /wallets/:name/balance.
type WalletBalanceResponse struct {
Siacoins types.Currency `json:"siacoins"`
ImmatureSiacoins types.Currency `json:"immatureSiacoins"`
Siafunds uint64 `json:"siafunds"`
}
// BalanceResponse is the response type for /wallets/:name/balance.
type BalanceResponse wallet.Balance

// WalletOutputsResponse is the response type for /wallets/:name/outputs.
type WalletOutputsResponse struct {
Expand Down
1 change: 1 addition & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestWallet(t *testing.T) {
t.Fatal(err)
}
defer ws.Close()

wm, err := wallet.NewManager(cm, ws, log.Named("wallet"))
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (c *WalletClient) Addresses() (resp map[types.Address]json.RawMessage, err
}

// Balance returns the current wallet balance.
func (c *WalletClient) Balance() (resp WalletBalanceResponse, err error) {
func (c *WalletClient) Balance() (resp BalanceResponse, err error) {
err = c.c.GET(fmt.Sprintf("/wallets/%v/balance", c.name), &resp)
return
}
Expand Down
12 changes: 4 additions & 8 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ type (
Events(name string, offset, limit int) ([]wallet.Event, error)
UnspentSiacoinOutputs(name string) ([]types.SiacoinElement, error)
UnspentSiafundOutputs(name string) ([]types.SiafundElement, error)
WalletBalance(walletID string) (sc, immatureSC types.Currency, sf uint64, err error)
WalletBalance(walletID string) (wallet.Balance, error)
Annotate(name string, pool []types.Transaction) ([]wallet.PoolTransaction, error)

Reserve(ids []types.Hash256, duration time.Duration) error
AddressBalance(address types.Address) (sc types.Currency, sf uint64, err error)
AddressBalance(address types.Address) (wallet.Balance, error)
}
)

Expand Down Expand Up @@ -245,15 +245,11 @@ func (s *server) walletsBalanceHandler(jc jape.Context) {
return
}

sc, isc, sf, err := s.wm.WalletBalance(name)
b, err := s.wm.WalletBalance(name)
if jc.Check("couldn't load balance", err) != nil {
return
}
jc.Encode(WalletBalanceResponse{
Siacoins: sc,
ImmatureSiacoins: isc,
Siafunds: sf,
})
jc.Encode(BalanceResponse(b))
}

func (s *server) walletsEventsHandler(jc jape.Context) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/walletd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func printTestnetEvents(c *api.Client, seed wallet.Seed) {
check("Couldn't get events:", err)
for i := range events {
e := events[len(events)-1-i]
switch t := e.Val.(type) {
switch t := e.Data.(type) {
case *wallet.EventTransaction:
if len(t.SiacoinInputs) == 0 || len(t.SiacoinOutputs) == 0 {
continue
Expand Down
Loading

0 comments on commit acf6fae

Please sign in to comment.