mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 21:31:23 +00:00
Remove StorageRoot from vm.Account
This commit is contained in:
@ -12,12 +12,11 @@ import (
|
|||||||
|
|
||||||
func toVMAccount(acc *acm.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,
|
||||||
Code: acc.Code, // This is crazy.
|
Code: acc.Code, // This is crazy.
|
||||||
Nonce: int64(acc.Sequence),
|
Nonce: int64(acc.Sequence),
|
||||||
StorageRoot: LeftPadWord256(acc.StorageRoot),
|
Other: acc.PubKey,
|
||||||
Other: acc.PubKey,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account {
|
|||||||
Balance: 0,
|
Balance: 0,
|
||||||
Code: nil,
|
Code: nil,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
StorageRoot: Zero256,
|
|
||||||
Permissions: cache.GetAccount(ptypes.GlobalPermissionsAddress256).Permissions,
|
Permissions: cache.GetAccount(ptypes.GlobalPermissionsAddress256).Permissions,
|
||||||
Other: nil,
|
Other: nil,
|
||||||
}
|
}
|
||||||
@ -157,7 +156,6 @@ func toVMAccount(acc *acm.Account) *vm.Account {
|
|||||||
Balance: acc.Balance,
|
Balance: acc.Balance,
|
||||||
Code: acc.Code, // This is crazy.
|
Code: acc.Code, // This is crazy.
|
||||||
Nonce: int64(acc.Sequence),
|
Nonce: int64(acc.Sequence),
|
||||||
StorageRoot: LeftPadWord256(acc.StorageRoot),
|
|
||||||
Permissions: acc.Permissions, // Copy
|
Permissions: acc.Permissions, // Copy
|
||||||
Other: acc.PubKey,
|
Other: acc.PubKey,
|
||||||
}
|
}
|
||||||
@ -170,19 +168,12 @@ func toStateAccount(acc *vm.Account) *acm.Account {
|
|||||||
pubKey = nil
|
pubKey = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var storageRoot []byte
|
|
||||||
if acc.StorageRoot.IsZero() {
|
|
||||||
storageRoot = nil
|
|
||||||
} else {
|
|
||||||
storageRoot = acc.StorageRoot.Postfix(20)
|
|
||||||
}
|
|
||||||
return &acm.Account{
|
return &acm.Account{
|
||||||
Address: acc.Address.Postfix(20),
|
Address: acc.Address.Postfix(20),
|
||||||
PubKey: pubKey,
|
PubKey: pubKey,
|
||||||
Balance: acc.Balance,
|
Balance: acc.Balance,
|
||||||
Code: acc.Code,
|
Code: acc.Code,
|
||||||
Sequence: int(acc.Nonce),
|
Sequence: int(acc.Nonce),
|
||||||
StorageRoot: storageRoot,
|
|
||||||
Permissions: acc.Permissions, // Copy
|
Permissions: acc.Permissions, // Copy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/common"
|
|
||||||
"github.com/tendermint/tendermint/wire"
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStateToFromVMAccount(t *testing.T) {
|
func TestStateToFromVMAccount(t *testing.T) {
|
||||||
acmAcc1, _ := RandAccount(true, 456)
|
acmAcc1, _ := RandAccount(true, 456)
|
||||||
acmAcc1.StorageRoot = RandBytes(20)
|
|
||||||
vmAcc := toVMAccount(acmAcc1)
|
vmAcc := toVMAccount(acmAcc1)
|
||||||
acmAcc2 := toStateAccount(vmAcc)
|
acmAcc2 := toStateAccount(vmAcc)
|
||||||
|
|
||||||
|
@ -36,11 +36,10 @@ func (fas *FakeAppState) CreateAccount(creator *Account) *Account {
|
|||||||
account := fas.accounts[addr.String()]
|
account := fas.accounts[addr.String()]
|
||||||
if account == nil {
|
if account == nil {
|
||||||
return &Account{
|
return &Account{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Balance: 0,
|
Balance: 0,
|
||||||
Code: nil,
|
Code: nil,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
StorageRoot: Zero256,
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic(Fmt("Invalid account addr: %X", addr))
|
panic(Fmt("Invalid account addr: %X", addr))
|
||||||
|
15
vm/types.go
15
vm/types.go
@ -10,12 +10,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Address Word256
|
Address Word256
|
||||||
Balance int64
|
Balance int64
|
||||||
Code []byte
|
Code []byte
|
||||||
Nonce int64
|
Nonce int64
|
||||||
StorageRoot Word256
|
Other interface{} // For holding all other data.
|
||||||
Other interface{} // For holding all other data.
|
|
||||||
|
|
||||||
Permissions ptypes.AccountPermissions
|
Permissions ptypes.AccountPermissions
|
||||||
}
|
}
|
||||||
@ -24,8 +23,8 @@ func (acc *Account) String() string {
|
|||||||
if acc == nil {
|
if acc == nil {
|
||||||
return "nil-VMAccount"
|
return "nil-VMAccount"
|
||||||
}
|
}
|
||||||
return Fmt("VMAccount{%X B:%v C:%X N:%v S:%X}",
|
return Fmt("VMAccount{%X B:%v C:%X N:%v}",
|
||||||
acc.Address, acc.Balance, acc.Code, acc.Nonce, acc.StorageRoot)
|
acc.Address, acc.Balance, acc.Code, acc.Nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This is serialized as an event from vm/vm.
|
// NOTE: This is serialized as an event from vm/vm.
|
||||||
|
Reference in New Issue
Block a user