Skip to content

Commit

Permalink
Merge pull request #45 from SiaFoundation/its-happening
Browse files Browse the repository at this point in the history
It has happened
  • Loading branch information
lukechampine authored Jan 16, 2024
2 parents cf7f1bf + 4572b28 commit a391465
Show file tree
Hide file tree
Showing 16 changed files with 716 additions and 1,079 deletions.
10 changes: 5 additions & 5 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ runs:
# uses: golangci/golangci-lint-action@v3
# with:
# skip-cache: true
- name: Analyze
uses: SiaFoundation/action-golang-analysis@HEAD
with:
analyzers: |
go.sia.tech/jape.Analyzer
# - name: Analyze
# uses: SiaFoundation/action-golang-analysis@HEAD
# with:
# analyzers: |
# go.sia.tech/jape.Analyzer
- name: Test
uses: n8maninger/action-golang-test@v1
with:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,8 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+-**'

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 'stable'
- name: Test
uses: ./.github/actions/test
docker:
runs-on: ubuntu-latest
needs: [ test ]
permissions:
packages: write
contents: read
Expand Down Expand Up @@ -55,7 +43,6 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
build-linux:
runs-on: ubuntu-latest
needs: [ test ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down Expand Up @@ -95,7 +82,6 @@ jobs:
path: release/
build-mac:
runs-on: macos-latest
needs: [ test ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down Expand Up @@ -180,7 +166,6 @@ jobs:
path: release/
build-windows:
runs-on: windows-latest
needs: [ test ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down
5 changes: 3 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type TxpoolTransactionsResponse struct {

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

// WalletOutputsResponse is the response type for /wallets/:name/outputs.
Expand Down
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"testing"
"time"

"go.sia.tech/core/chain"
"go.sia.tech/core/consensus"
"go.sia.tech/core/gateway"
"go.sia.tech/core/types"
"go.sia.tech/coreutils/chain"
"go.sia.tech/coreutils/syncer"
"go.sia.tech/jape"
"go.sia.tech/walletd/api"
"go.sia.tech/walletd/internal/syncerutil"
"go.sia.tech/walletd/internal/walletutil"
"go.sia.tech/walletd/syncer"
"go.sia.tech/walletd/wallet"
"lukechampine.com/frand"
)
Expand Down
31 changes: 20 additions & 11 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.sia.tech/core/consensus"
"go.sia.tech/core/gateway"
"go.sia.tech/core/types"
"go.sia.tech/walletd/syncer"
"go.sia.tech/coreutils/syncer"
"go.sia.tech/walletd/wallet"
)

Expand All @@ -27,8 +27,8 @@ type (
RecommendedFee() types.Currency
PoolTransactions() []types.Transaction
V2PoolTransactions() []types.V2Transaction
AddPoolTransactions(txns []types.Transaction) error
AddV2PoolTransactions(txns []types.V2Transaction) error
AddPoolTransactions(txns []types.Transaction) (bool, error)
AddV2PoolTransactions(index types.ChainIndex, txns []types.V2Transaction) (bool, error)
UnconfirmedParents(txn types.Transaction) []types.Transaction
}

Expand All @@ -40,7 +40,7 @@ type (
Connect(addr string) (*gateway.Peer, error)
BroadcastHeader(bh gateway.BlockHeader)
BroadcastTransactionSet(txns []types.Transaction)
BroadcastV2TransactionSet(txns []types.V2Transaction)
BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction)
BroadcastV2BlockOutline(bo gateway.V2BlockOutline)
}

Expand Down Expand Up @@ -148,16 +148,19 @@ func (s *server) txpoolBroadcastHandler(jc jape.Context) {
return
}
if len(tbr.Transactions) != 0 {
if jc.Check("invalid transaction set", s.cm.AddPoolTransactions(tbr.Transactions)) != nil {
_, err := s.cm.AddPoolTransactions(tbr.Transactions)
if jc.Check("invalid transaction set", err) != nil {
return
}
s.s.BroadcastTransactionSet(tbr.Transactions)
}
if len(tbr.V2Transactions) != 0 {
if jc.Check("invalid v2 transaction set", s.cm.AddV2PoolTransactions(tbr.V2Transactions)) != nil {
index := s.cm.TipState().Index
_, err := s.cm.AddV2PoolTransactions(index, tbr.V2Transactions)
if jc.Check("invalid v2 transaction set", err) != nil {
return
}
s.s.BroadcastV2TransactionSet(tbr.V2Transactions)
s.s.BroadcastV2TransactionSet(index, tbr.V2Transactions)
}
}

Expand Down Expand Up @@ -236,17 +239,23 @@ func (s *server) walletsBalanceHandler(jc jape.Context) {
if jc.Check("couldn't load outputs", err) != nil {
return
}
var sc types.Currency
height := s.cm.TipState().Index.Height
var sc, immature types.Currency
var sf uint64
for _, sco := range scos {
sc = sc.Add(sco.SiacoinOutput.Value)
if height >= sco.MaturityHeight {
sc = sc.Add(sco.SiacoinOutput.Value)
} else {
immature = immature.Add(sco.SiacoinOutput.Value)
}
}
for _, sfo := range sfos {
sf += sfo.SiafundOutput.Value
}
jc.Encode(WalletBalanceResponse{
Siacoins: sc,
Siafunds: sf,
Siacoins: sc,
ImmatureSiacoins: immature,
Siafunds: sf,
})
}

Expand Down
Loading

0 comments on commit a391465

Please sign in to comment.