2020-06-15 18:13:32 +00:00
|
|
|
package native
|
|
|
|
|
|
|
|
import (
|
2020-08-06 15:34:44 +00:00
|
|
|
"fmt"
|
2020-06-15 18:13:32 +00:00
|
|
|
"math/big"
|
|
|
|
"sort"
|
2020-06-18 18:36:20 +00:00
|
|
|
"sync"
|
2020-06-15 18:13:32 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
2020-12-13 18:25:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
2020-06-15 18:13:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-12-29 10:45:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
2020-06-15 18:13:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
2020-10-06 09:00:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-06-15 18:13:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-02-15 15:43:10 +00:00
|
|
|
policyContractID = -7
|
2020-06-15 18:13:32 +00:00
|
|
|
|
2021-02-17 15:22:57 +00:00
|
|
|
defaultExecFeeFactor = interop.DefaultBaseExecFee
|
|
|
|
defaultFeePerByte = 1000
|
2021-07-07 13:14:49 +00:00
|
|
|
defaultMaxVerificationGas = 1_50000000
|
2021-02-02 15:46:43 +00:00
|
|
|
// DefaultStoragePrice is the price to pay for 1 byte of storage.
|
|
|
|
DefaultStoragePrice = 100000
|
|
|
|
|
2020-12-14 09:18:59 +00:00
|
|
|
// maxExecFeeFactor is the maximum allowed execution fee factor.
|
2021-07-08 07:06:10 +00:00
|
|
|
maxExecFeeFactor = 100
|
2020-10-02 15:15:16 +00:00
|
|
|
// maxFeePerByte is the maximum allowed fee per byte value.
|
|
|
|
maxFeePerByte = 100_000_000
|
2020-12-14 09:41:23 +00:00
|
|
|
// maxStoragePrice is the maximum allowed price for a byte of storage.
|
|
|
|
maxStoragePrice = 10000000
|
2020-10-21 12:51:59 +00:00
|
|
|
|
|
|
|
// blockedAccountPrefix is a prefix used to store blocked account.
|
|
|
|
blockedAccountPrefix = 15
|
2020-06-15 18:13:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-12-14 09:18:59 +00:00
|
|
|
// execFeeFactorKey is a key used to store execution fee factor.
|
|
|
|
execFeeFactorKey = []byte{18}
|
2020-06-15 18:13:32 +00:00
|
|
|
// feePerByteKey is a key used to store the minimum fee per byte for
|
|
|
|
// transaction.
|
|
|
|
feePerByteKey = []byte{10}
|
2020-12-14 09:41:23 +00:00
|
|
|
// storagePriceKey is a key used to store storage price.
|
|
|
|
storagePriceKey = []byte{19}
|
2020-06-15 18:13:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Policy represents Policy native contract.
|
|
|
|
type Policy struct {
|
|
|
|
interop.ContractMD
|
2021-01-21 12:05:15 +00:00
|
|
|
NEO *NEO
|
2020-06-18 18:36:20 +00:00
|
|
|
lock sync.RWMutex
|
|
|
|
// isValid defies whether cached values were changed during the current
|
|
|
|
// consensus iteration. If false, these values will be updated after
|
|
|
|
// blockchain DAO persisting. If true, we can safely use cached values.
|
2021-02-17 15:22:57 +00:00
|
|
|
isValid bool
|
|
|
|
execFeeFactor uint32
|
|
|
|
feePerByte int64
|
|
|
|
maxVerificationGas int64
|
|
|
|
storagePrice uint32
|
|
|
|
blockedAccounts []util.Uint160
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ interop.Contract = (*Policy)(nil)
|
|
|
|
|
|
|
|
// newPolicy returns Policy native contract.
|
|
|
|
func newPolicy() *Policy {
|
2021-01-15 21:17:31 +00:00
|
|
|
p := &Policy{ContractMD: *interop.NewContractMD(nativenames.Policy, policyContractID)}
|
2021-02-15 13:40:44 +00:00
|
|
|
defer p.UpdateHash()
|
2020-06-15 18:13:32 +00:00
|
|
|
|
2021-02-17 15:33:53 +00:00
|
|
|
desc := newDescriptor("getFeePerByte", smartcontract.IntegerType)
|
2021-03-05 10:30:16 +00:00
|
|
|
md := newMethodAndPrice(p.getFeePerByte, 1<<15, callflag.ReadStates)
|
2020-12-08 10:27:41 +00:00
|
|
|
p.AddMethod(md, desc)
|
2020-06-15 18:13:32 +00:00
|
|
|
|
2020-10-21 12:51:59 +00:00
|
|
|
desc = newDescriptor("isBlocked", smartcontract.BoolType,
|
2021-01-12 15:06:27 +00:00
|
|
|
manifest.NewParameter("account", smartcontract.Hash160Type))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.isBlocked, 1<<15, callflag.ReadStates)
|
2020-12-08 10:27:41 +00:00
|
|
|
p.AddMethod(md, desc)
|
2020-06-15 18:13:32 +00:00
|
|
|
|
2020-12-14 09:18:59 +00:00
|
|
|
desc = newDescriptor("getExecFeeFactor", smartcontract.IntegerType)
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.getExecFeeFactor, 1<<15, callflag.ReadStates)
|
2020-12-14 09:18:59 +00:00
|
|
|
p.AddMethod(md, desc)
|
|
|
|
|
2021-01-28 15:01:30 +00:00
|
|
|
desc = newDescriptor("setExecFeeFactor", smartcontract.VoidType,
|
2020-12-14 09:18:59 +00:00
|
|
|
manifest.NewParameter("value", smartcontract.IntegerType))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.setExecFeeFactor, 1<<15, callflag.States)
|
2020-12-14 09:18:59 +00:00
|
|
|
p.AddMethod(md, desc)
|
|
|
|
|
2020-12-14 09:41:23 +00:00
|
|
|
desc = newDescriptor("getStoragePrice", smartcontract.IntegerType)
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.getStoragePrice, 1<<15, callflag.ReadStates)
|
2020-12-14 09:41:23 +00:00
|
|
|
p.AddMethod(md, desc)
|
|
|
|
|
2021-01-28 15:01:30 +00:00
|
|
|
desc = newDescriptor("setStoragePrice", smartcontract.VoidType,
|
2020-12-14 09:41:23 +00:00
|
|
|
manifest.NewParameter("value", smartcontract.IntegerType))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.setStoragePrice, 1<<15, callflag.States)
|
2020-12-14 09:41:23 +00:00
|
|
|
p.AddMethod(md, desc)
|
|
|
|
|
2021-01-28 15:01:30 +00:00
|
|
|
desc = newDescriptor("setFeePerByte", smartcontract.VoidType,
|
2020-06-15 18:13:32 +00:00
|
|
|
manifest.NewParameter("value", smartcontract.IntegerType))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.setFeePerByte, 1<<15, callflag.States)
|
2020-12-08 10:27:41 +00:00
|
|
|
p.AddMethod(md, desc)
|
2020-06-15 18:13:32 +00:00
|
|
|
|
|
|
|
desc = newDescriptor("blockAccount", smartcontract.BoolType,
|
2021-01-12 15:06:27 +00:00
|
|
|
manifest.NewParameter("account", smartcontract.Hash160Type))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.blockAccount, 1<<15, callflag.States)
|
2020-12-08 10:27:41 +00:00
|
|
|
p.AddMethod(md, desc)
|
2020-06-15 18:13:32 +00:00
|
|
|
|
|
|
|
desc = newDescriptor("unblockAccount", smartcontract.BoolType,
|
2021-01-12 15:06:27 +00:00
|
|
|
manifest.NewParameter("account", smartcontract.Hash160Type))
|
2021-03-05 10:30:16 +00:00
|
|
|
md = newMethodAndPrice(p.unblockAccount, 1<<15, callflag.States)
|
2020-12-08 10:27:41 +00:00
|
|
|
p.AddMethod(md, desc)
|
2020-06-15 18:13:32 +00:00
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metadata implements Contract interface.
|
|
|
|
func (p *Policy) Metadata() *interop.ContractMD {
|
|
|
|
return &p.ContractMD
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize initializes Policy native contract and implements Contract interface.
|
|
|
|
func (p *Policy) Initialize(ic *interop.Context) error {
|
2022-02-16 14:48:15 +00:00
|
|
|
setIntWithKey(p.ID, ic.DAO, feePerByteKey, defaultFeePerByte)
|
|
|
|
setIntWithKey(p.ID, ic.DAO, execFeeFactorKey, defaultExecFeeFactor)
|
|
|
|
setIntWithKey(p.ID, ic.DAO, storagePriceKey, DefaultStoragePrice)
|
2021-02-02 15:46:43 +00:00
|
|
|
|
2020-06-18 18:36:20 +00:00
|
|
|
p.isValid = true
|
2020-12-14 09:18:59 +00:00
|
|
|
p.execFeeFactor = defaultExecFeeFactor
|
2020-06-18 18:36:20 +00:00
|
|
|
p.feePerByte = defaultFeePerByte
|
2020-07-25 11:32:04 +00:00
|
|
|
p.maxVerificationGas = defaultMaxVerificationGas
|
2021-02-02 15:46:43 +00:00
|
|
|
p.storagePrice = DefaultStoragePrice
|
2020-10-06 09:00:42 +00:00
|
|
|
p.blockedAccounts = make([]util.Uint160, 0)
|
2020-06-18 18:36:20 +00:00
|
|
|
|
2020-06-15 18:13:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnPersist implements Contract interface.
|
|
|
|
func (p *Policy) OnPersist(ic *interop.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-13 18:36:06 +00:00
|
|
|
// PostPersist implements Contract interface.
|
|
|
|
func (p *Policy) PostPersist(ic *interop.Context) error {
|
2020-12-13 20:30:21 +00:00
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2020-06-18 18:36:20 +00:00
|
|
|
if p.isValid {
|
2020-10-06 09:00:42 +00:00
|
|
|
return nil
|
2020-06-18 18:36:20 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 09:26:25 +00:00
|
|
|
p.execFeeFactor = uint32(getIntWithKey(p.ID, ic.DAO, execFeeFactorKey))
|
|
|
|
p.feePerByte = getIntWithKey(p.ID, ic.DAO, feePerByteKey)
|
2020-08-03 10:30:51 +00:00
|
|
|
p.maxVerificationGas = defaultMaxVerificationGas
|
2021-02-09 09:26:25 +00:00
|
|
|
p.storagePrice = uint32(getIntWithKey(p.ID, ic.DAO, storagePriceKey))
|
2020-08-03 10:30:51 +00:00
|
|
|
|
2020-10-21 12:51:59 +00:00
|
|
|
p.blockedAccounts = make([]util.Uint160, 0)
|
2021-09-24 14:22:45 +00:00
|
|
|
siArr, err := ic.DAO.GetStorageItemsWithPrefix(p.ID, []byte{blockedAccountPrefix})
|
2020-10-06 09:00:42 +00:00
|
|
|
if err != nil {
|
2020-10-21 12:51:59 +00:00
|
|
|
return fmt.Errorf("failed to get blocked accounts from storage: %w", err)
|
2020-10-06 09:00:42 +00:00
|
|
|
}
|
2021-09-24 14:22:45 +00:00
|
|
|
for _, kv := range siArr {
|
|
|
|
hash, err := util.Uint160DecodeBytesBE([]byte(kv.Key))
|
2020-10-21 12:51:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to decode blocked account hash: %w", err)
|
|
|
|
}
|
|
|
|
p.blockedAccounts = append(p.blockedAccounts, hash)
|
|
|
|
}
|
2021-09-24 14:22:45 +00:00
|
|
|
// blockedAccounts should be sorted by account BE bytes, but GetStorageItemsWithPrefix
|
|
|
|
// returns values sorted by key (which is account's BE bytes), so don't need to sort
|
|
|
|
// one more time.
|
2020-10-06 09:00:42 +00:00
|
|
|
|
2020-06-18 18:36:20 +00:00
|
|
|
p.isValid = true
|
2020-10-06 09:00:42 +00:00
|
|
|
return nil
|
2020-06-18 18:36:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 18:13:32 +00:00
|
|
|
// getFeePerByte is Policy contract method and returns required transaction's fee
|
|
|
|
// per byte.
|
|
|
|
func (p *Policy) getFeePerByte(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
|
|
|
return stackitem.NewBigInteger(big.NewInt(p.GetFeePerByteInternal(ic.DAO)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFeePerByteInternal returns required transaction's fee per byte.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) GetFeePerByteInternal(dao *dao.Simple) int64 {
|
2020-06-18 18:36:20 +00:00
|
|
|
p.lock.RLock()
|
|
|
|
defer p.lock.RUnlock()
|
|
|
|
if p.isValid {
|
|
|
|
return p.feePerByte
|
|
|
|
}
|
2021-02-09 09:26:25 +00:00
|
|
|
return getIntWithKey(p.ID, dao, feePerByteKey)
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 11:32:04 +00:00
|
|
|
// GetMaxVerificationGas returns maximum gas allowed to be burned during verificaion.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) GetMaxVerificationGas(_ *dao.Simple) int64 {
|
2020-08-03 10:30:51 +00:00
|
|
|
if p.isValid {
|
|
|
|
return p.maxVerificationGas
|
|
|
|
}
|
|
|
|
return defaultMaxVerificationGas
|
2020-07-25 11:32:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 09:18:59 +00:00
|
|
|
func (p *Policy) getExecFeeFactor(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
|
|
|
return stackitem.NewBigInteger(big.NewInt(int64(p.GetExecFeeFactorInternal(ic.DAO))))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetExecFeeFactorInternal returns current execution fee factor.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) GetExecFeeFactorInternal(d *dao.Simple) int64 {
|
2020-12-14 09:18:59 +00:00
|
|
|
p.lock.RLock()
|
|
|
|
defer p.lock.RUnlock()
|
|
|
|
if p.isValid {
|
|
|
|
return int64(p.execFeeFactor)
|
|
|
|
}
|
2021-02-09 09:26:25 +00:00
|
|
|
return getIntWithKey(p.ID, d, execFeeFactorKey)
|
2020-12-14 09:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Policy) setExecFeeFactor(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
|
|
|
value := toUint32(args[0])
|
|
|
|
if value <= 0 || maxExecFeeFactor < value {
|
|
|
|
panic(fmt.Errorf("ExecFeeFactor must be between 0 and %d", maxExecFeeFactor))
|
|
|
|
}
|
2021-01-21 12:05:15 +00:00
|
|
|
if !p.NEO.checkCommittee(ic) {
|
2021-01-28 15:01:30 +00:00
|
|
|
panic("invalid committee signature")
|
2020-12-14 09:18:59 +00:00
|
|
|
}
|
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2022-02-16 14:48:15 +00:00
|
|
|
setIntWithKey(p.ID, ic.DAO, execFeeFactorKey, int64(value))
|
2020-12-14 09:18:59 +00:00
|
|
|
p.isValid = false
|
2021-01-28 15:01:30 +00:00
|
|
|
return stackitem.Null{}
|
2020-12-14 09:18:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 12:51:59 +00:00
|
|
|
// isBlocked is Policy contract method and checks whether provided account is blocked.
|
|
|
|
func (p *Policy) isBlocked(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
|
|
|
hash := toUint160(args[0])
|
|
|
|
return stackitem.NewBool(p.IsBlockedInternal(ic.DAO, hash))
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 20:17:03 +00:00
|
|
|
// IsBlockedInternal checks whether provided account is blocked.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) IsBlockedInternal(dao *dao.Simple, hash util.Uint160) bool {
|
2020-10-06 09:00:42 +00:00
|
|
|
p.lock.RLock()
|
|
|
|
defer p.lock.RUnlock()
|
|
|
|
if p.isValid {
|
2020-10-21 12:51:59 +00:00
|
|
|
length := len(p.blockedAccounts)
|
|
|
|
i := sort.Search(length, func(i int) bool {
|
|
|
|
return !p.blockedAccounts[i].Less(hash)
|
|
|
|
})
|
|
|
|
if length != 0 && i != length && p.blockedAccounts[i].Equals(hash) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
key := append([]byte{blockedAccountPrefix}, hash.BytesBE()...)
|
2021-02-09 09:26:25 +00:00
|
|
|
return dao.GetStorageItem(p.ID, key) != nil
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 09:41:23 +00:00
|
|
|
func (p *Policy) getStoragePrice(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
|
|
|
return stackitem.NewBigInteger(big.NewInt(p.GetStoragePriceInternal(ic.DAO)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStoragePriceInternal returns current execution fee factor.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) GetStoragePriceInternal(d *dao.Simple) int64 {
|
2020-12-14 09:41:23 +00:00
|
|
|
p.lock.RLock()
|
|
|
|
defer p.lock.RUnlock()
|
|
|
|
if p.isValid {
|
|
|
|
return int64(p.storagePrice)
|
|
|
|
}
|
2021-02-09 09:26:25 +00:00
|
|
|
return getIntWithKey(p.ID, d, storagePriceKey)
|
2020-12-14 09:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Policy) setStoragePrice(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
|
|
|
value := toUint32(args[0])
|
|
|
|
if value <= 0 || maxStoragePrice < value {
|
|
|
|
panic(fmt.Errorf("StoragePrice must be between 0 and %d", maxStoragePrice))
|
|
|
|
}
|
2021-01-21 12:05:15 +00:00
|
|
|
if !p.NEO.checkCommittee(ic) {
|
2021-01-28 15:01:30 +00:00
|
|
|
panic("invalid committee signature")
|
2020-12-14 09:41:23 +00:00
|
|
|
}
|
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2022-02-16 14:48:15 +00:00
|
|
|
setIntWithKey(p.ID, ic.DAO, storagePriceKey, int64(value))
|
2020-12-14 09:41:23 +00:00
|
|
|
p.isValid = false
|
2021-01-28 15:01:30 +00:00
|
|
|
return stackitem.Null{}
|
2020-12-14 09:41:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 18:13:32 +00:00
|
|
|
// setFeePerByte is Policy contract method and sets transaction's fee per byte.
|
|
|
|
func (p *Policy) setFeePerByte(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
2020-10-02 15:15:16 +00:00
|
|
|
value := toBigInt(args[0]).Int64()
|
|
|
|
if value < 0 || value > maxFeePerByte {
|
|
|
|
panic(fmt.Errorf("FeePerByte shouldn't be negative or greater than %d", maxFeePerByte))
|
|
|
|
}
|
2021-01-21 12:05:15 +00:00
|
|
|
if !p.NEO.checkCommittee(ic) {
|
2021-01-28 15:01:30 +00:00
|
|
|
panic("invalid committee signature")
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
2020-06-18 18:36:20 +00:00
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2022-02-16 14:48:15 +00:00
|
|
|
setIntWithKey(p.ID, ic.DAO, feePerByteKey, value)
|
2020-06-18 18:36:20 +00:00
|
|
|
p.isValid = false
|
2021-01-28 15:01:30 +00:00
|
|
|
return stackitem.Null{}
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// blockAccount is Policy contract method and adds given account hash to the list
|
|
|
|
// of blocked accounts.
|
|
|
|
func (p *Policy) blockAccount(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
2021-01-21 12:05:15 +00:00
|
|
|
if !p.NEO.checkCommittee(ic) {
|
2021-01-28 15:01:30 +00:00
|
|
|
panic("invalid committee signature")
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
hash := toUint160(args[0])
|
2021-09-03 08:08:30 +00:00
|
|
|
for i := range ic.Natives {
|
|
|
|
if ic.Natives[i].Metadata().Hash == hash {
|
|
|
|
panic("cannot block native contract")
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
if p.IsBlockedInternal(ic.DAO, hash) {
|
2020-06-15 18:13:32 +00:00
|
|
|
return stackitem.NewBool(false)
|
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
key := append([]byte{blockedAccountPrefix}, hash.BytesBE()...)
|
2020-10-06 09:00:42 +00:00
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2022-02-16 14:48:15 +00:00
|
|
|
ic.DAO.PutStorageItem(p.ID, key, state.StorageItem{})
|
2020-10-06 09:00:42 +00:00
|
|
|
p.isValid = false
|
2020-06-15 18:13:32 +00:00
|
|
|
return stackitem.NewBool(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// unblockAccount is Policy contract method and removes given account hash from
|
|
|
|
// the list of blocked accounts.
|
|
|
|
func (p *Policy) unblockAccount(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
2021-01-21 12:05:15 +00:00
|
|
|
if !p.NEO.checkCommittee(ic) {
|
2021-01-28 15:01:30 +00:00
|
|
|
panic("invalid committee signature")
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
hash := toUint160(args[0])
|
|
|
|
if !p.IsBlockedInternal(ic.DAO, hash) {
|
2020-06-15 18:13:32 +00:00
|
|
|
return stackitem.NewBool(false)
|
|
|
|
}
|
2020-10-21 12:51:59 +00:00
|
|
|
key := append([]byte{blockedAccountPrefix}, hash.BytesBE()...)
|
2020-10-06 09:00:42 +00:00
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
2022-02-16 14:48:15 +00:00
|
|
|
ic.DAO.DeleteStorageItem(p.ID, key)
|
2020-10-06 09:00:42 +00:00
|
|
|
p.isValid = false
|
2020-06-15 18:13:32 +00:00
|
|
|
return stackitem.NewBool(true)
|
|
|
|
}
|
|
|
|
|
2020-08-06 18:49:54 +00:00
|
|
|
// CheckPolicy checks whether transaction conforms to current policy restrictions
|
|
|
|
// like not being signed by blocked account or not exceeding block-level system
|
|
|
|
// fee limit.
|
2022-02-16 15:04:47 +00:00
|
|
|
func (p *Policy) CheckPolicy(d *dao.Simple, tx *transaction.Transaction) error {
|
2020-10-21 12:51:59 +00:00
|
|
|
for _, signer := range tx.Signers {
|
|
|
|
if p.IsBlockedInternal(d, signer.Account) {
|
|
|
|
return fmt.Errorf("account %s is blocked", signer.Account.StringLE())
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 15:34:44 +00:00
|
|
|
return nil
|
2020-06-15 18:13:32 +00:00
|
|
|
}
|