Skip to content

Commit 197a1ee

Browse files
fix: clean comments
1 parent 15b6e45 commit 197a1ee

7 files changed

Lines changed: 11 additions & 31 deletions

File tree

cmd/common/helpers.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
129129
func 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.
168163
func 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.
208194
func PrettyAddress(addr string) string {
209195
return PrettyAddressWith(GenAddressFormatContext(), addr)
210196
}

cmd/common/json.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ func PrettyPrint(npa *NPASelection, prefix string, blob interface{}) string {
155155
return PrettyPrintWithTxDetails(npa, prefix, blob, nil)
156156
}
157157

158-
// PrettyPrintWithTxDetails is like PrettyPrint but also includes transaction-specific details in the
159-
// signature context (if the blob is a transaction pretty-printer).
158+
// PrettyPrintWithTxDetails is like PrettyPrint but passes txDetails to the signature context.
160159
func PrettyPrintWithTxDetails(npa *NPASelection, prefix string, blob interface{}, txDetails *signature.TxDetails) string {
161160
ret := ""
162161
switch rtx := blob.(type) {

cmd/common/transaction.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ func PrintTransactionRaw(npa *NPASelection, tx interface{}) {
366366
PrintTransactionRawWithTxDetails(npa, tx, nil)
367367
}
368368

369-
// PrintTransactionRawWithTxDetails prints the transaction which can be either signed or unsigned,
370-
// and also provides transaction-specific details to the pretty-printer when applicable.
369+
// PrintTransactionRawWithTxDetails is like PrintTransactionRaw but passes txDetails to the pretty-printer.
371370
func PrintTransactionRawWithTxDetails(npa *NPASelection, tx interface{}, txDetails *signature.TxDetails) {
372371
switch tx.(type) {
373372
case consensusPretty.PrettyPrinter:
@@ -383,8 +382,7 @@ func PrintTransaction(npa *NPASelection, tx interface{}) {
383382
PrintTransactionWithTxDetails(npa, tx, nil)
384383
}
385384

386-
// PrintTransactionWithTxDetails is like PrintTransaction but also provides transaction-specific
387-
// details to the pretty-printer when applicable.
385+
// PrintTransactionWithTxDetails is like PrintTransaction but passes txDetails to the pretty-printer.
388386
func PrintTransactionWithTxDetails(npa *NPASelection, tx interface{}, txDetails *signature.TxDetails) {
389387
PrintTransactionRawWithTxDetails(npa, tx, txDetails)
390388

cmd/common/wallet.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ func LoadAccount(cfg *config.Config, name string) wallet.Account {
130130
acc, err := cfg.Wallet.Load(name, passphrase)
131131
cobra.CheckErr(err)
132132

133-
// Persist Ethereum address metadata (if available) so other commands can prefer it without
134-
// needing to unlock/load the account again. This is best-effort and should never fail the command.
133+
// Persist eth address on unlock so future commands can show it without unlocking again.
135134
if accCfg, ok := cfg.Wallet.All[name]; ok && accCfg.EthAddress == "" {
136135
if ethAddr := acc.EthAddress(); ethAddr != nil {
137136
accCfg.EthAddress = ethAddr.Hex()

cmd/rofl/list.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func outputAppsText(network *config.Network, apps []*rofl.AppConfig) {
8888
// Extract version from metadata.
8989
version := app.Metadata["net.oasis.rofl.version"]
9090

91-
// Format admin address with pretty formatting.
9291
var admin string
9392
if app.Admin != nil {
9493
admin = common.PrettyAddress(app.Admin.String())

cmd/rofl/provider/show.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func outputProviderText(npa *common.NPASelection, provider *roflmarket.Provider,
9292
fmt.Println("=== Basic Information ===")
9393
fmt.Printf("Scheduler App: %s\n", provider.SchedulerApp)
9494

95-
// Payment address with pretty formatting.
9695
var paymentAddr string
9796
switch {
9897
case provider.PaymentAddress.Native != nil:

config/wallet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (w *Wallet) Create(name string, passphrase string, nw *Account) error {
8383
}
8484
nw.Address = string(address)
8585

86-
// Store Ethereum address (if any) so we don't need to unlock/load the account later just to show it.
86+
// Store eth address so wallet list can show it without unlocking.
8787
if ethAddr := acc.EthAddress(); ethAddr != nil {
8888
nw.EthAddress = ethAddr.Hex()
8989
}
@@ -227,7 +227,7 @@ func (w *Wallet) Import(name string, passphrase string, nw *Account, src *wallet
227227
}
228228
nw.Address = string(address)
229229

230-
// Store Ethereum address (if any) so we don't need to unlock/load the account later just to show it.
230+
// Store eth address (same as Create).
231231
if ethAddr := acc.EthAddress(); ethAddr != nil {
232232
nw.EthAddress = ethAddr.Hex()
233233
}

0 commit comments

Comments
 (0)