Skip to content

Commit c01b7ad

Browse files
authored
Merge pull request #547 from oasisprotocol/amela/show-eth-addr
feat(cmd/account): Show Eth addr and name if avaliable
2 parents ae401ce + a8d9d66 commit c01b7ad

10 files changed

Lines changed: 41 additions & 21 deletions

File tree

cmd/account/show/show.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ var (
5454
c, err := connection.Connect(ctx, npa.Network)
5555
cobra.CheckErr(err)
5656

57-
addr, _, err := common.ResolveLocalAccountOrAddress(npa.Network, targetAddress)
57+
nativeAddr, ethAddr, err := common.ResolveLocalAccountOrAddress(npa.Network, targetAddress)
5858
cobra.CheckErr(err)
5959

60+
if name := common.FindAccountName(nativeAddr.String()); name != "" {
61+
fmt.Printf("Name: %s\n", name)
62+
}
63+
6064
height, err := common.GetActualHeight(
6165
ctx,
6266
c.Consensus().Core(),
6367
)
6468
cobra.CheckErr(err)
6569

6670
ownerQuery := &staking.OwnerQuery{
67-
Owner: addr.ConsensusAddress(),
71+
Owner: nativeAddr.ConsensusAddress(),
6872
Height: height,
6973
}
7074

@@ -73,8 +77,10 @@ var (
7377

7478
consensusAccount, err := c.Consensus().Staking().Account(ctx, ownerQuery)
7579
cobra.CheckErr(err)
76-
77-
fmt.Printf("Address: %s\n", addr)
80+
if ethAddr != nil {
81+
fmt.Printf("Ethereum address: %s\n", ethAddr)
82+
}
83+
fmt.Printf("Native address: %s\n", nativeAddr)
7884
fmt.Println()
7985
fmt.Printf("=== CONSENSUS LAYER (%s) ===\n", npa.NetworkName)
8086
fmt.Printf(" Nonce: %d\n", consensusAccount.General.Nonce)
@@ -93,7 +99,7 @@ var (
9399

94100
prettyPrintAccountBalanceAndDelegationsFrom(
95101
npa.Network,
96-
addr,
102+
nativeAddr,
97103
consensusAccount.General,
98104
outgoingDelegations,
99105
outgoingDebondingDelegations,
@@ -105,7 +111,7 @@ var (
105111
fmt.Println(" Allowances for this Account:")
106112
prettyPrintAllowances(
107113
npa.Network,
108-
addr,
114+
nativeAddr,
109115
consensusAccount.General.Allowances,
110116
" ",
111117
os.Stdout,
@@ -123,7 +129,7 @@ var (
123129
fmt.Println(" Active Delegations to this Account:")
124130
prettyPrintDelegationsTo(
125131
npa.Network,
126-
addr,
132+
nativeAddr,
127133
consensusAccount.Escrow.Active,
128134
incomingDelegations,
129135
" ",
@@ -135,7 +141,7 @@ var (
135141
fmt.Println(" Debonding Delegations to this Account:")
136142
prettyPrintDelegationsTo(
137143
npa.Network,
138-
addr,
144+
nativeAddr,
139145
consensusAccount.Escrow.Debonding,
140146
incomingDebondingDelegations,
141147
" ",
@@ -177,7 +183,7 @@ var (
177183
}
178184

179185
// Query runtime account when a ParaTime has been configured.
180-
rtBalances, err := c.Runtime(npa.ParaTime).Accounts.Balances(ctx, round, *addr)
186+
rtBalances, err := c.Runtime(npa.ParaTime).Accounts.Balances(ctx, round, *nativeAddr)
181187
cobra.CheckErr(err)
182188

183189
var hasNonZeroBalance bool
@@ -187,7 +193,7 @@ var (
187193
}
188194
}
189195

190-
nonce, err := c.Runtime(npa.ParaTime).Accounts.Nonce(ctx, round, *addr)
196+
nonce, err := c.Runtime(npa.ParaTime).Accounts.Nonce(ctx, round, *nativeAddr)
191197
cobra.CheckErr(err)
192198
hasNonZeroNonce := nonce > 0
193199

@@ -214,17 +220,17 @@ var (
214220
ctx,
215221
round,
216222
&consensusaccounts.DelegationsQuery{
217-
From: *addr,
223+
From: *nativeAddr,
218224
},
219225
)
220226
rtUndelegations, _ := c.Runtime(npa.ParaTime).ConsensusAccounts.Undelegations(
221227
ctx,
222228
round,
223229
&consensusaccounts.UndelegationsQuery{
224-
To: *addr,
230+
To: *nativeAddr,
225231
},
226232
)
227-
prettyPrintParaTimeDelegations(ctx, c, height, npa, addr, rtDelegations, rtUndelegations, " ", os.Stdout)
233+
prettyPrintParaTimeDelegations(ctx, c, height, npa, nativeAddr, rtDelegations, rtUndelegations, " ", os.Stdout)
228234
}
229235
}
230236
}

cmd/common/helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ func GenAccountNames() types.AccountNames {
4747

4848
return an
4949
}
50+
51+
// FindAccountName finds account's name (if exists).
52+
func FindAccountName(address string) string {
53+
an := GenAccountNames()
54+
return an[address]
55+
}

examples/account/show-eth.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Address: oasis1qzplmfaeywvtc2qnylyhk0uzcxr4y5s3euhaug7q
1+
Name: eric
2+
Ethereum address: 0xA3243B310CfA8D4b008780BC87E0bb9f6d4FDA06
3+
Native address: oasis1qzplmfaeywvtc2qnylyhk0uzcxr4y5s3euhaug7q
24

35
=== CONSENSUS LAYER (testnet) ===
46
Nonce: 0

examples/account/show-mainnet.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
1+
Name: test:cory
2+
Native address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
23

34
=== CONSENSUS LAYER (mainnet) ===
45
Nonce: 0

examples/account/show-named-pool.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Address: oasis1qqnv3peudzvekhulf8v3ht29z4cthkhy7gkxmph5
1+
Native address: oasis1qqnv3peudzvekhulf8v3ht29z4cthkhy7gkxmph5
22

33
=== CONSENSUS LAYER (testnet) ===
44
Nonce: 0

examples/account/show-named.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qq84sc4q0shp5c5klwklqu59evz2mg59hveg7dqx
1+
Name: orlando
2+
Native address: oasis1qq84sc4q0shp5c5klwklqu59evz2mg59hveg7dqx
23

34
=== CONSENSUS LAYER (testnet) ===
45
Nonce: 0

examples/account/show-no-paratime.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qzplmfaeywvtc2qnylyhk0uzcxr4y5s3euhaug7q
1+
Name: eric
2+
Native address: oasis1qzplmfaeywvtc2qnylyhk0uzcxr4y5s3euhaug7q
23

34
=== CONSENSUS LAYER (testnet) ===
45
Nonce: 0

examples/account/show-oasis.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
1+
Name: test:cory
2+
Native address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
23

34
=== CONSENSUS LAYER (testnet) ===
45
Nonce: 0

examples/account/show-testnet.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
1+
Name: test:cory
2+
Native address: oasis1qzzd6khm3acqskpxlk9vd5044cmmcce78y5l6000
23

34
=== CONSENSUS LAYER (testnet) ===
45
Nonce: 0

examples/account/show.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Address: oasis1qp87hflmelnpqhzcqcw8rhzakq4elj7jzv090p3e
1+
Name: oscar
2+
Native address: oasis1qp87hflmelnpqhzcqcw8rhzakq4elj7jzv090p3e
23

34
=== CONSENSUS LAYER (testnet) ===
45
Nonce: 2

0 commit comments

Comments
 (0)