Browse Source

Merge pull request #124 from tendermint/new_contract_address

move NewContractAddress to types and use ripemd160
pull/130/head
Jae Kwon 9 years ago
parent
commit
37c68e838e
3 changed files with 18 additions and 7 deletions
  1. +4
    -1
      config/tendermint/config.go
  2. +2
    -5
      state/tx_cache.go
  3. +12
    -1
      types/tx.go

+ 4
- 1
config/tendermint/config.go View File

@ -58,7 +58,10 @@ func GetConfig(rootDir string) cfg.Config {
Exit("Cannot set 'version' via config.toml") Exit("Cannot set 'version' via config.toml")
} }
mapConfig.SetDefault("chain_id", "tendermint_testnet_9") mapConfig.SetDefault("chain_id", "tendermint_testnet_9")
mapConfig.SetDefault("version", "0.5.0") // JAE: encrypted p2p!
// Major: alpha
// Minor: encrypted p2p!
// Revision: ripemd for NewContractAddress
mapConfig.SetDefault("version", "0.5.1")
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
mapConfig.SetDefault("moniker", "anonymous") mapConfig.SetDefault("moniker", "anonymous")
mapConfig.SetDefault("node_laddr", "0.0.0.0:46656") mapConfig.SetDefault("node_laddr", "0.0.0.0:46656")


+ 2
- 5
state/tx_cache.go View File

@ -4,8 +4,8 @@ import (
acm "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ... ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ...
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/vm" "github.com/tendermint/tendermint/vm"
"github.com/tendermint/tendermint/vm/sha3"
) )
type TxCache struct { type TxCache struct {
@ -146,10 +146,7 @@ func (cache *TxCache) AddLog(log *vm.Log) {
// Convenience function to return address of new contract // Convenience function to return address of new contract
func NewContractAddress(caller []byte, nonce int) []byte { func NewContractAddress(caller []byte, nonce int) []byte {
temp := make([]byte, 32+8)
copy(temp, caller)
PutInt64BE(temp[32:], int64(nonce))
return sha3.Sha3(temp)[:20]
return types.NewContractAddress(caller, nonce)
} }
// Converts backend.Account to vm.Account struct. // Converts backend.Account to vm.Account struct.


+ 12
- 1
types/tx.go View File

@ -5,10 +5,12 @@ import (
"errors" "errors"
"io" "io"
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
acm "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/wire"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
ptypes "github.com/tendermint/tendermint/permission/types" ptypes "github.com/tendermint/tendermint/permission/types"
"github.com/tendermint/tendermint/wire"
) )
var ( var (
@ -189,6 +191,15 @@ func (tx *CallTx) String() string {
return Fmt("CallTx{%v -> %x: %x}", tx.Input, tx.Address, tx.Data) return Fmt("CallTx{%v -> %x: %x}", tx.Input, tx.Address, tx.Data)
} }
func NewContractAddress(caller []byte, nonce int) []byte {
temp := make([]byte, 32+8)
copy(temp, caller)
PutInt64BE(temp[32:], int64(nonce))
hasher := ripemd160.New()
hasher.Write(temp) // does not error
return hasher.Sum(nil)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type NameTx struct { type NameTx struct {


Loading…
Cancel
Save