forked from TrueCloudLab/frostfs-contract
[#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:
parent
37d8905d55
commit
bd45e50480
8 changed files with 86 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package alphabetcontract
|
package alphabetcontract
|
||||||
|
|
||||||
import (
|
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/binary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
|
@ -51,6 +52,14 @@ func init() {
|
||||||
ctx = storage.GetContext()
|
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) {
|
func Init(addrNetmap []byte) {
|
||||||
if storage.Get(ctx, netmapContractKey) != nil {
|
if storage.Get(ctx, netmapContractKey) != nil {
|
||||||
panic("contract already deployed")
|
panic("contract already deployed")
|
||||||
|
|
Loading…
Reference in a new issue