From 161b83fd7f70ea0ce727f39ab2469ae9eb444d4e Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 23 Jan 2024 14:50:26 +0300 Subject: [PATCH] rpcclient: ensure nns.RecordType can be passed as a parameter to invoker Implement smartcontract.Convertible for nns.RecordType. Signed-off-by: Anna Shaleva --- pkg/rpcclient/nns/record.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/rpcclient/nns/record.go b/pkg/rpcclient/nns/record.go index da017f9ab..17ad4b40d 100644 --- a/pkg/rpcclient/nns/record.go +++ b/pkg/rpcclient/nns/record.go @@ -3,7 +3,9 @@ package nns import ( "errors" "fmt" + "math/big" + "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -17,6 +19,10 @@ type RecordState struct { // RecordType is domain name service record types. type RecordType byte +// Ensure RecordType implements smartcontract.Convertible for proper handling as +// a parameter to invoker.Invoker methods. +var _ = smartcontract.Convertible(RecordType(0)) + // Record types are defined in [RFC 1035](https://tools.ietf.org/html/rfc1035) const ( // A represents address record type. @@ -33,6 +39,14 @@ const ( AAAA RecordType = 28 ) +// ToSCParameter implements smartcontract.Convertible interface. +func (r RecordType) ToSCParameter() (smartcontract.Parameter, error) { + return smartcontract.Parameter{ + Type: smartcontract.IntegerType, + Value: big.NewInt(int64(r)), + }, nil +} + // FromStackItem fills RecordState with data from the given stack item if it can // be correctly converted to RecordState. func (r *RecordState) FromStackItem(itm stackitem.Item) error {