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

Refactor wallet store #49

Merged
merged 11 commits into from
Feb 16, 2024
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
Loading