account permissions and some gendoug

This commit is contained in:
Ethan Buchman
2015-07-07 14:07:07 -07:00
committed by Jae Kwon
parent 3468956e1f
commit a0f3b94e83
9 changed files with 421 additions and 23 deletions
+15 -3
View File
@@ -79,6 +79,7 @@ func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account {
Code: nil,
Nonce: 0,
StorageRoot: Zero256,
Other: otherAccountInfo{nil, toStateAccount(cache.GetAccount(LeftPadWord256(ac.GlobalPermissionsAddress))).Permissions},
}
cache.accounts[addr] = vmAccountInfo{account, false}
return account
@@ -154,6 +155,12 @@ func NewContractAddress(caller []byte, nonce int) []byte {
return sha3.Sha3(temp)[:20]
}
// struct for carrying data the vm need not know about
type otherAccountInfo struct {
PubKey ac.PubKey
Permissions ac.Permissions
}
// Converts backend.Account to vm.Account struct.
func toVMAccount(acc *ac.Account) *vm.Account {
return &vm.Account{
@@ -162,16 +169,20 @@ func toVMAccount(acc *ac.Account) *vm.Account {
Code: acc.Code, // This is crazy.
Nonce: int64(acc.Sequence),
StorageRoot: LeftPadWord256(acc.StorageRoot),
Other: acc.PubKey,
Other: otherAccountInfo{acc.PubKey, acc.Permissions},
}
}
// Converts vm.Account to backend.Account struct.
func toStateAccount(acc *vm.Account) *ac.Account {
pubKey, ok := acc.Other.(ac.PubKey)
otherInfo, ok := acc.Other.(otherAccountInfo)
if !ok {
pubKey = nil
panic("vm.Account.Other should be type state.otherAccountInfo")
}
pubKey := otherInfo.PubKey
perms := otherInfo.Permissions
var storageRoot []byte
if acc.StorageRoot.IsZero() {
storageRoot = nil
@@ -185,6 +196,7 @@ func toStateAccount(acc *vm.Account) *ac.Account {
Code: acc.Code,
Sequence: int(acc.Nonce),
StorageRoot: storageRoot,
Permissions: perms,
}
}