Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 21, 2023
1 parent a582640 commit 8f51db4
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,6 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply
if err != nil {
return err
}
defer user.Close()

// Get the user's keys
privKeys, err := keystore.GetKeychain(user, fromAddrs)
Expand Down Expand Up @@ -1279,12 +1278,17 @@ func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply

reply.TxID = tx.ID()
reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1349,7 +1353,6 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply
if err != nil {
return err
}
defer user.Close()

privKeys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil {
Expand Down Expand Up @@ -1390,12 +1393,17 @@ func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply

reply.TxID = tx.ID()
reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1457,7 +1465,6 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator
if err != nil {
return err
}
defer user.Close()

keys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil {
Expand Down Expand Up @@ -1497,12 +1504,17 @@ func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidator

response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1541,7 +1553,6 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon
if err != nil {
return err
}
defer user.Close()

privKeys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil {
Expand Down Expand Up @@ -1574,12 +1585,17 @@ func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, respon

response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1637,7 +1653,6 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response *
if err != nil {
return err
}
defer user.Close()

privKeys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil {
Expand Down Expand Up @@ -1671,12 +1686,17 @@ func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response *

response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1725,7 +1745,6 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response *
if err != nil {
return err
}
defer user.Close()

privKeys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil { // Get keys
Expand Down Expand Up @@ -1757,12 +1776,17 @@ func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response *

response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1846,7 +1870,6 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs
if err != nil {
return err
}
defer user.Close()

keys, err := keystore.GetKeychain(user, fromAddrs)
if err != nil {
Expand Down Expand Up @@ -1882,12 +1905,17 @@ func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs

response.TxID = tx.ID()
response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr)
if err != nil {
return fmt.Errorf("could not format address %s: %w", changeAddr, err)
}

s.vm.ctx.Lock.Unlock()
err = s.vm.Network.IssueTx(req.Context(), tx)
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

return utils.Err(
err,
s.vm.Network.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down

0 comments on commit 8f51db4

Please sign in to comment.