github.com/MetalBlockchain/metalgo@v1.11.9/api/keystore/blockchain_keystore.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package keystore 5 6 import ( 7 "go.uber.org/zap" 8 9 "github.com/MetalBlockchain/metalgo/database" 10 "github.com/MetalBlockchain/metalgo/database/encdb" 11 "github.com/MetalBlockchain/metalgo/ids" 12 "github.com/MetalBlockchain/metalgo/utils/logging" 13 ) 14 15 var _ BlockchainKeystore = (*blockchainKeystore)(nil) 16 17 type BlockchainKeystore interface { 18 // Get a database that is able to read and write unencrypted values from the 19 // underlying database. 20 GetDatabase(username, password string) (*encdb.Database, error) 21 22 // Get the underlying database that is able to read and write encrypted 23 // values. This Database will not perform any encrypting or decrypting of 24 // values and is not recommended to be used when implementing a VM. 25 GetRawDatabase(username, password string) (database.Database, error) 26 } 27 28 type blockchainKeystore struct { 29 blockchainID ids.ID 30 ks *keystore 31 } 32 33 func (bks *blockchainKeystore) GetDatabase(username, password string) (*encdb.Database, error) { 34 bks.ks.log.Warn("deprecated keystore called", 35 zap.String("method", "getDatabase"), 36 logging.UserString("username", username), 37 zap.Stringer("blockchainID", bks.blockchainID), 38 ) 39 40 return bks.ks.GetDatabase(bks.blockchainID, username, password) 41 } 42 43 func (bks *blockchainKeystore) GetRawDatabase(username, password string) (database.Database, error) { 44 bks.ks.log.Warn("deprecated keystore called", 45 zap.String("method", "getRawDatabase"), 46 logging.UserString("username", username), 47 zap.Stringer("blockchainID", bks.blockchainID), 48 ) 49 50 return bks.ks.GetRawDatabase(bks.blockchainID, username, password) 51 }