Browse Source

genpriv from hash(secret), evc fix in ExecTx

pull/68/head
Ethan Buchman 9 years ago
parent
commit
7a97fb464d
2 changed files with 17 additions and 1 deletions
  1. +16
    -0
      account/priv_account.go
  2. +1
    -1
      state/execution.go

+ 16
- 0
account/priv_account.go View File

@ -2,6 +2,7 @@ package account
import (
"github.com/tendermint/ed25519"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
)
@ -25,6 +26,21 @@ func GenPrivAccount() *PrivAccount {
}
}
// Generates a new account with private key from SHA256 hash of a secret
func GenPrivAccountFromSecret(secret []byte) *PrivAccount {
privKey32 := binary.BinarySha256(secret)
privKeyBytes := new([64]byte)
copy(privKeyBytes[:32], privKey32)
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
pubKey := PubKeyEd25519(pubKeyBytes[:])
privKey := PrivKeyEd25519(privKeyBytes[:])
return &PrivAccount{
Address: pubKey.Address(),
PubKey: pubKey,
PrivKey: privKey,
}
}
func GenPrivAccountFromKey(privKeyBytes [64]byte) *PrivAccount {
pubKeyBytes := ed25519.MakePublicKey(&privKeyBytes)
pubKey := PubKeyEd25519(pubKeyBytes[:])


+ 1
- 1
state/execution.go View File

@ -434,7 +434,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
txCache.UpdateAccount(caller) // because we adjusted by input above, and bumped nonce maybe.
txCache.UpdateAccount(callee) // because we adjusted by input above.
vmach := vm.NewVM(txCache, params, caller.Address, account.HashSignBytes(tx))
vmach.SetFireable(_s.evc)
vmach.SetFireable(evc)
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
ret, err := vmach.Call(caller, callee, code, tx.Data, value, &gas)


Loading…
Cancel
Save