permission/types pkg, Base and Roles

This commit is contained in:
Ethan Buchman
2015-07-07 14:07:56 -07:00
committed by Jae Kwon
parent 94f21ad012
commit 87ed1f5fda
9 changed files with 286 additions and 67 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ type Account struct {
StorageRoot Word256
Other interface{} // For holding all other data.
Permissions *ptypes.Permissions
Permissions *ptypes.AccountPermissions
}
func (acc *Account) String() string {
+11 -2
View File
@@ -8,6 +8,7 @@ import (
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/events"
ptypes "github.com/tendermint/tendermint/permission/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/vm/sha3"
)
@@ -90,6 +91,14 @@ func (vm *VM) EnablePermissions() {
vm.perms = true
}
func (vm *VM) HasPermission(acc *Account, perm ptypes.PermFlag) bool {
v, err := acc.Permissions.Base.Get(perm)
if _, ok := err.(ptypes.ErrValueNotSet); ok {
return vm.HasPermission(vm.appState.GetAccount(ptypes.GlobalPermissionsAddress256), perm)
}
return v
}
// CONTRACT appState is aware of caller and callee, so we can just mutate them.
// value: To be transferred from caller to callee. Refunded upon error.
// gas: Available gas. No refunds for gas.
@@ -681,7 +690,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
dbg.Printf(" => %v\n", log)
case CREATE: // 0xF0
if vm.perms && !callee.Permissions.Create {
if vm.perms && !vm.HasPermission(callee, ptypes.Create) {
return nil, ErrPermission{"create"}
}
contractValue := stack.Pop64()
@@ -709,7 +718,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
}
case CALL, CALLCODE: // 0xF1, 0xF2
if vm.perms && !callee.Permissions.Call {
if vm.perms && !vm.HasPermission(callee, ptypes.Call) {
return nil, ErrPermission{"call"}
}
gasLimit := stack.Pop64()