Skip to content

Commit

Permalink
update the local accountcreat with seed input to align with the cosmos
Browse files Browse the repository at this point in the history
wallet practise
  • Loading branch information
ewagmig authored and tedyyan committed Feb 15, 2019
1 parent 0ef3f2f commit 5b63494
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
62 changes: 62 additions & 0 deletions slim/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
// Bech32 prefixes
//Bech32PrefixAccPub = "cosmosaccpub"
AccountResultType = "local"
Denomtype = "qos"
)

func AccountCreate(password string) *ResultCreateAccount {
Expand Down Expand Up @@ -171,3 +172,64 @@ func PubAddrRetrievalStr(s string) string {
out := string(resp)
return out
}

//new account result with field of Denom
type AccountKeyOut struct {
PubKey string `json:"pubKey"`
PrivKey string `json:"privKey"`
Addr string `json:"addr"`
Mnemonic string `json:"mnemonic"`
Type string `json:"type"`
Denom string `json:"denom"`
}

//add new function for Account Creation with seed input
func AccountCreateFromSeed(mncode string) string {
// add mnemonics validation
if bip39local.IsMnemonicValid(mncode) == false {
err := errors.Errorf("Invalid mnemonic!")
resp, _ := respwrap.ResponseWrapper(Cdc, nil, err)
return string(resp)

}

var defaultBIP39Passphrase = ""
seed := bip39local.NewSeed(mncode, defaultBIP39Passphrase)
key := ed25519local.GenPrivKeyFromSecret(seed)
pub := key.PubKey()
pubkeyAmino, _ := Cdc.MarshalJSON(pub)
var pubkeyAminoStc PubkeyAmino
err := Cdc.UnmarshalJSON(pubkeyAmino, &pubkeyAminoStc)
if err != nil {
log.Fatalln(err.Error())
}
pubkeyAminoStr := pubkeyAminoStc.Value

addr := key.PubKey().Address()
//bech32Pub, _ := bech32local.ConvertAndEncode("cosmosaccpub", pub)
bech32Addr, _ := bech32local.ConvertAndEncode(PREF_ADD, addr.Bytes())

privkeyAmino, _ := Cdc.MarshalJSON(key)
var privkeyAminoStc PrivkeyAmino
err1 := Cdc.UnmarshalJSON(privkeyAmino, &privkeyAminoStc)
if err1 != nil {
log.Fatalln(err1.Error())
}
privkeyAminoStr := privkeyAminoStc.Value

Type := AccountResultType
Denom := Denomtype

result := &AccountKeyOut{}
result.PubKey = pubkeyAminoStr
result.PrivKey = privkeyAminoStr
result.Addr = bech32Addr
result.Mnemonic = mncode
result.Type = Type
result.Denom = Denom

resp, _ := respwrap.ResponseWrapper(Cdc, result, nil)
out := string(resp)
return out

}
6 changes: 6 additions & 0 deletions slim/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ func TestPubAddrRetrievalStr(t *testing.T) {
output := PubAddrRetrievalStr(s)
t.Log(output)
}

func TestAccountCreateFromSeed(t *testing.T) {
mncode := "oyster leave weird tiger road rose anger garden planet price small rain cradle rhythm wine spider manual wave plastic solar spray battle parent match"
output := AccountCreateFromSeed(mncode)
t.Log(output)
}
5 changes: 5 additions & 0 deletions slim/starsdkapp/starsdkapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ func AccountCreate(password string) string {
return output
}

func AccountCreateFromSeed(mncode string) string {
output := slim.AccountCreateFromSeed(mncode)
return output
}

//for QSCKVStoreset
func QSCKVStoreSet(k, v, privkey, chain string) string {
output := slim.QSCKVStoreSetPost(k, v, privkey, chain)
Expand Down
4 changes: 3 additions & 1 deletion stub/java/Aninterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ func main() {
//newout := NewArticle("address13mjc3n3xxj73dhkju9a0dfr4lrfvv3whxqg0dy", "address1zsqzn6wdecyar6c6nzem3e8qss2ws95csr8d0r", "a123", "20", "20", "20", "20", "20", "3")
//fmt.Println(newout)

//slim.SetBlockchainEntrance("192.168.1.223:1317", "192.168.1.223:9527")
//slim.SetBlockchainEntrance("106.14.178.99:1317", "192.168.1.223:9527")
//ad := slim.JQInvestAd("qos-testapp", "qstars-test", "abcd", "1AOE", "Ey+2bNFF2gTUV6skSBgRy3rZwo9nS4Dw0l2WpLrhVvV8MuMRbjN4tUK8orHiJgHTR+enkxyXcA8giVrsrIRM4Q==")
//adout := slim.QOSQueryAccountGet("address1tnjwjpgzamk9ngefwz72x4ew8nlug6y068t6k7")
//fmt.Println(adout)
//var ri ResultInvest
//err := json.Unmarshal([]byte(ad), &ri)
//fmt.Printf("error is:%s\n ", err)
Expand Down

0 comments on commit 5b63494

Please sign in to comment.