@@ -3,12 +3,12 @@ package common
33import (
44 "fmt"
55 "os"
6+ "sort"
67
78 ethCommon "github.com/ethereum/go-ethereum/common"
89 "github.com/spf13/cobra"
910
1011 staking "github.com/oasisprotocol/oasis-core/go/staking/api"
11- configSdk "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
1212 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/helpers"
1313 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing"
1414 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
@@ -46,17 +46,12 @@ func CheckForceErr(err interface{}) {
4646 cobra .CheckErr (errMsg )
4747}
4848
49- // GenAccountNames generates a map of all addresses -> account name for pretty printing.
50- // Priority order (later entries overwrite earlier): test accounts < addressbook < wallet.
51- // This ensures wallet identity takes precedence over addressbook labels for the same address.
49+ // GenAccountNames generates a map of all known native addresses -> account name for pretty printing.
50+ // It includes test accounts, configured networks (paratimes/ROFL defaults), addressbook and wallet.
51+ //
52+ // Priority order (later entries overwrite earlier):
53+ // test accounts < network entries < addressbook < wallet.
5254func GenAccountNames () types.AccountNames {
53- return GenAccountNamesForNetwork (nil )
54- }
55-
56- // GenAccountNamesForNetwork generates a map of all addresses -> account name for pretty printing,
57- // including network-specific entries (paratimes, ROFL providers) when a network is provided.
58- // Priority order (later entries overwrite earlier): test accounts < network entries < addressbook < wallet.
59- func GenAccountNamesForNetwork (net * configSdk.Network ) types.AccountNames {
6055 an := types.AccountNames {}
6156
6257 // Test accounts have lowest priority.
@@ -65,15 +60,34 @@ func GenAccountNamesForNetwork(net *configSdk.Network) types.AccountNames {
6560 }
6661
6762 // Network-derived entries (paratimes, ROFL providers) have second-lowest priority.
68- if net != nil {
63+ cfg := config .Global ()
64+ netNames := make ([]string , 0 , len (cfg .Networks .All ))
65+ for name := range cfg .Networks .All {
66+ netNames = append (netNames , name )
67+ }
68+ sort .Strings (netNames )
69+ for _ , netName := range netNames {
70+ net := cfg .Networks .All [netName ]
71+ if net == nil {
72+ continue
73+ }
74+
6975 // Include ParaTime runtime addresses as paratime:<name>.
70- for ptName , pt := range net .ParaTimes .All {
76+ ptNames := make ([]string , 0 , len (net .ParaTimes .All ))
77+ for ptName := range net .ParaTimes .All {
78+ ptNames = append (ptNames , ptName )
79+ }
80+ sort .Strings (ptNames )
81+ for _ , ptName := range ptNames {
82+ pt := net .ParaTimes .All [ptName ]
83+ if pt == nil {
84+ continue
85+ }
86+
7187 rtAddr := types .NewAddressFromConsensus (staking .NewRuntimeAddress (pt .Namespace ()))
7288 an [rtAddr .String ()] = fmt .Sprintf ("paratime:%s" , ptName )
73- }
7489
75- // Include ROFL default provider addresses as rofl:provider:<paratime>.
76- for ptName , pt := range net .ParaTimes .All {
90+ // Include ROFL default provider addresses as rofl:provider:<paratime>.
7791 if svc , ok := buildRoflProvider .DefaultRoflServices [pt .ID ]; ok {
7892 if svc .Provider != "" {
7993 if a , _ , err := helpers .ResolveEthOrOasisAddress (svc .Provider ); err == nil && a != nil {
@@ -85,12 +99,12 @@ func GenAccountNamesForNetwork(net *configSdk.Network) types.AccountNames {
8599 }
86100
87101 // Addressbook entries have medium priority.
88- for name , acc := range config . Global () .AddressBook .All {
102+ for name , acc := range cfg .AddressBook .All {
89103 an [acc .GetAddress ().String ()] = name
90104 }
91105
92106 // Wallet entries have highest priority.
93- for name , acc := range config . Global () .Wallet .All {
107+ for name , acc := range cfg .Wallet .All {
94108 an [acc .GetAddress ().String ()] = name
95109 }
96110
@@ -103,27 +117,17 @@ func FindAccountName(address string) string {
103117 return an [address ]
104118}
105119
106- // FindAccountNameForNetwork finds account's name in the context of a specific network.
107- func FindAccountNameForNetwork (net * configSdk.Network , address string ) string {
108- an := GenAccountNamesForNetwork (net )
109- return an [address ]
110- }
111-
112120// AddressFormatContext contains precomputed maps for address formatting.
113121type AddressFormatContext struct {
114122 // Names maps native address string to account name.
115123 Names types.AccountNames
116- // Eth maps native address string to Ethereum hex address string (if known).
124+ // Eth maps native address string to Ethereum hex address string, if known.
125+ // This is optional metadata coming from wallet/addressbook/test accounts (and never derived from chain state).
117126 Eth map [string ]string
118127}
119128
120129// GenAccountEthMap generates a map of native address string -> eth hex address (if known).
121130func GenAccountEthMap () map [string ]string {
122- return GenAccountEthMapForNetwork (nil )
123- }
124-
125- // GenAccountEthMapForNetwork generates a map of native address string -> eth hex address (if known).
126- func GenAccountEthMapForNetwork (_ * configSdk.Network ) map [string ]string {
127131 eth := make (map [string ]string )
128132
129133 // From test accounts.
@@ -152,15 +156,9 @@ func GenAccountEthMapForNetwork(_ *configSdk.Network) map[string]string {
152156
153157// GenAddressFormatContext builds both name and eth address maps for formatting.
154158func GenAddressFormatContext () AddressFormatContext {
155- return GenAddressFormatContextForNetwork (nil )
156- }
157-
158- // GenAddressFormatContextForNetwork builds both name and eth address maps for formatting,
159- // including network-specific entries when a network is provided.
160- func GenAddressFormatContextForNetwork (net * configSdk.Network ) AddressFormatContext {
161159 return AddressFormatContext {
162- Names : GenAccountNamesForNetwork ( net ),
163- Eth : GenAccountEthMapForNetwork ( net ),
160+ Names : GenAccountNames ( ),
161+ Eth : GenAccountEthMap ( ),
164162 }
165163}
166164
@@ -233,10 +231,3 @@ func PrettyResolvedAddressWith(ctx AddressFormatContext, nativeAddr *types.Addre
233231func PrettyAddress (addr string ) string {
234232 return PrettyAddressWith (GenAddressFormatContext (), addr )
235233}
236-
237- // PrettyAddressForNetwork formats an address for display with network context.
238- // This includes network-derived names like paratime addresses and ROFL providers.
239- func PrettyAddressForNetwork (net * configSdk.Network , addr types.Address ) string {
240- ctx := GenAddressFormatContextForNetwork (net )
241- return PrettyAddressWith (ctx , addr .String ())
242- }
0 commit comments