Merge pull request #115 from tendermint/sconn_jae

Sconn jae
This commit is contained in:
ebuchman 2015-07-19 13:27:09 -04:00
commit c6841e8499
30 changed files with 254 additions and 266 deletions

View File

@ -27,6 +27,8 @@ build_race:
go build -race -o build/logjack github.com/tendermint/tendermint/cmd/logjack go build -race -o build/logjack github.com/tendermint/tendermint/cmd/logjack
test: build test: build
-rm -rf ~/.tendermint_test_bak
-mv ~/.tendermint_test ~/.tendermint_test_bak
go test github.com/tendermint/tendermint/... go test github.com/tendermint/tendermint/...
draw_deps: draw_deps:

View File

@ -2,7 +2,6 @@ package account
import ( import (
"bytes" "bytes"
"errors"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519" "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
@ -12,7 +11,6 @@ import (
// PubKey is part of Account and Validator. // PubKey is part of Account and Validator.
type PubKey interface { type PubKey interface {
IsNil() bool
Address() []byte Address() []byte
VerifyBytes(msg []byte, sig Signature) bool VerifyBytes(msg []byte, sig Signature) bool
} }
@ -33,8 +31,6 @@ var _ = binary.RegisterInterface(
// Implements PubKey // Implements PubKey
type PubKeyEd25519 [32]byte type PubKeyEd25519 [32]byte
func (pubKey PubKeyEd25519) IsNil() bool { return false }
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.) // TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) } func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) }
@ -60,14 +56,6 @@ func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte {
return keyCurve25519 return keyCurve25519
} }
// redundant: compiler does it for us
func (pubKey PubKeyEd25519) ValidateBasic() error {
if len(pubKey) != ed25519.PublicKeySize {
return errors.New("Invalid PubKeyEd25519 key size")
}
return nil
}
func (pubKey PubKeyEd25519) String() string { func (pubKey PubKeyEd25519) String() string {
return Fmt("PubKeyEd25519{%X}", pubKey[:]) return Fmt("PubKeyEd25519{%X}", pubKey[:])
} }

View File

@ -9,6 +9,8 @@ import (
// Signature is a part of Txs and consensus Votes. // Signature is a part of Txs and consensus Votes.
type Signature interface { type Signature interface {
IsZero() bool
String() string
} }
// Types of Signature implementations // Types of Signature implementations
@ -27,8 +29,6 @@ var _ = binary.RegisterInterface(
// Implements Signature // Implements Signature
type SignatureEd25519 [64]byte type SignatureEd25519 [64]byte
func (sig SignatureEd25519) IsNil() bool { return false }
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 } func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) } func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }

View File

@ -670,7 +670,6 @@ func readReflectJSON(rv reflect.Value, rt reflect.Type, o interface{}, err *erro
return return
} }
log.Debug("Read bytearray", "bytes", buf) log.Debug("Read bytearray", "bytes", buf)
reflect.Copy(rv, reflect.ValueOf(buf)) reflect.Copy(rv, reflect.ValueOf(buf))
} else { } else {
oSlice, ok := o.([]interface{}) oSlice, ok := o.([]interface{})

View File

@ -16,40 +16,6 @@ type SimpleStruct struct {
Time time.Time Time time.Time
} }
type SimpleArray [5]byte
func TestSimpleArray(t *testing.T) {
var foo SimpleArray
// Type of pointer to array
rt := reflect.TypeOf(&foo)
fmt.Printf("rt: %v\n", rt)
// Type of array itself.
// NOTE: normally this is acquired through other means
// like introspecting on method signatures, or struct fields.
rte := rt.Elem()
fmt.Printf("rte: %v\n", rte)
// Get a new pointer to the array
// NOTE: calling .Interface() is to get the actual value,
// instead of reflection values.
ptr := reflect.New(rte).Interface()
fmt.Printf("ptr: %v", ptr)
// Make a simple int aray
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
fooBytes := BinaryBytes(fooArray)
fooReader := bytes.NewReader(fooBytes)
// Now you can read it.
n, err := new(int64), new(error)
it := ReadBinary(foo, fooReader, n, err)
fmt.Println(it, reflect.TypeOf(it))
}
//-------------------------------------
type Animal interface{} type Animal interface{}
const ( const (
@ -502,3 +468,40 @@ func TestBadAlloc(t *testing.T) {
res := ReadBinary(instance, b, n, err) res := ReadBinary(instance, b, n, err)
fmt.Println(res, *err) fmt.Println(res, *err)
} }
//------------------------------------------------------------------------------
type SimpleArray [5]byte
func TestSimpleArray(t *testing.T) {
var foo SimpleArray
// Type of pointer to array
rt := reflect.TypeOf(&foo)
fmt.Printf("rt: %v\n", rt) // *binary.SimpleArray
// Type of array itself.
// NOTE: normally this is acquired through other means
// like introspecting on method signatures, or struct fields.
rte := rt.Elem()
fmt.Printf("rte: %v\n", rte) // binary.SimpleArray
// Get a new pointer to the array
// NOTE: calling .Interface() is to get the actual value,
// instead of reflection values.
ptr := reflect.New(rte).Interface()
fmt.Printf("ptr: %v\n", ptr) // &[0 0 0 0 0]
// Make a simple int aray
fooArray := SimpleArray([5]byte{1, 10, 50, 100, 200})
fooBytes := BinaryBytes(fooArray)
fooReader := bytes.NewReader(fooBytes)
// Now you can read it.
n, err := new(int64), new(error)
it := ReadBinary(foo, fooReader, n, err).(SimpleArray)
if !bytes.Equal(it[:], fooArray[:]) {
t.Errorf("Expected %v but got %v", fooArray, it)
}
}

View File

@ -3,12 +3,12 @@ package main
import ( import (
"fmt" "fmt"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
) )
func gen_account() { func gen_account() {
privAccount := account.GenPrivAccount() privAccount := acm.GenPrivAccount()
privAccountJSONBytes := binary.JSONBytes(privAccount) privAccountJSONBytes := binary.JSONBytes(privAccount)
fmt.Printf(`Generated a new account! fmt.Printf(`Generated a new account!

View File

@ -8,7 +8,7 @@ import (
"os" "os"
"strconv" "strconv"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
@ -54,13 +54,13 @@ func gen_tx() {
// Get source pubkey // Get source pubkey
srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ") srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ")
r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error) r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error)
srcPubKey := binary.ReadBinary(struct{ account.PubKey }{}, r, n, err).(struct{ account.PubKey }).PubKey srcPubKey := binary.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey
if *err != nil { if *err != nil {
Exit(Fmt("Invalid PubKey. Error: %v", err)) Exit(Fmt("Invalid PubKey. Error: %v", err))
} }
// Get the state of the account. // Get the state of the account.
var srcAccount *account.Account var srcAccount *acm.Account
var srcAccountAddress = srcPubKey.Address() var srcAccountAddress = srcPubKey.Address()
var srcAccountBalanceStr = "unknown" var srcAccountBalanceStr = "unknown"
var srcAccountSequenceStr = "unknown" var srcAccountSequenceStr = "unknown"
@ -90,7 +90,7 @@ func gen_tx() {
Address: srcAddress, Address: srcAddress,
Amount: srcSendAmount, Amount: srcSendAmount,
Sequence: srcSendSequence, Sequence: srcSendSequence,
Signature: account.SignatureEd25519{}, Signature: acm.SignatureEd25519{},
PubKey: srcPubKey, PubKey: srcPubKey,
}, },
}, },
@ -108,12 +108,12 @@ func gen_tx() {
// Get source privkey (for signing) // Get source privkey (for signing)
srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ") srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ")
r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error) r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error)
srcPrivKey := binary.ReadBinary(struct{ account.PrivKey }{}, r, n, err).(struct{ account.PrivKey }).PrivKey srcPrivKey := binary.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey
if *err != nil { if *err != nil {
Exit(Fmt("Invalid PrivKey. Error: %v", err)) Exit(Fmt("Invalid PrivKey. Error: %v", err))
} }
// Sign // Sign
tx.Inputs[0].Signature = srcPrivKey.Sign(account.SignBytes(config.GetString("chain_id"), tx)) tx.Inputs[0].Signature = srcPrivKey.Sign(acm.SignBytes(config.GetString("chain_id"), tx))
fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx)) fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx))
} }

View File

@ -158,7 +158,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
bc "github.com/tendermint/tendermint/blockchain" bc "github.com/tendermint/tendermint/blockchain"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
@ -1011,7 +1011,7 @@ func (cs *ConsensusState) SetProposal(proposal *Proposal) error {
} }
// Verify signature // Verify signature
if !cs.Validators.Proposer().PubKey.VerifyBytes(account.SignBytes(cs.state.ChainID, proposal), proposal.Signature) { if !cs.Validators.Proposer().PubKey.VerifyBytes(acm.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
return ErrInvalidProposalSignature return ErrInvalidProposalSignature
} }

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -17,11 +17,11 @@ var (
) )
type Proposal struct { type Proposal struct {
Height int `json:"height"` Height int `json:"height"`
Round int `json:"round"` Round int `json:"round"`
BlockPartsHeader types.PartSetHeader `json:"block_parts_header"` BlockPartsHeader types.PartSetHeader `json:"block_parts_header"`
POLRound int `json:"pol_round"` // -1 if null. POLRound int `json:"pol_round"` // -1 if null.
Signature account.SignatureEd25519 `json:"signature"` Signature acm.SignatureEd25519 `json:"signature"`
} }
func NewProposal(height int, round int, blockPartsHeader types.PartSetHeader, polRound int) *Proposal { func NewProposal(height int, round int, blockPartsHeader types.PartSetHeader, polRound int) *Proposal {

View File

@ -3,7 +3,7 @@ package consensus
import ( import (
"testing" "testing"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
_ "github.com/tendermint/tendermint/config/tendermint_test" _ "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -16,7 +16,7 @@ func TestProposalSignable(t *testing.T) {
BlockPartsHeader: types.PartSetHeader{111, []byte("blockparts")}, BlockPartsHeader: types.PartSetHeader{111, []byte("blockparts")},
POLRound: -1, POLRound: -1,
} }
signBytes := account.SignBytes(config.GetString("chain_id"), proposal) signBytes := acm.SignBytes(config.GetString("chain_id"), proposal)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_round":-1,"round":23456}}`, expected := Fmt(`{"chain_id":"%s","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_round":-1,"round":23456}}`,

View File

@ -6,7 +6,7 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
@ -131,7 +131,7 @@ func (voteSet *VoteSet) addVote(val *sm.Validator, valIndex int, vote *types.Vot
} }
// Check signature. // Check signature.
if !val.PubKey.VerifyBytes(account.SignBytes(config.GetString("chain_id"), vote), vote.Signature) { if !val.PubKey.VerifyBytes(acm.SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
// Bad signature. // Bad signature.
return false, 0, types.ErrVoteInvalidSignature return false, 0, types.ErrVoteInvalidSignature
} }

View File

@ -2,7 +2,7 @@ package core
import ( import (
"fmt" "fmt"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state"
@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/vm" "github.com/tendermint/tendermint/vm"
) )
func toVMAccount(acc *account.Account) *vm.Account { func toVMAccount(acc *acm.Account) *vm.Account {
return &vm.Account{ return &vm.Account{
Address: LeftPadWord256(acc.Address), Address: LeftPadWord256(acc.Address),
Balance: acc.Balance, Balance: acc.Balance,
@ -78,7 +78,7 @@ func CallCode(code, data []byte) (*ctypes.ResponseCall, error) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) { func SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
// more checks? // more checks?
for i, privAccount := range privAccounts { for i, privAccount := range privAccounts {
@ -101,17 +101,17 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error)
bondTx := tx.(*types.BondTx) bondTx := tx.(*types.BondTx)
// the first privaccount corresponds to the BondTx pub key. // the first privaccount corresponds to the BondTx pub key.
// the rest to the inputs // the rest to the inputs
bondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), bondTx).(account.SignatureEd25519) bondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), bondTx).(acm.SignatureEd25519)
for i, input := range bondTx.Inputs { for i, input := range bondTx.Inputs {
input.PubKey = privAccounts[i+1].PubKey input.PubKey = privAccounts[i+1].PubKey
input.Signature = privAccounts[i+1].Sign(config.GetString("chain_id"), bondTx) input.Signature = privAccounts[i+1].Sign(config.GetString("chain_id"), bondTx)
} }
case *types.UnbondTx: case *types.UnbondTx:
unbondTx := tx.(*types.UnbondTx) unbondTx := tx.(*types.UnbondTx)
unbondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), unbondTx).(account.SignatureEd25519) unbondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), unbondTx).(acm.SignatureEd25519)
case *types.RebondTx: case *types.RebondTx:
rebondTx := tx.(*types.RebondTx) rebondTx := tx.(*types.RebondTx)
rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(account.SignatureEd25519) rebondTx.Signature = privAccounts[0].Sign(config.GetString("chain_id"), rebondTx).(acm.SignatureEd25519)
} }
return tx, nil return tx, nil
} }

View File

@ -1,7 +1,7 @@
package core_types package core_types
import ( import (
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -18,8 +18,8 @@ type ResponseCall struct {
} }
type ResponseListAccounts struct { type ResponseListAccounts struct {
BlockHeight int `json:"block_height"` BlockHeight int `json:"block_height"`
Accounts []*account.Account `json:"accounts"` Accounts []*acm.Account `json:"accounts"`
} }
type StorageItem struct { type StorageItem struct {
@ -51,7 +51,7 @@ type Receipt struct {
type ResponseStatus struct { type ResponseStatus struct {
NodeInfo *types.NodeInfo `json:"node_info"` NodeInfo *types.NodeInfo `json:"node_info"`
GenesisHash []byte `json:"genesis_hash"` GenesisHash []byte `json:"genesis_hash"`
PubKey account.PubKey `json:"pub_key"` PubKey acm.PubKey `json:"pub_key"`
LatestBlockHash []byte `json:"latest_block_hash"` LatestBlockHash []byte `json:"latest_block_hash"`
LatestBlockHeight int `json:"latest_block_height"` LatestBlockHeight int `json:"latest_block_height"`
LatestBlockTime int64 `json:"latest_block_time"` // nano LatestBlockTime int64 `json:"latest_block_time"` // nano

View File

@ -4,7 +4,6 @@ package core_client
import ( import (
"fmt" "fmt"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -33,7 +32,7 @@ type Client interface {
ListUnconfirmedTxs() ([]types.Tx, error) ListUnconfirmedTxs() ([]types.Tx, error)
ListValidators() (*ctypes.ResponseListValidators, error) ListValidators() (*ctypes.ResponseListValidators, error)
NetInfo() (*ctypes.ResponseNetInfo, error) NetInfo() (*ctypes.ResponseNetInfo, error)
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error)
Status() (*ctypes.ResponseStatus, error) Status() (*ctypes.ResponseStatus, error)
} }
@ -547,7 +546,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) { func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts) values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1066,7 +1065,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (types.Tx, error) { func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types.Tx, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
Method: reverseFuncMap["SignTx"], Method: reverseFuncMap["SignTx"],

View File

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
nm "github.com/tendermint/tendermint/node" nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
@ -37,11 +37,11 @@ var (
) )
// deterministic account generation, synced with genesis file in config/tendermint_test/config.go // deterministic account generation, synced with genesis file in config/tendermint_test/config.go
func makeUsers(n int) []*account.PrivAccount { func makeUsers(n int) []*acm.PrivAccount {
accounts := []*account.PrivAccount{} accounts := []*acm.PrivAccount{}
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
secret := []byte("mysecret" + strconv.Itoa(i)) secret := []byte("mysecret" + strconv.Itoa(i))
user := account.GenPrivAccountFromSecret(secret) user := acm.GenPrivAccountFromSecret(secret)
accounts = append(accounts, user) accounts = append(accounts, user)
} }
return accounts return accounts
@ -71,8 +71,8 @@ func init() {
// Save new priv_validator file. // Save new priv_validator file.
priv := &state.PrivValidator{ priv := &state.PrivValidator{
Address: user[0].Address, Address: user[0].Address,
PubKey: account.PubKeyEd25519(user[0].PubKey.(account.PubKeyEd25519)), PubKey: acm.PubKeyEd25519(user[0].PubKey.(acm.PubKeyEd25519)),
PrivKey: account.PrivKeyEd25519(user[0].PrivKey.(account.PrivKeyEd25519)), PrivKey: acm.PrivKeyEd25519(user[0].PrivKey.(acm.PrivKeyEd25519)),
} }
priv.SetFile(config.GetString("priv_validator_file")) priv.SetFile(config.GetString("priv_validator_file"))
priv.Save() priv.Save()
@ -133,7 +133,7 @@ func getNonce(t *testing.T, typ string, addr []byte) int {
} }
// get the account // get the account
func getAccount(t *testing.T, typ string, addr []byte) *account.Account { func getAccount(t *testing.T, typ string, addr []byte) *acm.Account {
client := clients[typ] client := clients[typ]
ac, err := client.GetAccount(addr) ac, err := client.GetAccount(addr)
if err != nil { if err != nil {
@ -143,9 +143,9 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account {
} }
// sign transaction // sign transaction
func signTx(t *testing.T, typ string, tx types.Tx, privAcc *account.PrivAccount) types.Tx { func signTx(t *testing.T, typ string, tx types.Tx, privAcc *acm.PrivAccount) types.Tx {
client := clients[typ] client := clients[typ]
signedTx, err := client.SignTx(tx, []*account.PrivAccount{privAcc}) signedTx, err := client.SignTx(tx, []*acm.PrivAccount{privAcc})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -219,12 +219,12 @@ func getNameRegEntry(t *testing.T, typ string, name string) *types.NameRegEntry
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// utility verification function // utility verification function
func checkTx(t *testing.T, fromAddr []byte, priv *account.PrivAccount, tx *types.SendTx) { func checkTx(t *testing.T, fromAddr []byte, priv *acm.PrivAccount, tx *types.SendTx) {
if bytes.Compare(tx.Inputs[0].Address, fromAddr) != 0 { if bytes.Compare(tx.Inputs[0].Address, fromAddr) != 0 {
t.Fatal("Tx input addresses don't match!") t.Fatal("Tx input addresses don't match!")
} }
signBytes := account.SignBytes(chainID, tx) signBytes := acm.SignBytes(chainID, tx)
in := tx.Inputs[0] //(*types.SendTx).Inputs[0] in := tx.Inputs[0] //(*types.SendTx).Inputs[0]
if err := in.ValidateBasic(); err != nil { if err := in.ValidateBasic(); err != nil {

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"sort" "sort"
ac "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
@ -48,7 +48,7 @@ func (cache *BlockCache) State() *State {
//------------------------------------- //-------------------------------------
// BlockCache.account // BlockCache.account
func (cache *BlockCache) GetAccount(addr []byte) *ac.Account { func (cache *BlockCache) GetAccount(addr []byte) *acm.Account {
acc, _, removed, _ := cache.accounts[string(addr)].unpack() acc, _, removed, _ := cache.accounts[string(addr)].unpack()
if removed { if removed {
return nil return nil
@ -61,7 +61,7 @@ func (cache *BlockCache) GetAccount(addr []byte) *ac.Account {
} }
} }
func (cache *BlockCache) UpdateAccount(acc *ac.Account) { func (cache *BlockCache) UpdateAccount(acc *acm.Account) {
addr := acc.Address addr := acc.Address
_, storage, removed, _ := cache.accounts[string(addr)].unpack() _, storage, removed, _ := cache.accounts[string(addr)].unpack()
// SANITY CHECK // SANITY CHECK
@ -178,7 +178,7 @@ func (cache *BlockCache) Sync() {
// Later we'll iterate over all the users and save storage + update storage root. // Later we'll iterate over all the users and save storage + update storage root.
var ( var (
curAddr Word256 curAddr Word256
curAcc *ac.Account curAcc *acm.Account
curAccRemoved bool curAccRemoved bool
curStorage merkle.Tree curStorage merkle.Tree
) )
@ -274,13 +274,13 @@ func (cache *BlockCache) Sync() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type accountInfo struct { type accountInfo struct {
account *ac.Account account *acm.Account
storage merkle.Tree storage merkle.Tree
removed bool removed bool
dirty bool dirty bool
} }
func (accInfo accountInfo) unpack() (*ac.Account, merkle.Tree, bool, bool) { func (accInfo accountInfo) unpack() (*acm.Account, merkle.Tree, bool, bool) {
return accInfo.account, accInfo.storage, accInfo.removed, accInfo.dirty return accInfo.account, accInfo.storage, accInfo.removed, accInfo.dirty
} }

View File

@ -1,13 +1,13 @@
package state package state
import ( import (
ac "github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/vm" "github.com/tendermint/tendermint/vm"
) )
type AccountGetter interface { type AccountGetter interface {
GetAccount(addr []byte) *ac.Account GetAccount(addr []byte) *acm.Account
} }
type VMAccountState interface { type VMAccountState interface {

View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/events" "github.com/tendermint/tendermint/events"
ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ... ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ...
@ -138,11 +138,11 @@ func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
} }
// The accounts from the TxInputs must either already have // The accounts from the TxInputs must either already have
// account.PubKey.(type) != nil, (it must be known), // acm.PubKey.(type) != nil, (it must be known),
// or it must be specified in the TxInput. If redeclared, // or it must be specified in the TxInput. If redeclared,
// the TxInput is modified and input.PubKey set to nil. // the TxInput is modified and input.PubKey set to nil.
func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*account.Account, error) { func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*acm.Account, error) {
accounts := map[string]*account.Account{} accounts := map[string]*acm.Account{}
for _, in := range ins { for _, in := range ins {
// Account shouldn't be duplicated // Account shouldn't be duplicated
if _, ok := accounts[string(in.Address)]; ok { if _, ok := accounts[string(in.Address)]; ok {
@ -161,9 +161,9 @@ func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*account.A
return accounts, nil return accounts, nil
} }
func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account, outs []*types.TxOutput) (map[string]*account.Account, error) { func getOrMakeOutputs(state AccountGetter, accounts map[string]*acm.Account, outs []*types.TxOutput) (map[string]*acm.Account, error) {
if accounts == nil { if accounts == nil {
accounts = make(map[string]*account.Account) accounts = make(map[string]*acm.Account)
} }
// we should err if an account is being created but the inputs don't have permission // we should err if an account is being created but the inputs don't have permission
@ -182,7 +182,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
} }
checkedCreatePerms = true checkedCreatePerms = true
} }
acc = &account.Account{ acc = &acm.Account{
Address: out.Address, Address: out.Address,
PubKey: nil, PubKey: nil,
Sequence: 0, Sequence: 0,
@ -195,7 +195,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
return accounts, nil return accounts, nil
} }
func checkInputPubKey(acc *account.Account, in *types.TxInput) error { func checkInputPubKey(acc *acm.Account, in *types.TxInput) error {
if acc.PubKey == nil { if acc.PubKey == nil {
if in.PubKey == nil { if in.PubKey == nil {
return types.ErrTxUnknownPubKey return types.ErrTxUnknownPubKey
@ -210,7 +210,7 @@ func checkInputPubKey(acc *account.Account, in *types.TxInput) error {
return nil return nil
} }
func validateInputs(accounts map[string]*account.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) { func validateInputs(accounts map[string]*acm.Account, signBytes []byte, ins []*types.TxInput) (total int64, err error) {
for _, in := range ins { for _, in := range ins {
acc := accounts[string(in.Address)] acc := accounts[string(in.Address)]
// SANITY CHECK // SANITY CHECK
@ -228,7 +228,7 @@ func validateInputs(accounts map[string]*account.Account, signBytes []byte, ins
return total, nil return total, nil
} }
func validateInput(acc *account.Account, signBytes []byte, in *types.TxInput) (err error) { func validateInput(acc *acm.Account, signBytes []byte, in *types.TxInput) (err error) {
// Check TxInput basic // Check TxInput basic
if err := in.ValidateBasic(); err != nil { if err := in.ValidateBasic(); err != nil {
return err return err
@ -263,7 +263,7 @@ func validateOutputs(outs []*types.TxOutput) (total int64, err error) {
return total, nil return total, nil
} }
func adjustByInputs(accounts map[string]*account.Account, ins []*types.TxInput) { func adjustByInputs(accounts map[string]*acm.Account, ins []*types.TxInput) {
for _, in := range ins { for _, in := range ins {
acc := accounts[string(in.Address)] acc := accounts[string(in.Address)]
// SANITY CHECK // SANITY CHECK
@ -279,7 +279,7 @@ func adjustByInputs(accounts map[string]*account.Account, ins []*types.TxInput)
} }
} }
func adjustByOutputs(accounts map[string]*account.Account, outs []*types.TxOutput) { func adjustByOutputs(accounts map[string]*acm.Account, outs []*types.TxOutput) {
for _, out := range outs { for _, out := range outs {
acc := accounts[string(out.Address)] acc := accounts[string(out.Address)]
// SANITY CHECK // SANITY CHECK
@ -319,7 +319,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return err return err
} }
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs) inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil { if err != nil {
return err return err
@ -354,7 +354,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return nil return nil
case *types.CallTx: case *types.CallTx:
var inAcc, outAcc *account.Account var inAcc, outAcc *acm.Account
// Validate input // Validate input
inAcc = blockCache.GetAccount(tx.Input.Address) inAcc = blockCache.GetAccount(tx.Input.Address)
@ -379,7 +379,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address)) log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
return err return err
} }
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input) err := validateInput(inAcc, signBytes, tx.Input)
if err != nil { if err != nil {
log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err)) log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
@ -433,7 +433,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
// check if its an snative // check if its an snative
if _, ok := vm.RegisteredSNativeContracts[LeftPadWord256(tx.Address)]; ok { if _, ok := vm.RegisteredSNativeContracts[LeftPadWord256(tx.Address)]; ok {
// set the outAcc (simply a placeholder until we reach the call) // set the outAcc (simply a placeholder until we reach the call)
outAcc = &account.Account{Address: tx.Address} outAcc = &acm.Account{Address: tx.Address}
} else { } else {
// if you call an account that doesn't exist // if you call an account that doesn't exist
// or an account with no code then we take fees (sorry pal) // or an account with no code then we take fees (sorry pal)
@ -511,7 +511,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return nil return nil
case *types.NameTx: case *types.NameTx:
var inAcc *account.Account var inAcc *acm.Account
// Validate input // Validate input
inAcc = blockCache.GetAccount(tx.Input.Address) inAcc = blockCache.GetAccount(tx.Input.Address)
@ -528,7 +528,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address)) log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address))
return err return err
} }
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input) err := validateInput(inAcc, signBytes, tx.Input)
if err != nil { if err != nil {
log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err)) log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
@ -661,14 +661,11 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return fmt.Errorf("At least one input lacks permission to bond") return fmt.Errorf("At least one input lacks permission to bond")
} }
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs) inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil { if err != nil {
return err return err
} }
if err := tx.PubKey.ValidateBasic(); err != nil {
return err
}
if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) { if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature return types.ErrTxInvalidSignature
} }
@ -720,7 +717,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
} }
// Verify the signature // Verify the signature
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) { if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature return types.ErrTxInvalidSignature
} }
@ -745,7 +742,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
} }
// Verify the signature // Verify the signature
signBytes := account.SignBytes(_s.ChainID, tx) signBytes := acm.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) { if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature return types.ErrTxInvalidSignature
} }
@ -774,8 +771,8 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return types.ErrTxInvalidAddress return types.ErrTxInvalidAddress
} }
} }
voteASignBytes := account.SignBytes(_s.ChainID, &tx.VoteA) voteASignBytes := acm.SignBytes(_s.ChainID, &tx.VoteA)
voteBSignBytes := account.SignBytes(_s.ChainID, &tx.VoteB) voteBSignBytes := acm.SignBytes(_s.ChainID, &tx.VoteB)
if !accused.PubKey.VerifyBytes(voteASignBytes, tx.VoteA.Signature) || if !accused.PubKey.VerifyBytes(voteASignBytes, tx.VoteA.Signature) ||
!accused.PubKey.VerifyBytes(voteBSignBytes, tx.VoteB.Signature) { !accused.PubKey.VerifyBytes(voteBSignBytes, tx.VoteB.Signature) {
return types.ErrTxInvalidSignature return types.ErrTxInvalidSignature
@ -814,7 +811,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
//--------------------------------------------------------------- //---------------------------------------------------------------
// Get permission on an account or fall back to global value // Get permission on an account or fall back to global value
func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFlag) bool { func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool {
if perm > ptypes.AllBasePermFlags { if perm > ptypes.AllBasePermFlags {
panic("Checking an unknown permission in state should never happen") panic("Checking an unknown permission in state should never happen")
} }
@ -840,7 +837,7 @@ func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFl
} }
// TODO: for debug log the failed accounts // TODO: for debug log the failed accounts
func hasSendPermission(state AccountGetter, accs map[string]*account.Account) bool { func hasSendPermission(state AccountGetter, accs map[string]*acm.Account) bool {
for _, acc := range accs { for _, acc := range accs {
if !HasPermission(state, acc, ptypes.Send) { if !HasPermission(state, acc, ptypes.Send) {
return false return false
@ -849,19 +846,19 @@ func hasSendPermission(state AccountGetter, accs map[string]*account.Account) bo
return true return true
} }
func hasNamePermission(state AccountGetter, acc *account.Account) bool { func hasNamePermission(state AccountGetter, acc *acm.Account) bool {
return HasPermission(state, acc, ptypes.Name) return HasPermission(state, acc, ptypes.Name)
} }
func hasCallPermission(state AccountGetter, acc *account.Account) bool { func hasCallPermission(state AccountGetter, acc *acm.Account) bool {
return HasPermission(state, acc, ptypes.Call) return HasPermission(state, acc, ptypes.Call)
} }
func hasCreateContractPermission(state AccountGetter, acc *account.Account) bool { func hasCreateContractPermission(state AccountGetter, acc *acm.Account) bool {
return HasPermission(state, acc, ptypes.CreateContract) return HasPermission(state, acc, ptypes.CreateContract)
} }
func hasCreateAccountPermission(state AccountGetter, accs map[string]*account.Account) bool { func hasCreateAccountPermission(state AccountGetter, accs map[string]*acm.Account) bool {
for _, acc := range accs { for _, acc := range accs {
if !HasPermission(state, acc, ptypes.CreateAccount) { if !HasPermission(state, acc, ptypes.CreateAccount) {
return false return false
@ -870,11 +867,11 @@ func hasCreateAccountPermission(state AccountGetter, accs map[string]*account.Ac
return true return true
} }
func hasBondPermission(state AccountGetter, acc *account.Account) bool { func hasBondPermission(state AccountGetter, acc *acm.Account) bool {
return HasPermission(state, acc, ptypes.Bond) return HasPermission(state, acc, ptypes.Bond)
} }
func hasBondOrSendPermission(state AccountGetter, accs map[string]*account.Account) bool { func hasBondOrSendPermission(state AccountGetter, accs map[string]*acm.Account) bool {
for _, acc := range accs { for _, acc := range accs {
if !HasPermission(state, acc, ptypes.Bond) { if !HasPermission(state, acc, ptypes.Bond) {
if !HasPermission(state, acc, ptypes.Send) { if !HasPermission(state, acc, ptypes.Send) {

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"time" "time"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
@ -35,10 +35,10 @@ type GenesisAccount struct {
} }
type GenesisValidator struct { type GenesisValidator struct {
PubKey account.PubKeyEd25519 `json:"pub_key"` PubKey acm.PubKeyEd25519 `json:"pub_key"`
Amount int64 `json:"amount"` Amount int64 `json:"amount"`
Name string `json:"name"` Name string `json:"name"`
UnbondTo []BasicAccount `json:"unbond_to"` UnbondTo []BasicAccount `json:"unbond_to"`
} }
type GenesisParams struct { type GenesisParams struct {
@ -86,13 +86,13 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
} }
// Make accounts state tree // Make accounts state tree
accounts := merkle.NewIAVLTree(binary.BasicCodec, account.AccountCodec, defaultAccountsCacheCapacity, db) accounts := merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
for _, genAcc := range genDoc.Accounts { for _, genAcc := range genDoc.Accounts {
perm := ptypes.ZeroAccountPermissions perm := ptypes.ZeroAccountPermissions
if genAcc.Permissions != nil { if genAcc.Permissions != nil {
perm = *genAcc.Permissions perm = *genAcc.Permissions
} }
acc := &account.Account{ acc := &acm.Account{
Address: genAcc.Address, Address: genAcc.Address,
PubKey: nil, PubKey: nil,
Sequence: 0, Sequence: 0,
@ -112,7 +112,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
globalPerms.Base.SetBit = ptypes.AllPermFlags globalPerms.Base.SetBit = ptypes.AllPermFlags
} }
permsAcc := &account.Account{ permsAcc := &acm.Account{
Address: ptypes.GlobalPermissionsAddress, Address: ptypes.GlobalPermissionsAddress,
PubKey: nil, PubKey: nil,
Sequence: 0, Sequence: 0,

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
"github.com/tendermint/tendermint/events" "github.com/tendermint/tendermint/events"
@ -81,11 +81,11 @@ x - roles: has, add, rm
var user = makeUsers(10) var user = makeUsers(10)
var chainID = "testchain" var chainID = "testchain"
func makeUsers(n int) []*account.PrivAccount { func makeUsers(n int) []*acm.PrivAccount {
accounts := []*account.PrivAccount{} accounts := []*acm.PrivAccount{}
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
secret := []byte("mysecret" + strconv.Itoa(i)) secret := []byte("mysecret" + strconv.Itoa(i))
user := account.GenPrivAccountFromSecret(secret) user := acm.GenPrivAccountFromSecret(secret)
accounts = append(accounts, user) accounts = append(accounts, user)
} }
return accounts return accounts
@ -115,7 +115,7 @@ func newBaseGenDoc(globalPerm, accountPerm ptypes.AccountPermissions) GenesisDoc
Accounts: genAccounts, Accounts: genAccounts,
Validators: []GenesisValidator{ Validators: []GenesisValidator{
GenesisValidator{ GenesisValidator{
PubKey: user[0].PubKey.(account.PubKeyEd25519), PubKey: user[0].PubKey.(acm.PubKeyEd25519),
Amount: 10, Amount: 10,
UnbondTo: []BasicAccount{ UnbondTo: []BasicAccount{
BasicAccount{ BasicAccount{
@ -348,7 +348,7 @@ func TestCallPermission(t *testing.T) {
// create simple contract // create simple contract
simpleContractAddr := NewContractAddress(user[0].Address, 100) simpleContractAddr := NewContractAddress(user[0].Address, 100)
simpleAcc := &account.Account{ simpleAcc := &acm.Account{
Address: simpleContractAddr, Address: simpleContractAddr,
Balance: 0, Balance: 0,
Code: []byte{0x60}, Code: []byte{0x60},
@ -372,7 +372,7 @@ func TestCallPermission(t *testing.T) {
// create contract that calls the simple contract // create contract that calls the simple contract
contractCode := callContractCode(simpleContractAddr) contractCode := callContractCode(simpleContractAddr)
caller1ContractAddr := NewContractAddress(user[0].Address, 101) caller1ContractAddr := NewContractAddress(user[0].Address, 101)
caller1Acc := &account.Account{ caller1Acc := &acm.Account{
Address: caller1ContractAddr, Address: caller1ContractAddr,
Balance: 0, Balance: 0,
Code: contractCode, Code: contractCode,
@ -416,7 +416,7 @@ func TestCallPermission(t *testing.T) {
contractCode2 := callContractCode(caller1ContractAddr) contractCode2 := callContractCode(caller1ContractAddr)
caller2ContractAddr := NewContractAddress(user[0].Address, 102) caller2ContractAddr := NewContractAddress(user[0].Address, 102)
caller2Acc := &account.Account{ caller2Acc := &acm.Account{
Address: caller2ContractAddr, Address: caller2ContractAddr,
Balance: 1000, Balance: 1000,
Code: contractCode2, Code: contractCode2,
@ -548,7 +548,7 @@ func TestCreatePermission(t *testing.T) {
code := callContractCode(zeroAddr) code := callContractCode(zeroAddr)
contractAddr = NewContractAddress(user[0].Address, 110) contractAddr = NewContractAddress(user[0].Address, 110)
contractAcc = &account.Account{ contractAcc = &acm.Account{
Address: contractAddr, Address: contractAddr,
Balance: 1000, Balance: 1000,
Code: code, Code: code,
@ -579,7 +579,7 @@ func TestBondPermission(t *testing.T) {
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse) genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
st := MakeGenesisState(stateDB, &genDoc) st := MakeGenesisState(stateDB, &genDoc)
blockCache := NewBlockCache(st) blockCache := NewBlockCache(st)
var bondAcc *account.Account var bondAcc *acm.Account
//------------------------------ //------------------------------
// one bonder without permission should fail // one bonder without permission should fail
@ -800,7 +800,7 @@ func TestCreateAccountPermission(t *testing.T) {
// create contract that calls the simple contract // create contract that calls the simple contract
contractCode := callContractCode(user[9].Address) contractCode := callContractCode(user[9].Address)
caller1ContractAddr := NewContractAddress(user[4].Address, 101) caller1ContractAddr := NewContractAddress(user[4].Address, 101)
caller1Acc := &account.Account{ caller1Acc := &acm.Account{
Address: caller1ContractAddr, Address: caller1ContractAddr,
Balance: 0, Balance: 0,
Code: contractCode, Code: contractCode,
@ -851,7 +851,7 @@ func TestSNativeCALL(t *testing.T) {
// Test CALL to SNative contracts // Test CALL to SNative contracts
// make the main contract once // make the main contract once
doug := &account.Account{ doug := &acm.Account{
Address: ptypes.DougAddress, Address: ptypes.DougAddress,
Balance: 0, Balance: 0,
Code: nil, Code: nil,
@ -985,7 +985,7 @@ func TestSNativeCallTx(t *testing.T) {
//---------------------------------------------------------- //----------------------------------------------------------
// Test CallTx to SNative contracts // Test CallTx to SNative contracts
var doug *account.Account = nil var doug *acm.Account = nil
fmt.Println("#### hasBasePerm") fmt.Println("#### hasBasePerm")
// hasBasePerm // hasBasePerm
@ -1131,7 +1131,7 @@ func execTxWaitEvent(t *testing.T, blockCache *BlockCache, tx types.Tx, eventid
} }
// give a contract perms for an snative, call it, it calls the snative, ensure the check funciton (f) succeeds // give a contract perms for an snative, call it, it calls the snative, ensure the check funciton (f) succeeds
func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *account.Account, snativeAddress, data []byte, f func([]byte) error) { func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte, f func([]byte) error) {
perm := vm.RegisteredSNativePermissions[LeftPadWord256(snativeAddress)] perm := vm.RegisteredSNativePermissions[LeftPadWord256(snativeAddress)]
var addr []byte var addr []byte
if doug != nil { if doug != nil {
@ -1160,7 +1160,7 @@ func testSNativeCALLExpectPass(t *testing.T, blockCache *BlockCache, doug *accou
} }
// assumes the contract has not been given the permission. calls the it, it calls the snative, expects to fail // assumes the contract has not been given the permission. calls the it, it calls the snative, expects to fail
func testSNativeCALLExpectFail(t *testing.T, blockCache *BlockCache, doug *account.Account, snativeAddress, data []byte) { func testSNativeCALLExpectFail(t *testing.T, blockCache *BlockCache, doug *acm.Account, snativeAddress, data []byte) {
var addr []byte var addr []byte
if doug != nil { if doug != nil {
contractCode := callContractCode(snativeAddress) contractCode := callContractCode(snativeAddress)
@ -1189,7 +1189,7 @@ func boolToWord256(v bool) Word256 {
return LeftPadWord256([]byte{vint}) return LeftPadWord256([]byte{vint})
} }
func snativePermTestInput(name string, user *account.PrivAccount, perm ptypes.PermFlag, val bool) (addr []byte, data []byte) { func snativePermTestInput(name string, user *acm.PrivAccount, perm ptypes.PermFlag, val bool) (addr []byte, data []byte) {
addr = LeftPadWord256([]byte(name)).Postfix(20) addr = LeftPadWord256([]byte(name)).Postfix(20)
switch name { switch name {
case "hasBasePerm", "unsetBasePerm": case "hasBasePerm", "unsetBasePerm":
@ -1207,7 +1207,7 @@ func snativePermTestInput(name string, user *account.PrivAccount, perm ptypes.Pe
return return
} }
func snativeRoleTestInput(name string, user *account.PrivAccount, role string) (addr []byte, data []byte) { func snativeRoleTestInput(name string, user *acm.PrivAccount, role string) (addr []byte, data []byte) {
addr = LeftPadWord256([]byte(name)).Postfix(20) addr = LeftPadWord256([]byte(name)).Postfix(20)
data = LeftPadBytes(user.Address, 32) data = LeftPadBytes(user.Address, 32)
data = append(data, LeftPadBytes([]byte(role), 32)...) data = append(data, LeftPadBytes([]byte(role), 32)...)

View File

@ -7,7 +7,7 @@ import (
"math" "math"
"sync" "sync"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/consensus/types" . "github.com/tendermint/tendermint/consensus/types"
@ -37,12 +37,12 @@ func voteToStep(vote *types.Vote) int8 {
} }
type PrivValidator struct { type PrivValidator struct {
Address []byte `json:"address"` Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"` PubKey acm.PubKeyEd25519 `json:"pub_key"`
PrivKey account.PrivKeyEd25519 `json:"priv_key"` PrivKey acm.PrivKeyEd25519 `json:"priv_key"`
LastHeight int `json:"last_height"` LastHeight int `json:"last_height"`
LastRound int `json:"last_round"` LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"` LastStep int8 `json:"last_step"`
// For persistence. // For persistence.
// Overloaded for testing. // Overloaded for testing.
@ -55,8 +55,8 @@ func GenPrivValidator() *PrivValidator {
privKeyBytes := new([64]byte) privKeyBytes := new([64]byte)
copy(privKeyBytes[:32], CRandBytes(32)) copy(privKeyBytes[:32], CRandBytes(32))
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
pubKey := account.PubKeyEd25519(*pubKeyBytes) pubKey := acm.PubKeyEd25519(*pubKeyBytes)
privKey := account.PrivKeyEd25519(*privKeyBytes) privKey := acm.PrivKeyEd25519(*privKeyBytes)
return &PrivValidator{ return &PrivValidator{
Address: pubKey.Address(), Address: pubKey.Address(),
PubKey: pubKey, PubKey: pubKey,
@ -138,7 +138,7 @@ func (privVal *PrivValidator) SignVote(chainID string, vote *types.Vote) error {
} }
func (privVal *PrivValidator) SignVoteUnsafe(chainID string, vote *types.Vote) { func (privVal *PrivValidator) SignVoteUnsafe(chainID string, vote *types.Vote) {
vote.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, vote)).(account.SignatureEd25519) vote.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, vote)).(acm.SignatureEd25519)
} }
func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error { func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) error {
@ -155,7 +155,7 @@ func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) e
privVal.save() privVal.save()
// Sign // Sign
proposal.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, proposal)).(account.SignatureEd25519) proposal.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, proposal)).(acm.SignatureEd25519)
return nil return nil
} else { } else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of proposal: Height %v, Round %v", proposal.Height, proposal.Round)) return errors.New(fmt.Sprintf("Attempt of duplicate signing of proposal: Height %v, Round %v", proposal.Height, proposal.Round))
@ -175,7 +175,7 @@ func (privVal *PrivValidator) SignRebondTx(chainID string, rebondTx *types.Rebon
privVal.save() privVal.save()
// Sign // Sign
rebondTx.Signature = privVal.PrivKey.Sign(account.SignBytes(chainID, rebondTx)).(account.SignatureEd25519) rebondTx.Signature = privVal.PrivKey.Sign(acm.SignBytes(chainID, rebondTx)).(acm.SignatureEd25519)
return nil return nil
} else { } else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height)) return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height))

View File

@ -5,7 +5,7 @@ import (
"io" "io"
"time" "time"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
@ -58,7 +58,7 @@ func LoadState(db dbm.DB) *State {
s.LastBondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) s.LastBondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
s.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet) s.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
accountsHash := binary.ReadByteSlice(r, n, err) accountsHash := binary.ReadByteSlice(r, n, err)
s.accounts = merkle.NewIAVLTree(binary.BasicCodec, account.AccountCodec, defaultAccountsCacheCapacity, db) s.accounts = merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
s.accounts.Load(accountsHash) s.accounts.Load(accountsHash)
validatorInfosHash := binary.ReadByteSlice(r, n, err) validatorInfosHash := binary.ReadByteSlice(r, n, err)
s.validatorInfos = merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db) s.validatorInfos = merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db)
@ -155,18 +155,18 @@ func (s *State) SetDB(db dbm.DB) {
// The returned Account is a copy, so mutating it // The returned Account is a copy, so mutating it
// has no side effects. // has no side effects.
// Implements Statelike // Implements Statelike
func (s *State) GetAccount(address []byte) *account.Account { func (s *State) GetAccount(address []byte) *acm.Account {
_, acc := s.accounts.Get(address) _, acc := s.accounts.Get(address)
if acc == nil { if acc == nil {
return nil return nil
} }
return acc.(*account.Account).Copy() return acc.(*acm.Account).Copy()
} }
// The account is copied before setting, so mutating it // The account is copied before setting, so mutating it
// afterwards has no side effects. // afterwards has no side effects.
// Implements Statelike // Implements Statelike
func (s *State) UpdateAccount(account *account.Account) bool { func (s *State) UpdateAccount(account *acm.Account) bool {
return s.accounts.Set(account.Address, account.Copy()) return s.accounts.Set(account.Address, account.Copy())
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"sort" "sort"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
ptypes "github.com/tendermint/tendermint/permission/types" ptypes "github.com/tendermint/tendermint/permission/types"
@ -23,10 +23,10 @@ func Tempfile(prefix string) (*os.File, string) {
return file, file.Name() return file, file.Name()
} }
func RandAccount(randBalance bool, minBalance int64) (*account.Account, *account.PrivAccount) { func RandAccount(randBalance bool, minBalance int64) (*acm.Account, *acm.PrivAccount) {
privAccount := account.GenPrivAccount() privAccount := acm.GenPrivAccount()
perms := ptypes.DefaultAccountPermissions perms := ptypes.DefaultAccountPermissions
acc := &account.Account{ acc := &acm.Account{
Address: privAccount.PubKey.Address(), Address: privAccount.PubKey.Address(),
PubKey: privAccount.PubKey, PubKey: privAccount.PubKey,
Sequence: RandInt(), Sequence: RandInt(),
@ -69,9 +69,9 @@ func RandValidator(randBonded bool, minBonded int64) (*ValidatorInfo, *Validator
return valInfo, val, privVal return valInfo, val, privVal
} }
func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*GenesisDoc, []*account.PrivAccount, []*PrivValidator) { func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*GenesisDoc, []*acm.PrivAccount, []*PrivValidator) {
accounts := make([]GenesisAccount, numAccounts) accounts := make([]GenesisAccount, numAccounts)
privAccounts := make([]*account.PrivAccount, numAccounts) privAccounts := make([]*acm.PrivAccount, numAccounts)
defaultPerms := ptypes.DefaultAccountPermissions defaultPerms := ptypes.DefaultAccountPermissions
for i := 0; i < numAccounts; i++ { for i := 0; i < numAccounts; i++ {
account, privAccount := RandAccount(randBalance, minBalance) account, privAccount := RandAccount(randBalance, minBalance)
@ -108,7 +108,7 @@ func RandGenesisDoc(numAccounts int, randBalance bool, minBalance int64, numVali
} }
func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*account.PrivAccount, []*PrivValidator) { func RandGenesisState(numAccounts int, randBalance bool, minBalance int64, numValidators int, randBonded bool, minBonded int64) (*State, []*acm.PrivAccount, []*PrivValidator) {
db := dbm.NewMemDB() db := dbm.NewMemDB()
genDoc, privAccounts, privValidators := RandGenesisDoc(numAccounts, randBalance, minBalance, numValidators, randBonded, minBonded) genDoc, privAccounts, privValidators := RandGenesisDoc(numAccounts, randBalance, minBalance, numValidators, randBonded, minBonded)
s0 := MakeGenesisState(db, genDoc) s0 := MakeGenesisState(db, genDoc)

View File

@ -1,7 +1,7 @@
package state package state
import ( import (
ac "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/vm" "github.com/tendermint/tendermint/vm"
@ -158,7 +158,7 @@ func NewContractAddress(caller []byte, nonce int) []byte {
} }
// Converts backend.Account to vm.Account struct. // Converts backend.Account to vm.Account struct.
func toVMAccount(acc *ac.Account) *vm.Account { func toVMAccount(acc *acm.Account) *vm.Account {
return &vm.Account{ return &vm.Account{
Address: LeftPadWord256(acc.Address), Address: LeftPadWord256(acc.Address),
Balance: acc.Balance, Balance: acc.Balance,
@ -171,8 +171,8 @@ func toVMAccount(acc *ac.Account) *vm.Account {
} }
// Converts vm.Account to backend.Account struct. // Converts vm.Account to backend.Account struct.
func toStateAccount(acc *vm.Account) *ac.Account { func toStateAccount(acc *vm.Account) *acm.Account {
pubKey, ok := acc.Other.(ac.PubKey) pubKey, ok := acc.Other.(acm.PubKey)
if !ok { if !ok {
pubKey = nil pubKey = nil
} }
@ -183,7 +183,7 @@ func toStateAccount(acc *vm.Account) *ac.Account {
} else { } else {
storageRoot = acc.StorageRoot.Bytes() storageRoot = acc.StorageRoot.Bytes()
} }
return &ac.Account{ return &acm.Account{
Address: acc.Address.Postfix(20), Address: acc.Address.Postfix(20),
PubKey: pubKey, PubKey: pubKey,
Balance: acc.Balance, Balance: acc.Balance,

View File

@ -5,21 +5,21 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
// Persistent (mostly) static data for each Validator // Persistent (mostly) static data for each Validator
type ValidatorInfo struct { type ValidatorInfo struct {
Address []byte `json:"address"` Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"` PubKey acm.PubKeyEd25519 `json:"pub_key"`
UnbondTo []*types.TxOutput `json:"unbond_to"` UnbondTo []*types.TxOutput `json:"unbond_to"`
FirstBondHeight int `json:"first_bond_height"` FirstBondHeight int `json:"first_bond_height"`
FirstBondAmount int64 `json:"first_bond_amount"` FirstBondAmount int64 `json:"first_bond_amount"`
DestroyedHeight int `json:"destroyed_height"` // If destroyed DestroyedHeight int `json:"destroyed_height"` // If destroyed
DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed
ReleasedHeight int `json:"released_height"` // If released ReleasedHeight int `json:"released_height"` // If released
} }
func (valInfo *ValidatorInfo) Copy() *ValidatorInfo { func (valInfo *ValidatorInfo) Copy() *ValidatorInfo {
@ -46,13 +46,13 @@ var ValidatorInfoCodec = binary.Codec{
// Also persisted with the state, but fields change // Also persisted with the state, but fields change
// every height|round so they don't go in merkle.Tree // every height|round so they don't go in merkle.Tree
type Validator struct { type Validator struct {
Address []byte `json:"address"` Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"` PubKey acm.PubKeyEd25519 `json:"pub_key"`
BondHeight int `json:"bond_height"` BondHeight int `json:"bond_height"`
UnbondHeight int `json:"unbond_height"` UnbondHeight int `json:"unbond_height"`
LastCommitHeight int `json:"last_commit_height"` LastCommitHeight int `json:"last_commit_height"`
VotingPower int64 `json:"voting_power"` VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"` Accum int64 `json:"accum"`
} }
// Creates a new copy of the validator so we can mutate accum. // Creates a new copy of the validator so we can mutate accum.

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/merkle" "github.com/tendermint/tendermint/merkle"
@ -310,7 +310,7 @@ func (data *Data) Hash() []byte {
if data.hash == nil { if data.hash == nil {
bs := make([]interface{}, len(data.Txs)) bs := make([]interface{}, len(data.Txs))
for i, tx := range data.Txs { for i, tx := range data.Txs {
bs[i] = account.SignBytes(config.GetString("chain_id"), tx) bs[i] = acm.SignBytes(config.GetString("chain_id"), tx)
} }
data.hash = merkle.SimpleHashFromBinaries(bs) // NOTE: leaves are TxIDs. data.hash = merkle.SimpleHashFromBinaries(bs) // NOTE: leaves are TxIDs.
} }

View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
"io" "io"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
) )
@ -78,11 +78,11 @@ var _ = binary.RegisterInterface(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type TxInput struct { type TxInput struct {
Address []byte `json:"address"` // Hash of the PubKey Address []byte `json:"address"` // Hash of the PubKey
Amount int64 `json:"amount"` // Must not exceed account balance Amount int64 `json:"amount"` // Must not exceed account balance
Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput Sequence int `json:"sequence"` // Must be 1 greater than the last committed TxInput
Signature account.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx Signature acm.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
PubKey account.PubKey `json:"pub_key"` // Must not be nil, may be nil PubKey acm.PubKey `json:"pub_key"` // Must not be nil, may be nil
} }
func (txIn *TxInput) ValidateBasic() error { func (txIn *TxInput) ValidateBasic() error {
@ -231,10 +231,10 @@ func (tx *NameTx) String() string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type BondTx struct { type BondTx struct {
PubKey account.PubKeyEd25519 `json:"pub_key"` PubKey acm.PubKeyEd25519 `json:"pub_key"`
Signature account.SignatureEd25519 `json:"signature"` Signature acm.SignatureEd25519 `json:"signature"`
Inputs []*TxInput `json:"inputs"` Inputs []*TxInput `json:"inputs"`
UnbondTo []*TxOutput `json:"unbond_to"` UnbondTo []*TxOutput `json:"unbond_to"`
} }
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
@ -265,9 +265,9 @@ func (tx *BondTx) String() string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type UnbondTx struct { type UnbondTx struct {
Address []byte `json:"address"` Address []byte `json:"address"`
Height int `json:"height"` Height int `json:"height"`
Signature account.SignatureEd25519 `json:"signature"` Signature acm.SignatureEd25519 `json:"signature"`
} }
func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
@ -282,9 +282,9 @@ func (tx *UnbondTx) String() string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type RebondTx struct { type RebondTx struct {
Address []byte `json:"address"` Address []byte `json:"address"`
Height int `json:"height"` Height int `json:"height"`
Signature account.SignatureEd25519 `json:"signature"` Signature acm.SignatureEd25519 `json:"signature"`
} }
func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
@ -316,7 +316,7 @@ func (tx *DupeoutTx) String() string {
// This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree. // This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree.
func TxID(chainID string, tx Tx) []byte { func TxID(chainID string, tx Tx) []byte {
signBytes := account.SignBytes(chainID, tx) signBytes := acm.SignBytes(chainID, tx)
return binary.BinaryRipemd160(signBytes) return binary.BinaryRipemd160(signBytes)
} }

View File

@ -3,7 +3,7 @@ package types
import ( import (
"testing" "testing"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
_ "github.com/tendermint/tendermint/config/tendermint_test" _ "github.com/tendermint/tendermint/config/tendermint_test"
) )
@ -39,7 +39,7 @@ func TestSendTxSignable(t *testing.T) {
}, },
}, },
} }
signBytes := account.SignBytes(chainID, sendTx) signBytes := acm.SignBytes(chainID, sendTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, expected := Fmt(`{"chain_id":"%s","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
@ -60,7 +60,7 @@ func TestCallTxSignable(t *testing.T) {
Fee: 222, Fee: 222,
Data: []byte("data1"), Data: []byte("data1"),
} }
signBytes := account.SignBytes(chainID, callTx) signBytes := acm.SignBytes(chainID, callTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`, expected := Fmt(`{"chain_id":"%s","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
@ -73,9 +73,9 @@ func TestBondTxSignable(t *testing.T) {
privKeyBytes := make([]byte, 64) privKeyBytes := make([]byte, 64)
var privKeyArray [64]byte var privKeyArray [64]byte
copy(privKeyArray[:], privKeyBytes) copy(privKeyArray[:], privKeyBytes)
privAccount := account.GenPrivAccountFromPrivKeyBytes(&privKeyArray) privAccount := acm.GenPrivAccountFromPrivKeyBytes(&privKeyArray)
bondTx := &BondTx{ bondTx := &BondTx{
PubKey: privAccount.PubKey.(account.PubKeyEd25519), PubKey: privAccount.PubKey.(acm.PubKeyEd25519),
Inputs: []*TxInput{ Inputs: []*TxInput{
&TxInput{ &TxInput{
Address: []byte("input1"), Address: []byte("input1"),
@ -99,7 +99,7 @@ func TestBondTxSignable(t *testing.T) {
}, },
}, },
} }
signBytes := account.SignBytes(chainID, bondTx) signBytes := acm.SignBytes(chainID, bondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, expected := Fmt(`{"chain_id":"%s","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
@ -113,7 +113,7 @@ func TestUnbondTxSignable(t *testing.T) {
Address: []byte("address1"), Address: []byte("address1"),
Height: 111, Height: 111,
} }
signBytes := account.SignBytes(chainID, unbondTx) signBytes := acm.SignBytes(chainID, unbondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[18,{"address":"6164647265737331","height":111}]}`, expected := Fmt(`{"chain_id":"%s","tx":[18,{"address":"6164647265737331","height":111}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))
@ -127,7 +127,7 @@ func TestRebondTxSignable(t *testing.T) {
Address: []byte("address1"), Address: []byte("address1"),
Height: 111, Height: 111,
} }
signBytes := account.SignBytes(chainID, rebondTx) signBytes := acm.SignBytes(chainID, rebondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`, expected := Fmt(`{"chain_id":"%s","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.GetString("chain_id")) config.GetString("chain_id"))

View File

@ -2,11 +2,11 @@ package types
import ( import (
"fmt" "fmt"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
) )
type AccountGetter interface { type AccountGetter interface {
GetAccount(addr []byte) *account.Account GetAccount(addr []byte) *acm.Account
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -19,7 +19,7 @@ func NewSendTx() *SendTx {
} }
} }
func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) error { func (tx *SendTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error {
addr := pubkey.Address() addr := pubkey.Address()
acc := st.GetAccount(addr) acc := st.GetAccount(addr)
if acc == nil { if acc == nil {
@ -28,13 +28,13 @@ func (tx *SendTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) e
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1) return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
} }
func (tx *SendTx) AddInputWithNonce(pubkey account.PubKey, amt int64, nonce int) error { func (tx *SendTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error {
addr := pubkey.Address() addr := pubkey.Address()
tx.Inputs = append(tx.Inputs, &TxInput{ tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr, Address: addr,
Amount: amt, Amount: amt,
Sequence: nonce, Sequence: nonce,
Signature: account.SignatureEd25519{}, Signature: acm.SignatureEd25519{},
PubKey: pubkey, PubKey: pubkey,
}) })
return nil return nil
@ -48,7 +48,7 @@ func (tx *SendTx) AddOutput(addr []byte, amt int64) error {
return nil return nil
} }
func (tx *SendTx) SignInput(chainID string, i int, privAccount *account.PrivAccount) error { func (tx *SendTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error {
if i >= len(tx.Inputs) { if i >= len(tx.Inputs) {
return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs)) return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs))
} }
@ -60,7 +60,7 @@ func (tx *SendTx) SignInput(chainID string, i int, privAccount *account.PrivAcco
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// CallTx interface for creating tx // CallTx interface for creating tx
func NewCallTx(st AccountGetter, from account.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error) { func NewCallTx(st AccountGetter, from acm.PubKey, to, data []byte, amt, gasLimit, fee int64) (*CallTx, error) {
addr := from.Address() addr := from.Address()
acc := st.GetAccount(addr) acc := st.GetAccount(addr)
if acc == nil { if acc == nil {
@ -71,13 +71,13 @@ func NewCallTx(st AccountGetter, from account.PubKey, to, data []byte, amt, gasL
return NewCallTxWithNonce(from, to, data, amt, gasLimit, fee, nonce), nil return NewCallTxWithNonce(from, to, data, amt, gasLimit, fee, nonce), nil
} }
func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx { func NewCallTxWithNonce(from acm.PubKey, to, data []byte, amt, gasLimit, fee int64, nonce int) *CallTx {
addr := from.Address() addr := from.Address()
input := &TxInput{ input := &TxInput{
Address: addr, Address: addr,
Amount: amt, Amount: amt,
Sequence: nonce, Sequence: nonce,
Signature: account.SignatureEd25519{}, Signature: acm.SignatureEd25519{},
PubKey: from, PubKey: from,
} }
@ -90,7 +90,7 @@ func NewCallTxWithNonce(from account.PubKey, to, data []byte, amt, gasLimit, fee
} }
} }
func (tx *CallTx) Sign(chainID string, privAccount *account.PrivAccount) { func (tx *CallTx) Sign(chainID string, privAccount *acm.PrivAccount) {
tx.Input.PubKey = privAccount.PubKey tx.Input.PubKey = privAccount.PubKey
tx.Input.Signature = privAccount.Sign(chainID, tx) tx.Input.Signature = privAccount.Sign(chainID, tx)
} }
@ -98,7 +98,7 @@ func (tx *CallTx) Sign(chainID string, privAccount *account.PrivAccount) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// NameTx interface for creating tx // NameTx interface for creating tx
func NewNameTx(st AccountGetter, from account.PubKey, name, data string, amt, fee int64) (*NameTx, error) { func NewNameTx(st AccountGetter, from acm.PubKey, name, data string, amt, fee int64) (*NameTx, error) {
addr := from.Address() addr := from.Address()
acc := st.GetAccount(addr) acc := st.GetAccount(addr)
if acc == nil { if acc == nil {
@ -109,13 +109,13 @@ func NewNameTx(st AccountGetter, from account.PubKey, name, data string, amt, fe
return NewNameTxWithNonce(from, name, data, amt, fee, nonce), nil return NewNameTxWithNonce(from, name, data, amt, fee, nonce), nil
} }
func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee int64, nonce int) *NameTx { func NewNameTxWithNonce(from acm.PubKey, name, data string, amt, fee int64, nonce int) *NameTx {
addr := from.Address() addr := from.Address()
input := &TxInput{ input := &TxInput{
Address: addr, Address: addr,
Amount: amt, Amount: amt,
Sequence: nonce, Sequence: nonce,
Signature: account.SignatureEd25519{}, Signature: acm.SignatureEd25519{},
PubKey: from, PubKey: from,
} }
@ -127,7 +127,7 @@ func NewNameTxWithNonce(from account.PubKey, name, data string, amt, fee int64,
} }
} }
func (tx *NameTx) Sign(chainID string, privAccount *account.PrivAccount) { func (tx *NameTx) Sign(chainID string, privAccount *acm.PrivAccount) {
tx.Input.PubKey = privAccount.PubKey tx.Input.PubKey = privAccount.PubKey
tx.Input.Signature = privAccount.Sign(chainID, tx) tx.Input.Signature = privAccount.Sign(chainID, tx)
} }
@ -135,8 +135,8 @@ func (tx *NameTx) Sign(chainID string, privAccount *account.PrivAccount) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// BondTx interface for adding inputs/outputs and adding signatures // BondTx interface for adding inputs/outputs and adding signatures
func NewBondTx(pubkey account.PubKey) (*BondTx, error) { func NewBondTx(pubkey acm.PubKey) (*BondTx, error) {
pubkeyEd, ok := pubkey.(account.PubKeyEd25519) pubkeyEd, ok := pubkey.(acm.PubKeyEd25519)
if !ok { if !ok {
return nil, fmt.Errorf("Pubkey must be ed25519") return nil, fmt.Errorf("Pubkey must be ed25519")
} }
@ -147,7 +147,7 @@ func NewBondTx(pubkey account.PubKey) (*BondTx, error) {
}, nil }, nil
} }
func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) error { func (tx *BondTx) AddInput(st AccountGetter, pubkey acm.PubKey, amt int64) error {
addr := pubkey.Address() addr := pubkey.Address()
acc := st.GetAccount(addr) acc := st.GetAccount(addr)
if acc == nil { if acc == nil {
@ -156,13 +156,13 @@ func (tx *BondTx) AddInput(st AccountGetter, pubkey account.PubKey, amt int64) e
return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1) return tx.AddInputWithNonce(pubkey, amt, acc.Sequence+1)
} }
func (tx *BondTx) AddInputWithNonce(pubkey account.PubKey, amt int64, nonce int) error { func (tx *BondTx) AddInputWithNonce(pubkey acm.PubKey, amt int64, nonce int) error {
addr := pubkey.Address() addr := pubkey.Address()
tx.Inputs = append(tx.Inputs, &TxInput{ tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr, Address: addr,
Amount: amt, Amount: amt,
Sequence: nonce, Sequence: nonce,
Signature: account.SignatureEd25519{}, Signature: acm.SignatureEd25519{},
PubKey: pubkey, PubKey: pubkey,
}) })
return nil return nil
@ -176,9 +176,9 @@ func (tx *BondTx) AddOutput(addr []byte, amt int64) error {
return nil return nil
} }
func (tx *BondTx) SignBond(chainID string, privAccount *account.PrivAccount) error { func (tx *BondTx) SignBond(chainID string, privAccount *acm.PrivAccount) error {
sig := privAccount.Sign(chainID, tx) sig := privAccount.Sign(chainID, tx)
sigEd, ok := sig.(account.SignatureEd25519) sigEd, ok := sig.(acm.SignatureEd25519)
if !ok { if !ok {
return fmt.Errorf("Bond signer must be ED25519") return fmt.Errorf("Bond signer must be ED25519")
} }
@ -186,7 +186,7 @@ func (tx *BondTx) SignBond(chainID string, privAccount *account.PrivAccount) err
return nil return nil
} }
func (tx *BondTx) SignInput(chainID string, i int, privAccount *account.PrivAccount) error { func (tx *BondTx) SignInput(chainID string, i int, privAccount *acm.PrivAccount) error {
if i >= len(tx.Inputs) { if i >= len(tx.Inputs) {
return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs)) return fmt.Errorf("Index %v is greater than number of inputs (%v)", i, len(tx.Inputs))
} }
@ -205,8 +205,8 @@ func NewUnbondTx(addr []byte, height int) *UnbondTx {
} }
} }
func (tx *UnbondTx) Sign(chainID string, privAccount *account.PrivAccount) { func (tx *UnbondTx) Sign(chainID string, privAccount *acm.PrivAccount) {
tx.Signature = privAccount.Sign(chainID, tx).(account.SignatureEd25519) tx.Signature = privAccount.Sign(chainID, tx).(acm.SignatureEd25519)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -219,6 +219,6 @@ func NewRebondTx(addr []byte, height int) *RebondTx {
} }
} }
func (tx *RebondTx) Sign(chainID string, privAccount *account.PrivAccount) { func (tx *RebondTx) Sign(chainID string, privAccount *acm.PrivAccount) {
tx.Signature = privAccount.Sign(chainID, tx).(account.SignatureEd25519) tx.Signature = privAccount.Sign(chainID, tx).(acm.SignatureEd25519)
} }

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/tendermint/tendermint/account" acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
) )
@ -28,12 +28,12 @@ func (err *ErrVoteConflictingSignature) Error() string {
// Represents a prevote, precommit, or commit vote from validators for consensus. // Represents a prevote, precommit, or commit vote from validators for consensus.
type Vote struct { type Vote struct {
Height int `json:"height"` Height int `json:"height"`
Round int `json:"round"` Round int `json:"round"`
Type byte `json:"type"` Type byte `json:"type"`
BlockHash []byte `json:"block_hash"` // empty if vote is nil. BlockHash []byte `json:"block_hash"` // empty if vote is nil.
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil. BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
Signature account.SignatureEd25519 `json:"signature"` Signature acm.SignatureEd25519 `json:"signature"`
} }
// Types of votes // Types of votes