@@ -121,29 +121,26 @@ type AddressFormatContext struct {
121121 // Names maps native address string to account name.
122122 Names types.AccountNames
123123 // Eth maps native address string to Ethereum hex address string, if known.
124- // This is optional metadata coming from wallet/addressbook/test accounts (and never derived from chain state).
125124 Eth map [string ]string
126125}
127126
128127// GenAccountEthMap generates a map of native address string -> eth hex address (if known).
128+ // Priority order matches GenAccountNames: test accounts < addressbook < wallet.
129129func GenAccountEthMap () map [string ]string {
130130 eth := make (map [string ]string )
131131
132- // From test accounts.
133132 for _ , acc := range testing .TestAccounts {
134133 if acc .EthAddress != nil {
135134 eth [acc .Address .String ()] = acc .EthAddress .Hex ()
136135 }
137136 }
138137
139- // From address book entries (higher priority than test accounts).
140138 for _ , acc := range config .Global ().AddressBook .All {
141139 if ethAddr := acc .GetEthAddress (); ethAddr != nil {
142140 eth [acc .GetAddress ().String ()] = ethAddr .Hex ()
143141 }
144142 }
145143
146- // From wallet entries (highest priority), when an Ethereum address is available in config.
147144 for _ , acc := range config .Global ().Wallet .All {
148145 if ethAddr := acc .GetEthAddress (); ethAddr != nil {
149146 eth [acc .GetAddress ().String ()] = ethAddr .Hex ()
@@ -161,29 +158,22 @@ func GenAddressFormatContext() AddressFormatContext {
161158 }
162159}
163160
164- // PrettyAddressWith formats an address using a precomputed context.
165- // If the address is known (in wallet, addressbook, or test accounts), it returns "name (address)".
166- // For secp256k1 accounts with a known Ethereum address, the Ethereum hex format is preferred in parentheses.
167- // If the address is unknown, it returns the original address string unchanged.
161+ // PrettyAddressWith formats a string address for display using a precomputed context.
162+ // Known addresses return "name (preferred_addr)", unknown addresses return the input unchanged.
168163func PrettyAddressWith (ctx AddressFormatContext , addr string ) string {
169- // Try to parse the address to get canonical native form.
170164 nativeAddr , ethFromInput , err := helpers .ResolveEthOrOasisAddress (addr )
171165 if err != nil || nativeAddr == nil {
172- // Cannot parse, return unchanged.
173166 return addr
174167 }
175168
176169 nativeStr := nativeAddr .String ()
177170
178- // Look up the name.
179171 name := ctx .Names [nativeStr ]
180172 if name == "" {
181- // Unknown address, return the original input.
182173 return addr
183174 }
184175
185- // Determine which address to show in parentheses.
186- // Prefer Ethereum address if available (from input or from known eth addresses).
176+ // Prefer eth address in parentheses when available.
187177 var parenAddr string
188178 if ethFromInput != nil {
189179 parenAddr = ethFromInput .Hex ()
@@ -193,18 +183,14 @@ func PrettyAddressWith(ctx AddressFormatContext, addr string) string {
193183 parenAddr = nativeStr
194184 }
195185
196- // Guard against redundant "name (name)" output.
197186 if name == parenAddr {
198187 return parenAddr
199188 }
200189
201190 return fmt .Sprintf ("%s (%s)" , name , parenAddr )
202191}
203192
204- // PrettyAddress formats an address for display without network context.
205- // If the address is known (in wallet, addressbook, or test accounts), it returns "name (address)".
206- // For secp256k1 accounts with a known Ethereum address, the Ethereum hex format is preferred in parentheses.
207- // If the address is unknown, it returns the original address string unchanged.
193+ // PrettyAddress is like PrettyAddressWith but builds a fresh context on each call.
208194func PrettyAddress (addr string ) string {
209195 return PrettyAddressWith (GenAddressFormatContext (), addr )
210196}
0 commit comments