Skip to content

Commit 8903335

Browse files
authored
vms/platformvm/service: preallocate address slice and improve error msg (ava-labs#1477)
1 parent b3a07d8 commit 8903335

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

vms/platformvm/service.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (s *Service) GetUTXOs(_ *http.Request, args *api.GetUTXOsArgs, response *ap
479479
}
480480
response.UTXOs[i], err = formatting.Encode(args.Encoding, bytes)
481481
if err != nil {
482-
return fmt.Errorf("couldn't encode UTXO %s as string: %w", utxo.InputID(), err)
482+
return fmt.Errorf("couldn't encode UTXO %s as %s: %w", utxo.InputID(), args.Encoding, err)
483483
}
484484
}
485485

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

21612161
response.Tx, err = formatting.Encode(args.Encoding, txBytes)
21622162
if err != nil {
2163-
return fmt.Errorf("couldn't encode tx as a string: %w", err)
2163+
return fmt.Errorf("couldn't encode tx as %s: %w", args.Encoding, err)
21642164
}
21652165
return nil
21662166
}
@@ -2332,7 +2332,7 @@ func (s *Service) GetStake(_ *http.Request, args *GetStakeArgs, response *GetSta
23322332
}
23332333
response.Outputs[i], err = formatting.Encode(args.Encoding, bytes)
23342334
if err != nil {
2335-
return fmt.Errorf("couldn't encode output %s as string: %w", output.ID, err)
2335+
return fmt.Errorf("couldn't encode output %s as %s: %w", output.ID, args.Encoding, err)
23362336
}
23372337
}
23382338
response.Encoding = args.Encoding
@@ -2505,7 +2505,7 @@ func (s *Service) GetRewardUTXOs(_ *http.Request, args *api.GetTxArgs, reply *Ge
25052505

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

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

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

0 commit comments

Comments
 (0)