|
|
@ -12,15 +12,17 @@ import ( |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/accounts" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/accounts/keystore" |
|
|
|
"github.com/harmony-one/harmony/api/client" |
|
|
|
"github.com/harmony-one/harmony/api/client" |
|
|
|
clientService "github.com/harmony-one/harmony/api/client/service" |
|
|
|
clientService "github.com/harmony-one/harmony/api/client/service" |
|
|
|
proto_node "github.com/harmony-one/harmony/api/proto/node" |
|
|
|
proto_node "github.com/harmony-one/harmony/api/proto/node" |
|
|
|
"github.com/harmony-one/harmony/common/denominations" |
|
|
|
"github.com/harmony-one/harmony/common/denominations" |
|
|
|
"github.com/harmony-one/harmony/core" |
|
|
|
"github.com/harmony-one/harmony/core" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
|
|
|
|
common2 "github.com/harmony-one/harmony/internal/common" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
"github.com/harmony-one/harmony/internal/ctxerror" |
|
|
|
"github.com/harmony-one/harmony/internal/ctxerror" |
|
|
|
"github.com/harmony-one/harmony/internal/shardchain" |
|
|
|
"github.com/harmony-one/harmony/internal/shardchain" |
|
|
@ -29,9 +31,6 @@ import ( |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
p2p_host "github.com/harmony-one/harmony/p2p/host" |
|
|
|
p2p_host "github.com/harmony-one/harmony/p2p/host" |
|
|
|
"github.com/harmony-one/harmony/p2p/p2pimpl" |
|
|
|
"github.com/harmony-one/harmony/p2p/p2pimpl" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/accounts" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/accounts/keystore" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -273,19 +272,19 @@ func processNewCommnad() { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Printf("new account error: %v\n", err) |
|
|
|
fmt.Printf("new account error: %v\n", err) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Printf("account: %s\n", account.Address.Hex()) |
|
|
|
fmt.Printf("account: %s\n", common2.MustAddressToBech32(account.Address)) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func _exportAccount(account accounts.Account) { |
|
|
|
func _exportAccount(account accounts.Account) { |
|
|
|
fmt.Printf("account: %s\n", account.Address.Hex()) |
|
|
|
fmt.Printf("account: %s\n", common2.MustAddressToBech32(account.Address)) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
pass := utils.AskForPassphrase("Original Passphrase: ") |
|
|
|
pass := utils.AskForPassphrase("Original Passphrase: ") |
|
|
|
newpass := utils.AskForPassphrase("Export Passphrase: ") |
|
|
|
newpass := utils.AskForPassphrase("Export Passphrase: ") |
|
|
|
|
|
|
|
|
|
|
|
data, err := ks.Export(account, pass, newpass) |
|
|
|
data, err := ks.Export(account, pass, newpass) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
filename := fmt.Sprintf(".hmy/%s.key", account.Address.Hex()) |
|
|
|
filename := fmt.Sprintf(".hmy/%s.key", common2.MustAddressToBech32(account.Address)) |
|
|
|
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0644) |
|
|
|
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0644) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
panic("Failed to open keystore") |
|
|
|
panic("Failed to open keystore") |
|
|
@ -317,7 +316,7 @@ func processListCommand() { |
|
|
|
|
|
|
|
|
|
|
|
allAccounts := ks.Accounts() |
|
|
|
allAccounts := ks.Accounts() |
|
|
|
for _, account := range allAccounts { |
|
|
|
for _, account := range allAccounts { |
|
|
|
fmt.Printf("account: %s\n", account.Address.Hex()) |
|
|
|
fmt.Printf("account: %s\n", common2.MustAddressToBech32(account.Address)) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
fmt.Printf("URL: %s\n", account.URL) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -331,7 +330,7 @@ func processExportCommand() { |
|
|
|
|
|
|
|
|
|
|
|
allAccounts := ks.Accounts() |
|
|
|
allAccounts := ks.Accounts() |
|
|
|
for _, account := range allAccounts { |
|
|
|
for _, account := range allAccounts { |
|
|
|
if acc == "" || acc == account.Address.Hex() { |
|
|
|
if acc == "" || acc == common2.MustAddressToBech32(account.Address) { |
|
|
|
_exportAccount(account) |
|
|
|
_exportAccount(account) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -361,7 +360,7 @@ func processImportCommnad() { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
panic("Failed to import the private key") |
|
|
|
panic("Failed to import the private key") |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Printf("Private key imported for account: %s\n", account.Address.Hex()) |
|
|
|
fmt.Printf("Private key imported for account: %s\n", common2.MustAddressToBech32(account.Address)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func processBalancesCommand() { |
|
|
|
func processBalancesCommand() { |
|
|
@ -374,14 +373,14 @@ func processBalancesCommand() { |
|
|
|
allAccounts := ks.Accounts() |
|
|
|
allAccounts := ks.Accounts() |
|
|
|
for i, account := range allAccounts { |
|
|
|
for i, account := range allAccounts { |
|
|
|
fmt.Printf("Account %d:\n", i) |
|
|
|
fmt.Printf("Account %d:\n", i) |
|
|
|
fmt.Printf(" Address: %s\n", account.Address.Hex()) |
|
|
|
fmt.Printf(" Address: %s\n", common2.MustAddressToBech32(account.Address)) |
|
|
|
for shardID, balanceNonce := range FetchBalance(account.Address) { |
|
|
|
for shardID, balanceNonce := range FetchBalance(account.Address) { |
|
|
|
fmt.Printf(" Balance in Shard %d: %s, nonce: %v \n", shardID, convertBalanceIntoReadableFormat(balanceNonce.balance), balanceNonce.nonce) |
|
|
|
fmt.Printf(" Balance in Shard %d: %s, nonce: %v \n", shardID, convertBalanceIntoReadableFormat(balanceNonce.balance), balanceNonce.nonce) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
address := common.HexToAddress(*balanceAddressPtr) |
|
|
|
address := common2.ParseAddr(*balanceAddressPtr) |
|
|
|
fmt.Printf("Account: %s:\n", address.Hex()) |
|
|
|
fmt.Printf("Account: %s:\n", common2.MustAddressToBech32(address)) |
|
|
|
for shardID, balanceNonce := range FetchBalance(address) { |
|
|
|
for shardID, balanceNonce := range FetchBalance(address) { |
|
|
|
fmt.Printf(" Balance in Shard %d: %s, nonce: %v \n", shardID, convertBalanceIntoReadableFormat(balanceNonce.balance), balanceNonce.nonce) |
|
|
|
fmt.Printf(" Balance in Shard %d: %s, nonce: %v \n", shardID, convertBalanceIntoReadableFormat(balanceNonce.balance), balanceNonce.nonce) |
|
|
|
} |
|
|
|
} |
|
|
@ -397,7 +396,7 @@ func processGetFreeToken() { |
|
|
|
if *freeTokenAddressPtr == "" { |
|
|
|
if *freeTokenAddressPtr == "" { |
|
|
|
fmt.Println("Error: --address is required") |
|
|
|
fmt.Println("Error: --address is required") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
address := common.HexToAddress(*freeTokenAddressPtr) |
|
|
|
address := common2.ParseAddr(*freeTokenAddressPtr) |
|
|
|
GetFreeToken(address) |
|
|
|
GetFreeToken(address) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -430,13 +429,13 @@ func processTransferCommand() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
receiverAddress := common.HexToAddress(receiver) |
|
|
|
receiverAddress := common2.ParseAddr(receiver) |
|
|
|
if len(receiverAddress) != 20 { |
|
|
|
if len(receiverAddress) != 20 { |
|
|
|
fmt.Println("The receiver address is not valid.") |
|
|
|
fmt.Println("The receiver address is not valid.") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
senderAddress := common.HexToAddress(sender) |
|
|
|
senderAddress := common2.ParseAddr(sender) |
|
|
|
if len(senderAddress) != 20 { |
|
|
|
if len(senderAddress) != 20 { |
|
|
|
fmt.Println("The sender address is not valid.") |
|
|
|
fmt.Println("The sender address is not valid.") |
|
|
|
return |
|
|
|
return |
|
|
|