mirror of
https://gitee.com/BTAJL/repchain.git
synced 2024-12-04 12:48:32 +08:00
Merge remote-tracking branch 'origin/dev_jby_preview' into yf_preview
This commit is contained in:
commit
6994d489f8
@ -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
|
||||
|
||||
@ -98,7 +98,7 @@ system {
|
||||
"122000002n00123567.node3","921000005k36123789.node4","921000006e0012v696.node5"]
|
||||
}
|
||||
account{
|
||||
chaincodename = "REPCHAINACCOUNTMGR"//账户管理合约的名称
|
||||
chaincodename = "ContractCert"//账户管理合约的名称
|
||||
chaincodeversion = 1
|
||||
}
|
||||
|
||||
|
614
json/gensis.json
614
json/gensis.json
File diff suppressed because one or more lines are too long
@ -199,6 +199,8 @@ class PreloadTransactionModule(moduleName: String, transProcessor:ActorRef) exte
|
||||
val result = new rep.protos.peer.TransactionResult(t.id,
|
||||
olist, 0, "")
|
||||
|
||||
|
||||
val tmpsr = ImpDataPreloadMgr.GetImpDataPreload(pe.getDBTag,"preload_"+blk.transactions.head.id)
|
||||
//todo与执行之后需要记录当前交易执行之后的merkle值,目前结构中没有产生
|
||||
preLoadTrans(t.id) = t//t.withMetadata(ByteString.copyFrom(SerializeUtils.serialise(mb)))
|
||||
|
||||
|
@ -73,14 +73,17 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
|
||||
cobj.init(ctx)
|
||||
//deploy返回chancode.name
|
||||
//利用kv记住cid对应的txid,并增加kv操作日志,以便恢复deploy时能根据cid找到当时deploy的tx及其代码内容
|
||||
val txid = ByteString.copyFromUtf8(t.id).toByteArray()
|
||||
shim.sr.Put(key_tx,txid)
|
||||
shim.ol.append(new Oper(key_tx, null, txid))
|
||||
|
||||
//利用kv记住合约的开发者
|
||||
val coder = ByteString.copyFromUtf8(t.signature.get.certId.get.creditCode).toByteArray()
|
||||
shim.sr.Put(key_code,coder)
|
||||
shim.ol.append(new Oper(key_code, null, coder))
|
||||
//如果是部署合约需要登记部署合约相关的信息,包括:合约内容等。
|
||||
if(!isForInvoke){
|
||||
val txid = ByteString.copyFromUtf8(t.id).toByteArray()
|
||||
shim.sr.Put(key_tx,txid)
|
||||
shim.ol.append(new Oper(key_tx, null, txid))
|
||||
|
||||
//利用kv记住合约的开发者
|
||||
val coder = ByteString.copyFromUtf8(t.signature.get.certId.get.creditCode).toByteArray()
|
||||
shim.sr.Put(key_code,coder)
|
||||
shim.ol.append(new Oper(key_code, null, coder))
|
||||
}
|
||||
new ActionResult(1,None)
|
||||
}
|
||||
//新建class实例并执行合约,传参为json数据
|
||||
|
@ -34,9 +34,9 @@ case class Transfer(from:String, to:String, amount:Int)
|
||||
class ContractAssetsTPL extends IContract{
|
||||
|
||||
// 需要跨合约读账户
|
||||
val chaincodeName = "ContractCert"// SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = 1 //SystemProfile.getAccountChaincodeVersion
|
||||
val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
@ -55,9 +55,9 @@ class ContractAssetsTPL extends IContract{
|
||||
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
|
||||
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
return new ActionResult(-1, Some("只允许从本人账户转出"))
|
||||
val signerKey = prefix + "_" + data.to
|
||||
val signerKey = data.to
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if(ctx.api.getStateEx(chaincodeName,signerKey)==null)
|
||||
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
|
||||
return new ActionResult(-2, Some("目标账户不存在"))
|
||||
val sfrom = ctx.api.getVal(data.from)
|
||||
var dfrom =sfrom.asInstanceOf[Int]
|
||||
|
@ -30,9 +30,9 @@ class ContractCert extends IContract {
|
||||
val certExists = "证书已存在"
|
||||
val certNotExists = "证书不存在"
|
||||
val unknownError = "未知错误"
|
||||
val chaincodeName = "ContractCert"// SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = 1 //SystemProfile.getAccountChaincodeVersion
|
||||
val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
val underline = "_"
|
||||
val dot = "."
|
||||
// 锚点,错误回退
|
||||
@ -59,11 +59,11 @@ class ContractCert extends IContract {
|
||||
return ActionResult(0,Some(notNodeCert))
|
||||
}
|
||||
// 存Signer账户
|
||||
val signerKey = prefix + underline + data.creditCode
|
||||
val signer = ctx.api.getState(signerKey)
|
||||
//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(signerKey, data)
|
||||
ctx.api.setVal(data.creditCode, data)
|
||||
ActionResult(1,None)
|
||||
} else {
|
||||
ActionResult(0,Some(signerExists))
|
||||
@ -81,9 +81,9 @@ class ContractCert extends IContract {
|
||||
if (!isNodeCert) {
|
||||
return ActionResult(0,Some(notNodeCert))
|
||||
}
|
||||
val certKey = prefix + underline + data.credit_code + dot + data.name
|
||||
val certKey = data.credit_code + dot + data.name
|
||||
val certInfo = ctx.api.getState(certKey)
|
||||
val signerKey = prefix + underline + data.credit_code
|
||||
val signerKey = data.credit_code
|
||||
val signerContent = ctx.api.getState(signerKey)
|
||||
// 先判断证书,若证书不存在,则向账户添加name
|
||||
if (certInfo == null || new String(certInfo).equalsIgnoreCase("null")) {
|
||||
@ -121,7 +121,7 @@ class ContractCert extends IContract {
|
||||
if (!isNodeCert) {
|
||||
return ActionResult(0,Some(notNodeCert))
|
||||
}
|
||||
val certKey = prefix + underline + data.credit_code + dot + data.name
|
||||
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))
|
||||
|
@ -425,7 +425,9 @@ class ImpDataAccess private(SystemName:String) extends IDataAccess(SystemName){
|
||||
trans.foreach(f=>{
|
||||
if(f.id.equals(txid)){
|
||||
//rel = f.getPayload.getChaincodeID.name
|
||||
rel = IdTool.getCid(f.cid.get)
|
||||
//根据合约编写的时候不添加版本好的规则生成
|
||||
//rel = IdTool.getCid(f.cid.get)
|
||||
rel = f.getCid.chaincodeName
|
||||
//rel = f.chaincodeID.toStringUtf8()
|
||||
}
|
||||
})
|
||||
|
@ -114,16 +114,20 @@ class ImpDataPreload (SystemName:String,InstanceName:String) extends AbstractLev
|
||||
"ImpDataPreload_" + SystemName + "_" + s"ImpDataPreload Put failed, error info= value is null")
|
||||
}
|
||||
if(key != null && bb != null){
|
||||
if(this.update.get(key) != null){
|
||||
val obbstr = toString(this.update.get(key))
|
||||
this.update.put(key, bb)
|
||||
//this.merkleop.Put(key, bb)
|
||||
this.PutWorldStateToMerkle(key,bb)
|
||||
/*if(this.update.get(key) != null){
|
||||
/*val obbstr = toString(this.update.get(key))
|
||||
val bbstr = toString(bb)
|
||||
if(!obbstr.equals(bbstr)){
|
||||
this.update.put(key, bb)
|
||||
//this.merkleop.Put(key, bb)
|
||||
this.PutWorldStateToMerkle(key,bb)
|
||||
}
|
||||
}*/
|
||||
|
||||
}else{
|
||||
if(this.dbop.Get(key) != null){
|
||||
/*if(this.dbop.Get(key) != null){
|
||||
val obbstr = toString(this.dbop.Get(key))
|
||||
val bbstr = toString(bb)
|
||||
if(!obbstr.equals(bbstr)){
|
||||
@ -135,8 +139,8 @@ class ImpDataPreload (SystemName:String,InstanceName:String) extends AbstractLev
|
||||
this.update.put(key, bb)
|
||||
//this.merkleop.Put(key, bb)
|
||||
this.PutWorldStateToMerkle(key,bb)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}*/
|
||||
}
|
||||
setUseTime
|
||||
}catch{
|
||||
@ -252,8 +256,13 @@ class ImpDataPreload (SystemName:String,InstanceName:String) extends AbstractLev
|
||||
|
||||
if(jobj != null && jobj.length > 0){
|
||||
jobj.foreach(f=>{
|
||||
var tmpkeystr = IdxPrefix.WorldStateKeyPreFix+cid+"_"+f.key
|
||||
this.Put(IdxPrefix.WorldStateKeyPreFix+cid+"_"+f.key, f.newValue.toByteArray())
|
||||
if(f.key.startsWith(IdxPrefix.WorldStateKeyPreFix)){
|
||||
this.Put(f.key, f.newValue.toByteArray())
|
||||
}else{
|
||||
this.Put(IdxPrefix.WorldStateKeyPreFix+cid+"_"+f.key, f.newValue.toByteArray())
|
||||
}
|
||||
//var tmpkeystr = IdxPrefix.WorldStateKeyPreFix+cid+"_"+f.key
|
||||
//this.Put(tmpkeystr, f.newValue.toByteArray())
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -14,7 +14,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package rep.storage.timeAnalysiser
|
||||
package rep.storage.test
|
||||
|
||||
import rep.storage._
|
||||
import rep.protos.peer._
|
||||
|
@ -14,14 +14,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package rep.storage.timeAnalysiser
|
||||
package rep.storage.test
|
||||
|
||||
import rep.storage._;
|
||||
import rep.storage.leveldb._;
|
||||
import rep.protos.peer._;
|
||||
import rep.utils._
|
||||
import rep.crypto._
|
||||
import java.util
|
||||
import java.util._
|
||||
import com.google.protobuf.ByteString
|
||||
|
||||
|
||||
/**
|
||||
@ -30,96 +31,26 @@ import java.util
|
||||
* @since 2017-09-28
|
||||
* */
|
||||
object teststoragemgr {
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
/*val s = StorageMgr.GetStorageMgr("1")
|
||||
val s1 = StorageMgr.GetStorageMgr("2")
|
||||
val prefix = "c_"
|
||||
val ccid = "sfsldfsffkwiiwuqoq_"
|
||||
s.BeginTrans()
|
||||
s1.BeginTrans()
|
||||
for(a <- 1 to 1000){
|
||||
val b = (new util.Random()).nextInt(9000)
|
||||
val key = prefix+ccid+b
|
||||
s.put(key, String.valueOf("s"+b).getBytes)
|
||||
s1.put(key, String.valueOf("s1"+b).getBytes)
|
||||
}
|
||||
println("s merkle="+s.GetComputeMerkle4String);
|
||||
println("s1 merkle="+s1.GetComputeMerkle4String);
|
||||
*/
|
||||
|
||||
// val lh = StorageMgr.GetStorageMgr("testSystem");
|
||||
|
||||
|
||||
/*ls.put("a_1001", "bbbbb".getBytes());
|
||||
println("key=a_1001\tvalue="+ls.get("a_1001"));
|
||||
ls.delete("a_1001");
|
||||
println("key=a_1001\tvalue="+ls.get("a_1001"));*/
|
||||
|
||||
/*lh.put("a_1001", "nnnn".getBytes());
|
||||
lh.put("a_1000", "uuuu".getBytes());
|
||||
println("key=a_1000\tvalue="+lh.byteToString(lh.get("a_1000")));
|
||||
lh.BeginTrans();
|
||||
lh.delete("a_1000");
|
||||
System.out.println("key=a_1000\tvalue="+lh.byteToString(lh.get("a_1000")));
|
||||
lh.put("c_1000", "dddd".getBytes());
|
||||
System.out.println("key=c_1000\tvalue="+lh.byteToString(lh.get("c_1000")));
|
||||
lh.put("c_1000", "eeee".getBytes());
|
||||
System.out.println("key=c_1000\tvalue="+lh.byteToString(lh.get("c_1000")));
|
||||
System.out.println("in trans");
|
||||
lh.printmap(lh.FindByLike("a_"));
|
||||
System.out.println("");
|
||||
lh.printmap(lh.FindByLike("c_"));
|
||||
System.out.println("");
|
||||
lh.CommitTrans();
|
||||
System.out.println("key=a_1000\tvalue="+lh.byteToString(lh.get("a_1000")));
|
||||
System.out.println("key=c_1000\tvalue="+lh.byteToString(lh.get("c_1000")));
|
||||
System.out.println("out trnas");
|
||||
lh.printmap(lh.FindByLike("a_"));
|
||||
System.out.println("");
|
||||
lh.printmap(lh.FindByLike("c_"));*/
|
||||
|
||||
/*
|
||||
val atemp = s.FindByLike("c_")
|
||||
atemp.foreach(f=>{
|
||||
val key = f._1
|
||||
val value1 = s.get(key)
|
||||
val value2 = s1.get(key)
|
||||
println("key="+key+"\tvalue1="+BytesHex.bytes2hex(value1)+"\tvalue2="+BytesHex.bytes2hex(value2))
|
||||
//+"\tvalue2="+BytesHex.bytes2hex(value2)
|
||||
//println(f._1, String.valueOf(f._2))
|
||||
})
|
||||
|
||||
println(s.GetComputeMerkle4String)
|
||||
println(s1.GetComputeMerkle4String)
|
||||
def getAllKeyValue():Unit={
|
||||
val sr = ImpDataAccess.GetDataAccess("121000005l35120456.node1")
|
||||
val hr = sr.FindByLike("c_")
|
||||
hr.foreach(f=>{
|
||||
if(f._2 != null){
|
||||
try{
|
||||
println(s"key=${f._1}\tvalue=${SerializeUtils.deserialise(f._2)}")
|
||||
}catch{
|
||||
case e:Exception => println(s"key=${f._1}\t")
|
||||
}
|
||||
}else{
|
||||
println(s"key=${f._1}\t")
|
||||
}
|
||||
//println(s"key=${f._1}|||||\tvalue=${ByteString.copyFrom(f._2).toStringUtf8()}\r\n||||||")
|
||||
|
||||
s.BeginTrans()
|
||||
s.put("c_key_a", "a".getBytes)
|
||||
s.put("c_key_b", "d".getBytes)
|
||||
println(s.GetComputeMerkle4String)
|
||||
s.RollbackTrans()
|
||||
s1.BeginTrans()
|
||||
s1.put("c_key_a", "a".getBytes)
|
||||
s1.put("c_key_b", "d".getBytes)
|
||||
println(s1.GetComputeMerkle4String)
|
||||
s1.RollbackTrans()*/
|
||||
|
||||
/*println(s.getBlockHeight())
|
||||
val blk = s.getBlockByHeight(1)
|
||||
val blkobj = Block.parseFrom(blk);
|
||||
println(blkobj.toString())
|
||||
|
||||
println(s1.getBlockHeight())
|
||||
val blk1 = s1.getBlockByHeight(1)
|
||||
val blkobj1 = Block.parseFrom(blk1);
|
||||
println(blkobj1.toString())*/
|
||||
|
||||
/* val tidVal = s.get("c_" + "267454856593c8a7f9941e723767801d67e42130aa81d5720fddac932c39134e")
|
||||
|
||||
val tid = SerializeUtils.deserialise(tidVal)
|
||||
println(tid)
|
||||
val txId = SerializeUtils.deserialise(tidVal).asInstanceOf[String]
|
||||
println(txId)*/
|
||||
})
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
getAllKeyValue()
|
||||
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ object GenesisBuilder {
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
|
||||
val cid = new ChaincodeId("REPCHAINACCOUNTMGR",1)
|
||||
val cid = new ChaincodeId("ContractCert",1)
|
||||
|
||||
var translist : Array[Transaction] = new Array[Transaction] (15)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user