github.com/turingchain2020/turingchain@v1.1.21/system/dapp/allow.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package dapp 6 7 import ( 8 "bytes" 9 10 "github.com/turingchain2020/turingchain/types" 11 ) 12 13 // AllowIsSame allow issame drivername 14 func (d *DriverBase) AllowIsSame(execer []byte) bool { 15 types.AssertConfig(d.api) 16 cfg := d.api.GetConfig() 17 execer = cfg.GetParaExec(execer) 18 return d.child.GetDriverName() == string(execer) 19 } 20 21 // AllowIsUserDot1 user.evm 22 func (d *DriverBase) AllowIsUserDot1(execer []byte) bool { 23 types.AssertConfig(d.api) 24 cfg := d.api.GetConfig() 25 execer = cfg.GetParaExec(execer) 26 if !bytes.HasPrefix(execer, types.UserKey) { 27 return false 28 } 29 return d.AllowIsSame(execer[len(types.UserKey):]) 30 } 31 32 // AllowIsUserDot2 user.evm.xxx 33 func (d *DriverBase) AllowIsUserDot2(execer []byte) bool { 34 types.AssertConfig(d.api) 35 cfg := d.api.GetConfig() 36 execer = cfg.GetParaExec(execer) 37 if !bytes.HasPrefix(execer, types.UserKey) { 38 return false 39 } 40 count := 0 41 index := 0 42 s := len(types.UserKey) 43 for i := s; i < len(execer); i++ { 44 if execer[i] == '.' { 45 count++ 46 index = i 47 } 48 } 49 if count == 1 && d.AllowIsSame(execer[s:index]) { 50 return true 51 } 52 return false 53 } 54 55 // Allow default behavior: same name or parallel chain 56 func (d *DriverBase) Allow(tx *types.Transaction, index int) error { 57 if d.AllowIsSame(tx.Execer) { 58 return nil 59 } 60 return types.ErrNotAllow 61 } 62 63 // IsFriend defines a isfriend function 64 func (d *DriverBase) IsFriend(myexec, writekey []byte, othertx *types.Transaction) bool { 65 return false 66 }