Skip to content

Commit 88d7d00

Browse files
authored
feat(sc-99672): add GetAddressExploreURL to return explorer url by address (#199)
1 parent b506e1a commit 88d7d00

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed

coin/models.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,147 @@ func GetCoinExploreURL(c Coin, tokenID, tokenType string) (string, error) {
196196

197197
return "", errors.New("no explorer for coin: " + c.Handle)
198198
}
199+
200+
// nolint:cyclop
201+
func GetAddressExploreURL(c Coin, address string) (string, error) {
202+
switch c.ID {
203+
case ETHEREUM:
204+
return fmt.Sprintf("https://etherscan.io/address/%s", address), nil
205+
case TRON:
206+
return fmt.Sprintf("https://tronscan.io/#/address/%s", address), nil
207+
case BINANCE:
208+
return fmt.Sprintf("https://explorer.binance.org/address/%s", address), nil
209+
case SMARTCHAIN:
210+
return fmt.Sprintf("https://bscscan.com/address/%s", address), nil
211+
case EOS:
212+
return fmt.Sprintf("https://bloks.io/account/%s", address), nil
213+
case NULS:
214+
return fmt.Sprintf("https://nulscan.io/token/info?address=%s", address), nil
215+
case WANCHAIN:
216+
return fmt.Sprintf("https://www.wanscan.org/address/%s", address), nil
217+
case SOLANA:
218+
return fmt.Sprintf("https://solscan.io/account/%s", address), nil
219+
case TOMOCHAIN:
220+
return fmt.Sprintf("https://tomoscan.io/address/%s", address), nil
221+
case KAVA:
222+
return "https://www.mintscan.io/kava", nil
223+
case ONTOLOGY:
224+
return "https://explorer.ont.io", nil
225+
case GOCHAIN:
226+
return fmt.Sprintf("https://explorer.gochain.io/addr/%s", address), nil
227+
case THETA:
228+
return "https://explorer.thetatoken.org/", nil
229+
case THUNDERTOKEN:
230+
return fmt.Sprintf("https://explorer-mainnet.thundercore.com/address/%s", address), nil
231+
case CLASSIC:
232+
return fmt.Sprintf("https://blockscout.com/etc/mainnet/address/%s", address), nil
233+
case VECHAIN:
234+
return fmt.Sprintf("https://explore.vechain.org/accounts/%s", address), nil
235+
case WAVES:
236+
return fmt.Sprintf("https://wavesexplorer.com/addresses/%s", address), nil
237+
case XDAI:
238+
return fmt.Sprintf("https://blockscout.com/xdai/mainnet/address/%s", address), nil
239+
case POLYGON:
240+
return fmt.Sprintf("https://polygonscan.com/address/%s", address), nil
241+
case OPTIMISM:
242+
return fmt.Sprintf("https://optimistic.etherscan.io/address/%s", address), nil
243+
case AVALANCHEC:
244+
return fmt.Sprintf("https://snowtrace.io/address/%s", address), nil
245+
case ARBITRUM:
246+
return fmt.Sprintf("https://arbiscan.io/address/%s", address), nil
247+
case FANTOM:
248+
return fmt.Sprintf("https://explorer.fantom.network/address/%s", address), nil // not working
249+
case TERRA:
250+
return fmt.Sprintf("https://finder.terra.money/mainnet/address/%s", address), nil
251+
case RONIN:
252+
return fmt.Sprintf("https://explorer.roninchain.com/address/%s", address), nil
253+
case CELO:
254+
return fmt.Sprintf("https://explorer.celo.org/mainnet/address/%s", address), nil
255+
case ELROND:
256+
return fmt.Sprintf("https://explorer.multiversx.com/accounts/%s", address), nil
257+
case CRONOS:
258+
return fmt.Sprintf("https://explorer.cronos.org/address/%s", address), nil
259+
case STELLAR:
260+
return fmt.Sprintf("https://stellar.expert/explorer/public/account/%s", address), nil
261+
case KCC:
262+
return fmt.Sprintf("https://explorer.kcc.io/address/%s", address), nil
263+
case AURORA:
264+
return fmt.Sprintf("https://aurorascan.dev/address/%s", address), nil
265+
case KAVAEVM:
266+
return fmt.Sprintf("https://explorer.kava.io/address/%s", address), nil
267+
case METER:
268+
return fmt.Sprintf("https://scan.meter.io/address/%s", address), nil
269+
case APTOS:
270+
return fmt.Sprintf("https://explorer.aptoslabs.com/account/%s?network=mainnet", address), nil
271+
case MOONBEAM:
272+
return fmt.Sprintf("https://moonscan.io/address/%s", address), nil
273+
case KLAYTN:
274+
return fmt.Sprintf("https://kaiascan.io/address/%s", address), nil
275+
case METIS:
276+
return fmt.Sprintf("https://andromeda-explorer.metis.io/address/%s", address), nil
277+
case MOONRIVER:
278+
return fmt.Sprintf("https://moonriver.moonscan.io/address/%s", address), nil
279+
case BOBA:
280+
return fmt.Sprintf("https://bobascan.com/address/%s", address), nil
281+
case TON:
282+
return fmt.Sprintf("https://tonscan.org/address/%s", address), nil
283+
case POLYGONZKEVM:
284+
return fmt.Sprintf("https://explorer.public.zkevm-test.net/address/%s", address), nil
285+
case ZKSYNC:
286+
return fmt.Sprintf("https://explorer.zksync.io/address/%s", address), nil
287+
case SUI:
288+
return fmt.Sprintf("https://explorer.sui.io/address/%s", address), nil
289+
case STRIDE:
290+
return fmt.Sprintf("https://www.mintscan.io/stride/account/%s", address), nil
291+
case NEUTRON:
292+
return fmt.Sprintf("https://www.mintscan.io/neutron/account/%s", address), nil
293+
case IOTEXEVM:
294+
return fmt.Sprintf("https://iotexscan.io/address/%s#transactions", address), nil
295+
case CRYPTOORG:
296+
return fmt.Sprintf("https://crypto.org/explorer/account/%s", address), nil
297+
case TEZOS:
298+
return fmt.Sprintf("https://tzstats.com/%s", address), nil
299+
case CFXEVM:
300+
return fmt.Sprintf("https://evm.confluxscan.net/address/%s", address), nil
301+
case ACALA:
302+
return fmt.Sprintf("https://acala.subscan.io/account/%s", address), nil
303+
case ACALAEVM:
304+
return fmt.Sprintf("https://blockscout.acala.network/address/%s", address), nil
305+
case BASE:
306+
return fmt.Sprintf("https://basescan.org/address/%s", address), nil
307+
case CARDANO:
308+
return fmt.Sprintf("https://cexplorer.io/address/%s", address), nil
309+
case NEON:
310+
return fmt.Sprintf("https://neonscan.org/address/%s", address), nil
311+
case MANTLE:
312+
return fmt.Sprintf("https://explorer.mantle.xyz/address/%s", address), nil
313+
case LINEA:
314+
return fmt.Sprintf("https://explorer.linea.build/address/%s", address), nil
315+
case OPBNB:
316+
return fmt.Sprintf("https://opbnbscan.com/address/%s", address), nil
317+
case MANTA:
318+
return fmt.Sprintf("https://pacific-explorer.manta.network/address/%s", address), nil
319+
case ZETACHAIN:
320+
return fmt.Sprintf("https://explorer.zetachain.com/address/%s", address), nil
321+
case ZETAEVM:
322+
return fmt.Sprintf("https://explorer.zetachain.com/address/%s", address), nil
323+
case BLAST:
324+
return fmt.Sprintf("https://blastscan.io/address/%s", address), nil
325+
case SCROLL:
326+
return fmt.Sprintf("https://scrollscan.com/address/%s", address), nil
327+
case ZKLINKNOVA:
328+
return fmt.Sprintf("https://explorer.zklink.io/address/%s", address), nil
329+
case RIPPLE:
330+
return fmt.Sprintf("https://xrpscan.com/account/%s", address), nil
331+
case SONIC:
332+
return fmt.Sprintf("https://sonicscan.org/address/%s", address), nil
333+
case TIA:
334+
return "https://www.mintscan.io/celestia", nil
335+
case DYDX:
336+
return "https://www.mintscan.io/dydx", nil
337+
case PLASMA:
338+
return fmt.Sprintf("https://plasmascan.to/address/%s", address), nil
339+
}
340+
341+
return "", errors.New("no explorer for coin: " + c.Handle)
342+
}

coin/models_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,70 @@ func TestGetCoinExploreURL(t *testing.T) {
492492
}
493493
}
494494

495+
func TestGetAddressExploreURL(t *testing.T) {
496+
type args struct {
497+
addr string
498+
chain Coin
499+
}
500+
501+
tests := []struct {
502+
name string
503+
args args
504+
want string
505+
wantErr bool
506+
}{
507+
{
508+
name: "Test Ethereum",
509+
args: args{
510+
addr: "0x90adE3B7065fa715c7a150313877dF1d33e777D5",
511+
chain: Ethereum(),
512+
},
513+
want: "https://etherscan.io/address/0x90adE3B7065fa715c7a150313877dF1d33e777D5",
514+
wantErr: false,
515+
},
516+
{
517+
name: "Test BSC",
518+
args: args{
519+
addr: "0x90adE3B7065fa715c7a150313877dF1d33e777D5",
520+
chain: Smartchain(),
521+
},
522+
want: "https://bscscan.com/address/0x90adE3B7065fa715c7a150313877dF1d33e777D5",
523+
wantErr: false,
524+
},
525+
{
526+
name: "Test BASE",
527+
args: args{
528+
addr: "0x90adE3B7065fa715c7a150313877dF1d33e777D5",
529+
chain: Base(),
530+
},
531+
want: "https://basescan.org/address/0x90adE3B7065fa715c7a150313877dF1d33e777D5",
532+
wantErr: false,
533+
},
534+
{
535+
name: "Test TRON",
536+
args: args{
537+
addr: "TKXVRaBsughUd1ZqqUQCs4dudMcg5BjUsa",
538+
chain: Tron(),
539+
},
540+
want: "https://tronscan.io/#/address/TKXVRaBsughUd1ZqqUQCs4dudMcg5BjUsa",
541+
wantErr: false,
542+
},
543+
}
544+
545+
for _, tt := range tests {
546+
t.Run(tt.name, func(t *testing.T) {
547+
got, err := GetAddressExploreURL(tt.args.chain, tt.args.addr)
548+
if (err != nil) != tt.wantErr {
549+
t.Errorf("GetCoinForId() error = %v, wantErr %v", err, tt.wantErr)
550+
return
551+
}
552+
if !reflect.DeepEqual(got, tt.want) {
553+
t.Errorf("GetCoinForId() got = %v, want %v", got, tt.want)
554+
}
555+
})
556+
}
557+
}
558+
495559
var evmCoinsTestSet = map[uint]struct{}{
496560
ETHEREUM: {},
497561
CLASSIC: {},

0 commit comments

Comments
 (0)