Skip to content

Commit

Permalink
feat: account vanity generator
Browse files Browse the repository at this point in the history
chore: chain broadcast unittest
  • Loading branch information
randomshinichi committed Apr 1, 2019
1 parent b9dd2f3 commit 3b5c5bd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
package cmd

import (
"fmt"
"regexp"
"runtime"
"sync"

"github.com/aeternity/aepp-sdk-go/aeternity"
"github.com/aeternity/aepp-sdk-go/utils"

Expand Down Expand Up @@ -200,13 +205,49 @@ func saveFunc(cmd *cobra.Command, args []string) (err error) {
return nil
}

var vanityCmd = &cobra.Command{
Use: "vanity",
Short: "find the account you like",
Long: ``,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

prefix := fmt.Sprintf("^%s", args[0])
r, err := regexp.Compile(prefix)
if err != nil {
fmt.Println("Ouch! The search input ", prefix, "is not a valid regexp")
return
}
fmt.Println("The search for your account matching", prefix, "has begun")

var wg sync.WaitGroup
wg.Add(runtime.NumCPU())
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
for {
a, _ := aeternity.NewAccount()

if r.MatchString(a.Address[3:]) {
fmt.Println("FOUND!")
fmt.Println("Secret: ", a.SigningKeyToHexString())
fmt.Println("Address", a.Address)
}
}
}()
}
wg.Wait()

},
}

func init() {
RootCmd.AddCommand(accountCmd)
accountCmd.AddCommand(addressCmd)
accountCmd.AddCommand(createCmd)
accountCmd.AddCommand(saveCmd)
accountCmd.AddCommand(balanceCmd)
accountCmd.AddCommand(signCmd)
accountCmd.AddCommand(vanityCmd)
accountCmd.PersistentFlags().StringVar(&password, "password", "", "Read account password from stdin [WARN: this method is not secure]")
// account address flags
addressCmd.Flags().BoolVar(&printPrivateKey, "private-key", false, "Print the private key as hex string")
Expand Down
9 changes: 9 additions & 0 deletions cmd/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ func TestChainTop(t *testing.T) {
}
}

func TestChainBroadcast(t *testing.T) {
setConfigTestParams()
emptyCmd := cobra.Command{}
err := broadcastFunc(&emptyCmd, []string{"tx_+KgLAfhCuEAPX1l3BdFOcLeduH3PPwPV25mETXZE8IBDe6PGuasSEKJeB/cDDm+kW05Cdp38+mpvVSTTPMx7trL/7qxfUr8IuGD4XhYBoQHOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+8wGTcXVlcnkgU3BlY2lmaWNhdGlvbpZyZXNwb25zZSBTcGVjaWZpY2F0aW9uAABkhrXmIPSAAIIB9AHdGxXf"})
if err != nil {
t.Error(err)
}
}

func TestChainStatus(t *testing.T) {
setConfigTestParams()
emptyCmd := cobra.Command{}
Expand Down

0 comments on commit 3b5c5bd

Please sign in to comment.