Skip to content

Commit

Permalink
Downgrade to previous version of proof-verification-tool
Browse files Browse the repository at this point in the history
 - downgrade due to 'unexpected token' error inside the pvt
 - overall adjustments due to the upgrade to corda v3 on flow and unit tests
 - add proof folder inside test/resources for testing
  • Loading branch information
Mauro Piazza committed Jul 13, 2018
1 parent 0bbbbd4 commit d4df4b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libs/proof-verification-tool
Submodule proof-verification-tool updated from b086a1 to 07034c
22 changes: 13 additions & 9 deletions src/main/kotlin/it/oraclize/cordapi/OraclizeUtils.kt
Expand Up @@ -3,7 +3,6 @@ package it.oraclize.cordapi
import co.paralleluniverse.fibers.Suspendable
import com.eclipsesource.v8.*
import com.eclipsesource.v8.utils.MemoryManager
import com.fasterxml.jackson.databind.ObjectMapper
import it.oraclize.cordapi.entities.Answer
import net.corda.core.contracts.Command
import net.corda.core.flows.FlowException
Expand All @@ -30,6 +29,7 @@ class OraclizeUtils {
"London",
"GB"
)

}

@Suspendable
Expand Down Expand Up @@ -106,13 +106,16 @@ class OraclizeUtils {
* verifying the proof.
*/
@Suspendable
private fun verify(proofs: List<ByteArray>, timer: Long? = null): Boolean {
private fun verify(proofs: List<ByteArray>, timer: Long? = null): Boolean {

val bundleFile = setBundleFile().toFile()

console("Bundle defined at $bundleFile")

// TODO think to use the nodeJS.runtime.locker for thread safety

val nodeJS = NodeJS.createNodeJS()

val memV8 = MemoryManager(nodeJS.runtime)

val module = nodeJS.require(bundleFile)
Expand All @@ -136,6 +139,7 @@ class OraclizeUtils {
}
)


val v8proofs = proofs.map { toV8TypedArray(nodeJS, it) }

console("Required variables defined")
Expand All @@ -151,10 +155,6 @@ class OraclizeUtils {
FlowException("Proof verification failed due to the following error: \n\n ${e.message}",
e.cause)
}
// catch (e: Exception) {
// FlowException("Proof verification failed due to an unhandled error : \n\n ${e.message}",
// e.cause)
// }

val timeToSleep = timer ?: 300000L

Expand All @@ -170,7 +170,8 @@ class OraclizeUtils {

timeout.start()

// When isRunning is false until NodeJS.createNodeJS()

// [isRunning] is false until NodeJS.createNodeJS()
// is called or handleMessage is called
do {
nodeJS.handleMessage()
Expand All @@ -191,19 +192,22 @@ class OraclizeUtils {
timeout.interrupt()
memV8.release()
}

}

/**
* Verify the Oraclize's proof
*/
@Suspendable
fun verifyProof(proof: ByteArray, timer: Long? = null) : Boolean { return verify(listOf(proof), timer) }
fun verifyProof(proof: ByteArray, timer: Long? = null) = verify(listOf(proof), timer)


/**
* Verify a list of Oraclize's proofs
*/
@Suspendable
fun verifyProofs(proofs: List<ByteArray>, timer: Long? = null) : Boolean { return verify(proofs, timer) }
fun verifyProofs(proofs: List<ByteArray>, timer: Long? = null) = verify(proofs, timer)

}

}
4 changes: 2 additions & 2 deletions src/main/kotlin/it/oraclize/cordapi/entities/Query.kt
Expand Up @@ -22,8 +22,8 @@ data class Query(
@get:JsonProperty("proof_type") val proofType: Int = 0) {

// Constants
// @get:JsonIgnore val CONTEXT_NAME = "corda_r3_testnet_1"
@get:JsonIgnore val CONTEXT_NAME = ""
@get:JsonIgnore val CONTEXT_NAME = "corda_r3_testnet_1"
// @get:JsonIgnore val CONTEXT_NAME = ""
var context : Any? = null

fun addContext(session: FlowSession, serviceHub: ServiceHub) {
Expand Down
Expand Up @@ -31,10 +31,6 @@ class OraclizeQueryAwaitFlow(val datasource: String,

@Suspendable
override fun call(): Answer {

val oracle = serviceHub.identityService
.wellKnownPartyFromX500Name(OraclizeUtils.getNodeName()) as Party

val queryId = subFlow(OraclizeQueryFlow(datasource, query, proofType))

while (!subFlow(OraclizeQueryStatusFlow(queryId)))
Expand Down

0 comments on commit d4df4b0

Please sign in to comment.