diff --git a/alphabet/alphabet.tpl b/alphabet/alphabet.tpl index 27f6b67..39a2360 100644 --- a/alphabet/alphabet.tpl +++ b/alphabet/alphabet.tpl @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") diff --git a/alphabet/az/az_contract.go b/alphabet/az/az_contract.go index b01f365..8a73d42 100644 --- a/alphabet/az/az_contract.go +++ b/alphabet/az/az_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/buky/buky_contract.go b/alphabet/buky/buky_contract.go index 6c289f4..5f648ac 100644 --- a/alphabet/buky/buky_contract.go +++ b/alphabet/buky/buky_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/dobro/dobro_contract.go b/alphabet/dobro/dobro_contract.go index b0e2957..33ac6b4 100644 --- a/alphabet/dobro/dobro_contract.go +++ b/alphabet/dobro/dobro_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/glagoli/glagoli_contract.go b/alphabet/glagoli/glagoli_contract.go index cb4cb7a..5c92f7f 100644 --- a/alphabet/glagoli/glagoli_contract.go +++ b/alphabet/glagoli/glagoli_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/jest/jest_contract.go b/alphabet/jest/jest_contract.go index 152dc00..d96a7e1 100644 --- a/alphabet/jest/jest_contract.go +++ b/alphabet/jest/jest_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/vedi/vedi_contract.go b/alphabet/vedi/vedi_contract.go index a5f623b..e480d08 100644 --- a/alphabet/vedi/vedi_contract.go +++ b/alphabet/vedi/vedi_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) ) diff --git a/alphabet/zhivete/zhivete_contract.go b/alphabet/zhivete/zhivete_contract.go index 2a76f6f..5c060cd 100644 --- a/alphabet/zhivete/zhivete_contract.go +++ b/alphabet/zhivete/zhivete_contract.go @@ -1,6 +1,7 @@ package alphabetcontract import ( + "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/crypto" @@ -33,7 +34,7 @@ const ( netmapContractKey = "netmapScriptHash" - threshold = totalAlphabetContracts * 2 / 3 + 1 + threshold = totalAlphabetContracts*2/3 + 1 voteKey = "ballots" totalAlphabetContracts = 7 @@ -51,6 +52,14 @@ func init() { ctx = storage.GetContext() } +// OnPayment is a callback for NEP-17 compatible native GAS and NEO contracts. +func OnPayment(from interop.Hash160, amount int, data interface{}) { + caller := runtime.GetCallingScriptHash() + if !bytesEqual(caller, []byte(gasHash)) && !bytesEqual(caller, []byte(neoHash)) { + panic("onPayment: alphabet contract accepts GAS and NEO only") + } +} + func Init(addrNetmap []byte) { if storage.Get(ctx, netmapContractKey) != nil { panic("contract already deployed") @@ -264,7 +273,7 @@ func bytesEqual(a []byte, b []byte) bool { func voteID(epoch interface{}, args [][]byte) []byte { var ( - result []byte + result []byte epochBytes = epoch.([]byte) )