Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit be859c9

Browse files
authored
remove keystore and related APIs (#748)
1 parent 5013851 commit be859c9

File tree

7 files changed

+7
-530
lines changed

7 files changed

+7
-530
lines changed

RELEASES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## Pending Release
4+
5+
- Removed deprecated `ExportKey`, `ExportAVAX`, `Export`, `ImportKey`, `ImportAVAX`, `Import` APIs
6+
37
## [v0.14.1](https://github.com/ava-labs/coreth/releases/tag/v0.14.1)
48

59
- IMPORTANT: `eth_getProof` calls for historical state will be rejected by default.

plugin/evm/api.go

Lines changed: 3 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/ava-labs/coreth/plugin/evm/atomic"
2020
"github.com/ava-labs/coreth/plugin/evm/client"
2121
"github.com/ethereum/go-ethereum/common"
22-
"github.com/ethereum/go-ethereum/common/hexutil"
2322
"github.com/ethereum/go-ethereum/log"
2423
)
2524

@@ -33,10 +32,9 @@ const (
3332
)
3433

3534
var (
36-
errNoAddresses = errors.New("no addresses provided")
37-
errNoSourceChain = errors.New("no source chain provided")
38-
errNilTxID = errors.New("nil transaction ID")
39-
errMissingPrivateKey = errors.New("argument 'privateKey' not given")
35+
errNoAddresses = errors.New("no addresses provided")
36+
errNoSourceChain = errors.New("no source chain provided")
37+
errNilTxID = errors.New("nil transaction ID")
4038

4139
initialBaseFee = big.NewInt(params.ApricotPhase3InitialBaseFee)
4240
)
@@ -71,17 +69,6 @@ func (api *SnowmanAPI) IssueBlock(ctx context.Context) error {
7169
// AvaxAPI offers Avalanche network related API methods
7270
type AvaxAPI struct{ vm *VM }
7371

74-
// parseAssetID parses an assetID string into an ID
75-
func (service *AvaxAPI) parseAssetID(assetID string) (ids.ID, error) {
76-
if assetID == "" {
77-
return ids.ID{}, fmt.Errorf("assetID is required")
78-
} else if assetID == "AVAX" {
79-
return service.vm.ctx.AVAXAssetID, nil
80-
} else {
81-
return ids.FromString(assetID)
82-
}
83-
}
84-
8572
type VersionReply struct {
8673
Version string `json:"version"`
8774
}
@@ -92,198 +79,6 @@ func (service *AvaxAPI) Version(r *http.Request, _ *struct{}, reply *VersionRepl
9279
return nil
9380
}
9481

95-
// ExportKey returns a private key from the provided user
96-
func (service *AvaxAPI) ExportKey(r *http.Request, args *client.ExportKeyArgs, reply *client.ExportKeyReply) error {
97-
log.Info("EVM: ExportKey called")
98-
99-
address, err := client.ParseEthAddress(args.Address)
100-
if err != nil {
101-
return fmt.Errorf("couldn't parse %s to address: %s", args.Address, err)
102-
}
103-
104-
service.vm.ctx.Lock.Lock()
105-
defer service.vm.ctx.Lock.Unlock()
106-
107-
db, err := service.vm.ctx.Keystore.GetDatabase(args.Username, args.Password)
108-
if err != nil {
109-
return fmt.Errorf("problem retrieving user '%s': %w", args.Username, err)
110-
}
111-
defer db.Close()
112-
113-
user := user{db: db}
114-
reply.PrivateKey, err = user.getKey(address)
115-
if err != nil {
116-
return fmt.Errorf("problem retrieving private key: %w", err)
117-
}
118-
reply.PrivateKeyHex = hexutil.Encode(reply.PrivateKey.Bytes())
119-
return nil
120-
}
121-
122-
// ImportKey adds a private key to the provided user
123-
func (service *AvaxAPI) ImportKey(r *http.Request, args *client.ImportKeyArgs, reply *api.JSONAddress) error {
124-
log.Info("EVM: ImportKey called", "username", args.Username)
125-
126-
if args.PrivateKey == nil {
127-
return errMissingPrivateKey
128-
}
129-
130-
reply.Address = args.PrivateKey.EthAddress().Hex()
131-
132-
service.vm.ctx.Lock.Lock()
133-
defer service.vm.ctx.Lock.Unlock()
134-
135-
db, err := service.vm.ctx.Keystore.GetDatabase(args.Username, args.Password)
136-
if err != nil {
137-
return fmt.Errorf("problem retrieving data: %w", err)
138-
}
139-
defer db.Close()
140-
141-
user := user{db: db}
142-
if err := user.putAddress(args.PrivateKey); err != nil {
143-
return fmt.Errorf("problem saving key %w", err)
144-
}
145-
return nil
146-
}
147-
148-
// ImportAVAX is a deprecated name for Import.
149-
func (service *AvaxAPI) ImportAVAX(_ *http.Request, args *client.ImportArgs, response *api.JSONTxID) error {
150-
return service.Import(nil, args, response)
151-
}
152-
153-
// Import issues a transaction to import AVAX from the X-chain. The AVAX
154-
// must have already been exported from the X-Chain.
155-
func (service *AvaxAPI) Import(_ *http.Request, args *client.ImportArgs, response *api.JSONTxID) error {
156-
log.Info("EVM: ImportAVAX called")
157-
158-
chainID, err := service.vm.ctx.BCLookup.Lookup(args.SourceChain)
159-
if err != nil {
160-
return fmt.Errorf("problem parsing chainID %q: %w", args.SourceChain, err)
161-
}
162-
163-
service.vm.ctx.Lock.Lock()
164-
defer service.vm.ctx.Lock.Unlock()
165-
166-
// Get the user's info
167-
db, err := service.vm.ctx.Keystore.GetDatabase(args.Username, args.Password)
168-
if err != nil {
169-
return fmt.Errorf("couldn't get user '%s': %w", args.Username, err)
170-
}
171-
defer db.Close()
172-
173-
user := user{db: db}
174-
privKeys, err := user.getKeys()
175-
if err != nil { // Get keys
176-
return fmt.Errorf("couldn't get keys controlled by the user: %w", err)
177-
}
178-
179-
var baseFee *big.Int
180-
if args.BaseFee == nil {
181-
// Get the base fee to use
182-
baseFee, err = service.vm.estimateBaseFee(context.Background())
183-
if err != nil {
184-
return err
185-
}
186-
} else {
187-
baseFee = args.BaseFee.ToInt()
188-
}
189-
190-
tx, err := service.vm.newImportTx(chainID, args.To, baseFee, privKeys)
191-
if err != nil {
192-
return err
193-
}
194-
195-
response.TxID = tx.ID()
196-
if err := service.vm.mempool.AddLocalTx(tx); err != nil {
197-
return err
198-
}
199-
service.vm.atomicTxPushGossiper.Add(&atomic.GossipAtomicTx{Tx: tx})
200-
return nil
201-
}
202-
203-
// ExportAVAX exports AVAX from the C-Chain to the X-Chain
204-
// It must be imported on the X-Chain to complete the transfer
205-
func (service *AvaxAPI) ExportAVAX(_ *http.Request, args *client.ExportAVAXArgs, response *api.JSONTxID) error {
206-
return service.Export(nil, &client.ExportArgs{
207-
ExportAVAXArgs: *args,
208-
AssetID: service.vm.ctx.AVAXAssetID.String(),
209-
}, response)
210-
}
211-
212-
// Export exports an asset from the C-Chain to the X-Chain
213-
// It must be imported on the X-Chain to complete the transfer
214-
func (service *AvaxAPI) Export(_ *http.Request, args *client.ExportArgs, response *api.JSONTxID) error {
215-
log.Info("EVM: Export called")
216-
217-
assetID, err := service.parseAssetID(args.AssetID)
218-
if err != nil {
219-
return err
220-
}
221-
222-
if args.Amount == 0 {
223-
return errors.New("argument 'amount' must be > 0")
224-
}
225-
226-
// Get the chainID and parse the to address
227-
chainID, to, err := service.vm.ParseAddress(args.To)
228-
if err != nil {
229-
chainID, err = service.vm.ctx.BCLookup.Lookup(args.TargetChain)
230-
if err != nil {
231-
return err
232-
}
233-
to, err = ids.ShortFromString(args.To)
234-
if err != nil {
235-
return err
236-
}
237-
}
238-
239-
service.vm.ctx.Lock.Lock()
240-
defer service.vm.ctx.Lock.Unlock()
241-
242-
// Get this user's data
243-
db, err := service.vm.ctx.Keystore.GetDatabase(args.Username, args.Password)
244-
if err != nil {
245-
return fmt.Errorf("problem retrieving user '%s': %w", args.Username, err)
246-
}
247-
defer db.Close()
248-
249-
user := user{db: db}
250-
privKeys, err := user.getKeys()
251-
if err != nil {
252-
return fmt.Errorf("couldn't get addresses controlled by the user: %w", err)
253-
}
254-
255-
var baseFee *big.Int
256-
if args.BaseFee == nil {
257-
// Get the base fee to use
258-
baseFee, err = service.vm.estimateBaseFee(context.Background())
259-
if err != nil {
260-
return err
261-
}
262-
} else {
263-
baseFee = args.BaseFee.ToInt()
264-
}
265-
266-
// Create the transaction
267-
tx, err := service.vm.newExportTx(
268-
assetID, // AssetID
269-
uint64(args.Amount), // Amount
270-
chainID, // ID of the chain to send the funds to
271-
to, // Address
272-
baseFee,
273-
privKeys, // Private keys
274-
)
275-
if err != nil {
276-
return fmt.Errorf("couldn't create tx: %w", err)
277-
}
278-
279-
response.TxID = tx.ID()
280-
if err := service.vm.mempool.AddLocalTx(tx); err != nil {
281-
return err
282-
}
283-
service.vm.atomicTxPushGossiper.Add(&atomic.GossipAtomicTx{Tx: tx})
284-
return nil
285-
}
286-
28782
// GetUTXOs gets all utxos for passed in addresses
28883
func (service *AvaxAPI) GetUTXOs(r *http.Request, args *api.GetUTXOsArgs, reply *api.GetUTXOsReply) error {
28984
log.Info("EVM: GetUTXOs called", "Addresses", args.Addresses)

0 commit comments

Comments
 (0)