tendermint/account -> acm

This commit is contained in:
Jae Kwon
2015-07-19 09:40:55 -07:00
parent 8d1e176180
commit 1e7cc32597
25 changed files with 213 additions and 214 deletions
+6 -6
View File
@@ -4,7 +4,7 @@ import (
"bytes"
"sort"
ac "github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db"
@@ -48,7 +48,7 @@ func (cache *BlockCache) State() *State {
//-------------------------------------
// 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()
if removed {
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
_, storage, removed, _ := cache.accounts[string(addr)].unpack()
// SANITY CHECK
@@ -178,7 +178,7 @@ func (cache *BlockCache) Sync() {
// Later we'll iterate over all the users and save storage + update storage root.
var (
curAddr Word256
curAcc *ac.Account
curAcc *acm.Account
curAccRemoved bool
curStorage merkle.Tree
)
@@ -274,13 +274,13 @@ func (cache *BlockCache) Sync() {
//-----------------------------------------------------------------------------
type accountInfo struct {
account *ac.Account
account *acm.Account
storage merkle.Tree
removed 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
}
+2 -2
View File
@@ -1,13 +1,13 @@
package state
import (
ac "github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/vm"
)
type AccountGetter interface {
GetAccount(addr []byte) *ac.Account
GetAccount(addr []byte) *acm.Account
}
type VMAccountState interface {
+31 -31
View File
@@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/events"
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
// 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,
// the TxInput is modified and input.PubKey set to nil.
func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*account.Account, error) {
accounts := map[string]*account.Account{}
func getInputs(state AccountGetter, ins []*types.TxInput) (map[string]*acm.Account, error) {
accounts := map[string]*acm.Account{}
for _, in := range ins {
// Account shouldn't be duplicated
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
}
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 {
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
@@ -182,7 +182,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
}
checkedCreatePerms = true
}
acc = &account.Account{
acc = &acm.Account{
Address: out.Address,
PubKey: nil,
Sequence: 0,
@@ -195,7 +195,7 @@ func getOrMakeOutputs(state AccountGetter, accounts map[string]*account.Account,
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 in.PubKey == nil {
return types.ErrTxUnknownPubKey
@@ -210,7 +210,7 @@ func checkInputPubKey(acc *account.Account, in *types.TxInput) error {
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 {
acc := accounts[string(in.Address)]
// SANITY CHECK
@@ -228,7 +228,7 @@ func validateInputs(accounts map[string]*account.Account, signBytes []byte, ins
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
if err := in.ValidateBasic(); err != nil {
return err
@@ -263,7 +263,7 @@ func validateOutputs(outs []*types.TxOutput) (total int64, err error) {
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 {
acc := accounts[string(in.Address)]
// 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 {
acc := accounts[string(out.Address)]
// SANITY CHECK
@@ -319,7 +319,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return err
}
signBytes := account.SignBytes(_s.ChainID, tx)
signBytes := acm.SignBytes(_s.ChainID, tx)
inTotal, err := validateInputs(accounts, signBytes, tx.Inputs)
if err != nil {
return err
@@ -354,7 +354,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return nil
case *types.CallTx:
var inAcc, outAcc *account.Account
var inAcc, outAcc *acm.Account
// Validate input
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))
return err
}
signBytes := account.SignBytes(_s.ChainID, tx)
signBytes := acm.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input)
if err != nil {
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
if _, ok := vm.RegisteredSNativeContracts[LeftPadWord256(tx.Address)]; ok {
// set the outAcc (simply a placeholder until we reach the call)
outAcc = &account.Account{Address: tx.Address}
outAcc = &acm.Account{Address: tx.Address}
} else {
// if you call an account that doesn't exist
// 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
case *types.NameTx:
var inAcc *account.Account
var inAcc *acm.Account
// Validate input
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))
return err
}
signBytes := account.SignBytes(_s.ChainID, tx)
signBytes := acm.SignBytes(_s.ChainID, tx)
err := validateInput(inAcc, signBytes, tx.Input)
if err != nil {
log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err))
@@ -661,7 +661,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
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)
if err != nil {
return err
@@ -717,7 +717,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
}
// Verify the signature
signBytes := account.SignBytes(_s.ChainID, tx)
signBytes := acm.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature
}
@@ -742,7 +742,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
}
// Verify the signature
signBytes := account.SignBytes(_s.ChainID, tx)
signBytes := acm.SignBytes(_s.ChainID, tx)
if !val.PubKey.VerifyBytes(signBytes, tx.Signature) {
return types.ErrTxInvalidSignature
}
@@ -771,8 +771,8 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
return types.ErrTxInvalidAddress
}
}
voteASignBytes := account.SignBytes(_s.ChainID, &tx.VoteA)
voteBSignBytes := account.SignBytes(_s.ChainID, &tx.VoteB)
voteASignBytes := acm.SignBytes(_s.ChainID, &tx.VoteA)
voteBSignBytes := acm.SignBytes(_s.ChainID, &tx.VoteB)
if !accused.PubKey.VerifyBytes(voteASignBytes, tx.VoteA.Signature) ||
!accused.PubKey.VerifyBytes(voteBSignBytes, tx.VoteB.Signature) {
return types.ErrTxInvalidSignature
@@ -811,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
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 {
panic("Checking an unknown permission in state should never happen")
}
@@ -837,7 +837,7 @@ func HasPermission(state AccountGetter, acc *account.Account, perm ptypes.PermFl
}
// 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 {
if !HasPermission(state, acc, ptypes.Send) {
return false
@@ -846,19 +846,19 @@ func hasSendPermission(state AccountGetter, accs map[string]*account.Account) bo
return true
}
func hasNamePermission(state AccountGetter, acc *account.Account) bool {
func hasNamePermission(state AccountGetter, acc *acm.Account) bool {
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)
}
func hasCreateContractPermission(state AccountGetter, acc *account.Account) bool {
func hasCreateContractPermission(state AccountGetter, acc *acm.Account) bool {
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 {
if !HasPermission(state, acc, ptypes.CreateAccount) {
return false
@@ -867,11 +867,11 @@ func hasCreateAccountPermission(state AccountGetter, accs map[string]*account.Ac
return true
}
func hasBondPermission(state AccountGetter, acc *account.Account) bool {
func hasBondPermission(state AccountGetter, acc *acm.Account) bool {
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 {
if !HasPermission(state, acc, ptypes.Bond) {
if !HasPermission(state, acc, ptypes.Send) {
+8 -8
View File
@@ -5,7 +5,7 @@ import (
"os"
"time"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db"
@@ -35,10 +35,10 @@ type GenesisAccount struct {
}
type GenesisValidator struct {
PubKey account.PubKeyEd25519 `json:"pub_key"`
Amount int64 `json:"amount"`
Name string `json:"name"`
UnbondTo []BasicAccount `json:"unbond_to"`
PubKey acm.PubKeyEd25519 `json:"pub_key"`
Amount int64 `json:"amount"`
Name string `json:"name"`
UnbondTo []BasicAccount `json:"unbond_to"`
}
type GenesisParams struct {
@@ -86,13 +86,13 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
}
// 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 {
perm := ptypes.ZeroAccountPermissions
if genAcc.Permissions != nil {
perm = *genAcc.Permissions
}
acc := &account.Account{
acc := &acm.Account{
Address: genAcc.Address,
PubKey: nil,
Sequence: 0,
@@ -112,7 +112,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
globalPerms.Base.SetBit = ptypes.AllPermFlags
}
permsAcc := &account.Account{
permsAcc := &acm.Account{
Address: ptypes.GlobalPermissionsAddress,
PubKey: nil,
Sequence: 0,
+17 -17
View File
@@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db"
"github.com/tendermint/tendermint/events"
@@ -81,11 +81,11 @@ x - roles: has, add, rm
var user = makeUsers(10)
var chainID = "testchain"
func makeUsers(n int) []*account.PrivAccount {
accounts := []*account.PrivAccount{}
func makeUsers(n int) []*acm.PrivAccount {
accounts := []*acm.PrivAccount{}
for i := 0; i < n; i++ {
secret := []byte("mysecret" + strconv.Itoa(i))
user := account.GenPrivAccountFromSecret(secret)
user := acm.GenPrivAccountFromSecret(secret)
accounts = append(accounts, user)
}
return accounts
@@ -115,7 +115,7 @@ func newBaseGenDoc(globalPerm, accountPerm ptypes.AccountPermissions) GenesisDoc
Accounts: genAccounts,
Validators: []GenesisValidator{
GenesisValidator{
PubKey: user[0].PubKey.(account.PubKeyEd25519),
PubKey: user[0].PubKey.(acm.PubKeyEd25519),
Amount: 10,
UnbondTo: []BasicAccount{
BasicAccount{
@@ -348,7 +348,7 @@ func TestCallPermission(t *testing.T) {
// create simple contract
simpleContractAddr := NewContractAddress(user[0].Address, 100)
simpleAcc := &account.Account{
simpleAcc := &acm.Account{
Address: simpleContractAddr,
Balance: 0,
Code: []byte{0x60},
@@ -372,7 +372,7 @@ func TestCallPermission(t *testing.T) {
// create contract that calls the simple contract
contractCode := callContractCode(simpleContractAddr)
caller1ContractAddr := NewContractAddress(user[0].Address, 101)
caller1Acc := &account.Account{
caller1Acc := &acm.Account{
Address: caller1ContractAddr,
Balance: 0,
Code: contractCode,
@@ -416,7 +416,7 @@ func TestCallPermission(t *testing.T) {
contractCode2 := callContractCode(caller1ContractAddr)
caller2ContractAddr := NewContractAddress(user[0].Address, 102)
caller2Acc := &account.Account{
caller2Acc := &acm.Account{
Address: caller2ContractAddr,
Balance: 1000,
Code: contractCode2,
@@ -548,7 +548,7 @@ func TestCreatePermission(t *testing.T) {
code := callContractCode(zeroAddr)
contractAddr = NewContractAddress(user[0].Address, 110)
contractAcc = &account.Account{
contractAcc = &acm.Account{
Address: contractAddr,
Balance: 1000,
Code: code,
@@ -579,7 +579,7 @@ func TestBondPermission(t *testing.T) {
genDoc := newBaseGenDoc(PermsAllFalse, PermsAllFalse)
st := MakeGenesisState(stateDB, &genDoc)
blockCache := NewBlockCache(st)
var bondAcc *account.Account
var bondAcc *acm.Account
//------------------------------
// one bonder without permission should fail
@@ -800,7 +800,7 @@ func TestCreateAccountPermission(t *testing.T) {
// create contract that calls the simple contract
contractCode := callContractCode(user[9].Address)
caller1ContractAddr := NewContractAddress(user[4].Address, 101)
caller1Acc := &account.Account{
caller1Acc := &acm.Account{
Address: caller1ContractAddr,
Balance: 0,
Code: contractCode,
@@ -851,7 +851,7 @@ func TestSNativeCALL(t *testing.T) {
// Test CALL to SNative contracts
// make the main contract once
doug := &account.Account{
doug := &acm.Account{
Address: ptypes.DougAddress,
Balance: 0,
Code: nil,
@@ -985,7 +985,7 @@ func TestSNativeCallTx(t *testing.T) {
//----------------------------------------------------------
// Test CallTx to SNative contracts
var doug *account.Account = nil
var doug *acm.Account = nil
fmt.Println("#### 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
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)]
var addr []byte
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
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
if doug != nil {
contractCode := callContractCode(snativeAddress)
@@ -1189,7 +1189,7 @@ func boolToWord256(v bool) Word256 {
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)
switch name {
case "hasBasePerm", "unsetBasePerm":
@@ -1207,7 +1207,7 @@ func snativePermTestInput(name string, user *account.PrivAccount, perm ptypes.Pe
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)
data = LeftPadBytes(user.Address, 32)
data = append(data, LeftPadBytes([]byte(role), 32)...)
+12 -12
View File
@@ -7,7 +7,7 @@ import (
"math"
"sync"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/consensus/types"
@@ -37,12 +37,12 @@ func voteToStep(vote *types.Vote) int8 {
}
type PrivValidator struct {
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
PrivKey account.PrivKeyEd25519 `json:"priv_key"`
LastHeight int `json:"last_height"`
LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"`
Address []byte `json:"address"`
PubKey acm.PubKeyEd25519 `json:"pub_key"`
PrivKey acm.PrivKeyEd25519 `json:"priv_key"`
LastHeight int `json:"last_height"`
LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"`
// For persistence.
// Overloaded for testing.
@@ -55,8 +55,8 @@ func GenPrivValidator() *PrivValidator {
privKeyBytes := new([64]byte)
copy(privKeyBytes[:32], CRandBytes(32))
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
pubKey := account.PubKeyEd25519(*pubKeyBytes)
privKey := account.PrivKeyEd25519(*privKeyBytes)
pubKey := acm.PubKeyEd25519(*pubKeyBytes)
privKey := acm.PrivKeyEd25519(*privKeyBytes)
return &PrivValidator{
Address: pubKey.Address(),
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) {
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 {
@@ -155,7 +155,7 @@ func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) e
privVal.save()
// 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
} else {
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()
// 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
} else {
return errors.New(fmt.Sprintf("Attempt of duplicate signing of rebondTx: Height %v", rebondTx.Height))
+5 -5
View File
@@ -5,7 +5,7 @@ import (
"io"
"time"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
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.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
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)
validatorInfosHash := binary.ReadByteSlice(r, n, err)
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
// has no side effects.
// Implements Statelike
func (s *State) GetAccount(address []byte) *account.Account {
func (s *State) GetAccount(address []byte) *acm.Account {
_, acc := s.accounts.Get(address)
if acc == nil {
return nil
}
return acc.(*account.Account).Copy()
return acc.(*acm.Account).Copy()
}
// The account is copied before setting, so mutating it
// afterwards has no side effects.
// 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())
}
+7 -7
View File
@@ -4,7 +4,7 @@ import (
"bytes"
"sort"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
dbm "github.com/tendermint/tendermint/db"
ptypes "github.com/tendermint/tendermint/permission/types"
@@ -23,10 +23,10 @@ func Tempfile(prefix string) (*os.File, string) {
return file, file.Name()
}
func RandAccount(randBalance bool, minBalance int64) (*account.Account, *account.PrivAccount) {
privAccount := account.GenPrivAccount()
func RandAccount(randBalance bool, minBalance int64) (*acm.Account, *acm.PrivAccount) {
privAccount := acm.GenPrivAccount()
perms := ptypes.DefaultAccountPermissions
acc := &account.Account{
acc := &acm.Account{
Address: privAccount.PubKey.Address(),
PubKey: privAccount.PubKey,
Sequence: RandInt(),
@@ -69,9 +69,9 @@ func RandValidator(randBonded bool, minBonded int64) (*ValidatorInfo, *Validator
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)
privAccounts := make([]*account.PrivAccount, numAccounts)
privAccounts := make([]*acm.PrivAccount, numAccounts)
defaultPerms := ptypes.DefaultAccountPermissions
for i := 0; i < numAccounts; i++ {
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()
genDoc, privAccounts, privValidators := RandGenesisDoc(numAccounts, randBalance, minBalance, numValidators, randBonded, minBonded)
s0 := MakeGenesisState(db, genDoc)
+5 -5
View File
@@ -1,7 +1,7 @@
package state
import (
ac "github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/common"
ptypes "github.com/tendermint/tendermint/permission/types" // for GlobalPermissionAddress ...
"github.com/tendermint/tendermint/vm"
@@ -158,7 +158,7 @@ func NewContractAddress(caller []byte, nonce int) []byte {
}
// Converts backend.Account to vm.Account struct.
func toVMAccount(acc *ac.Account) *vm.Account {
func toVMAccount(acc *acm.Account) *vm.Account {
return &vm.Account{
Address: LeftPadWord256(acc.Address),
Balance: acc.Balance,
@@ -171,8 +171,8 @@ func toVMAccount(acc *ac.Account) *vm.Account {
}
// Converts vm.Account to backend.Account struct.
func toStateAccount(acc *vm.Account) *ac.Account {
pubKey, ok := acc.Other.(ac.PubKey)
func toStateAccount(acc *vm.Account) *acm.Account {
pubKey, ok := acc.Other.(acm.PubKey)
if !ok {
pubKey = nil
}
@@ -183,7 +183,7 @@ func toStateAccount(acc *vm.Account) *ac.Account {
} else {
storageRoot = acc.StorageRoot.Bytes()
}
return &ac.Account{
return &acm.Account{
Address: acc.Address.Postfix(20),
PubKey: pubKey,
Balance: acc.Balance,
+16 -16
View File
@@ -5,21 +5,21 @@ import (
"fmt"
"io"
"github.com/tendermint/tendermint/account"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
"github.com/tendermint/tendermint/types"
)
// Persistent (mostly) static data for each Validator
type ValidatorInfo struct {
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
UnbondTo []*types.TxOutput `json:"unbond_to"`
FirstBondHeight int `json:"first_bond_height"`
FirstBondAmount int64 `json:"first_bond_amount"`
DestroyedHeight int `json:"destroyed_height"` // If destroyed
DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed
ReleasedHeight int `json:"released_height"` // If released
Address []byte `json:"address"`
PubKey acm.PubKeyEd25519 `json:"pub_key"`
UnbondTo []*types.TxOutput `json:"unbond_to"`
FirstBondHeight int `json:"first_bond_height"`
FirstBondAmount int64 `json:"first_bond_amount"`
DestroyedHeight int `json:"destroyed_height"` // If destroyed
DestroyedAmount int64 `json:"destroyed_amount"` // If destroyed
ReleasedHeight int `json:"released_height"` // If released
}
func (valInfo *ValidatorInfo) Copy() *ValidatorInfo {
@@ -46,13 +46,13 @@ var ValidatorInfoCodec = binary.Codec{
// Also persisted with the state, but fields change
// every height|round so they don't go in merkle.Tree
type Validator struct {
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
BondHeight int `json:"bond_height"`
UnbondHeight int `json:"unbond_height"`
LastCommitHeight int `json:"last_commit_height"`
VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"`
Address []byte `json:"address"`
PubKey acm.PubKeyEd25519 `json:"pub_key"`
BondHeight int `json:"bond_height"`
UnbondHeight int `json:"unbond_height"`
LastCommitHeight int `json:"last_commit_height"`
VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"`
}
// Creates a new copy of the validator so we can mutate accum.