diff --git a/common/shared/src/main/scala/sigma/CoreLibReflection.scala b/common/shared/src/main/scala/sigma/CoreLibReflection.scala deleted file mode 100644 index 3b68b1547f..0000000000 --- a/common/shared/src/main/scala/sigma/CoreLibReflection.scala +++ /dev/null @@ -1,405 +0,0 @@ -package sigma - -import sigma.data.RType -import sigma.reflection.CommonReflection.registerClassEntry -import sigma.reflection._ - -/** Registrations of reflection metadata for core-lib module. - * For each class of this module that needs reflection metadata, - * we register a class entry with the necessary information. - * Only information that is needed at runtime is registered. - */ -object CoreLibReflection { - val reflection = CommonReflection - - { val clazz = classOf[SigmaProp] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "$bar$bar", Array[Class[_]](classOf[SigmaProp])) { (obj, args) => - obj.asInstanceOf[SigmaProp].$bar$bar(args(0).asInstanceOf[SigmaProp]) - }, - mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[SigmaProp].isValid - }, - mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[SigmaProp].propBytes - }, - mkMethod(clazz, "$amp$amp", Array[Class[_]](classOf[SigmaProp])) { (obj, args) => - obj.asInstanceOf[SigmaProp].$amp$amp(args(0).asInstanceOf[SigmaProp]) - } - ) - ) - } - - { val clazz = classOf[sigma.BigInt] - val paramTypes = Array[Class[_]](clazz) - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "add", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].add(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "max", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].max(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "min", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].min(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "subtract", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].subtract(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "multiply", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].multiply(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "mod", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].mod(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "divide", paramTypes) { (obj, args) => - obj.asInstanceOf[BigInt].divide(args(0).asInstanceOf[BigInt]) - } - ) - ) - } - - { val clazz = classOf[CollBuilder] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "xor", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[CollBuilder].xor( - args(0).asInstanceOf[Coll[Byte]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "fromItems", Array[Class[_]](classOf[Seq[_]], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[CollBuilder].fromItems[Any]( - args(0).asInstanceOf[Seq[Any]]: _*)(args(1).asInstanceOf[RType[Any]]) - }, - mkMethod(clazz, "replicate", Array[Class[_]](classOf[Int], classOf[Object], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[CollBuilder].replicate(args(0).asInstanceOf[Int], - args(1).asInstanceOf[Any])(args(2).asInstanceOf[RType[Any]]) - } - ) - ) - } - - { val clazz = classOf[Coll[_]] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "updated", Array[Class[_]](classOf[Int], classOf[java.lang.Object])) { (obj, args) => - obj.asInstanceOf[Coll[Any]].updated(args(0).asInstanceOf[Int], args(1).asInstanceOf[Any]) - }, - mkMethod(clazz, "flatMap", Array[Class[_]](classOf[Function1[_, _]], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[Coll[Any]].flatMap( - args(0).asInstanceOf[Any => Coll[Any]])(args(1).asInstanceOf[RType[Any]]) - }, - mkMethod(clazz, "apply", Array[Class[_]](classOf[Int])) { (obj, args) => - obj.asInstanceOf[Coll[_]].apply(args(0).asInstanceOf[Int]) - }, - mkMethod(clazz, "append", Array[Class[_]](classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[Coll[Any]].append(args(0).asInstanceOf[Coll[Any]]) - }, - mkMethod(clazz, "indexOf", Array[Class[_]](classOf[java.lang.Object], classOf[Int])) { (obj, args) => - obj.asInstanceOf[Coll[Any]].indexOf(args(0).asInstanceOf[Any], args(1).asInstanceOf[Int]) - }, - mkMethod(clazz, "map", Array[Class[_]](classOf[Function1[_, _]], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[Coll[Any]].map(args(0).asInstanceOf[Any => Any])(args(1).asInstanceOf[RType[Any]]) - } - ) - ) - } - - { val clazz = classOf[AvlTree] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "updateOperations", Array[Class[_]](classOf[Byte])) { (obj, args) => - obj.asInstanceOf[AvlTree].updateOperations(args(0).asInstanceOf[Byte]) - }, - mkMethod(clazz, "getMany", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].getMany(args(0).asInstanceOf[Coll[Coll[Byte]]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "update", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].update(args(0).asInstanceOf[Coll[(Coll[Byte], Coll[Byte])]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].keyLength - }, - mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].enabledOperations - }, - mkMethod(clazz, "updateDigest", Array[Class[_]](classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].updateDigest(args(0).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].digest - }, - mkMethod(clazz, "insert", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].insert(args(0).asInstanceOf[Coll[(Coll[Byte], Coll[Byte])]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].isRemoveAllowed - }, - mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].valueLengthOpt - }, - mkMethod(clazz, "get", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].get(args(0).asInstanceOf[Coll[Byte]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "remove", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].remove(args(0).asInstanceOf[Coll[Coll[Byte]]], args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "contains", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => - obj.asInstanceOf[AvlTree].contains(args(0).asInstanceOf[Coll[Byte]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].isUpdateAllowed - }, - mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[AvlTree].isInsertAllowed - } - ) - ) - } - - { val clazz = classOf[Box] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "value", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].value - }, - mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].id - }, - mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].creationInfo - }, - mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].bytes - }, - mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].tokens - }, - mkMethod(clazz, "getReg", Array[Class[_]](classOf[Int], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[Box].getReg(args(0).asInstanceOf[Int])(args(1).asInstanceOf[RType[_]]) - }, - mkMethod (clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].bytesWithoutRef - }, - mkMethod(clazz, "propositionBytes", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Box].propositionBytes - } - ) - ) - } - - { val clazz = classOf[Context] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "LastBlockUtxoRootHash", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].LastBlockUtxoRootHash - }, - mkMethod(clazz, "dataInputs", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].dataInputs - }, - mkMethod(clazz, "selfBoxIndex", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].selfBoxIndex - }, - mkMethod(clazz, "INPUTS", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].INPUTS - }, - mkMethod(clazz, "minerPubKey", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].minerPubKey - }, - mkMethod(clazz, "HEIGHT", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].HEIGHT - }, - mkMethod(clazz, "OUTPUTS", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].OUTPUTS - }, - mkMethod(clazz, "SELF", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].SELF - }, - mkMethod(clazz, "preHeader", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].preHeader - }, - mkMethod(clazz, "getVar", Array[Class[_]](classOf[Byte], classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[Context].getVar(args(0).asInstanceOf[Byte])(args(1).asInstanceOf[RType[_]]) - }, - mkMethod(clazz, "headers", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Context].headers - } - ) - ) - } - - { val clazz = classOf[GroupElement] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "exp", Array[Class[_]](classOf[BigInt])) { (obj, args) => - obj.asInstanceOf[GroupElement].exp(args(0).asInstanceOf[BigInt]) - }, - mkMethod(clazz, "multiply", Array[Class[_]](classOf[GroupElement])) { (obj, args) => - obj.asInstanceOf[GroupElement].multiply(args(0).asInstanceOf[GroupElement]) - }, - mkMethod(clazz, "getEncoded", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[GroupElement].getEncoded - }, - mkMethod(clazz, "negate", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[GroupElement].negate - } - ) - ) - } - - { val clazz = classOf[Header] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].minerPk - }, - mkMethod(clazz, "powNonce", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].powNonce - }, - mkMethod(clazz, "transactionsRoot", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].transactionsRoot - }, - mkMethod(clazz, "powOnetimePk", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].powOnetimePk - }, - mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].nBits - }, - mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].votes - }, - mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].id - }, - mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].version - }, - mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].parentId - }, - mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].timestamp - }, - mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].height - }, - mkMethod(clazz, "extensionRoot", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].extensionRoot - }, - mkMethod(clazz, "ADProofsRoot", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].ADProofsRoot - }, - mkMethod(clazz, "stateRoot", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].stateRoot - }, - mkMethod(clazz, "powDistance", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[Header].powDistance - } - ) - ) - } - - { val clazz = classOf[PreHeader] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].minerPk - }, - mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].votes - }, - mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].nBits - }, - mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].version - }, - mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].timestamp - }, - mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].parentId - }, - mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[PreHeader].height - } - ) - ) - } - - { val clazz = classOf[SigmaDslBuilder] - val cColl = classOf[Coll[_]] - val cGroupElement = classOf[GroupElement] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "byteArrayToLong", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].byteArrayToLong(args(0).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "anyOf", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].anyOf(args(0).asInstanceOf[Coll[Boolean]]) - }, - mkMethod(clazz, "allZK", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].allZK(args(0).asInstanceOf[Coll[SigmaProp]]) - }, - mkMethod(clazz, "xorOf", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].xorOf(args(0).asInstanceOf[Coll[Boolean]]) - }, - mkMethod(clazz, "substConstants", Array[Class[_]](cColl, cColl, cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].substConstants(args(0).asInstanceOf[Coll[Byte]], - args(1).asInstanceOf[Coll[Int]], args(2).asInstanceOf[Coll[Any]]) - }, - mkMethod(clazz, "groupGenerator", Array[Class[_]]()) { (obj, _) => - obj.asInstanceOf[SigmaDslBuilder].groupGenerator - }, - mkMethod(clazz, "sigmaProp", Array[Class[_]](classOf[Boolean])) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].sigmaProp(args(0).asInstanceOf[Boolean]) - }, - mkMethod(clazz, "proveDlog", Array[Class[_]](cGroupElement)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].proveDlog(args(0).asInstanceOf[GroupElement]) - }, - mkMethod(clazz, "blake2b256", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].blake2b256(args(0).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "longToByteArray", Array[Class[_]](classOf[Long])) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].longToByteArray(args(0).asInstanceOf[Long]) - }, - mkMethod(clazz, "xor", Array[Class[_]](cColl, cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].xor(args(0).asInstanceOf[Coll[Byte]], - args(1).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "atLeast", Array[Class[_]](classOf[Int], cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].atLeast(args(0).asInstanceOf[Int], - args(1).asInstanceOf[Coll[SigmaProp]]) - }, - mkMethod(clazz, "byteArrayToBigInt", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].byteArrayToBigInt(args(0).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "allOf", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].allOf(args(0).asInstanceOf[Coll[Boolean]]) - }, - mkMethod(clazz, "proveDHTuple", Array[Class[_]](cGroupElement, cGroupElement, cGroupElement, cGroupElement)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].proveDHTuple(args(0).asInstanceOf[GroupElement], - args(1).asInstanceOf[GroupElement], - args(2).asInstanceOf[GroupElement], - args(3).asInstanceOf[GroupElement]) - }, - mkMethod(clazz, "anyZK", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].anyZK(args(0).asInstanceOf[Coll[SigmaProp]]) - }, - mkMethod(clazz, "sha256", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].sha256(args(0).asInstanceOf[Coll[Byte]]) - }, - mkMethod(clazz, "decodePoint", Array[Class[_]](cColl)) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].decodePoint(args(0).asInstanceOf[Coll[Byte]]) - } - ) - ) - } - -} diff --git a/common/shared/src/main/scala/sigma/package.scala b/common/shared/src/main/scala/sigma/package.scala index 7ccb5990fd..d4fc53d978 100644 --- a/common/shared/src/main/scala/sigma/package.scala +++ b/common/shared/src/main/scala/sigma/package.scala @@ -8,8 +8,6 @@ import scala.reflect.ClassTag * @see [[RType]] class */ package object sigma { - /** Forces reflection data initialization */ - val coreLibReflection = CoreLibReflection val AnyType: RType[Any] = GeneralType[Any](ClassTag.Any) diff --git a/common/shared/src/main/scala/sigma/reflection/CommonReflection.scala b/common/shared/src/main/scala/sigma/reflection/CommonReflection.scala index 9bf15b0e1b..782ae819e7 100644 --- a/common/shared/src/main/scala/sigma/reflection/CommonReflection.scala +++ b/common/shared/src/main/scala/sigma/reflection/CommonReflection.scala @@ -1,5 +1,8 @@ package sigma.reflection +import sigma._ +import sigma.data.RType + import scala.collection.compat.immutable.ArraySeq import scala.collection.mutable import scala.collection.immutable @@ -70,5 +73,394 @@ object CommonReflection { ) ) } - + { + val clazz = classOf[SigmaProp] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "$bar$bar", Array[Class[_]](classOf[SigmaProp])) { (obj, args) => + obj.asInstanceOf[SigmaProp].$bar$bar(args(0).asInstanceOf[SigmaProp]) + }, + mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[SigmaProp].isValid + }, + mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[SigmaProp].propBytes + }, + mkMethod(clazz, "$amp$amp", Array[Class[_]](classOf[SigmaProp])) { (obj, args) => + obj.asInstanceOf[SigmaProp].$amp$amp(args(0).asInstanceOf[SigmaProp]) + } + ) + ) + } + { + val clazz = classOf[sigma.BigInt] + val paramTypes = Array[Class[_]](clazz) + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "add", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].add(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "max", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].max(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "min", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].min(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "subtract", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].subtract(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "multiply", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].multiply(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "mod", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].mod(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "divide", paramTypes) { (obj, args) => + obj.asInstanceOf[BigInt].divide(args(0).asInstanceOf[BigInt]) + } + ) + ) + } + { + val clazz = classOf[CollBuilder] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "xor", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[CollBuilder].xor( + args(0).asInstanceOf[Coll[Byte]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "fromItems", Array[Class[_]](classOf[Seq[_]], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[CollBuilder].fromItems[Any]( + args(0).asInstanceOf[Seq[Any]]: _*)(args(1).asInstanceOf[RType[Any]]) + }, + mkMethod(clazz, "replicate", Array[Class[_]](classOf[Int], classOf[Object], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[CollBuilder].replicate(args(0).asInstanceOf[Int], + args(1).asInstanceOf[Any])(args(2).asInstanceOf[RType[Any]]) + } + ) + ) + } + { + val clazz = classOf[Coll[_]] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "updated", Array[Class[_]](classOf[Int], classOf[java.lang.Object])) { (obj, args) => + obj.asInstanceOf[Coll[Any]].updated(args(0).asInstanceOf[Int], args(1).asInstanceOf[Any]) + }, + mkMethod(clazz, "flatMap", Array[Class[_]](classOf[Function1[_, _]], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[Coll[Any]].flatMap( + args(0).asInstanceOf[Any => Coll[Any]])(args(1).asInstanceOf[RType[Any]]) + }, + mkMethod(clazz, "apply", Array[Class[_]](classOf[Int])) { (obj, args) => + obj.asInstanceOf[Coll[_]].apply(args(0).asInstanceOf[Int]) + }, + mkMethod(clazz, "append", Array[Class[_]](classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[Coll[Any]].append(args(0).asInstanceOf[Coll[Any]]) + }, + mkMethod(clazz, "indexOf", Array[Class[_]](classOf[java.lang.Object], classOf[Int])) { (obj, args) => + obj.asInstanceOf[Coll[Any]].indexOf(args(0).asInstanceOf[Any], args(1).asInstanceOf[Int]) + }, + mkMethod(clazz, "map", Array[Class[_]](classOf[Function1[_, _]], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[Coll[Any]].map(args(0).asInstanceOf[Any => Any])(args(1).asInstanceOf[RType[Any]]) + } + ) + ) + } + { + val clazz = classOf[AvlTree] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "updateOperations", Array[Class[_]](classOf[Byte])) { (obj, args) => + obj.asInstanceOf[AvlTree].updateOperations(args(0).asInstanceOf[Byte]) + }, + mkMethod(clazz, "getMany", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].getMany(args(0).asInstanceOf[Coll[Coll[Byte]]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "update", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].update(args(0).asInstanceOf[Coll[(Coll[Byte], Coll[Byte])]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].keyLength + }, + mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].enabledOperations + }, + mkMethod(clazz, "updateDigest", Array[Class[_]](classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].updateDigest(args(0).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].digest + }, + mkMethod(clazz, "insert", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].insert(args(0).asInstanceOf[Coll[(Coll[Byte], Coll[Byte])]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].isRemoveAllowed + }, + mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].valueLengthOpt + }, + mkMethod(clazz, "get", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].get(args(0).asInstanceOf[Coll[Byte]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "remove", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].remove(args(0).asInstanceOf[Coll[Coll[Byte]]], args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "contains", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => + obj.asInstanceOf[AvlTree].contains(args(0).asInstanceOf[Coll[Byte]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].isUpdateAllowed + }, + mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[AvlTree].isInsertAllowed + } + ) + ) + } + { + val clazz = classOf[Box] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "value", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].value + }, + mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].id + }, + mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].creationInfo + }, + mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].bytes + }, + mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].tokens + }, + mkMethod(clazz, "getReg", Array[Class[_]](classOf[Int], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[Box].getReg(args(0).asInstanceOf[Int])(args(1).asInstanceOf[RType[_]]) + }, + mkMethod(clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].bytesWithoutRef + }, + mkMethod(clazz, "propositionBytes", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Box].propositionBytes + } + ) + ) + } + { + val clazz = classOf[Context] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "LastBlockUtxoRootHash", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].LastBlockUtxoRootHash + }, + mkMethod(clazz, "dataInputs", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].dataInputs + }, + mkMethod(clazz, "selfBoxIndex", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].selfBoxIndex + }, + mkMethod(clazz, "INPUTS", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].INPUTS + }, + mkMethod(clazz, "minerPubKey", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].minerPubKey + }, + mkMethod(clazz, "HEIGHT", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].HEIGHT + }, + mkMethod(clazz, "OUTPUTS", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].OUTPUTS + }, + mkMethod(clazz, "SELF", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].SELF + }, + mkMethod(clazz, "preHeader", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].preHeader + }, + mkMethod(clazz, "getVar", Array[Class[_]](classOf[Byte], classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[Context].getVar(args(0).asInstanceOf[Byte])(args(1).asInstanceOf[RType[_]]) + }, + mkMethod(clazz, "headers", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Context].headers + } + ) + ) + } + { + val clazz = classOf[GroupElement] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "exp", Array[Class[_]](classOf[BigInt])) { (obj, args) => + obj.asInstanceOf[GroupElement].exp(args(0).asInstanceOf[BigInt]) + }, + mkMethod(clazz, "multiply", Array[Class[_]](classOf[GroupElement])) { (obj, args) => + obj.asInstanceOf[GroupElement].multiply(args(0).asInstanceOf[GroupElement]) + }, + mkMethod(clazz, "getEncoded", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[GroupElement].getEncoded + }, + mkMethod(clazz, "negate", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[GroupElement].negate + } + ) + ) + } + { + val clazz = classOf[Header] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].minerPk + }, + mkMethod(clazz, "powNonce", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].powNonce + }, + mkMethod(clazz, "transactionsRoot", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].transactionsRoot + }, + mkMethod(clazz, "powOnetimePk", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].powOnetimePk + }, + mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].nBits + }, + mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].votes + }, + mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].id + }, + mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].version + }, + mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].parentId + }, + mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].timestamp + }, + mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].height + }, + mkMethod(clazz, "extensionRoot", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].extensionRoot + }, + mkMethod(clazz, "ADProofsRoot", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].ADProofsRoot + }, + mkMethod(clazz, "stateRoot", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].stateRoot + }, + mkMethod(clazz, "powDistance", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[Header].powDistance + } + ) + ) + } + { + val clazz = classOf[PreHeader] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].minerPk + }, + mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].votes + }, + mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].nBits + }, + mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].version + }, + mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].timestamp + }, + mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].parentId + }, + mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[PreHeader].height + } + ) + ) + } + { + val clazz = classOf[SigmaDslBuilder] + val cColl = classOf[Coll[_]] + val cGroupElement = classOf[GroupElement] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "byteArrayToLong", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].byteArrayToLong(args(0).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "anyOf", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].anyOf(args(0).asInstanceOf[Coll[Boolean]]) + }, + mkMethod(clazz, "allZK", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].allZK(args(0).asInstanceOf[Coll[SigmaProp]]) + }, + mkMethod(clazz, "xorOf", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].xorOf(args(0).asInstanceOf[Coll[Boolean]]) + }, + mkMethod(clazz, "substConstants", Array[Class[_]](cColl, cColl, cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].substConstants(args(0).asInstanceOf[Coll[Byte]], + args(1).asInstanceOf[Coll[Int]], args(2).asInstanceOf[Coll[Any]]) + }, + mkMethod(clazz, "groupGenerator", Array[Class[_]]()) { (obj, _) => + obj.asInstanceOf[SigmaDslBuilder].groupGenerator + }, + mkMethod(clazz, "sigmaProp", Array[Class[_]](classOf[Boolean])) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].sigmaProp(args(0).asInstanceOf[Boolean]) + }, + mkMethod(clazz, "proveDlog", Array[Class[_]](cGroupElement)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].proveDlog(args(0).asInstanceOf[GroupElement]) + }, + mkMethod(clazz, "blake2b256", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].blake2b256(args(0).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "longToByteArray", Array[Class[_]](classOf[Long])) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].longToByteArray(args(0).asInstanceOf[Long]) + }, + mkMethod(clazz, "xor", Array[Class[_]](cColl, cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].xor(args(0).asInstanceOf[Coll[Byte]], + args(1).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "atLeast", Array[Class[_]](classOf[Int], cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].atLeast(args(0).asInstanceOf[Int], + args(1).asInstanceOf[Coll[SigmaProp]]) + }, + mkMethod(clazz, "byteArrayToBigInt", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].byteArrayToBigInt(args(0).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "allOf", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].allOf(args(0).asInstanceOf[Coll[Boolean]]) + }, + mkMethod(clazz, "proveDHTuple", Array[Class[_]](cGroupElement, cGroupElement, cGroupElement, cGroupElement)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].proveDHTuple(args(0).asInstanceOf[GroupElement], + args(1).asInstanceOf[GroupElement], + args(2).asInstanceOf[GroupElement], + args(3).asInstanceOf[GroupElement]) + }, + mkMethod(clazz, "anyZK", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].anyZK(args(0).asInstanceOf[Coll[SigmaProp]]) + }, + mkMethod(clazz, "sha256", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].sha256(args(0).asInstanceOf[Coll[Byte]]) + }, + mkMethod(clazz, "decodePoint", Array[Class[_]](cColl)) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].decodePoint(args(0).asInstanceOf[Coll[Byte]]) + } + ) + ) + } } diff --git a/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala b/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala index 4f89b9a465..3e92ac1b31 100644 --- a/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala +++ b/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala @@ -2,9 +2,9 @@ package sigmastate import org.ergoplatform.ErgoBox.RegisterId import sigma.reflection.CommonReflection.registerClassEntry -import sigma.reflection.{mkConstructor, mkMethod} +import sigma.reflection.{CommonReflection, mkConstructor, mkMethod} import sigma.Coll -import sigma.{AvlTree, CoreLibReflection, SigmaDslBuilder} +import sigma.{AvlTree, SigmaDslBuilder} import sigmastate.SAvlTree.KeyValueColl import sigmastate.SCollection.{SBooleanArray, SByteArray, SIntArray} import sigmastate.Values._ @@ -21,7 +21,7 @@ import sigmastate.utxo._ * Only information that is needed at runtime is registered. */ object InterpreterReflection { - val reflection = CoreLibReflection + val reflection = CommonReflection registerClassEntry(classOf[AND], constructors = Array( diff --git a/sc/shared/src/main/scala/scalan/GraphIRReflection.scala b/sc/shared/src/main/scala/scalan/GraphIRReflection.scala index 2b1e8c95b6..52686c14f5 100644 --- a/sc/shared/src/main/scala/scalan/GraphIRReflection.scala +++ b/sc/shared/src/main/scala/scalan/GraphIRReflection.scala @@ -3,7 +3,6 @@ package scalan import scalan.primitives.Thunks import sigma.reflection.CommonReflection.registerClassEntry import sigma.reflection.{CommonReflection, mkConstructor, mkMethod} -import sigma.CoreLibReflection import sigmastate.eval.SigmaLibrary import sigma.Colls import sigma.SigmaDsl @@ -18,7 +17,7 @@ import wrappers.scalan.WRTypes */ object GraphIRReflection { /** Forces initialization of reflection data. */ - val reflection = (CommonReflection, CoreLibReflection) + val reflection = CommonReflection { val clazz = classOf[wrappers.scala.WOptions#WOption[_]] val ctx = null.asInstanceOf[scalan.Library] // ok! type level only diff --git a/sc/shared/src/test/scala/scalan/TestContexts.scala b/sc/shared/src/test/scala/scalan/TestContexts.scala index 9811473d3a..a86bf42276 100644 --- a/sc/shared/src/test/scala/scalan/TestContexts.scala +++ b/sc/shared/src/test/scala/scalan/TestContexts.scala @@ -1,7 +1,7 @@ package scalan import sigma.reflection.RMethod -import sigma.{BaseNestedTests, BaseShouldTests, BaseTests, CoreLibReflection, TestUtils} +import sigma.{BaseNestedTests, BaseShouldTests, BaseTests, TestUtils} trait TestContexts extends TestUtils { @@ -35,7 +35,7 @@ trait TestContexts extends TestUtils { } abstract class BaseCtxTests extends BaseTests with TestContexts { - val reflection = (CoreLibReflection, GraphIRReflection) + val reflection = GraphIRReflection } abstract class BaseNestedCtxTests extends BaseNestedTests with TestContexts diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala index d0c64fbfa7..328ffba714 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala @@ -9,6 +9,7 @@ import org.ergoplatform.sdk.wallet.secrets.{DerivationPath, ExtendedSecretKey} import org.ergoplatform.sdk.wallet.{Constants, TokensMap} import org.ergoplatform.settings.ErgoAlgos import scorex.crypto.authds.ADKey +import sigmastate.utils.Helpers._ // don't remove, required for Scala 2.11 import scorex.util.encode.Base16 import scorex.util.{ModifierId, bytesToId, idToBytes} import sigma.data.ExactIntegral.LongIsExactIntegral