[#23] alphabet: Add OnPayment method

Without OnPayment method alphabet contracts won't be able
to receive NEO and produce GAS.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-10 13:41:16 +03:00 committed by Alex Vanin
parent 37d8905d55
commit bd45e50480
8 changed files with 86 additions and 14 deletions

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")