isForInvoke允许恢复已部署的合约

This commit is contained in:
c4w 2019-03-18 14:27:32 +08:00
parent 421fad9aba
commit 3f285809a7
4 changed files with 9 additions and 8 deletions

View File

@ -124,8 +124,8 @@ abstract class Sandbox(cid:ChaincodeId) extends Actor {
shim.rollback()
sender ! tr
//恢复chainCode,不回消息
case DeployTransaction(t:Transaction,from:ActorRef, da:String) =>
val tr = doTransaction(t,from,da)
case DeployTransaction(t:Transaction,from:ActorRef, da:String,isForInvoke:Boolean) =>
val tr = doTransaction(t,from,da,isForInvoke)
shim.rollback()
}
/** 交易处理抽象方法,接受待处理交易,返回处理结果
@ -134,6 +134,6 @@ abstract class Sandbox(cid:ChaincodeId) extends Actor {
* @param da 存储访问标示
* @return 交易执行结果
*/
def doTransaction(t:Transaction,from:ActorRef, da:String):DoTransactionResult
def doTransaction(t:Transaction,from:ActorRef, da:String,isForInvoke:Boolean=false):DoTransactionResult
}

View File

@ -76,7 +76,7 @@ object TransProcessor {
* @param from 来源actor指向
* @param da 数据访问标示
*/
case class DeployTransaction(t:Transaction, from:ActorRef, da:String,isForInvoke:Boolean)
case class DeployTransaction(t:Transaction, from:ActorRef, da:String, isForInvoke:Boolean=false)
/** 根据传入参数返回actor的Props
* @param name actor的命名
@ -179,7 +179,7 @@ class TransProcessor(name: String, da:String, parent: ActorRef) extends Actor {
//默认采用jdk内置的javascript作为合约容器
case _ => context.actorOf(Props(new SandboxJS(cid)), sn)
}
actor ! DeployTransaction(tx_deploy, from, da)
actor ! DeployTransaction(tx_deploy, from, da, true)
actor
}else
//新执行的deploy交易,新建actor

View File

@ -41,7 +41,7 @@ class SandboxJS(cid:ChaincodeId) extends Sandbox(cid){
val sandbox= new ScriptEngineManager().getEngineByName("nashorn")
sandbox.put("shim",shim)
override def doTransaction(t:Transaction,from:ActorRef, da:String):DoTransactionResult ={
override def doTransaction(t:Transaction,from:ActorRef, da:String, isForInvoke:Boolean):DoTransactionResult ={
//上下文可获得交易
sandbox.put("tx", t)
//for test print sandbox id

View File

@ -39,7 +39,7 @@ import rep.sc.contract._
class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
var cobj:IContract = null
def doTransaction(t:Transaction,from:ActorRef, da:String):DoTransactionResult ={
def doTransaction(t:Transaction,from:ActorRef, da:String, isForInvoke:Boolean):DoTransactionResult ={
//上下文可获得交易
//要么上一份给result重新建一份
shim.sr = ImpDataPreloadMgr.GetImpDataPreload(sTag, da)
@ -59,7 +59,8 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
val key_code = WorldStateKeyPreFix+ cid.chaincodeName
val coder = shim.sr.Get(key_code)
if(shim.sr.Get(key_tx) != null)
//isForInvoke是恢复已部署的合约而不是新部署合约
if(!isForInvoke && shim.sr.Get(key_tx) != null)
ActionResult(-1, Some("存在重复的合约Id"))
else if(coder!= null && !t.signature.get.certId.get.creditCode.equals(new String(coder))){
ActionResult(-2, Some("合约只能由部署者升级更新"))