From 36b6236936fdb332fd710d9a4374a741914f5373 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Tue, 4 Jun 2024 10:45:01 -0400 Subject: [PATCH] use UnlockKey instead of byte slice for ContractsKey --- explorer/explorer.go | 4 ++-- persist/sqlite/consensus_test.go | 16 ++++++++-------- persist/sqlite/contracts.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/explorer/explorer.go b/explorer/explorer.go index 9e239348..8f3dc276 100644 --- a/explorer/explorer.go +++ b/explorer/explorer.go @@ -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. @@ -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) } diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index 182c866a..6a69af23 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/persist/sqlite/contracts.go b/persist/sqlite/contracts.go index 21817cec..b477bed1 100644 --- a/persist/sqlite/contracts.go +++ b/persist/sqlite/contracts.go @@ -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 }