Skip to content

Commit

Permalink
use UnlockKey instead of byte slice for ContractsKey
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Jun 4, 2024
1 parent 47af014 commit 36b6236
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Store interface {
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 []FileContract, err error)
ContractsKey(key []byte) (result []FileContract, err error)
ContractsKey(key types.UnlockKey) (result []FileContract, err error)
}

// Explorer implements a Sia explorer.
Expand Down Expand Up @@ -171,6 +171,6 @@ func (e *Explorer) Contracts(ids []types.FileContractID) (result []FileContract,
}

// ContractsKey returns the contracts for a particular ed25519 key.
func (e *Explorer) ContractsKey(key []byte) (result []FileContract, err error) {
func (e *Explorer) ContractsKey(key types.UnlockKey) (result []FileContract, err error) {
return e.s.ContractsKey(key)
}
16 changes: 8 additions & 8 deletions persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,11 @@ func TestFileContract(t *testing.T) {
syncDB(t, db, cm)

{
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey().Key)
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey().Key)
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -946,11 +946,11 @@ func TestFileContract(t *testing.T) {
}

{
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey().Key)
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey().Key)
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1100,11 +1100,11 @@ func TestEphemeralFileContract(t *testing.T) {
syncDB(t, db, cm)

{
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey().Key)
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey().Key)
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1188,11 +1188,11 @@ func TestEphemeralFileContract(t *testing.T) {
}

{
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey().Key)
renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey().Key)
hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey())
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions persist/sqlite/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func (s *Store) Contracts(ids []types.FileContractID) (result []explorer.FileCon
}

// ContractsKey implements explorer.Store.
func (s *Store) ContractsKey(key []byte) (result []explorer.FileContract, err error) {
func (s *Store) ContractsKey(key types.UnlockKey) (result []explorer.FileContract, err error) {
err = s.transaction(func(tx *txn) error {
query := `SELECT fc1.id, fc1.contract_id, fc1.leaf_index, fc1.resolved, fc1.valid, 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
INNER JOIN last_contract_revision rev ON (rev.contract_element_id = fc1.id)
WHERE rev.ed25519_renter_key = ? OR rev.ed25519_host_key = ?`
rows, err := tx.Query(query, key, key)
rows, err := tx.Query(query, key.Key, key.Key)
if err != nil {
return err
}
Expand Down

0 comments on commit 36b6236

Please sign in to comment.