-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2089 from wavesplatform/sc-140-add-directives-to-…
…decompiled-script SC-140 Add directives to decompiled script
- Loading branch information
Showing
4 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/scala/com/wavesplatform/transaction/smart/script/PolyDecompile.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.wavesplatform.transaction.smart.script | ||
|
||
import com.wavesplatform.lang.ContentType.{ContentType, DApp, Expression} | ||
import com.wavesplatform.lang.ScriptType.{Account, Asset, ScriptType} | ||
import com.wavesplatform.lang.StdLibVersion.{StdLibVersion, V1, V2, V3} | ||
import shapeless.Poly1 | ||
|
||
object PolyDecompile extends Poly1 { | ||
implicit def decompile[A](implicit d: Decompile[A]) = at[A](d.decompile) | ||
} | ||
|
||
trait Decompile[A] { | ||
def decompile(value: A): (String, Any) = (key, decompileValue(value)) | ||
def key: String | ||
def decompileValue(value: A): Any | ||
} | ||
|
||
object DecompileInstances { | ||
implicit val versionDecompiler = new Decompile[StdLibVersion] { | ||
override def key = "STDLIB_VERSION" | ||
override def decompileValue(value: StdLibVersion): Int = value match { | ||
case V1 => 1 | ||
case V2 => 2 | ||
case V3 => 3 | ||
} | ||
} | ||
|
||
implicit val expressionDecompiler = new Decompile[ContentType] { | ||
override def key = "CONTENT_TYPE" | ||
override def decompileValue(value: ContentType): String = value match { | ||
case Expression => "EXPRESSION" | ||
case DApp => "DAPP" | ||
} | ||
} | ||
|
||
implicit val scriptDecompiler = new Decompile[ScriptType] { | ||
override def key = "SCRIPT_TYPE" | ||
override def decompileValue(value: ScriptType): String = value match { | ||
case Account => "ACCOUNT" | ||
case Asset => "ASSET" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters