From 090d68f8fa286d6460d86c07ddb703f3f6587c4d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 6 Apr 2021 21:45:15 +0300 Subject: [PATCH] oracle: add response codes to interop defintions Client should be aware of them. --- pkg/compiler/native_test.go | 13 +++++++++++++ pkg/interop/native/oracle/oracle.go | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index a8ac1361e..e9a0fd6ff 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/interop/native/crypto" "github.com/nspcc-dev/neo-go/pkg/interop/native/gas" "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" @@ -89,6 +90,18 @@ func TestCryptoLibNamedCurve(t *testing.T) { require.EqualValues(t, native.Secp256r1, crypto.Secp256r1) } +func TestOracleResponseCodes(t *testing.T) { + require.EqualValues(t, oracle.Success, transaction.Success) + require.EqualValues(t, oracle.ProtocolNotSupported, transaction.ProtocolNotSupported) + require.EqualValues(t, oracle.ConsensusUnreachable, transaction.ConsensusUnreachable) + require.EqualValues(t, oracle.NotFound, transaction.NotFound) + require.EqualValues(t, oracle.Timeout, transaction.Timeout) + require.EqualValues(t, oracle.Forbidden, transaction.Forbidden) + require.EqualValues(t, oracle.ResponseTooLarge, transaction.ResponseTooLarge) + require.EqualValues(t, oracle.InsufficientFunds, transaction.InsufficientFunds) + require.EqualValues(t, oracle.Error, transaction.Error) +} + type nativeTestCase struct { method string params []string diff --git a/pkg/interop/native/oracle/oracle.go b/pkg/interop/native/oracle/oracle.go index 3a8332346..c1594d67c 100644 --- a/pkg/interop/native/oracle/oracle.go +++ b/pkg/interop/native/oracle/oracle.go @@ -10,6 +10,21 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/contract" ) +// These are potential response codes you get in your callback completing +// oracle request. Resulting data is only passed with Success code, it's +// nil otherwise. +const ( + Success = 0x00 + ProtocolNotSupported = 0x10 + ConsensusUnreachable = 0x12 + NotFound = 0x14 + Timeout = 0x16 + Forbidden = 0x18 + ResponseTooLarge = 0x1a + InsufficientFunds = 0x1c + Error = 0xff +) + // Hash represents Oracle contract hash. const Hash = "\x58\x87\x17\x11\x7e\x0a\xa8\x10\x72\xaf\xab\x71\xd2\xdd\x89\xfe\x7c\x4b\x92\xfe"