Skip to content

Commit

Permalink
types: remove unnecessary casts
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Nov 6, 2024
1 parent 6103436 commit dcba785
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions explorer/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {
v2fces := make(map[types.FileContractID]types.V2FileContractElement)
cu.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) {
sce.StateElement.MerkleProof = nil
sces[types.SiacoinOutputID(sce.ID)] = sce
sces[sce.ID] = sce
})
cu.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) {
sfe.StateElement.MerkleProof = nil
sfes[types.SiafundOutputID(sfe.ID)] = sfe
sfes[sfe.ID] = sfe
})
cu.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fce.StateElement.MerkleProof = nil
fces[types.FileContractID(fce.ID)] = fce
fces[fce.ID] = fce
})
cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
fce.StateElement.MerkleProof = nil
v2fces[types.FileContractID(fce.ID)] = fce
v2fces[fce.ID] = fce
})

relevantTxn := func(txn types.Transaction) (addrs []types.Address) {
Expand Down Expand Up @@ -221,7 +221,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {
for _, a := range txn.Attestations {
var ha chain.V2HostAnnouncement
if ha.FromAttestation(a) == nil {
panic("implement me")
// TODO: handle attestation
}
}
addEvent(types.Hash256(txn.ID()), cs.Index.Height, &e, relevant) // transaction maturity height is the current block height
Expand All @@ -235,7 +235,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {

if valid {
for i := range fce.FileContract.ValidProofOutputs {
outputID := types.FileContractID(fce.ID).ValidOutputID(i)
outputID := fce.ID.ValidOutputID(i)
addEvent(types.Hash256(outputID), cs.MaturityHeight(), &EventContractPayout{
FileContract: fce,
SiacoinOutput: sces[outputID],
Expand All @@ -244,7 +244,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {
}
} else {
for i := range fce.FileContract.MissedProofOutputs {
outputID := types.FileContractID(fce.ID).MissedOutputID(i)
outputID := fce.ID.MissedOutputID(i)
addEvent(types.Hash256(outputID), cs.MaturityHeight(), &EventContractPayout{
FileContract: fce,
SiacoinOutput: sces[outputID],
Expand Down
10 changes: 5 additions & 5 deletions explorer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {
if created && spent {
ephemeralSiacoinElements = append(ephemeralSiacoinElements, SiacoinOutput{
SiacoinElement: se,
Source: sources[types.SiacoinOutputID(se.ID)],
Source: sources[se.ID],
})
return
}

if spent {
spentSiacoinElements = append(spentSiacoinElements, SiacoinOutput{
SiacoinElement: se,
Source: sources[types.SiacoinOutputID(se.ID)],
Source: sources[se.ID],
})
} else {
newSiacoinElements = append(newSiacoinElements, SiacoinOutput{
SiacoinElement: se,
Source: sources[types.SiacoinOutputID(se.ID)],
Source: sources[se.ID],
})
}
})
Expand All @@ -126,7 +126,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {

fceMap := make(map[types.FileContractID]FileContractUpdate)
cau.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fceMap[types.FileContractID(fce.ID)] = FileContractUpdate{
fceMap[fce.ID] = FileContractUpdate{
FileContractElement: fce,
Revision: rev,
Resolved: resolved,
Expand Down Expand Up @@ -244,7 +244,7 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types.

fceMap := make(map[types.FileContractID]FileContractUpdate)
cru.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fceMap[types.FileContractID(fce.ID)] = FileContractUpdate{
fceMap[fce.ID] = FileContractUpdate{
FileContractElement: fce,
Revision: rev,
Resolved: resolved,
Expand Down
10 changes: 5 additions & 5 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme
return nil, fmt.Errorf("addSiacoinElements: failed to get last insert ID: %w", err)
}

scDBIds[types.SiacoinOutputID(sce.ID)] = dbID
scDBIds[sce.ID] = dbID
}
}
if len(spentElements) > 0 {
Expand Down Expand Up @@ -571,7 +571,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme
return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err)
}

sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID
sfDBIds[sfe.ID] = dbID
}
}
if len(spentElements) > 0 {
Expand All @@ -595,7 +595,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme
return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err)
}

sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID
sfDBIds[sfe.ID] = dbID
}
}
return sfDBIds, nil
Expand Down Expand Up @@ -732,7 +732,7 @@ func addEvents(tx *txn, scDBIds map[types.SiacoinOutputID]int64, fcDBIds map[exp
case *explorer.EventMinerPayout:
_, err = minerPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)])
case *explorer.EventContractPayout:
_, err = contractPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(v.SiacoinOutput.ID)], fcDBIds[explorer.DBFileContract{ID: types.FileContractID(v.FileContract.ID), RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed)
_, err = contractPayoutEventStmt.Exec(eventID, scDBIds[v.SiacoinOutput.ID], fcDBIds[explorer.DBFileContract{ID: v.FileContract.ID, RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed)
case *explorer.EventFoundationSubsidy:
_, err = foundationSubsidyEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)])
default:
Expand Down Expand Up @@ -917,7 +917,7 @@ func updateFileContractElements(tx *txn, revert bool, b types.Block, fces []expl
}

if err := addFC(
types.FileContractID(fce.ID),
fce.ID,
fce.StateElement.LeafIndex,
fce.FileContract,
update.Resolved,
Expand Down
14 changes: 7 additions & 7 deletions persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestBalance(t *testing.T) {
parentTxn := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: types.SiacoinOutputID(utxos[0].ID),
ParentID: utxos[0].ID,
UnlockConditions: unlockConditions,
},
},
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestSiafundBalance(t *testing.T) {
parentTxn := types.Transaction{
SiafundInputs: []types.SiafundInput{
{
ParentID: types.SiafundOutputID(genesisBlock.Transactions[0].SiafundOutputID(0)),
ParentID: genesisBlock.Transactions[0].SiafundOutputID(0),
UnlockConditions: unlockConditions,
},
},
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestSendTransactions(t *testing.T) {
parentTxn := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: types.SiacoinOutputID(scOutputID),
ParentID: scOutputID,
UnlockConditions: unlockConditions,
},
},
Expand All @@ -379,7 +379,7 @@ func TestSendTransactions(t *testing.T) {
}

testutil.SignTransaction(cm.TipState(), pk1, &parentTxn)
scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2))
scOutputID = parentTxn.SiacoinOutputID(2)
sfOutputID = parentTxn.SiafundOutputID(2)

// Mine a block with the above transaction
Expand Down Expand Up @@ -1220,7 +1220,7 @@ func TestRevertBalance(t *testing.T) {
parentTxn := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: types.SiacoinOutputID(utxos2[0].ID),
ParentID: utxos2[0].ID,
UnlockConditions: unlockConditions,
},
},
Expand Down Expand Up @@ -1415,7 +1415,7 @@ func TestRevertSendTransactions(t *testing.T) {
parentTxn := types.Transaction{
SiacoinInputs: []types.SiacoinInput{
{
ParentID: types.SiacoinOutputID(scOutputID),
ParentID: scOutputID,
UnlockConditions: unlockConditions,
},
},
Expand All @@ -1438,7 +1438,7 @@ func TestRevertSendTransactions(t *testing.T) {
}

testutil.SignTransaction(cm.TipState(), pk1, &parentTxn)
scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2))
scOutputID = parentTxn.SiacoinOutputID(2)
sfOutputID = parentTxn.SiafundOutputID(2)

// Mine a block with the above transaction
Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ CREATE TABLE events (
CREATE INDEX events_block_id_height_index ON events(block_id, height);

CREATE TABLE event_addresses (
event_id INTEGER NOT NULL REFERENCES events(id) ON DELETE CASCADE,
event_id INTEGER NOT NULL REFERENCES events(id) ON DELETE CASCADE,
address_id INTEGER NOT NULL REFERENCES address_balance(id),
PRIMARY KEY (event_id, address_id)
);
Expand Down

0 comments on commit dcba785

Please sign in to comment.