Skip to content

Commit

Permalink
Merge pull request #108 from SiaFoundation/change-revision-type
Browse files Browse the repository at this point in the history
Change ContractRevisions return type for consistency
  • Loading branch information
n8maninger authored Oct 3, 2024
2 parents 4dece7a + 3d52959 commit 1ff58d9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Client) ContractsKey(key types.PublicKey) (resp []explorer.FileContract

// ContractRevisions returns all the revisions of the contract with the
// specified ID.
func (c *Client) ContractRevisions(id types.FileContractID) (resp []types.FileContractElement, err error) {
func (c *Client) ContractRevisions(id types.FileContractID) (resp []explorer.FileContract, err error) {
err = c.c.GET(fmt.Sprintf("/contracts/%s/revisions", id), &resp)
return
}
Expand Down
2 changes: 1 addition & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type (
AddressEvents(address types.Address, offset, limit uint64) (events []explorer.Event, err error)
Contracts(ids []types.FileContractID) (result []explorer.FileContract, err error)
ContractsKey(key types.PublicKey) (result []explorer.FileContract, err error)
ContractRevisions(id types.FileContractID) (result []types.FileContractElement, err error)
ContractRevisions(id types.FileContractID) (result []explorer.FileContract, err error)
Search(id types.Hash256) (explorer.SearchType, error)

Hosts(pks []types.PublicKey) ([]explorer.Host, error)
Expand Down
4 changes: 2 additions & 2 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Store interface {
Balance(address types.Address) (sc types.Currency, immatureSC types.Currency, sf uint64, err error)
Contracts(ids []types.FileContractID) (result []FileContract, err error)
ContractsKey(key types.PublicKey) (result []FileContract, err error)
ContractRevisions(id types.FileContractID) (result []types.FileContractElement, err error)
ContractRevisions(id types.FileContractID) (result []FileContract, err error)
SiacoinElements(ids []types.SiacoinOutputID) (result []SiacoinOutput, err error)
SiafundElements(ids []types.SiafundOutputID) (result []SiafundOutput, err error)

Expand Down Expand Up @@ -243,7 +243,7 @@ func (e *Explorer) ContractsKey(key types.PublicKey) (result []FileContract, err

// ContractRevisions returns all the revisions of the contract with the
// specified ID.
func (e *Explorer) ContractRevisions(id types.FileContractID) (result []types.FileContractElement, err error) {
func (e *Explorer) ContractRevisions(id types.FileContractID) (result []FileContract, err error) {
return e.s.ContractRevisions(id)
}

Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func checkMetrics(t *testing.T, db explorer.Store, cm *chain.Manager, expected e
// don't check circulating supply here because it requires a lot of accounting
}

func checkFCRevisions(t *testing.T, revisionNumbers []uint64, fcs []types.FileContractElement) {
func checkFCRevisions(t *testing.T, revisionNumbers []uint64, fcs []explorer.FileContract) {
t.Helper()

check(t, "number of revisions", len(revisionNumbers), len(fcs))
Expand Down
12 changes: 6 additions & 6 deletions persist/sqlite/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.FileCon
}

// ContractRevisions implements explorer.Store.
func (s *Store) ContractRevisions(id types.FileContractID) (revisions []types.FileContractElement, err error) {
func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer.FileContract, err error) {
err = s.transaction(func(tx *txn) error {
query := `SELECT fc.id, fc.contract_id, fc.leaf_index, fc.resolved, fc.valid, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc.filesize, fc.file_merkle_root, fc.window_start, fc.window_end, fc.payout, fc.unlock_hash, fc.revision_number
FROM file_contract_elements fc
Expand All @@ -97,8 +97,8 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []types.Fi

// fetch revisions
type fce struct {
ID int64
types.FileContractElement
ID int64
FileContract explorer.FileContract
}
var fces []fce
var contractIDs []int64
Expand All @@ -108,7 +108,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []types.Fi
return fmt.Errorf("failed to scan file contract: %w", err)
}

fces = append(fces, fce{ID: contractID, FileContractElement: fc.FileContractElement})
fces = append(fces, fce{ID: contractID, FileContract: fc})
contractIDs = append(contractIDs, contractID)
}

Expand All @@ -119,7 +119,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []types.Fi
}

// merge outputs into revisions
revisions = make([]types.FileContractElement, len(fces))
revisions = make([]explorer.FileContract, len(fces))
for i, revision := range fces {
output, found := proofOutputs[revision.ID]
if !found {
Expand All @@ -131,7 +131,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []types.Fi
}

for i, fce := range fces {
revisions[i] = fce.FileContractElement
revisions[i] = fce.FileContract
}

if len(revisions) == 0 {
Expand Down

0 comments on commit 1ff58d9

Please sign in to comment.