Skip to content

Commit

Permalink
vms/platformvm/service: preallocate address slice and improve error m…
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed May 6, 2023
1 parent b3a07d8 commit 8903335
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (s *Service) GetUTXOs(_ *http.Request, args *api.GetUTXOsArgs, response *ap
}
response.UTXOs[i], err = formatting.Encode(args.Encoding, bytes)
if err != nil {
return fmt.Errorf("couldn't encode UTXO %s as string: %w", utxo.InputID(), err)
return fmt.Errorf("couldn't encode UTXO %s as %s: %w", utxo.InputID(), args.Encoding, err)
}
}

Expand Down Expand Up @@ -2160,7 +2160,7 @@ func (s *Service) GetTx(_ *http.Request, args *api.GetTxArgs, response *api.GetT

response.Tx, err = formatting.Encode(args.Encoding, txBytes)
if err != nil {
return fmt.Errorf("couldn't encode tx as a string: %w", err)
return fmt.Errorf("couldn't encode tx as %s: %w", args.Encoding, err)
}
return nil
}
Expand Down Expand Up @@ -2332,7 +2332,7 @@ func (s *Service) GetStake(_ *http.Request, args *GetStakeArgs, response *GetSta
}
response.Outputs[i], err = formatting.Encode(args.Encoding, bytes)
if err != nil {
return fmt.Errorf("couldn't encode output %s as string: %w", output.ID, err)
return fmt.Errorf("couldn't encode output %s as %s: %w", output.ID, args.Encoding, err)
}
}
response.Encoding = args.Encoding
Expand Down Expand Up @@ -2505,7 +2505,7 @@ func (s *Service) GetRewardUTXOs(_ *http.Request, args *api.GetTxArgs, reply *Ge

utxoStr, err := formatting.Encode(args.Encoding, utxoBytes)
if err != nil {
return fmt.Errorf("couldn't encode utxo as a string: %w", err)
return fmt.Errorf("couldn't encode utxo as %s: %w", args.Encoding, err)
}
reply.UTXOs[i] = utxoStr
}
Expand Down Expand Up @@ -2589,7 +2589,7 @@ func (s *Service) GetBlock(_ *http.Request, args *api.GetBlockArgs, response *ap

response.Block, err = formatting.Encode(args.Encoding, block.Bytes())
if err != nil {
return fmt.Errorf("couldn't encode block %s as string: %w", args.BlockID, err)
return fmt.Errorf("couldn't encode block %s as %s: %w", args.BlockID, args.Encoding, err)
}

return nil
Expand All @@ -2615,6 +2615,7 @@ func (s *Service) getAPIOwner(owner *secp256k1fx.OutputOwners) (*platformapi.Own
apiOwner := &platformapi.Owner{
Locktime: json.Uint64(owner.Locktime),
Threshold: json.Uint32(owner.Threshold),
Addresses: make([]string, 0, len(owner.Addrs)),
}
for _, addr := range owner.Addrs {
addrStr, err := s.addrManager.FormatLocalAddress(addr)
Expand Down

0 comments on commit 8903335

Please sign in to comment.