diff --git a/api/server.go b/api/server.go index 62ddc485..632666c8 100644 --- a/api/server.go +++ b/api/server.go @@ -51,7 +51,7 @@ type ( 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.FileContract, err error) - ContractsKey(key types.UnlockKey) (result []explorer.FileContract, err error) + ContractsKey(key types.PublicKey) (result []explorer.FileContract, err error) } ) @@ -309,7 +309,7 @@ func (s *server) explorerContractIDHandler(jc jape.Context) { func (s *server) explorerContractKeyHandler(jc jape.Context) { errNotFound := errors.New("no contract found") - var key types.UnlockKey + var key types.PublicKey if jc.DecodeParam("key", &key) != nil { return } diff --git a/explorer/explorer.go b/explorer/explorer.go index 8f3dc276..1dfb4e7e 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 types.UnlockKey) (result []FileContract, err error) + ContractsKey(key types.PublicKey) (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 types.UnlockKey) (result []FileContract, err error) { +func (e *Explorer) ContractsKey(key types.PublicKey) (result []FileContract, err error) { return e.s.ContractsKey(key) } diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index aa432117..e4aaba16 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -750,7 +750,7 @@ func addFileContractElements(tx *txn, b types.Block, fces []explorer.FileContrac } defer revisionStmt.Close() - fcKeys := make(map[explorer.DBFileContract][]types.UnlockKey) + fcKeys := make(map[explorer.DBFileContract][2]types.PublicKey) // populate fcKeys using revision UnlockConditions fields for _, txn := range b.Transactions { for _, fcr := range txn.FileContractRevisions { @@ -760,6 +760,7 @@ func addFileContractElements(tx *txn, b types.Block, fces []explorer.FileContrac // check for 2 ed25519 keys ok := true + var result [2]types.PublicKey for i := 0; i < 2; i++ { // fewer than 2 keys if i >= len(uc.PublicKeys) { @@ -767,13 +768,15 @@ func addFileContractElements(tx *txn, b types.Block, fces []explorer.FileContrac break } - // not an ed25519 key - if uc.PublicKeys[i].Algorithm != types.SpecifierEd25519 { + if uc.PublicKeys[i].Algorithm == types.SpecifierEd25519 { + result[i] = types.PublicKey(uc.PublicKeys[i].Key) + } else { + // not an ed25519 key ok = false } } if ok { - fcKeys[dbFC] = fcr.UnlockConditions.PublicKeys + fcKeys[dbFC] = result } } } @@ -792,8 +795,8 @@ func addFileContractElements(tx *txn, b types.Block, fces []explorer.FileContrac if lastRevision { var renterKey, hostKey []byte if keys, ok := fcKeys[dbFC]; ok { - renterKey = keys[0].Key - hostKey = keys[1].Key + renterKey = encode(keys[0]).([]byte) + hostKey = encode(keys[1]).([]byte) } if _, err := revisionStmt.Exec(encode(fcID), dbID, renterKey, hostKey, dbID, renterKey, hostKey); err != nil { diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index 6a69af23..6290d6eb 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()) + renterContracts, err := db.ContractsKey(renterPublicKey) if err != nil { t.Fatal(err) } - hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey()) + hostContracts, err := db.ContractsKey(hostPublicKey) if err != nil { t.Fatal(err) } @@ -946,11 +946,11 @@ func TestFileContract(t *testing.T) { } { - renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey()) + renterContracts, err := db.ContractsKey(renterPublicKey) if err != nil { t.Fatal(err) } - hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey()) + hostContracts, err := db.ContractsKey(hostPublicKey) 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()) + renterContracts, err := db.ContractsKey(renterPublicKey) if err != nil { t.Fatal(err) } - hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey()) + hostContracts, err := db.ContractsKey(hostPublicKey) if err != nil { t.Fatal(err) } @@ -1188,11 +1188,11 @@ func TestEphemeralFileContract(t *testing.T) { } { - renterContracts, err := db.ContractsKey(renterPublicKey.UnlockKey()) + renterContracts, err := db.ContractsKey(renterPublicKey) if err != nil { t.Fatal(err) } - hostContracts, err := db.ContractsKey(hostPublicKey.UnlockKey()) + hostContracts, err := db.ContractsKey(hostPublicKey) if err != nil { t.Fatal(err) } diff --git a/persist/sqlite/contracts.go b/persist/sqlite/contracts.go index b477bed1..f51ea073 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 types.UnlockKey) (result []explorer.FileContract, err error) { +func (s *Store) ContractsKey(key types.PublicKey) (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, key.Key) + rows, err := tx.Query(query, encode(key), encode(key)) if err != nil { return err }