Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: ed25519: bad private key length: 128 #11

Open
jsrj78 opened this issue Jul 27, 2019 · 5 comments
Open

panic: ed25519: bad private key length: 128 #11

jsrj78 opened this issue Jul 27, 2019 · 5 comments

Comments

@jsrj78
Copy link

jsrj78 commented Jul 27, 2019

Hi, Ibraheem Bello
When I run transfer coins example. I got error "panic: ed25519: bad private key length: 128".
Can you help me!

Thanks a lot of

@codemaveric
Copy link
Owner

Hi @jsrj78,

Can I see what you are doing? paste your code here

@codemaveric
Copy link
Owner

Hi @jsrj78,

This issue has been resolved with my latest push. there was a problem with the way I was decoding the secret key value. Please lemme know if you still have the same issue.

My Bad I didnt read your comment carefully to understand the issue the first time.

@jsrj78
Copy link
Author

jsrj78 commented Jul 29, 2019

Hi, Ibraheem Bello
I have appreciated it. The bug is fixed. But when I run my code. A source account balance is 5000000.After transfer 1000000 from source account to the destination account. I think final source account balance is 4000000 and destination account is 1000000, But I got source account balance is 5000000 and destination account is 1000000000. Can you help me?

code:

func main() {
// Change the mnemonic to something else,
// or you will get address used by others.
mnemonic := "presentx good satochit coin future media giant"
wallet := librawallet.NewWalletLibrary(mnemonic)

// create a new address
address1, childNum, err := wallet.NewAddress()
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Source Account Address: %s\n", address1.ToString())

// Create account  with mnemonic and childNum
sourceAccount, err := librawallet.NewAccount(mnemonic, childNum)
if err != nil {
	log.Fatal(err)
}
// If you have your secrey key you can create account from it.
// secreyKey := "hex string of secret key here"
// sourceAccount, err := librawallet.NewAccountFromSecret(secretKey)

// Libra Client Configuration
config := goclient.LibraClientConfig{
	Host:    "ac.testnet.libra.org",
	Port:    "80",
	Network: goclient.TestNet,
}
// Instantiate LibraClient with Configuration
libraClient := goclient.NewLibraClient(config)

// Mint Coin from Test Faucet to account generated.
err = libraClient.MintWithFaucetService(sourceAccount.Address.ToString(), 5000000, true)

if err != nil {
	log.Fatal(err)
}
// Get Account State.
SourceaccState, err := libraClient.GetAccountState(sourceAccount.Address.ToString())
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Source Account Balance: %s\n", SourceaccState.Balance)

// Set the current account sequence.
sourceAccount.Sequence = SourceaccState.SequenceNumber

// Amount in Micro-Libra
var amount uint64 = 1000000
destinationAddress := "f4aebe371e4176143c3409122d0adf43c0e00a6552b5b0ae9980d8981fcd0221"

// Note: Make sure the current source account sequence is set
// Get the Account State and Set the current account sequence.
// Transfer Coins from source account to destination address.
err = libraClient.TransferCoins(sourceAccount, destinationAddress, amount, 0, 10000, true)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Transfer %d coins from %x to %s", amount, sourceAccount.Address, destinationAddress)

DestinationaccState, err := libraClient.GetAccountState(destinationAddress)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Source Account Balance: %s\n", SourceaccState.Balance)

fmt.Printf("Destination Account Balance: %s\n", DestinationaccState.Balance)

}

@codemaveric
Copy link
Owner

Hi @jsrj78,

Sorry, am responding late. I have been away for some days.

I dont think you have any issue.

  1. For SourceaccState, I can see you not getting the new account state after calling TransferCoins, thats why you still getting the previous balance of 5000000
  2. For the destination account, pretty sure alot of other people are using that same account for test. So you neccessarily wont get the balance you are expecting because someone else may have transferred money to that account. You can generate a new destination address

@jsrj78
Copy link
Author

jsrj78 commented Aug 2, 2019

Hi codemaveric,
Thanks your reply.I add GetAccountState after transferCoins.But Balance also not change.Can you help me? List my code:

func main() {
// Change the mnemonic to something else,
// or you will get address used by others.
mnemonic := "presentx goodxd satochit coinu futuree media gianto"
wallet := librawallet.NewWalletLibrary(mnemonic)

// create a new address
address1, childNum, err := wallet.NewAddress()
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Source Account Address: %s\n", address1.ToString())

// Create account  with mnemonic and childNum
sourceAccount, err := librawallet.NewAccount(mnemonic, childNum)
if err != nil {
	log.Fatal(err)
}

address2, childNum2, err := wallet.NewAddress()
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Destination Account Address: %s\n", address2.ToString())
destinationAccount, err := librawallet.NewAccount(mnemonic, childNum2)

// If you have your secrey key you can create account from it.
// secreyKey := "hex string of secret key here"
// sourceAccount, err := librawallet.NewAccountFromSecret(secretKey)

// Libra Client Configuration
config := goclient.LibraClientConfig{
	Host:    "ac.testnet.libra.org",
	Port:    "80",
	Network: goclient.TestNet,
}
// Instantiate LibraClient with Configuration
libraClient := goclient.NewLibraClient(config)

// Mint Coin from Test Faucet to account generated.
err = libraClient.MintWithFaucetService(sourceAccount.Address.ToString(), 500000000, true)

if err != nil {
	log.Fatal(err)
}
// Get Account State.
SourceaccState, err := libraClient.GetAccountState(sourceAccount.Address.ToString())
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Source Account Balance: %s\n", SourceaccState.Balance)

// Set the current account sequence.
sourceAccount.Sequence = SourceaccState.SequenceNumber
fmt.Printf("Source Account Balance: %s\n", SourceaccState.SequenceNumber)

// Amount in Micro-Libra

//DestinationState, err := libraClient.GetAccountState(destinationAccount.Address.ToString())

//fmt.Printf("Destination Account Balance: %s\n", DestinationState.Balance)
var amount uint64 = 100000000
destinationAddress := destinationAccount.Address.ToString()

// Note: Make sure the current source account sequence is set
// Get the Account State and Set the current account sequence.
// Transfer Coins from source account to destination address.
err = libraClient.TransferCoins(sourceAccount, destinationAddress, amount, 0, 10000, true)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Transfer %d coins from %x to %s", amount, sourceAccount.Address, destinationAddress)

SourceaccState, err = libraClient.GetAccountState(sourceAccount.Address.ToString())
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Source Account Balance: %s\n", SourceaccState.Balance)

DestinationaccState, err := libraClient.GetAccountState(destinationAddress)
if err != nil {
	log.Fatal(err)
}
//fmt.Printf("Source Account Balance: %s\n", SourceaccState.Balance)

fmt.Printf("Destination Account Balance: %s\n", DestinationaccState.Balance)

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants