Skip to content

Commit

Permalink
update FileContract docstring and rename EnhancedFileContract to Exte…
Browse files Browse the repository at this point in the history
…ndedFileContract
  • Loading branch information
chris124567 committed Nov 7, 2024
1 parent f98d4fa commit 718ad2b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,26 @@ func (c *Client) AddressBalance(address types.Address) (resp AddressBalanceRespo
}

// Contract returns the file contract with the specified ID.
func (c *Client) Contract(id types.FileContractID) (resp explorer.EnhancedFileContract, err error) {
func (c *Client) Contract(id types.FileContractID) (resp explorer.ExtendedFileContract, err error) {
err = c.c.GET(fmt.Sprintf("/contracts/%s", id), &resp)
return
}

// Contracts returns the transactions with the specified IDs.
func (c *Client) Contracts(ids []types.FileContractID) (resp []explorer.EnhancedFileContract, err error) {
func (c *Client) Contracts(ids []types.FileContractID) (resp []explorer.ExtendedFileContract, err error) {
err = c.c.POST("/contracts", ids, &resp)
return
}

// ContractsKey returns the contracts for a particular ed25519 key.
func (c *Client) ContractsKey(key types.PublicKey) (resp []explorer.EnhancedFileContract, err error) {
func (c *Client) ContractsKey(key types.PublicKey) (resp []explorer.ExtendedFileContract, err error) {
err = c.c.GET(fmt.Sprintf("/pubkey/%s/contracts", key), &resp)
return
}

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

Hosts(pks []types.PublicKey) ([]explorer.Host, error)
Expand Down
12 changes: 6 additions & 6 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ type Store interface {
UnspentSiafundOutputs(address types.Address, offset, limit uint64) ([]SiafundOutput, error)
AddressEvents(address types.Address, offset, limit uint64) (events []Event, err error)
Balance(address types.Address) (sc types.Currency, immatureSC types.Currency, sf uint64, err error)
Contracts(ids []types.FileContractID) (result []EnhancedFileContract, err error)
ContractsKey(key types.PublicKey) (result []EnhancedFileContract, err error)
ContractRevisions(id types.FileContractID) (result []EnhancedFileContract, err error)
Contracts(ids []types.FileContractID) (result []ExtendedFileContract, err error)
ContractsKey(key types.PublicKey) (result []ExtendedFileContract, err error)
ContractRevisions(id types.FileContractID) (result []ExtendedFileContract, err error)
SiacoinElements(ids []types.SiacoinOutputID) (result []SiacoinOutput, err error)
SiafundElements(ids []types.SiafundOutputID) (result []SiafundOutput, err error)

Expand Down Expand Up @@ -247,18 +247,18 @@ func (e *Explorer) Balance(address types.Address) (sc types.Currency, immatureSC
}

// Contracts returns the contracts with the specified IDs.
func (e *Explorer) Contracts(ids []types.FileContractID) (result []EnhancedFileContract, err error) {
func (e *Explorer) Contracts(ids []types.FileContractID) (result []ExtendedFileContract, err error) {
return e.s.Contracts(ids)
}

// ContractsKey returns the contracts for a particular ed25519 key.
func (e *Explorer) ContractsKey(key types.PublicKey) (result []EnhancedFileContract, err error) {
func (e *Explorer) ContractsKey(key types.PublicKey) (result []ExtendedFileContract, err error) {
return e.s.ContractsKey(key)
}

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

Expand Down
12 changes: 6 additions & 6 deletions explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ type ContractSiacoinOutput struct {
}

// A FileContract is a storage agreement between a renter and a host. It
// contains a bidirectional payment channel that resolves as either "valid" or
// "missed" depending on whether a valid StorageProof is submitted for the
// serves as a bidirectional payment channel that resolves as either "valid"
// or "missed" depending on whether a valid StorageProof is submitted for the
// contract.
type FileContract struct {
ID types.FileContractID `json:"id"`
Expand All @@ -146,9 +146,9 @@ type FileContract struct {
RevisionNumber uint64 `json:"revisionNumber"`
}

// A EnhancedFileContract is a FileContractElement with added fields for
// A ExtendedFileContract is a FileContract with added fields for
// resolved/valid state, and when the transaction was confirmed and proved.
type EnhancedFileContract struct {
type ExtendedFileContract struct {
Resolved bool `json:"resolved"`
Valid bool `json:"valid"`

Expand All @@ -169,7 +169,7 @@ type FileContractRevision struct {
ParentID types.FileContractID `json:"parentID"`
UnlockConditions types.UnlockConditions `json:"unlockConditions"`

EnhancedFileContract
ExtendedFileContract
}

// A Transaction is a transaction that uses the wrapped types above.
Expand All @@ -179,7 +179,7 @@ type Transaction struct {
SiacoinOutputs []SiacoinOutput `json:"siacoinOutputs,omitempty"`
SiafundInputs []SiafundInput `json:"siafundInputs,omitempty"`
SiafundOutputs []SiafundOutput `json:"siafundOutputs,omitempty"`
FileContracts []EnhancedFileContract `json:"fileContracts,omitempty"`
FileContracts []ExtendedFileContract `json:"fileContracts,omitempty"`
FileContractRevisions []FileContractRevision `json:"fileContractRevisions,omitempty"`
StorageProofs []types.StorageProof `json:"storageProofs,omitempty"`
MinerFees []types.Currency `json:"minerFees,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func CheckV2ChainIndices(t *testing.T, db explorer.Store, txnID types.Transactio

// CheckFC checks the retrieved file contract with the source file contract in
// addition to checking the resolved and valid fields.
func CheckFC(t *testing.T, revision, resolved, valid bool, expected types.FileContract, got explorer.EnhancedFileContract) {
func CheckFC(t *testing.T, revision, resolved, valid bool, expected types.FileContract, got explorer.ExtendedFileContract) {
t.Helper()

Equal(t, "resolved state", resolved, got.Resolved)
Expand Down
12 changes: 6 additions & 6 deletions persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func CheckChainIndices(t *testing.T, db explorer.Store, txnID types.TransactionI
}

// CheckFCRevisions checks that the revision numbers for the file contracts match.
func CheckFCRevisions(t *testing.T, confirmationIndex types.ChainIndex, confirmationTransactionID types.TransactionID, valid, missed []types.SiacoinOutput, revisionNumbers []uint64, fcs []explorer.EnhancedFileContract) {
func CheckFCRevisions(t *testing.T, confirmationIndex types.ChainIndex, confirmationTransactionID types.TransactionID, valid, missed []types.SiacoinOutput, revisionNumbers []uint64, fcs []explorer.ExtendedFileContract) {
t.Helper()

testutil.Equal(t, "number of revisions", len(revisionNumbers), len(fcs))
Expand Down Expand Up @@ -715,7 +715,7 @@ func TestFileContract(t *testing.T) {
testutil.Equal(t, "confirmation index", prevTip, *fcr.ConfirmationIndex)
testutil.Equal(t, "confirmation transaction ID", txn.ID(), *fcr.ConfirmationTransactionID)

testutil.CheckFC(t, false, false, false, fc, fcr.EnhancedFileContract)
testutil.CheckFC(t, false, false, false, fc, fcr.ExtendedFileContract)
}

for i := cm.Tip().Height; i < windowEnd; i++ {
Expand Down Expand Up @@ -938,7 +938,7 @@ func TestEphemeralFileContract(t *testing.T) {
testutil.Equal(t, "parent id", txn.FileContractID(0), fcr.ParentID)
testutil.Equal(t, "unlock conditions", uc, fcr.UnlockConditions)

testutil.CheckFC(t, true, false, false, revisedFC1, fcr.EnhancedFileContract)
testutil.CheckFC(t, true, false, false, revisedFC1, fcr.ExtendedFileContract)
}

revisedFC2 := revisedFC1
Expand Down Expand Up @@ -1020,7 +1020,7 @@ func TestEphemeralFileContract(t *testing.T) {
fcr := txns[0].FileContractRevisions[0]
testutil.Equal(t, "parent id", txn.FileContractID(0), fcr.ParentID)
testutil.Equal(t, "unlock conditions", uc, fcr.UnlockConditions)
testutil.CheckFC(t, true, false, false, revisedFC2, fcr.EnhancedFileContract)
testutil.CheckFC(t, true, false, false, revisedFC2, fcr.ExtendedFileContract)
}

{
Expand All @@ -1034,7 +1034,7 @@ func TestEphemeralFileContract(t *testing.T) {
fcr := txns[0].FileContractRevisions[0]
testutil.Equal(t, "parent id", txn.FileContractID(0), fcr.ParentID)
testutil.Equal(t, "unlock conditions", uc, fcr.UnlockConditions)
testutil.CheckFC(t, true, false, false, revisedFC3, fcr.EnhancedFileContract)
testutil.CheckFC(t, true, false, false, revisedFC3, fcr.ExtendedFileContract)
}
}

Expand Down Expand Up @@ -2348,7 +2348,7 @@ func TestMultipleReorgFileContract(t *testing.T) {
testutil.Equal(t, "parent id", txn.FileContractID(0), fcr.ParentID)
testutil.Equal(t, "unlock conditions", uc, fcr.UnlockConditions)

testutil.CheckFC(t, false, false, false, revFC, fcr.EnhancedFileContract)
testutil.CheckFC(t, false, false, false, revFC, fcr.ExtendedFileContract)
}

{
Expand Down
18 changes: 9 additions & 9 deletions persist/sqlite/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func encodedIDs(ids []types.FileContractID) []any {
return result
}

func scanFileContract(s scanner) (contractID int64, fc explorer.EnhancedFileContract, err error) {
func scanFileContract(s scanner) (contractID int64, fc explorer.ExtendedFileContract, err error) {
var confirmationIndex, proofIndex types.ChainIndex
var confirmationTransactionID, proofTransactionID types.TransactionID
err = s.Scan(&contractID, decode(&fc.ID), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.FileContract.Filesize), decode(&fc.FileContract.FileMerkleRoot), decode(&fc.FileContract.WindowStart), decode(&fc.FileContract.WindowEnd), decode(&fc.FileContract.Payout), decode(&fc.FileContract.UnlockHash), decode(&fc.FileContract.RevisionNumber))
Expand All @@ -37,7 +37,7 @@ func scanFileContract(s scanner) (contractID int64, fc explorer.EnhancedFileCont
}

// Contracts implements explorer.Store.
func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.EnhancedFileContract, err error) {
func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.ExtendedFileContract, err error) {
err = s.transaction(func(tx *txn) error {
query := `SELECT fc1.id, fc1.contract_id, fc1.resolved, fc1.valid, fc1.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc1.filesize, fc1.file_merkle_root, fc1.window_start, fc1.window_end, fc1.payout, fc1.unlock_hash, fc1.revision_number
FROM file_contract_elements fc1
Expand All @@ -50,10 +50,10 @@ func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.Enhance
defer rows.Close()

var contractIDs []int64
idContract := make(map[int64]explorer.EnhancedFileContract)
idContract := make(map[int64]explorer.ExtendedFileContract)
for rows.Next() {
var contractID int64
var fc explorer.EnhancedFileContract
var fc explorer.ExtendedFileContract

contractID, fc, err := scanFileContract(rows)
if err != nil {
Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.Enhance
}

// ContractRevisions implements explorer.Store.
func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer.EnhancedFileContract, err error) {
func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer.ExtendedFileContract, err error) {
err = s.transaction(func(tx *txn) error {
query := `SELECT fc.id, fc.contract_id, fc.resolved, fc.valid, fc.transaction_id, 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 @@ -98,7 +98,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer
// fetch revisions
type fce struct {
ID int64
FileContract explorer.EnhancedFileContract
FileContract explorer.ExtendedFileContract
}
var fces []fce
var contractIDs []int64
Expand All @@ -119,7 +119,7 @@ func (s *Store) ContractRevisions(id types.FileContractID) (revisions []explorer
}

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

// ContractsKey implements explorer.Store.
func (s *Store) ContractsKey(key types.PublicKey) (result []explorer.EnhancedFileContract, err error) {
func (s *Store) ContractsKey(key types.PublicKey) (result []explorer.ExtendedFileContract, err error) {
err = s.transaction(func(tx *txn) error {
query := `SELECT fc1.id, fc1.contract_id, fc1.resolved, fc1.valid, fc1.transaction_id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc1.filesize, fc1.file_merkle_root, fc1.window_start, fc1.window_end, fc1.payout, fc1.unlock_hash, fc1.revision_number
FROM file_contract_elements fc1
Expand All @@ -153,7 +153,7 @@ func (s *Store) ContractsKey(key types.PublicKey) (result []explorer.EnhancedFil
defer rows.Close()

var contractIDs []int64
idContract := make(map[int64]explorer.EnhancedFileContract)
idContract := make(map[int64]explorer.ExtendedFileContract)
for rows.Next() {
contractID, fc, err := scanFileContract(rows)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions persist/sqlite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ type contractOrder struct {
}

// transactionFileContracts returns the file contracts for each transaction.
func transactionFileContracts(tx *txn, txnIDs []int64) (map[int64][]explorer.EnhancedFileContract, error) {
func transactionFileContracts(tx *txn, txnIDs []int64) (map[int64][]explorer.ExtendedFileContract, error) {
query := `SELECT ts.transaction_id, fc.id, rev.confirmation_index, rev.confirmation_transaction_id, rev.proof_index, rev.proof_transaction_id, fc.contract_id, fc.resolved, fc.valid, fc.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
INNER JOIN transaction_file_contracts ts ON (ts.contract_id = fc.id)
Expand All @@ -296,12 +296,12 @@ ORDER BY ts.transaction_order ASC`

var contractIDs []int64
// map transaction ID to contract list
result := make(map[int64][]explorer.EnhancedFileContract)
result := make(map[int64][]explorer.ExtendedFileContract)
// map contract ID to transaction ID
contractTransaction := make(map[int64]contractOrder)
for rows.Next() {
var txnID, contractID int64
var fc explorer.EnhancedFileContract
var fc explorer.ExtendedFileContract

var confirmationIndex, proofIndex types.ChainIndex
var confirmationTransactionID, proofTransactionID types.TransactionID
Expand Down Expand Up @@ -366,7 +366,7 @@ ORDER BY ts.transaction_order ASC`

var confirmationIndex, proofIndex types.ChainIndex
var confirmationTransactionID, proofTransactionID types.TransactionID
if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.ParentID), decode(&fc.UnlockConditions), decode(&fc.ID), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.EnhancedFileContract.FileContract.Filesize), decode(&fc.EnhancedFileContract.FileContract.FileMerkleRoot), decode(&fc.EnhancedFileContract.FileContract.WindowStart), decode(&fc.EnhancedFileContract.FileContract.WindowEnd), decode(&fc.EnhancedFileContract.FileContract.Payout), decode(&fc.EnhancedFileContract.FileContract.UnlockHash), decode(&fc.EnhancedFileContract.FileContract.RevisionNumber)); err != nil {
if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.ParentID), decode(&fc.UnlockConditions), decode(&fc.ID), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.ExtendedFileContract.FileContract.Filesize), decode(&fc.ExtendedFileContract.FileContract.FileMerkleRoot), decode(&fc.ExtendedFileContract.FileContract.WindowStart), decode(&fc.ExtendedFileContract.FileContract.WindowEnd), decode(&fc.ExtendedFileContract.FileContract.Payout), decode(&fc.ExtendedFileContract.FileContract.UnlockHash), decode(&fc.ExtendedFileContract.FileContract.RevisionNumber)); err != nil {
return nil, fmt.Errorf("failed to scan file contract: %w", err)
}

Expand Down Expand Up @@ -395,8 +395,8 @@ ORDER BY ts.transaction_order ASC`
}
for contractID, output := range proofOutputs {
index := contractTransaction[contractID]
result[index.txnID][index.transactionOrder].EnhancedFileContract.FileContract.ValidProofOutputs = output.valid
result[index.txnID][index.transactionOrder].EnhancedFileContract.FileContract.MissedProofOutputs = output.missed
result[index.txnID][index.transactionOrder].ExtendedFileContract.FileContract.ValidProofOutputs = output.valid
result[index.txnID][index.transactionOrder].ExtendedFileContract.FileContract.MissedProofOutputs = output.missed
}

return result, nil
Expand Down

0 comments on commit 718ad2b

Please sign in to comment.