diff --git a/runtime/sema/account.gen.go b/runtime/sema/account.gen.go index 43b85befa4..958e200997 100644 --- a/runtime/sema/account.gen.go +++ b/runtime/sema/account.gen.go @@ -445,8 +445,8 @@ var Account_StorageType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_StorageTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -731,8 +731,8 @@ var Account_ContractsType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_ContractsTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -918,8 +918,8 @@ var Account_KeysType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_KeysTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -1096,8 +1096,8 @@ var Account_InboxType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_InboxTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -1291,8 +1291,8 @@ var Account_CapabilitiesType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_CapabilitiesTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -1497,8 +1497,8 @@ var Account_StorageCapabilitiesType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_StorageCapabilitiesTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -1669,8 +1669,8 @@ var Account_AccountCapabilitiesType = func() *CompositeType { var t = &CompositeType{ Identifier: Account_AccountCapabilitiesTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -1730,8 +1730,8 @@ var AccountType = func() *CompositeType { var t = &CompositeType{ Identifier: AccountTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } t.SetNestedType(Account_StorageTypeName, Account_StorageType) diff --git a/runtime/sema/crypto_algorithm_types.go b/runtime/sema/crypto_algorithm_types.go index a061e71e2c..b74d326bff 100644 --- a/runtime/sema/crypto_algorithm_types.go +++ b/runtime/sema/crypto_algorithm_types.go @@ -278,10 +278,10 @@ func newNativeEnumType( membersConstructor func(enumType *CompositeType) []*Member, ) *CompositeType { ty := &CompositeType{ - Identifier: identifier, - EnumRawType: rawType, - Kind: common.CompositeKindEnum, - importable: true, + Identifier: identifier, + EnumRawType: rawType, + Kind: common.CompositeKindEnum, + ImportableBuiltin: true, } // Members of the enum type are *not* the enum cases! diff --git a/runtime/sema/gen/main.go b/runtime/sema/gen/main.go index 798302f973..9d7ed032fe 100644 --- a/runtime/sema/gen/main.go +++ b/runtime/sema/gen/main.go @@ -19,6 +19,7 @@ package main import ( + "flag" "fmt" "go/token" "os" @@ -39,6 +40,11 @@ import ( "github.com/onflow/cadence/runtime/pretty" ) +const semaPath = "github.com/onflow/cadence/runtime/sema" +const astPath = "github.com/onflow/cadence/runtime/ast" + +var packagePathFlag = flag.String("p", semaPath, "package path") + const headerTemplate = `// Code generated from {{ . }}. DO NOT EDIT. /* * Cadence - The resource-oriented smart contract programming language @@ -325,7 +331,8 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ compositeKind := decl.CompositeKind switch compositeKind { case common.CompositeKindStructure, - common.CompositeKindResource: + common.CompositeKindResource, + common.CompositeKindContract: break default: panic(fmt.Sprintf("%s declarations are not supported", compositeKind.Name())) @@ -364,6 +371,15 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ // Otherwise, we have to generate a CompositeType canGenerateSimpleType := len(g.typeStack) == 1 + if canGenerateSimpleType { + switch compositeKind { + case common.CompositeKindStructure, + common.CompositeKindResource: + break + default: + canGenerateSimpleType = false + } + } for _, memberDeclaration := range decl.Members.Declarations() { ast.AcceptDeclaration[struct{}](memberDeclaration, g) @@ -375,13 +391,15 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ memberDeclaration, ) - switch memberDeclaration.(type) { - case *ast.FieldDeclaration, - *ast.FunctionDeclaration: - break + if canGenerateSimpleType { + switch memberDeclaration.(type) { + case *ast.FieldDeclaration, + *ast.FunctionDeclaration: + break - default: - canGenerateSimpleType = false + default: + canGenerateSimpleType = false + } } } @@ -528,7 +546,10 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ Tok: token.ASSIGN, Rhs: []dst.Expr{ &dst.CallExpr{ - Fun: dst.NewIdent("MembersAsMap"), + Fun: &dst.Ident{ + Name: "MembersAsMap", + Path: semaPath, + }, Args: []dst.Expr{ dst.NewIdent(membersVariableIdentifier), }, @@ -545,7 +566,10 @@ func (g *generator) VisitCompositeDeclaration(decl *ast.CompositeDeclaration) (_ Tok: token.ASSIGN, Rhs: []dst.Expr{ &dst.CallExpr{ - Fun: dst.NewIdent("MembersFieldNames"), + Fun: &dst.Ident{ + Name: "MembersFieldNames", + Path: semaPath, + }, Args: []dst.Expr{ dst.NewIdent(membersVariableIdentifier), }, @@ -642,7 +666,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("GenericType"), + Type: &dst.Ident{ + Name: "GenericType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("TypeParameter", dst.NewIdent(typeParamVarName)), }, @@ -661,7 +688,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("CapabilityType"), + Type: &dst.Ident{ + Name: "CapabilityType", + Path: semaPath, + }, }, } default: @@ -683,7 +713,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("OptionalType"), + Type: &dst.Ident{ + Name: "OptionalType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Type", innerType), }, @@ -695,11 +728,20 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("ReferenceType"), + Type: &dst.Ident{ + Name: "ReferenceType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Type", borrowType), // TODO: add support for parsing entitlements - goKeyValue("Authorization", dst.NewIdent("UnauthorizedAccess")), + goKeyValue( + "Authorization", + &dst.Ident{ + Name: "UnauthorizedAccess", + Path: semaPath, + }, + ), }, }, } @@ -709,7 +751,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("VariableSizedType"), + Type: &dst.Ident{ + Name: "VariableSizedType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Type", elementType), }, @@ -721,7 +766,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("ConstantSizedType"), + Type: &dst.Ident{ + Name: "ConstantSizedType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Type", elementType), goKeyValue( @@ -735,6 +783,23 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { }, } + case *ast.DictionaryType: + keyType := typeExpr(t.KeyType, typeParams) + valueType := typeExpr(t.ValueType, typeParams) + return &dst.UnaryExpr{ + Op: token.AND, + X: &dst.CompositeLit{ + Type: &dst.Ident{ + Name: "DictionaryType", + Path: semaPath, + }, + Elts: []dst.Expr{ + goKeyValue("KeyType", keyType), + goKeyValue("ValueType", valueType), + }, + }, + } + case *ast.FunctionType: return functionTypeExpr(t, nil, nil, typeParams) @@ -757,7 +822,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { } return &dst.CallExpr{ - Fun: dst.NewIdent("MustInstantiate"), + Fun: &dst.Ident{ + Name: "MustInstantiate", + Path: semaPath, + }, Args: argumentExprs, } @@ -778,7 +846,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { &dst.CompositeLit{ Type: &dst.ArrayType{ Elt: &dst.StarExpr{ - X: dst.NewIdent("InterfaceType"), + X: &dst.Ident{ + Name: "InterfaceType", + Path: semaPath, + }, }, }, Elts: intersectedTypes, @@ -790,7 +861,10 @@ func typeExpr(t ast.Type, typeParams map[string]string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("IntersectionType"), + Type: &dst.Ident{ + Name: "IntersectionType", + Path: semaPath, + }, Elts: elements, }, } @@ -811,7 +885,10 @@ func functionTypeExpr( var purityExpr dst.Expr if t.PurityAnnotation == ast.FunctionPurityView { - purityExpr = dst.NewIdent("FunctionPurityView") + purityExpr = &dst.Ident{ + Name: "FunctionPurityView", + Path: semaPath, + } } // Type parameters @@ -843,7 +920,10 @@ func functionTypeExpr( typeParametersExpr = &dst.CompositeLit{ Type: &dst.ArrayType{ Elt: &dst.StarExpr{ - X: dst.NewIdent("TypeParameter"), + X: &dst.Ident{ + Name: "TypeParameter", + Path: semaPath, + }, }, }, Elts: typeParameterExprs, @@ -875,6 +955,7 @@ func functionTypeExpr( if parameter.Label == "_" { lit = &dst.Ident{ Name: "ArgumentLabelNotRequired", + Path: semaPath, } } else { lit = goStringLit(parameter.Label) @@ -915,7 +996,10 @@ func functionTypeExpr( parametersExpr = &dst.CompositeLit{ Type: &dst.ArrayType{ - Elt: dst.NewIdent("Parameter"), + Elt: &dst.Ident{ + Name: "Parameter", + Path: semaPath, + }, }, Elts: parameterExprs, } @@ -978,7 +1062,10 @@ func functionTypeExpr( return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("FunctionType"), + Type: &dst.Ident{ + Name: "FunctionType", + Path: semaPath, + }, Elts: compositeElements, }, } @@ -1328,7 +1415,10 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("SimpleType"), + Type: &dst.Ident{ + Name: "SimpleType", + Path: semaPath, + }, Elts: elements, }, } @@ -1344,7 +1434,10 @@ func simpleTypeMemberResolversFunc(fullTypeName string, declarations []ast.Decla returnStatement := &dst.ReturnStmt{ Results: []dst.Expr{ &dst.CallExpr{ - Fun: dst.NewIdent("MembersAsResolvers"), + Fun: &dst.Ident{ + Name: "MembersAsResolvers", + Path: semaPath, + }, Args: []dst.Expr{ membersExpr(fullTypeName, typeVarName, declarations), }, @@ -1431,25 +1524,38 @@ func membersExpr( return &dst.CompositeLit{ Type: &dst.ArrayType{ - Elt: &dst.StarExpr{X: dst.NewIdent("Member")}, + Elt: &dst.StarExpr{ + X: &dst.Ident{ + Name: "Member", + Path: semaPath, + }, + }, }, Elts: elements, } } func simpleType() *dst.StarExpr { - return &dst.StarExpr{X: dst.NewIdent("SimpleType")} + return &dst.StarExpr{ + X: &dst.Ident{ + Name: "SimpleType", + Path: semaPath, + }, + } } func accessExpr(access ast.Access) dst.Expr { switch access := access.(type) { case ast.PrimitiveAccess: return &dst.CallExpr{ - Fun: dst.NewIdent("PrimitiveAccess"), + Fun: &dst.Ident{ + Name: "PrimitiveAccess", + Path: semaPath, + }, Args: []dst.Expr{ &dst.Ident{ Name: access.String(), - Path: "github.com/onflow/cadence/runtime/ast", + Path: astPath, }, }, } @@ -1468,9 +1574,15 @@ func accessExpr(access ast.Access) dst.Expr { switch access.EntitlementSet.Separator() { case ast.Conjunction: - setKind = dst.NewIdent("Conjunction") + setKind = &dst.Ident{ + Name: "Conjunction", + Path: semaPath, + } case ast.Disjunction: - setKind = dst.NewIdent("Disjunction") + setKind = &dst.Ident{ + Name: "Disjunction", + Path: semaPath, + } default: panic(errors.NewUnreachableError()) } @@ -1478,7 +1590,10 @@ func accessExpr(access ast.Access) dst.Expr { args := []dst.Expr{ &dst.CompositeLit{ Type: &dst.ArrayType{ - Elt: dst.NewIdent("Type"), + Elt: &dst.Ident{ + Name: "Type", + Path: semaPath, + }, }, Elts: entitlementExprs, }, @@ -1491,7 +1606,10 @@ func accessExpr(access ast.Access) dst.Expr { } return &dst.CallExpr{ - Fun: dst.NewIdent("newEntitlementAccess"), + Fun: &dst.Ident{ + Name: "newEntitlementAccess", + Path: semaPath, + }, Args: args, } @@ -1503,7 +1621,7 @@ func accessExpr(access ast.Access) dst.Expr { func variableKindIdent(variableKind ast.VariableKind) *dst.Ident { return &dst.Ident{ Name: variableKind.String(), - Path: "github.com/onflow/cadence/runtime/ast", + Path: astPath, } } @@ -1542,7 +1660,10 @@ func newDeclarationMember( } return &dst.CallExpr{ - Fun: dst.NewIdent("NewUnmeteredFieldMember"), + Fun: &dst.Ident{ + Name: "NewUnmeteredFieldMember", + Path: semaPath, + }, Args: args, } } @@ -1566,7 +1687,10 @@ func newDeclarationMember( } return &dst.CallExpr{ - Fun: dst.NewIdent("NewUnmeteredFunctionMember"), + Fun: &dst.Ident{ + Name: "NewUnmeteredFunctionMember", + Path: semaPath, + }, Args: args, } } @@ -1579,8 +1703,11 @@ func newDeclarationMember( func stringMemberResolverMapType() *dst.MapType { return &dst.MapType{ - Key: dst.NewIdent("string"), - Value: dst.NewIdent("MemberResolver"), + Key: dst.NewIdent("string"), + Value: &dst.Ident{ + Name: "MemberResolver", + Path: semaPath, + }, } } @@ -1590,8 +1717,8 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { // var t = &CompositeType{ // Identifier: FooTypeName, // Kind: common.CompositeKindStructure, - // importable: false, - // hasComputedMembers: true, + // ImportableBuiltin: false, + // HasComputedMembers: true, // } // // t.SetNestedType(FooBarTypeName, FooBarType) @@ -1644,7 +1771,10 @@ func compositeTypeExpr(ty *typeDecl) dst.Expr { List: []*dst.Field{ { Type: &dst.StarExpr{ - X: dst.NewIdent("CompositeType"), + X: &dst.Ident{ + Name: "CompositeType", + Path: semaPath, + }, }, }, }, @@ -1663,14 +1793,17 @@ func compositeTypeLiteral(ty *typeDecl) dst.Expr { elements := []dst.Expr{ goKeyValue("Identifier", typeNameVarIdent(ty.fullTypeName)), goKeyValue("Kind", kind), - goKeyValue("importable", goBoolLit(ty.importable)), - goKeyValue("hasComputedMembers", goBoolLit(true)), + goKeyValue("ImportableBuiltin", goBoolLit(ty.importable)), + goKeyValue("HasComputedMembers", goBoolLit(true)), } return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("CompositeType"), + Type: &dst.Ident{ + Name: "CompositeType", + Path: semaPath, + }, Elts: elements, }, } @@ -1678,7 +1811,10 @@ func compositeTypeLiteral(ty *typeDecl) dst.Expr { func typeAnnotationCallExpr(ty dst.Expr) *dst.CallExpr { return &dst.CallExpr{ - Fun: dst.NewIdent("NewTypeAnnotation"), + Fun: &dst.Ident{ + Name: "NewTypeAnnotation", + Path: semaPath, + }, Args: []dst.Expr{ ty, }, @@ -1699,7 +1835,10 @@ func typeParameterExpr(name string, typeBound dst.Expr) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("TypeParameter"), + Type: &dst.Ident{ + Name: "TypeParameter", + Path: semaPath, + }, Elts: elements, }, } @@ -1713,7 +1852,10 @@ func entitlementTypeLiteral(name string) dst.Expr { return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("EntitlementType"), + Type: &dst.Ident{ + Name: "EntitlementType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Identifier", goStringLit(name)), }, @@ -1750,7 +1892,10 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement } relationExpr := &dst.CompositeLit{ - Type: dst.NewIdent("EntitlementRelation"), + Type: &dst.Ident{ + Name: "EntitlementRelation", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Input", typeExpr(relation.Input, nil)), goKeyValue("Output", typeExpr(relation.Output, nil)), @@ -1765,7 +1910,10 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement relationsExpr := &dst.CompositeLit{ Type: &dst.ArrayType{ - Elt: dst.NewIdent("EntitlementRelation"), + Elt: &dst.Ident{ + Name: "EntitlementRelation", + Path: semaPath, + }, }, Elts: relationExprs, } @@ -1773,7 +1921,10 @@ func entitlementMapTypeLiteral(name string, elements []ast.EntitlementMapElement return &dst.UnaryExpr{ Op: token.AND, X: &dst.CompositeLit{ - Type: dst.NewIdent("EntitlementMapType"), + Type: &dst.Ident{ + Name: "EntitlementMapType", + Path: semaPath, + }, Elts: []dst.Expr{ goKeyValue("Identifier", goStringLit(name)), goKeyValue("IncludesIdentity", goBoolLit(includesIdentity)), @@ -1797,7 +1948,7 @@ func parseCadenceFile(path string) *ast.Program { return program } -func gen(inPath string, outFile *os.File) { +func gen(inPath string, outFile *os.File, packagePath string) { program := parseCadenceFile(inPath) var gen generator @@ -1808,21 +1959,27 @@ func gen(inPath string, outFile *os.File) { gen.generateTypeInit(program) - writeGoFile(inPath, outFile, gen.decls) + writeGoFile(inPath, outFile, gen.decls, packagePath) } -func writeGoFile(inPath string, outFile *os.File, decls []dst.Decl) { +func writeGoFile(inPath string, outFile *os.File, decls []dst.Decl, packagePath string) { err := parsedHeaderTemplate.Execute(outFile, inPath) if err != nil { panic(err) } - restorer := decorator.NewRestorerWithImports("sema", guess.RestorerResolver{}) + resolver := guess.New() + restorer := decorator.NewRestorerWithImports(packagePath, resolver) + + packageName, err := resolver.ResolvePackage(packagePath) + if err != nil { + panic(err) + } err = restorer.Fprint( outFile, &dst.File{ - Name: dst.NewIdent("sema"), + Name: dst.NewIdent(packageName), Decls: decls, }, ) @@ -1832,14 +1989,17 @@ func writeGoFile(inPath string, outFile *os.File, decls []dst.Decl) { } func main() { - if len(os.Args) < 2 { + flag.Parse() + argumentCount := flag.NArg() + + if argumentCount < 1 { panic("Missing path to input Cadence file") } - if len(os.Args) < 3 { + if argumentCount < 2 { panic("Missing path to output Go file") } - inPath := os.Args[1] - outPath := os.Args[2] + inPath := flag.Arg(0) + outPath := flag.Arg(1) outFile, err := os.Create(outPath) if err != nil { @@ -1847,5 +2007,5 @@ func main() { } defer outFile.Close() - gen(inPath, outFile) + gen(inPath, outFile, *packagePathFlag) } diff --git a/runtime/sema/gen/main_test.go b/runtime/sema/gen/main_test.go index 173adc1df1..1e8def123d 100644 --- a/runtime/sema/gen/main_test.go +++ b/runtime/sema/gen/main_test.go @@ -50,7 +50,7 @@ func TestFiles(t *testing.T) { require.NoError(t, err) defer outFile.Close() - gen(inputPath, outFile) + gen(inputPath, outFile, "github.com/onflow/cadence/runtime/sema") goldenPath := filepath.Join(testDataDirectory, testname+".golden.go") want, err := os.ReadFile(goldenPath) diff --git a/runtime/sema/gen/testdata/fields.cdc b/runtime/sema/gen/testdata/fields.cdc index 667f50b712..1cf74e4f96 100644 --- a/runtime/sema/gen/testdata/fields.cdc +++ b/runtime/sema/gen/testdata/fields.cdc @@ -14,6 +14,9 @@ access(all) struct Test { /// This is a test constant-sized integer array. access(all) let testConstInts: [UInt64; 2] + /// This is a test integer dictionary. + access(all) let testIntDict: {UInt64: Bool} + /// This is a test parameterized-type field. access(all) let testParam: Foo diff --git a/runtime/sema/gen/testdata/fields.golden.go b/runtime/sema/gen/testdata/fields.golden.go index 9fdabd602e..f4af42f973 100644 --- a/runtime/sema/gen/testdata/fields.golden.go +++ b/runtime/sema/gen/testdata/fields.golden.go @@ -71,6 +71,17 @@ const TestTypeTestConstIntsFieldDocString = ` This is a test constant-sized integer array. ` +const TestTypeTestIntDictFieldName = "testIntDict" + +var TestTypeTestIntDictFieldType = &DictionaryType{ + KeyType: UInt64Type, + ValueType: BoolType, +} + +const TestTypeTestIntDictFieldDocString = ` +This is a test integer dictionary. +` + const TestTypeTestParamFieldName = "testParam" var TestTypeTestParamFieldType = MustInstantiate( @@ -186,6 +197,14 @@ func init() { TestTypeTestConstIntsFieldType, TestTypeTestConstIntsFieldDocString, ), + NewUnmeteredFieldMember( + t, + PrimitiveAccess(ast.AccessAll), + ast.VariableKindConstant, + TestTypeTestIntDictFieldName, + TestTypeTestIntDictFieldType, + TestTypeTestIntDictFieldDocString, + ), NewUnmeteredFieldMember( t, PrimitiveAccess(ast.AccessAll), diff --git a/runtime/sema/gen/testdata/nested.golden.go b/runtime/sema/gen/testdata/nested.golden.go index 3f998c940a..73c94c99c1 100644 --- a/runtime/sema/gen/testdata/nested.golden.go +++ b/runtime/sema/gen/testdata/nested.golden.go @@ -62,8 +62,8 @@ var Foo_BarType = func() *CompositeType { var t = &CompositeType{ Identifier: Foo_BarTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } return t @@ -90,8 +90,8 @@ var FooType = func() *CompositeType { var t = &CompositeType{ Identifier: FooTypeName, Kind: common.CompositeKindStructure, - importable: false, - hasComputedMembers: true, + ImportableBuiltin: false, + HasComputedMembers: true, } t.SetNestedType(Foo_BarTypeName, Foo_BarType) diff --git a/runtime/sema/type.go b/runtime/sema/type.go index 92be3fb113..96bd29be52 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -4279,9 +4279,9 @@ type CompositeType struct { effectiveInterfaceConformancesOnce sync.Once memberResolversOnce sync.Once ConstructorPurity FunctionPurity - hasComputedMembers bool + HasComputedMembers bool // Only applicable for native composite types - importable bool + ImportableBuiltin bool supportedEntitlements *EntitlementOrderedSet } @@ -4490,7 +4490,7 @@ func (*CompositeType) IsInvalidType() bool { } func (t *CompositeType) IsStorable(results map[*Member]bool) bool { - if t.hasComputedMembers { + if t.HasComputedMembers { return false } @@ -4526,7 +4526,7 @@ func (t *CompositeType) IsStorable(results map[*Member]bool) bool { func (t *CompositeType) IsImportable(results map[*Member]bool) bool { // Use the pre-determined flag for native types if t.Location == nil { - return t.importable + return t.ImportableBuiltin } // Only structures and enums can be imported @@ -7455,9 +7455,9 @@ const AccountKeyIsRevokedFieldName = "isRevoked" var AccountKeyType = func() *CompositeType { accountKeyType := &CompositeType{ - Identifier: AccountKeyTypeName, - Kind: common.CompositeKindStructure, - importable: false, + Identifier: AccountKeyTypeName, + Kind: common.CompositeKindStructure, + ImportableBuiltin: false, } const accountKeyKeyIndexFieldDocString = `The index of the account key` @@ -7538,8 +7538,8 @@ var PublicKeyType = func() *CompositeType { publicKeyType := &CompositeType{ Identifier: PublicKeyTypeName, Kind: common.CompositeKindStructure, - hasComputedMembers: true, - importable: true, + HasComputedMembers: true, + ImportableBuiltin: true, } var members = []*Member{ diff --git a/runtime/stdlib/bls.cdc b/runtime/stdlib/bls.cdc new file mode 100644 index 0000000000..25e291bd12 --- /dev/null +++ b/runtime/stdlib/bls.cdc @@ -0,0 +1,22 @@ +access(all) +contract BLS { + /// Aggregates multiple BLS signatures into one, + /// considering the proof of possession as a defense against rogue attacks. + /// + /// Signatures could be generated from the same or distinct messages, + /// they could also be the aggregation of other signatures. + /// The order of the signatures in the slice does not matter since the aggregation is commutative. + /// No subgroup membership check is performed on the input signatures. + /// The function returns nil if the array is empty or if decoding one of the signature fails. + access(all) + view fun aggregateSignatures(_ signatures: [[UInt8]]): [UInt8]? + + + /// Aggregates multiple BLS public keys into one. + /// + /// The order of the public keys in the slice does not matter since the aggregation is commutative. + /// No subgroup membership check is performed on the input keys. + /// The function returns nil if the array is empty or any of the input keys is not a BLS key. + access(all) + view fun aggregatePublicKeys(_ keys: [PublicKey]): PublicKey? +} diff --git a/runtime/stdlib/bls.gen.go b/runtime/stdlib/bls.gen.go new file mode 100644 index 0000000000..e88a5939fa --- /dev/null +++ b/runtime/stdlib/bls.gen.go @@ -0,0 +1,124 @@ +// Code generated from bls.cdc. DO NOT EDIT. +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Dapper Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package stdlib + +import ( + "github.com/onflow/cadence/runtime/ast" + "github.com/onflow/cadence/runtime/common" + "github.com/onflow/cadence/runtime/sema" +) + +const BLSTypeAggregateSignaturesFunctionName = "aggregateSignatures" + +var BLSTypeAggregateSignaturesFunctionType = &sema.FunctionType{ + Purity: sema.FunctionPurityView, + Parameters: []sema.Parameter{ + { + Label: sema.ArgumentLabelNotRequired, + Identifier: "signatures", + TypeAnnotation: sema.NewTypeAnnotation(&sema.VariableSizedType{ + Type: &sema.VariableSizedType{ + Type: UInt8Type, + }, + }), + }, + }, + ReturnTypeAnnotation: sema.NewTypeAnnotation( + &sema.OptionalType{ + Type: &sema.VariableSizedType{ + Type: UInt8Type, + }, + }, + ), +} + +const BLSTypeAggregateSignaturesFunctionDocString = ` +Aggregates multiple BLS signatures into one, +considering the proof of possession as a defense against rogue attacks. + +Signatures could be generated from the same or distinct messages, +they could also be the aggregation of other signatures. +The order of the signatures in the slice does not matter since the aggregation is commutative. +No subgroup membership check is performed on the input signatures. +The function returns nil if the array is empty or if decoding one of the signature fails. +` + +const BLSTypeAggregatePublicKeysFunctionName = "aggregatePublicKeys" + +var BLSTypeAggregatePublicKeysFunctionType = &sema.FunctionType{ + Purity: sema.FunctionPurityView, + Parameters: []sema.Parameter{ + { + Label: sema.ArgumentLabelNotRequired, + Identifier: "keys", + TypeAnnotation: sema.NewTypeAnnotation(&sema.VariableSizedType{ + Type: PublicKeyType, + }), + }, + }, + ReturnTypeAnnotation: sema.NewTypeAnnotation( + &sema.OptionalType{ + Type: PublicKeyType, + }, + ), +} + +const BLSTypeAggregatePublicKeysFunctionDocString = ` +Aggregates multiple BLS public keys into one. + +The order of the public keys in the slice does not matter since the aggregation is commutative. +No subgroup membership check is performed on the input keys. +The function returns nil if the array is empty or any of the input keys is not a BLS key. +` + +const BLSTypeName = "BLS" + +var BLSType = func() *sema.CompositeType { + var t = &sema.CompositeType{ + Identifier: BLSTypeName, + Kind: common.CompositeKindContract, + ImportableBuiltin: false, + HasComputedMembers: true, + } + + return t +}() + +func init() { + var members = []*sema.Member{ + sema.NewUnmeteredFunctionMember( + BLSType, + sema.PrimitiveAccess(ast.AccessAll), + BLSTypeAggregateSignaturesFunctionName, + BLSTypeAggregateSignaturesFunctionType, + BLSTypeAggregateSignaturesFunctionDocString, + ), + sema.NewUnmeteredFunctionMember( + BLSType, + sema.PrimitiveAccess(ast.AccessAll), + BLSTypeAggregatePublicKeysFunctionName, + BLSTypeAggregatePublicKeysFunctionType, + BLSTypeAggregatePublicKeysFunctionDocString, + ), + } + + BLSType.Members = sema.MembersAsMap(members) + BLSType.Fields = sema.MembersFieldNames(members) +} diff --git a/runtime/stdlib/bls.go b/runtime/stdlib/bls.go index f99591db2c..62cc7ad6ae 100644 --- a/runtime/stdlib/bls.go +++ b/runtime/stdlib/bls.go @@ -18,6 +18,8 @@ package stdlib +//go:generate go run ../sema/gen -p stdlib bls.cdc bls.gen.go + import ( "github.com/onflow/cadence/runtime/common" "github.com/onflow/cadence/runtime/errors" @@ -25,89 +27,6 @@ import ( "github.com/onflow/cadence/runtime/sema" ) -var blsContractType = func() *sema.CompositeType { - ty := &sema.CompositeType{ - Identifier: "BLS", - Kind: common.CompositeKindContract, - } - - ty.Members = sema.MembersAsMap([]*sema.Member{ - sema.NewUnmeteredPublicFunctionMember( - ty, - blsAggregatePublicKeysFunctionName, - blsAggregatePublicKeysFunctionType, - blsAggregatePublicKeysFunctionDocString, - ), - sema.NewUnmeteredPublicFunctionMember( - ty, - blsAggregateSignaturesFunctionName, - blsAggregateSignaturesFunctionType, - blsAggregateSignaturesFunctionDocString, - ), - }) - return ty -}() - -var blsContractStaticType interpreter.StaticType = interpreter.ConvertSemaCompositeTypeToStaticCompositeType( - nil, - blsContractType, -) - -const blsAggregateSignaturesFunctionDocString = ` -Aggregates multiple BLS signatures into one, -considering the proof of possession as a defense against rogue attacks. - -Signatures could be generated from the same or distinct messages, -they could also be the aggregation of other signatures. -The order of the signatures in the slice does not matter since the aggregation is commutative. -No subgroup membership check is performed on the input signatures. -The function returns nil if the array is empty or if decoding one of the signature fails. -` - -const blsAggregateSignaturesFunctionName = "aggregateSignatures" - -var blsAggregateSignaturesFunctionType = sema.NewSimpleFunctionType( - sema.FunctionPurityView, - []sema.Parameter{ - { - Label: sema.ArgumentLabelNotRequired, - Identifier: "signatures", - TypeAnnotation: sema.ByteArrayArrayTypeAnnotation, - }, - }, - sema.NewTypeAnnotation( - &sema.OptionalType{ - Type: sema.ByteArrayType, - }, - ), -) - -const blsAggregatePublicKeysFunctionDocString = ` -Aggregates multiple BLS public keys into one. - -The order of the public keys in the slice does not matter since the aggregation is commutative. -No subgroup membership check is performed on the input keys. -The function returns nil if the array is empty or any of the input keys is not a BLS key. -` - -const blsAggregatePublicKeysFunctionName = "aggregatePublicKeys" - -var blsAggregatePublicKeysFunctionType = sema.NewSimpleFunctionType( - sema.FunctionPurityView, - []sema.Parameter{ - { - Label: sema.ArgumentLabelNotRequired, - Identifier: "keys", - TypeAnnotation: sema.PublicKeyArrayTypeAnnotation, - }, - }, - sema.NewTypeAnnotation( - &sema.OptionalType{ - Type: sema.PublicKeyType, - }, - ), -) - type BLSPublicKeyAggregator interface { PublicKeySignatureVerifier BLSPoPVerifier @@ -121,7 +40,7 @@ func newBLSAggregatePublicKeysFunction( ) *interpreter.HostFunctionValue { return interpreter.NewHostFunctionValue( gauge, - blsAggregatePublicKeysFunctionType, + BLSTypeAggregatePublicKeysFunctionType, func(invocation interpreter.Invocation) interpreter.Value { publicKeysValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) if !ok { @@ -193,7 +112,7 @@ func newBLSAggregateSignaturesFunction( ) *interpreter.HostFunctionValue { return interpreter.NewHostFunctionValue( gauge, - blsAggregateSignaturesFunctionType, + BLSTypeAggregateSignaturesFunctionType, func(invocation interpreter.Invocation) interpreter.Value { signaturesValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) if !ok { @@ -256,19 +175,21 @@ type BLSContractHandler interface { BLSSignatureAggregator } +var BLSTypeStaticType = interpreter.ConvertSemaToStaticType(nil, BLSType) + func NewBLSContract( gauge common.MemoryGauge, handler BLSContractHandler, ) StandardLibraryValue { - var blsContractFields = map[string]interpreter.Value{ - blsAggregatePublicKeysFunctionName: newBLSAggregatePublicKeysFunction(gauge, handler), - blsAggregateSignaturesFunctionName: newBLSAggregateSignaturesFunction(gauge, handler), + blsContractFields := map[string]interpreter.Value{ + BLSTypeAggregatePublicKeysFunctionName: newBLSAggregatePublicKeysFunction(gauge, handler), + BLSTypeAggregateSignaturesFunctionName: newBLSAggregateSignaturesFunction(gauge, handler), } - var blsContractValue = interpreter.NewSimpleCompositeValue( - nil, - blsContractType.ID(), - blsContractStaticType, + blsContractValue := interpreter.NewSimpleCompositeValue( + gauge, + BLSType.ID(), + BLSTypeStaticType, nil, blsContractFields, nil, @@ -277,8 +198,8 @@ func NewBLSContract( ) return StandardLibraryValue{ - Name: "BLS", - Type: blsContractType, + Name: BLSTypeName, + Type: BLSType, Value: blsContractValue, Kind: common.DeclarationKindContract, } diff --git a/runtime/stdlib/builtin.go b/runtime/stdlib/builtin.go index d292eb1bef..d462a5f83d 100644 --- a/runtime/stdlib/builtin.go +++ b/runtime/stdlib/builtin.go @@ -18,6 +18,10 @@ package stdlib +import "github.com/onflow/cadence/runtime/sema" + +var UInt8Type = sema.UInt8Type + type StandardLibraryHandler interface { Logger UnsafeRandomGenerator diff --git a/runtime/stdlib/flow.go b/runtime/stdlib/flow.go index 47451caf56..f34cfd633a 100644 --- a/runtime/stdlib/flow.go +++ b/runtime/stdlib/flow.go @@ -193,7 +193,7 @@ var AccountEventCodeHashParameter = sema.Parameter{ var AccountEventPublicKeyParameterAsCompositeType = sema.Parameter{ Identifier: "publicKey", TypeAnnotation: sema.NewTypeAnnotation( - sema.PublicKeyType, + PublicKeyType, ), } diff --git a/runtime/stdlib/publickey.go b/runtime/stdlib/publickey.go index ef27bebc3a..5b02f4250d 100644 --- a/runtime/stdlib/publickey.go +++ b/runtime/stdlib/publickey.go @@ -25,6 +25,8 @@ import ( "github.com/onflow/cadence/runtime/sema" ) +var PublicKeyType = sema.PublicKeyType + const publicKeyConstructorFunctionDocString = ` Constructs a new public key ` @@ -258,7 +260,7 @@ func newPublicKeyVerifySignatureFunction( inter.ExpectType( publicKeyValue, - sema.PublicKeyType, + PublicKeyType, locationRange, ) @@ -328,7 +330,7 @@ func newPublicKeyVerifyPoPFunction( inter.ExpectType( publicKeyValue, - sema.PublicKeyType, + PublicKeyType, locationRange, ) diff --git a/runtime/stdlib/rlp.cdc b/runtime/stdlib/rlp.cdc new file mode 100644 index 0000000000..6102f9c4b9 --- /dev/null +++ b/runtime/stdlib/rlp.cdc @@ -0,0 +1,18 @@ +access(all) +contract RLP { + /// Decodes an RLP-encoded byte array (called string in the context of RLP). + /// The byte array should only contain of a single encoded value for a string; + /// if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. + /// If any error is encountered while decoding, the program aborts. + access(all) + view fun decodeString(_ input: [UInt8]): [UInt8] + + + /// Decodes an RLP-encoded list into an array of RLP-encoded items. + /// Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data. + /// The byte array should only contain of a single encoded value for a list; + /// if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. + /// If any error is encountered while decoding, the program aborts. + access(all) + view fun decodeList(_ input: [UInt8]): [[UInt8]] +} diff --git a/runtime/stdlib/rlp.gen.go b/runtime/stdlib/rlp.gen.go new file mode 100644 index 0000000000..44aac52a78 --- /dev/null +++ b/runtime/stdlib/rlp.gen.go @@ -0,0 +1,118 @@ +// Code generated from rlp.cdc. DO NOT EDIT. +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright Dapper Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package stdlib + +import ( + "github.com/onflow/cadence/runtime/ast" + "github.com/onflow/cadence/runtime/common" + "github.com/onflow/cadence/runtime/sema" +) + +const RLPTypeDecodeStringFunctionName = "decodeString" + +var RLPTypeDecodeStringFunctionType = &sema.FunctionType{ + Purity: sema.FunctionPurityView, + Parameters: []sema.Parameter{ + { + Label: sema.ArgumentLabelNotRequired, + Identifier: "input", + TypeAnnotation: sema.NewTypeAnnotation(&sema.VariableSizedType{ + Type: UInt8Type, + }), + }, + }, + ReturnTypeAnnotation: sema.NewTypeAnnotation( + &sema.VariableSizedType{ + Type: UInt8Type, + }, + ), +} + +const RLPTypeDecodeStringFunctionDocString = ` +Decodes an RLP-encoded byte array (called string in the context of RLP). +The byte array should only contain of a single encoded value for a string; +if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. +If any error is encountered while decoding, the program aborts. +` + +const RLPTypeDecodeListFunctionName = "decodeList" + +var RLPTypeDecodeListFunctionType = &sema.FunctionType{ + Purity: sema.FunctionPurityView, + Parameters: []sema.Parameter{ + { + Label: sema.ArgumentLabelNotRequired, + Identifier: "input", + TypeAnnotation: sema.NewTypeAnnotation(&sema.VariableSizedType{ + Type: UInt8Type, + }), + }, + }, + ReturnTypeAnnotation: sema.NewTypeAnnotation( + &sema.VariableSizedType{ + Type: &sema.VariableSizedType{ + Type: UInt8Type, + }, + }, + ), +} + +const RLPTypeDecodeListFunctionDocString = ` +Decodes an RLP-encoded list into an array of RLP-encoded items. +Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data. +The byte array should only contain of a single encoded value for a list; +if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. +If any error is encountered while decoding, the program aborts. +` + +const RLPTypeName = "RLP" + +var RLPType = func() *sema.CompositeType { + var t = &sema.CompositeType{ + Identifier: RLPTypeName, + Kind: common.CompositeKindContract, + ImportableBuiltin: false, + HasComputedMembers: true, + } + + return t +}() + +func init() { + var members = []*sema.Member{ + sema.NewUnmeteredFunctionMember( + RLPType, + sema.PrimitiveAccess(ast.AccessAll), + RLPTypeDecodeStringFunctionName, + RLPTypeDecodeStringFunctionType, + RLPTypeDecodeStringFunctionDocString, + ), + sema.NewUnmeteredFunctionMember( + RLPType, + sema.PrimitiveAccess(ast.AccessAll), + RLPTypeDecodeListFunctionName, + RLPTypeDecodeListFunctionType, + RLPTypeDecodeListFunctionDocString, + ), + } + + RLPType.Members = sema.MembersAsMap(members) + RLPType.Fields = sema.MembersFieldNames(members) +} diff --git a/runtime/stdlib/rlp.go b/runtime/stdlib/rlp.go index 4743450d23..a8c9faae3f 100644 --- a/runtime/stdlib/rlp.go +++ b/runtime/stdlib/rlp.go @@ -18,67 +18,17 @@ package stdlib +//go:generate go run ../sema/gen -p stdlib rlp.cdc rlp.gen.go + import ( "fmt" "github.com/onflow/cadence/runtime/common" "github.com/onflow/cadence/runtime/errors" "github.com/onflow/cadence/runtime/interpreter" - "github.com/onflow/cadence/runtime/sema" "github.com/onflow/cadence/runtime/stdlib/rlp" ) -var rlpContractType = func() *sema.CompositeType { - ty := &sema.CompositeType{ - Identifier: "RLP", - Kind: common.CompositeKindContract, - } - - ty.Members = sema.MembersAsMap([]*sema.Member{ - sema.NewUnmeteredPublicFunctionMember( - ty, - rlpDecodeListFunctionName, - rlpDecodeListFunctionType, - rlpDecodeListFunctionDocString, - ), - sema.NewUnmeteredPublicFunctionMember( - ty, - rlpDecodeStringFunctionName, - rlpDecodeStringFunctionType, - rlpDecodeStringFunctionDocString, - ), - }) - return ty -}() - -var rlpContractStaticType interpreter.StaticType = interpreter.ConvertSemaCompositeTypeToStaticCompositeType( - nil, - rlpContractType, -) - -const rlpErrMsgInputContainsExtraBytes = "input data is expected to be RLP-encoded of a single string or a single list but it seems it contains extra trailing bytes." - -const rlpDecodeStringFunctionDocString = ` -Decodes an RLP-encoded byte array (called string in the context of RLP). -The byte array should only contain of a single encoded value for a string; -if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. -If any error is encountered while decoding, the program aborts. -` - -const rlpDecodeStringFunctionName = "decodeString" - -var rlpDecodeStringFunctionType = sema.NewSimpleFunctionType( - sema.FunctionPurityView, - []sema.Parameter{ - { - Label: sema.ArgumentLabelNotRequired, - Identifier: "input", - TypeAnnotation: sema.ByteArrayTypeAnnotation, - }, - }, - sema.ByteArrayTypeAnnotation, -) - type RLPDecodeStringError struct { interpreter.LocationRange Msg string @@ -92,8 +42,10 @@ func (e RLPDecodeStringError) Error() string { return fmt.Sprintf("failed to RLP-decode string: %s", e.Msg) } +const rlpErrMsgInputContainsExtraBytes = "input data is expected to be RLP-encoded of a single string or a single list but it seems it contains extra trailing bytes." + var rlpDecodeStringFunction = interpreter.NewUnmeteredHostFunctionValue( - rlpDecodeStringFunctionType, + RLPTypeDecodeStringFunctionType, func(invocation interpreter.Invocation) interpreter.Value { input, ok := invocation.Arguments[0].(*interpreter.ArrayValue) if !ok { @@ -128,28 +80,6 @@ var rlpDecodeStringFunction = interpreter.NewUnmeteredHostFunctionValue( }, ) -const rlpDecodeListFunctionDocString = ` -Decodes an RLP-encoded list into an array of RLP-encoded items. -Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data. -The byte array should only contain of a single encoded value for a list; -if the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts. -If any error is encountered while decoding, the program aborts. -` - -const rlpDecodeListFunctionName = "decodeList" - -var rlpDecodeListFunctionType = sema.NewSimpleFunctionType( - sema.FunctionPurityView, - []sema.Parameter{ - { - Label: sema.ArgumentLabelNotRequired, - Identifier: "input", - TypeAnnotation: sema.ByteArrayTypeAnnotation, - }, - }, - sema.ByteArrayArrayTypeAnnotation, -) - type RLPDecodeListError struct { interpreter.LocationRange Msg string @@ -164,7 +94,7 @@ func (e RLPDecodeListError) Error() string { } var rlpDecodeListFunction = interpreter.NewUnmeteredHostFunctionValue( - rlpDecodeListFunctionType, + RLPTypeDecodeListFunctionType, func(invocation interpreter.Invocation) interpreter.Value { input, ok := invocation.Arguments[0].(*interpreter.ArrayValue) if !ok { @@ -218,14 +148,16 @@ var rlpDecodeListFunction = interpreter.NewUnmeteredHostFunctionValue( ) var rlpContractFields = map[string]interpreter.Value{ - rlpDecodeListFunctionName: rlpDecodeListFunction, - rlpDecodeStringFunctionName: rlpDecodeStringFunction, + RLPTypeDecodeListFunctionName: rlpDecodeListFunction, + RLPTypeDecodeStringFunctionName: rlpDecodeStringFunction, } +var RLPTypeStaticType = interpreter.ConvertSemaToStaticType(nil, RLPType) + var rlpContractValue = interpreter.NewSimpleCompositeValue( nil, - rlpContractType.ID(), - rlpContractStaticType, + RLPType.ID(), + RLPTypeStaticType, nil, rlpContractFields, nil, @@ -234,8 +166,8 @@ var rlpContractValue = interpreter.NewSimpleCompositeValue( ) var RLPContract = StandardLibraryValue{ - Name: "RLP", - Type: rlpContractType, + Name: RLPTypeName, + Type: RLPType, Value: rlpContractValue, Kind: common.DeclarationKindContract, }