replace TransactionResult

This commit is contained in:
c4w 2019-04-01 22:51:04 +08:00
parent dbe4532ba6
commit b76cf8ccbb
20 changed files with 127 additions and 133 deletions

View File

@ -71,7 +71,7 @@ system {
//如果是单机多节点测试模式Repchain则选择0默认节点1会开启
ws_enable = 1//api 0,不开启;1,开启
//交易生产方式
trans_create_type = 1 //0,手动;1,自动
trans_create_type = 0 //0,手动;1,自动
//是否进行TPS测试
statistic_enable = 0 // 0,unable;able
@ -79,7 +79,7 @@ system {
checkCertValidate = 0//设置是否检查证书的有效性默认为0 0=不校验1=校验
contractOperationMode = 1//设置合约的运行方式0=debug方式1=deploy默认为debug方式如果发布部署必须使用deploy方式。
contractOperationMode = 0//设置合约的运行方式0=debug方式1=deploy默认为debug方式如果发布部署必须使用deploy方式。
block {
//块内交易的最大数量

View File

@ -142,17 +142,17 @@ message OperLog{
bytes oldValue =2;
bytes newValue=3;
}
message ActionResult{
int32 code = 1;
string reason = 2;
}
//()
//block中的各个交易
message TransactionResult {
//Transaction
string txId = 1;
// result - The return value of the transaction.
repeated OperLog ol = 2;
// errorCode - An error code. 5xx will be logged as a failure in the dashboard.
uint32 errorCode = 3;
// error - An error string for logging an issue.
string error = 4;
ActionResult result = 3;
}

View File

@ -44,7 +44,7 @@ import rep.utils.GlobalUtils.ActorType
import akka.actor.Props
import rep.crypto.cert.SignTool
import rep.log.trace._
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
import rep.app.conf.SystemProfile
/**
* RestActor伴生object包含可接受的传入消息定义以及处理的返回结果定义

View File

@ -187,17 +187,17 @@ class PreloadTransactionModule(moduleName: String, transProcessor:ActorRef) exte
for (l <- ol) {
val bso = l.oldValue match {
case null => _root_.com.google.protobuf.ByteString.EMPTY
case _ => ByteString.copyFrom(l.oldValue)
case _ => ByteString.copyFrom(l.oldValue.get)
}
val bsn = l.newValue match {
case null => _root_.com.google.protobuf.ByteString.EMPTY
case _ => ByteString.copyFrom(l.newValue)
case _ => ByteString.copyFrom(l.newValue.get)
}
olist += new OperLog(l.key, bso, bsn)
}
val result = new rep.protos.peer.TransactionResult(t.id,
olist, 0, "")
olist, None)
//val tmpsr = ImpDataPreloadMgr.GetImpDataPreload(pe.getDBTag,"preload_"+blk.transactions.head.id)

View File

@ -36,7 +36,6 @@ import Shim._
import rep.crypto.BytesHex
import rep.network.tools.PeerExtension
import rep.storage.IdxPrefix.WorldStateKeyPreFix
import rep.sc.scalax.ActionResult
import rep.storage._
import rep.utils.SerializeUtils.deserialise
import rep.utils.SerializeUtils.serialise
@ -115,9 +114,9 @@ abstract class Sandbox(cid:ChaincodeId) extends Actor {
def errAction(errCode: Int) :ActionResult = {
errCode match{
case -101 =>
ActionResult(errCode,Some("目标合约不存在"))
ActionResult(errCode,"目标合约不存在")
}
ActionResult(errCode,Some("不明原因"))
ActionResult(errCode,"不明原因")
}
/** 消息处理主流程,包括对交易处理请求、交易的预执行处理请求、从存储恢复合约的请求
*

View File

@ -30,7 +30,6 @@ import rep.sc.Shim.Oper
import com.google.protobuf.ByteString
import org.json4s._
import rep.log.trace.{RepLogger,ModuleType}
import rep.sc.scalax.ActionResult
/**
* @author c4w
@ -48,7 +47,7 @@ class SandboxJS(cid:ChaincodeId) extends Sandbox(cid){
sandbox.put("tx_account", t.signature.get.certId.get.creditCode)
//要么上一份给result重新建一份
shim.sr = ImpDataPreloadMgr.GetImpDataPreload(sTag, da)
shim.mb = scala.collection.mutable.Map[String,Array[Byte]]()
shim.mb = scala.collection.mutable.Map[String,Option[Array[Byte]]]()
shim.ol = scala.collection.mutable.ListBuffer.empty[Oper]
//如果执行中出现异常,返回异常
try{
@ -65,8 +64,8 @@ class SandboxJS(cid:ChaincodeId) extends Sandbox(cid){
val key = WorldStateKeyPreFix+ cid
shim.sr.Put(key,txid)
//ol value改为byte array
shim.ol.append(new Oper(key, null, txid))
new ActionResult(1,None)
shim.ol.append(new Oper(key, null, Some(txid)))
new ActionResult(1)
//调用方法时只需要执行function
case Transaction.Type.CHAINCODE_INVOKE =>
val r1 = sandbox.eval(t.para.ipt.get.function)
@ -77,7 +76,6 @@ class SandboxJS(cid:ChaincodeId) extends Sandbox(cid){
shim.ol.toList,shim.mb,None)
}catch{
case e: Exception =>
shim.rollback
log.error(t.id, e)
//val e1 = new Exception(e.getMessage, e.getCause)

View File

@ -17,10 +17,10 @@
package rep.sc.scalax
import rep.protos.peer.Transaction
import rep.protos.peer.ActionResult
import rep.sc.Shim
class ContractContext(val api:Shim, val t:Transaction)
case class ActionResult(code:Int, reason:Option[String])
/**
* @author c4w

View File

@ -77,7 +77,7 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
shim.sr.Put(key_coder,coder_bytes)
shim.ol.append(new Oper(key_coder, null, Some(coder_bytes)))
}
new ActionResult(1,None)
new ActionResult(1)
//由于Invoke为最频繁调用因此应尽量避免在处理中I/O读写,比如合约状态的检查就最好在内存中处理
//TODO case Transaction.Type.CHAINCODE_DESC 增加对合约描述的处理
case Transaction.Type.CHAINCODE_INVOKE =>
@ -93,7 +93,7 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
val state_bytes = serialise(state)
shim.sr.Put(key_tx_state,state_bytes)
shim.ol.append(new Oper(key_tx_state, null, Some(state_bytes)))
new ActionResult(1,None)
new ActionResult(1)
}
val mb = shim.sr.GetComputeMerkle4String
val mbstr = mb match {

View File

@ -25,8 +25,7 @@ import rep.utils.IdTool
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* 资产管理合约
@ -50,26 +49,26 @@ class ContractAssetsTPL extends IContract{
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
println(s"set data:$data")
for((k,v)<-data){
ctx.api.setVal(k, v)
ctx.api.setVal(k, Some(v))
}
new ActionResult(1,None)
new ActionResult(1)
}
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
return new ActionResult(-1, Some("只允许从本人账户转出"))
return new ActionResult(-1, "只允许从本人账户转出")
val signerKey = data.to
// 跨合约读账户该处并未反序列化
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
return new ActionResult(-2, Some("目标账户不存在"))
return new ActionResult(-2, "目标账户不存在")
val sfrom = ctx.api.getVal(data.from)
var dfrom =sfrom.asInstanceOf[Int]
if(dfrom < data.amount)
return new ActionResult(-3, Some("余额不足"))
return new ActionResult(-3, "余额不足")
var dto = ctx.api.getVal(data.to).toString.toInt
ctx.api.setVal(data.from,dfrom - data.amount)
ctx.api.setVal(data.to,dto + data.amount)
new ActionResult(1,None)
ctx.api.setVal(data.from,Some(dfrom - data.amount))
ctx.api.setVal(data.to,Some(dto + data.amount))
new ActionResult(1)
}
/**
* 根据action,找到对应的method并将传入的json字符串parse为method需要的传入参数

View File

@ -26,8 +26,7 @@ import java.text.SimpleDateFormat
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* 资产管理合约
@ -51,35 +50,35 @@ case class Transfer(from:String, to:String, amount:Int)
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
println(s"set data:$data")
for((k,v)<-data){
ctx.api.setVal(k, v)
ctx.api.setVal(k, Some(v))
}
new ActionResult(1,None)
new ActionResult(1)
}
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
return new ActionResult(-1, Some("只允许从本人账户转出"))
return new ActionResult(-1, "只允许从本人账户转出")
val signerKey = data.to
// 跨合约读账户该处并未反序列化
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
return new ActionResult(-2, Some("目标账户不存在"))
return new ActionResult(-2, "目标账户不存在")
val sfrom = ctx.api.getVal(data.from)
var dfrom =sfrom.asInstanceOf[Int]
if(dfrom < data.amount)
return new ActionResult(-3, Some("余额不足"))
return new ActionResult(-3, "余额不足")
var dto = ctx.api.getVal(data.to).toString.toInt
val df:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
val t1 = System.currentTimeMillis()
val s1 = s"setval begin:${ctx.t.id} " + df.format(t1)
ctx.api.setVal(data.from,dfrom - data.amount)
ctx.api.setVal(data.from,Some(dfrom - data.amount))
//for test 同合约交易串行测试
Thread.sleep(5000)
ctx.api.setVal(data.to,dto + data.amount)
ctx.api.setVal(data.to,Some(dto + data.amount))
val t2 = System.currentTimeMillis()
val s2 = s"setval end:${ctx.t.id} " + df.format(t2)
new ActionResult(1,Some(s1+"\n"+s2) )
new ActionResult(1, s1+"\n"+s2)
}
/**
* 根据action,找到对应的method并将传入的json字符串parse为method需要的传入参数

View File

@ -24,10 +24,9 @@ import rep.protos.peer.ChaincodeId
import rep.utils.IdTool
import java.text.SimpleDateFormat
import rep.sc.scalax.IContract
import rep.protos.peer.ActionResult
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
/**
* 资产管理合约
@ -51,38 +50,38 @@ case class Transfer(from:String, to:String, amount:Int, remind:String)
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
println(s"set data:$data")
for((k,v)<-data){
ctx.api.setVal(k, v)
ctx.api.setVal(k, Some(v))
}
new ActionResult(1,None)
new ActionResult(1)
}
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
return new ActionResult(-1, Some("只允许从本人账户转出"))
return new ActionResult(-1, "只允许从本人账户转出")
val signerKey = data.to
// 跨合约读账户该处并未反序列化
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
return new ActionResult(-2, Some("目标账户不存在"))
return new ActionResult(-2, "目标账户不存在")
val sfrom = ctx.api.getVal(data.from)
var dfrom =sfrom.asInstanceOf[Int]
if(dfrom < data.amount)
return new ActionResult(-3, Some("余额不足"))
return new ActionResult(-3, "余额不足")
val rstr = s"""确定签名从本人所持有的账户【${data.from}
向账户${data.to}
转账${data.amount}"""
//预执行获得结果提醒
if(data.remind==null){
new ActionResult(2,Some(rstr))
new ActionResult(2,rstr)
}else{
if(!data.remind.equals(rstr))
new ActionResult(-4,Some("提醒内容不符"))
new ActionResult(-4,"提醒内容不符")
else{
var dto = ctx.api.getVal(data.to).toString.toInt
ctx.api.setVal(data.from,dfrom - data.amount)
ctx.api.setVal(data.to,dto + data.amount)
new ActionResult(1,None)
ctx.api.setVal(data.from,Some(dfrom - data.amount))
ctx.api.setVal(data.to,Some(dto + data.amount))
new ActionResult(1)
}
}
}

View File

@ -9,7 +9,7 @@ import rep.app.conf.SystemProfile
import rep.utils.{IdTool, SerializeUtils}
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* @author zyf
@ -53,17 +53,17 @@ class ContractCert extends IContract {
def signUpSigner(ctx: ContractContext, data:Signer):ActionResult = {
val isNodeCert = ctx.api.bNodeCreditCode(ctx.t.getSignature.getCertId.creditCode)
if (!isNodeCert) {
return ActionResult(0,Some(notNodeCert))
return ActionResult(0,notNodeCert)
}
// 存Signer账户
//val signerKey = prefix + underline + data.creditCode
val signer = ctx.api.getState(data.creditCode)
// 如果是null表示已注销如果不是null则判断是否有值
if (signer == null || new String(signer).equalsIgnoreCase("null")){
ctx.api.setVal(data.creditCode, data)
ActionResult(1,None)
if (signer == None ){
ctx.api.setVal(data.creditCode, Some(data))
ActionResult(1)
} else {
ActionResult(0,Some(signerExists))
ActionResult(0,signerExists)
}
}
@ -76,27 +76,27 @@ class ContractCert extends IContract {
def signUpCert(ctx: ContractContext, data:CertInfo): ActionResult = {
val isNodeCert = ctx.api.bNodeCreditCode(ctx.t.getSignature.getCertId.creditCode)
if (!isNodeCert) {
return ActionResult(0,Some(notNodeCert))
return ActionResult(0,notNodeCert)
}
val certKey = data.credit_code + dot + data.name
val certInfo = ctx.api.getState(certKey)
val signerKey = data.credit_code
val signerContent = ctx.api.getState(signerKey)
// 先判断证书若证书不存在则向账户添加name
if (certInfo == null || new String(certInfo).equalsIgnoreCase("null")) {
if (signerContent == null || new String(signerContent).equalsIgnoreCase("null")){
return ActionResult(0,Some(signerNotExists))
if (certInfo == None) {
if (signerContent == None){
return ActionResult(0,signerNotExists)
} else {
ctx.api.setVal(certKey, data.cert)
val signer = SerializeUtils.deserialise(signerContent).asInstanceOf[Signer]
ctx.api.setVal(certKey, Some(data.cert))
val signer = SerializeUtils.deserialise(signerContent.get).asInstanceOf[Signer]
if (!signer.certNames.contains(data.name)){
signer.addCertNames(data.name)
ctx.api.setVal(signerKey, signer)
ctx.api.setVal(signerKey, Some(signer))
}
}
ActionResult(1, None)
ActionResult(1)
} else {
ActionResult(0, Some(certExists))
ActionResult(0, certExists)
}
}
@ -112,17 +112,17 @@ class ContractCert extends IContract {
def updateCertStatus(ctx: ContractContext, data: CertStatus): ActionResult = {
val isNodeCert = ctx.api.bNodeCreditCode(ctx.t.getSignature.getCertId.creditCode)
if (!isNodeCert) {
return ActionResult(0,Some(notNodeCert))
return ActionResult(0,notNodeCert)
}
val certKey = data.credit_code + dot + data.name
val certInfo = ctx.api.getState(certKey)
if (certInfo == null || new String(certInfo).equalsIgnoreCase("null")) {
ActionResult(0,Some(certNotExists))
if (certInfo == None) {
ActionResult(0,certNotExists)
} else {
val cert = SerializeUtils.deserialise(certInfo).asInstanceOf[Certificate]
val cert = SerializeUtils.deserialise(certInfo.get).asInstanceOf[Certificate]
cert.withCertValid(data.status)
ctx.api.setVal(certKey, cert)
ActionResult(1,None)
ctx.api.setVal(certKey, Some(cert))
ActionResult(1)
}
}
@ -135,15 +135,15 @@ class ContractCert extends IContract {
def updateSigner(ctx: ContractContext, data: Signer): ActionResult = {
val isNodeCert = ctx.api.bNodeCreditCode(ctx.t.getSignature.getCertId.creditCode)
if (!isNodeCert) {
return ActionResult(0,Some(notNodeCert))
return ActionResult(0,notNodeCert)
}
val signer = ctx.api.getState(data.creditCode)
// 如果是null账户不存在不存在则不能更新
if (signer == null || new String(signer).equalsIgnoreCase("null")){
ActionResult(0,Some(signerNotExists))
if (signer == None){
ActionResult(0,signerNotExists)
} else {
ctx.api.setVal(data.creditCode, data)
ActionResult(1,None)
ctx.api.setVal(data.creditCode, Some(data))
ActionResult(1)
}
}

View File

@ -29,7 +29,7 @@ import org.json4s.{DefaultFormats, Formats, jackson}
import rep.sc.tpl.SupplyType._
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* 供应链分账合约
@ -49,13 +49,13 @@ class SupplyTPL extends IContract {
* 追加确认签名 TODO 逻辑实现
*/
def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
* 取消追加确认签名 TODO 逻辑实现
*/
def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
@ -65,7 +65,7 @@ class SupplyTPL extends IContract {
* @return
*/
def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = {
ActionResult(1,None)
ActionResult(1)
}
/**
@ -75,18 +75,18 @@ class SupplyTPL extends IContract {
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化,默认的类型转换无法胜任以json字符串形式持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Share)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Share))
ActionResult(1)
}
def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Fixed)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Fixed))
ActionResult(1)
}
/**
@ -110,7 +110,7 @@ class SupplyTPL extends IContract {
}
//返回分账计算结果
addToAccount(ctx, mr)
ActionResult(1,None)
ActionResult(1)
}
/**
@ -120,7 +120,7 @@ class SupplyTPL extends IContract {
for ((k, v) <- mr) {
val sk = ctx.api.getVal(k)
var dk = if(sk==null) 0 else sk.toString.toInt
ctx.api.setVal(k, dk+v)
ctx.api.setVal(k, Some(dk+v))
}
}
/**

View File

@ -29,7 +29,7 @@ import org.json4s.{DefaultFormats, Formats, jackson}
import rep.sc.tpl.SupplyType._
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* 供应链分账合约
@ -49,13 +49,13 @@ class SupplyTPL2 extends IContract {
* 追加确认签名 TODO 逻辑实现
*/
def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
* 取消追加确认签名 TODO 逻辑实现
*/
def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
@ -65,7 +65,7 @@ class SupplyTPL2 extends IContract {
* @return
*/
def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = {
ActionResult(1,None)
ActionResult(1)
}
/**
@ -75,18 +75,18 @@ class SupplyTPL2 extends IContract {
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化,默认的类型转换无法胜任以json字符串形式持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Share)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Share))
ActionResult(1)
}
def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Fixed)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Fixed))
ActionResult(1)
}
/**
@ -110,7 +110,7 @@ class SupplyTPL2 extends IContract {
}
//返回分账计算结果
addToAccount(ctx, mr)
ActionResult(1,None)
ActionResult(1)
}
/**
@ -120,7 +120,7 @@ class SupplyTPL2 extends IContract {
for ((k, v) <- mr) {
val sk = ctx.api.getVal(k)
var dk = if(sk==null) 0 else sk.toString.toInt
ctx.api.setVal(k, dk+v)
ctx.api.setVal(k, Some(dk+v))
}
}
/**

View File

@ -29,7 +29,7 @@ import org.json4s.{DefaultFormats, Formats, jackson}
import rep.sc.tpl.SupplyType._
import rep.sc.scalax.IContract
import rep.sc.scalax.ContractContext
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
/**
* 供应链分账合约
@ -49,13 +49,13 @@ class SupplyTPL3 extends IContract {
* 追加确认签名 TODO 逻辑实现
*/
def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
* 取消追加确认签名 TODO 逻辑实现
*/
def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={
ActionResult(1,None)
ActionResult(1)
}
/**
@ -65,7 +65,7 @@ class SupplyTPL3 extends IContract {
* @return
*/
def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = {
ActionResult(1,None)
ActionResult(1)
}
/**
@ -75,18 +75,18 @@ class SupplyTPL3 extends IContract {
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化,默认的类型转换无法胜任以json字符串形式持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Share)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Share))
ActionResult(1)
}
def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={
val sid = data.account_sale +SPLIT_CHAR + data.product_id
val pid = sid+TPL_MODE
//签约输入持久化
ctx.api.setVal(sid, write(data))
ctx.api.setVal(pid, TPL.Fixed)
ActionResult(1,None)
ctx.api.setVal(sid, Some(write(data)))
ctx.api.setVal(pid, Some(TPL.Fixed))
ActionResult(1)
}
/**
@ -110,7 +110,7 @@ class SupplyTPL3 extends IContract {
}
//返回分账计算结果
addToAccount(ctx, mr)
ActionResult(1,None)
ActionResult(1)
}
/**
@ -120,7 +120,7 @@ class SupplyTPL3 extends IContract {
for ((k, v) <- mr) {
val sk = ctx.api.getVal(k)
var dk = if(sk==null) 0 else sk.toString.toInt
ctx.api.setVal(k, dk+v)
ctx.api.setVal(k, Some(dk+v))
}
}
/**

View File

@ -126,7 +126,7 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (0)
msg_recv.r.reason.getOrElse("UnKnow Error") should be ("证书已存在")
msg_recv.r.reason should be ("证书已存在")
}
// 不能将证书注册到一个不存在的账户
@ -137,7 +137,7 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (0)
msg_recv.r.reason.getOrElse("UnKnow Error") should be ("账户不存在")
msg_recv.r.reason should be ("账户不存在")
}
// 将证书2追加到 node1的账户中使用node2作为certName
@ -148,7 +148,7 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (1)
msg_recv.r.reason.getOrElse("default") should be ("default")
msg_recv.r.reason should be ("default")
}
// 更新证书状态,将刚刚追加的node2的证书状态修改为false
@ -159,7 +159,7 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (1)
msg_recv.r.reason.getOrElse("default") should be ("default")
msg_recv.r.reason should be ("default")
}
// 更新证书状态对应的证书不存在
@ -170,7 +170,7 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (0)
msg_recv.r.reason.getOrElse("default") should be ("证书不存在")
msg_recv.r.reason should be ("证书不存在")
}
// 更新账户信息将账户node1中的name改为node2并且修改手机号
@ -182,6 +182,6 @@ class ContractCertSpec (_system: ActorSystem)
probe.send(sandbox, msg_send)
val msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
msg_recv.r.code should be (1)
msg_recv.r.reason.getOrElse("default") should be ("default")
msg_recv.r.reason should be ("default")
}
}

View File

@ -150,9 +150,9 @@ class SupplySpec(_system: ActorSystem)
var total = 0
ol4.foreach {
ol =>
total += deserialise(ol.newValue).asInstanceOf[Int]
total += deserialise(ol.newValue.get).asInstanceOf[Int]
if(ol.oldValue!= null)
total -= deserialise(ol.oldValue).asInstanceOf[Int]
total -= deserialise(ol.oldValue.get).asInstanceOf[Int]
}
total should be(el)
}
@ -173,9 +173,9 @@ class SupplySpec(_system: ActorSystem)
var total = 0
ol4.foreach {
ol =>
total += deserialise(ol.newValue).asInstanceOf[Int]
total += deserialise(ol.newValue.get).asInstanceOf[Int]
if(ol.oldValue!= null)
total -= deserialise(ol.oldValue).asInstanceOf[Int]
total -= deserialise(ol.oldValue.get).asInstanceOf[Int]
}
total should be(el)
}

View File

@ -175,9 +175,9 @@ class SupplySpec2(_system: ActorSystem)
var total = 0
ol4.foreach {
ol =>
total += deserialise(ol.newValue).asInstanceOf[Int]
total += deserialise(ol.newValue.get).asInstanceOf[Int]
if(ol.oldValue!= null)
total -= deserialise(ol.oldValue).asInstanceOf[Int]
total -= deserialise(ol.oldValue.get).asInstanceOf[Int]
}
total should be(el)
}
@ -198,10 +198,10 @@ class SupplySpec2(_system: ActorSystem)
var total = 0
ol4.foreach {
ol =>
total += deserialise(ol.newValue).asInstanceOf[Int]
total += deserialise(ol.newValue.get).asInstanceOf[Int]
//由于不同版本共享kv,前面的分账结果导致账户不为空
ol.oldValue should not be null
total -= deserialise(ol.oldValue).asInstanceOf[Int]
total -= deserialise(ol.oldValue.get).asInstanceOf[Int]
}
total should be(el)
}

View File

@ -125,7 +125,7 @@ class TransferSpec_Legal(_system: ActorSystem)
msg_recv.r.code should be (2)
//对提醒文本签名
val remind = msg_recv.r.reason.get
val remind = msg_recv.r.reason
println(remind)
p = Transfer("121000005l35120456", "12110107bi45jh675g", 5,remind )
t = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(toJson(p)))

View File

@ -17,7 +17,7 @@
package rep.utils
import rep.sc.Shim.Oper
import rep.sc.Sandbox.DoTransactionResult
import rep.sc.scalax.ActionResult
import rep.protos.peer.ActionResult
import org.scalatest._
import prop._
@ -35,7 +35,7 @@ import SerializeUtils._
*/
class SerializeSpec extends PropSpec with TableDrivenPropertyChecks with Matchers {
val ol = List(Oper("key1",None,Some(BigInt(8).toByteArray)),Oper("key1",Some(BigInt(8).toByteArray),None))
val tr = new DoTransactionResult(null,null, new ActionResult(1,None),
val tr = new DoTransactionResult(null,null, new ActionResult(1),
None,
ol,null,None)