|
@ -462,10 +462,8 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea |
|
|
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
|
|
|
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
|
|
|
|
|
|
|
|
|
if isDoug { |
|
|
if isDoug { |
|
|
// we need to bind a copy of the accounts tree (from the txCache)
|
|
|
|
|
|
// so the gendoug can make a native call to create accounts and update
|
|
|
|
|
|
// permissions
|
|
|
|
|
|
// setupDoug(vmach, txCache, _s)
|
|
|
|
|
|
|
|
|
// enables the snative contracts
|
|
|
|
|
|
vmach.EnableDoug() // setupDoug(vmach, txCache, _s)
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ret, err := vmach.Call(caller, callee, code, tx.Data, value, &gas) |
|
|
ret, err := vmach.Call(caller, callee, code, tx.Data, value, &gas) |
|
@ -831,126 +829,3 @@ func hasBondPermission(state AccountGetter, accs map[string]*account.Account) bo |
|
|
} |
|
|
} |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
// permission management functions
|
|
|
|
|
|
// get/set closures which bind the txCache (for modifying an accounts permissions)
|
|
|
|
|
|
// add/rm closures which bind txCache & state (for creating/removing permissions on *all* accounts - expensive!)
|
|
|
|
|
|
func setupDoug(vmach *vm.VM, txCache *TxCache, _s *State) { |
|
|
|
|
|
|
|
|
|
|
|
// get takes (address, permissionNum Word256), returns a permission int
|
|
|
|
|
|
getFunc := func(args []byte, gas *uint64) (output []byte, err error) { |
|
|
|
|
|
if len(args) != 2*32 { |
|
|
|
|
|
return nil, fmt.Errorf("Get() takes two arguments (address, permission number)") |
|
|
|
|
|
} |
|
|
|
|
|
var addr, permNum Word256 |
|
|
|
|
|
copy(addr[:], args[:32]) |
|
|
|
|
|
copy(permNum[:], args[32:64]) |
|
|
|
|
|
vmAcc := txCache.GetAccount(addr) |
|
|
|
|
|
if vmAcc == nil { |
|
|
|
|
|
return nil, fmt.Errorf("Unknown account %X", addr) |
|
|
|
|
|
} |
|
|
|
|
|
stAcc := toStateAccount(vmAcc) |
|
|
|
|
|
permN := uint(Uint64FromWord256(permNum)) |
|
|
|
|
|
perm, err := stAcc.Permissions.Base.Get(permN) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
var permInt byte |
|
|
|
|
|
if perm { |
|
|
|
|
|
permInt = 0x1 |
|
|
|
|
|
} else { |
|
|
|
|
|
permInt = 0x0 |
|
|
|
|
|
} |
|
|
|
|
|
return LeftPadWord256([]byte{permInt}).Bytes(), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set takes (address, permissionNum, permissionValue Word256), returns the permission value
|
|
|
|
|
|
setFunc := func(args []byte, gas *uint64) (output []byte, err error) { |
|
|
|
|
|
if len(args) != 3*32 { |
|
|
|
|
|
return nil, fmt.Errorf("Set() takes three arguments (address, permission number, permission value)") |
|
|
|
|
|
} |
|
|
|
|
|
var addr, permNum, perm Word256 |
|
|
|
|
|
copy(addr[:], args[:32]) |
|
|
|
|
|
copy(permNum[:], args[32:64]) |
|
|
|
|
|
copy(perm[:], args[64:96]) |
|
|
|
|
|
vmAcc := txCache.GetAccount(addr) |
|
|
|
|
|
if vmAcc == nil { |
|
|
|
|
|
return nil, fmt.Errorf("Unknown account %X", addr) |
|
|
|
|
|
} |
|
|
|
|
|
stAcc := toStateAccount(vmAcc) |
|
|
|
|
|
permN := uint(Uint64FromWord256(permNum)) |
|
|
|
|
|
permV := !perm.IsZero() |
|
|
|
|
|
if err = stAcc.Permissions.Base.Set(permN, permV); err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
vmAcc = toVMAccount(stAcc) |
|
|
|
|
|
txCache.UpdateAccount(vmAcc) |
|
|
|
|
|
return perm.Bytes(), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// add creates a new permission at the next available index and returns the index
|
|
|
|
|
|
addFunc := func(args []byte, gas *uint64) (output []byte, err error) { |
|
|
|
|
|
if len(args) != 0 { |
|
|
|
|
|
return nil, fmt.Errorf("Add() takes no arguments") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
accounts := _s.GetAccounts() |
|
|
|
|
|
size := accounts.Size() |
|
|
|
|
|
var l int |
|
|
|
|
|
for i := uint64(0); i < size; i++ { |
|
|
|
|
|
_, v := accounts.GetByIndex(uint64(i)) |
|
|
|
|
|
acc := v.(*account.Account) |
|
|
|
|
|
|
|
|
|
|
|
if i == 0 { |
|
|
|
|
|
l = len(acc.Permissions.Other) |
|
|
|
|
|
} else if l != len(acc.Permissions.Other) { |
|
|
|
|
|
panic(Fmt("Accounts have different numbers of permissions: %v, %v", l, acc.Permissions.Other)) |
|
|
|
|
|
} |
|
|
|
|
|
if _, err := acc.Permissions.Add(false); err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
txCache.UpdateAccount(toVMAccount(acc)) |
|
|
|
|
|
} |
|
|
|
|
|
return Uint64ToWord256(uint64(l)).Bytes(), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// rm takes (permissionNum) and removes the corresponding permission, shortening the `Other` list.
|
|
|
|
|
|
// returns the permissionNum
|
|
|
|
|
|
rmFunc := func(args []byte, gas *uint64) (output []byte, err error) { |
|
|
|
|
|
if len(args) != 32 { |
|
|
|
|
|
return nil, fmt.Errorf("Get() takes one argument (permissionNum)") |
|
|
|
|
|
} |
|
|
|
|
|
var permNum Word256 |
|
|
|
|
|
copy(permNum[:], args[:32]) |
|
|
|
|
|
permN := uint(Uint64FromWord256(permNum)) // danger?
|
|
|
|
|
|
|
|
|
|
|
|
accounts := _s.GetAccounts() |
|
|
|
|
|
size := accounts.Size() |
|
|
|
|
|
var l int |
|
|
|
|
|
for i := uint64(0); i < size; i++ { |
|
|
|
|
|
_, v := accounts.GetByIndex(uint64(i)) |
|
|
|
|
|
acc := v.(*account.Account) |
|
|
|
|
|
|
|
|
|
|
|
if i == 0 { |
|
|
|
|
|
l = len(acc.Permissions.Other) |
|
|
|
|
|
} else if l != len(acc.Permissions.Other) { |
|
|
|
|
|
panic(Fmt("Accounts have different numbers of permissions: %v, %v", l, acc.Permissions.Other)) |
|
|
|
|
|
} |
|
|
|
|
|
acc.Permissions.Remove(permN) |
|
|
|
|
|
txCache.UpdateAccount(toVMAccount(acc)) |
|
|
|
|
|
} |
|
|
|
|
|
return args, nil |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set the native contract addresses and functions
|
|
|
|
|
|
vmach.SetDougFunc(RightPadWord256([]byte("get")), vm.NativeContract(getFunc)) |
|
|
|
|
|
vmach.SetDougFunc(RightPadWord256([]byte("set")), vm.NativeContract(setFunc)) |
|
|
|
|
|
vmach.SetDougFunc(RightPadWord256([]byte("add")), vm.NativeContract(addFunc)) |
|
|
|
|
|
vmach.SetDougFunc(RightPadWord256([]byte("rm")), vm.NativeContract(rmFunc)) |
|
|
|
|
|
|
|
|
|
|
|
// must be called or else functions not accessible
|
|
|
|
|
|
vmach.EnableDoug() |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|