[#49] Revert "Do not read context in init with OnNEP17Payment"
This reverts commit 76c63b7d
It was workaround for neo-go#1725 but now it is fixed
so we don't need that anymore.
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
9cdfcd438e
commit
59d11af046
2 changed files with 14 additions and 43 deletions
|
@ -20,10 +20,16 @@ const (
|
|||
voteKey = "ballots"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx storage.Context
|
||||
)
|
||||
|
||||
func init() {
|
||||
if runtime.GetTrigger() != runtime.Application {
|
||||
panic("contract has not been called in application node")
|
||||
}
|
||||
|
||||
ctx = storage.GetContext()
|
||||
}
|
||||
|
||||
// OnNEP17Payment is a callback for NEP-17 compatible native GAS and NEO contracts.
|
||||
|
@ -35,8 +41,6 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|||
}
|
||||
|
||||
func Init(addrNetmap []byte, name string, index, total int) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if storage.Get(ctx, netmapKey) != nil {
|
||||
panic("contract already deployed")
|
||||
}
|
||||
|
@ -64,33 +68,23 @@ func Neo() int {
|
|||
}
|
||||
|
||||
func irList() []common.IRNode {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return common.InnerRingListViaStorage(ctx, netmapKey)
|
||||
}
|
||||
|
||||
func currentEpoch() int {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
netmapContractAddr := storage.Get(ctx, netmapKey).([]byte)
|
||||
return contract.Call(netmapContractAddr, "epoch", contract.ReadOnly).(int)
|
||||
}
|
||||
|
||||
func name() string {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return storage.Get(ctx, nameKey).(string)
|
||||
}
|
||||
|
||||
func index() int {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return storage.Get(ctx, indexKey).(int)
|
||||
}
|
||||
|
||||
func total() int {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return storage.Get(ctx, totalKey).(int)
|
||||
}
|
||||
|
||||
|
@ -135,8 +129,6 @@ func Emit() bool {
|
|||
}
|
||||
|
||||
func Vote(epoch int, candidates [][]byte) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
innerRingKeys := irList()
|
||||
threshold := total()/3*2 + 1
|
||||
index := index()
|
||||
|
@ -178,8 +170,6 @@ func Name() string {
|
|||
}
|
||||
|
||||
func vote(ctx storage.Context, epoch int, id, from []byte) int {
|
||||
ctx = storage.GetContext()
|
||||
|
||||
var (
|
||||
newCandidates []common.Ballot
|
||||
candidates = getBallots(ctx)
|
||||
|
@ -223,8 +213,6 @@ func vote(ctx storage.Context, epoch int, id, from []byte) int {
|
|||
}
|
||||
|
||||
func removeVotes(ctx storage.Context, id []byte) {
|
||||
ctx = storage.GetContext()
|
||||
|
||||
var (
|
||||
newCandidates []common.Ballot
|
||||
candidates = getBallots(ctx)
|
||||
|
|
|
@ -73,7 +73,11 @@ const (
|
|||
ignoreDepositNotification = "\x57\x0b"
|
||||
)
|
||||
|
||||
var configPrefix = []byte("config")
|
||||
var (
|
||||
configPrefix = []byte("config")
|
||||
|
||||
ctx storage.Context
|
||||
)
|
||||
|
||||
func init() {
|
||||
// The trigger determines whether this smart-contract is being
|
||||
|
@ -81,12 +85,13 @@ func init() {
|
|||
if runtime.GetTrigger() != runtime.Application {
|
||||
panic("contract has not been called in application node")
|
||||
}
|
||||
|
||||
ctx = storage.GetContext()
|
||||
|
||||
}
|
||||
|
||||
// Init set up initial inner ring node keys.
|
||||
func Init(args [][]byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if storage.Get(ctx, innerRingKey) != nil {
|
||||
panic("neofs: contract already deployed")
|
||||
}
|
||||
|
@ -118,22 +123,16 @@ func Init(args [][]byte) bool {
|
|||
|
||||
// InnerRingList returns array of inner ring node keys.
|
||||
func InnerRingList() []common.IRNode {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return getInnerRingNodes(ctx, innerRingKey)
|
||||
}
|
||||
|
||||
// InnerRingCandidates returns array of inner ring candidate node keys.
|
||||
func InnerRingCandidates() []common.IRNode {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return getInnerRingNodes(ctx, candidatesKey)
|
||||
}
|
||||
|
||||
// InnerRingCandidateRemove removes key from the list of inner ring candidates.
|
||||
func InnerRingCandidateRemove(key []byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if !runtime.CheckWitness(key) {
|
||||
panic("irCandidateRemove: you should be the owner of the public key")
|
||||
}
|
||||
|
@ -157,8 +156,6 @@ func InnerRingCandidateRemove(key []byte) bool {
|
|||
|
||||
// InnerRingCandidateAdd adds key to the list of inner ring candidates.
|
||||
func InnerRingCandidateAdd(key []byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if !runtime.CheckWitness(key) {
|
||||
panic("irCandidateAdd: you should be the owner of the public key")
|
||||
}
|
||||
|
@ -262,8 +259,6 @@ func Withdraw(user []byte, amount int) bool {
|
|||
// Cheque sends gas assets back to the user if they were successfully
|
||||
// locked in NeoFS balance contract.
|
||||
func Cheque(id, user []byte, amount int, lockAcc []byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
irList := getInnerRingNodes(ctx, innerRingKey)
|
||||
threshold := len(irList)/3*2 + 1
|
||||
|
||||
|
@ -341,8 +336,6 @@ func Unbind(user []byte, keys [][]byte) bool {
|
|||
// InnerRingUpdate updates list of inner ring nodes with provided list of
|
||||
// public keys.
|
||||
func InnerRingUpdate(chequeID []byte, args [][]byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if len(args) < minInnerRingSize {
|
||||
panic("irUpdate: bad arguments")
|
||||
}
|
||||
|
@ -416,8 +409,6 @@ loop:
|
|||
|
||||
// IsInnerRing returns 'true' if key is inside of inner ring list.
|
||||
func IsInnerRing(key []byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if len(key) != publicKeySize {
|
||||
panic("isInnerRing: incorrect public key")
|
||||
}
|
||||
|
@ -436,15 +427,11 @@ func IsInnerRing(key []byte) bool {
|
|||
|
||||
// Config returns value of NeoFS configuration with provided key.
|
||||
func Config(key []byte) interface{} {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
return getConfig(ctx, key)
|
||||
}
|
||||
|
||||
// SetConfig key-value pair as a NeoFS runtime configuration value.
|
||||
func SetConfig(id, key, val []byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
// check if it is inner ring invocation
|
||||
irList := getInnerRingNodes(ctx, innerRingKey)
|
||||
threshold := len(irList)/3*2 + 1
|
||||
|
@ -482,8 +469,6 @@ func SetConfig(id, key, val []byte) bool {
|
|||
|
||||
// ListConfig returns array of all key-value pairs of NeoFS configuration.
|
||||
func ListConfig() []record {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
var config []record
|
||||
|
||||
it := storage.Find(ctx, configPrefix, storage.None)
|
||||
|
@ -501,8 +486,6 @@ func ListConfig() []record {
|
|||
|
||||
// InitConfig set up initial NeoFS key-value configuration.
|
||||
func InitConfig(args [][]byte) bool {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
if getConfig(ctx, candidateFeeConfigKey) != nil {
|
||||
panic("neofs: configuration already installed")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue