Skip to content

Commit

Permalink
Merge pull request bcosorg#14 from ywy2090/master
Browse files Browse the repository at this point in the history
cns更新, 1. 文档整理 2. cns_manager增加被覆盖的注册信息找回的功能
  • Loading branch information
fisco-dev authored Feb 2, 2018
2 parents 7ae5648 + 1420ff7 commit ee1c098
Show file tree
Hide file tree
Showing 11 changed files with 954 additions and 311 deletions.
577 changes: 409 additions & 168 deletions doc/CNS_Contract_Name_Service_服务使用说明文档.md

Large diffs are not rendered by default.

Binary file added doc/命名服务总体框架.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 83 additions & 49 deletions systemcontractv2/ContractAbiMgr.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,129 @@ contract ContractAbiMgr {
uint256 timestamp; //timestamp
}

event AddAbi(string name,string contractname,string version,string abi,address addr,uint256 blocknumber,uint256 timestamp);
event UpdateAbi(string name,string contractname,string version,string abi,address addr,uint256 blocknumber,uint256 timestamp);

//name => AbiInfo
mapping(string=>AbiInfo) private map_abi_infos;
event AddAbi(string cns_name,string contractname,string version,string abi,address addr,uint256 blocknumber,uint256 timestamp);
event UpdateAbi(string cns_name,string contractname,string version,string abi,address addr,uint256 blocknumber,uint256 timestamp);
event AddOldAbi(string cns_name,string contractname,string version,string abi,address addr,uint256 blocknumber,uint256 timestamp);
event AbiNotExist(string cns_name,string contractname,string version);
event AbiExist(string cns_name,string contractname,string version,string abi,address addr,uint256 bn,uint256 t);

//name => AbiInfo current call cns
mapping(string=>AbiInfo) private map_cur_cns_info;
//name => all AbiInfos
mapping(string=>AbiInfo[]) private map_history_cns_info;
//
string[] private names;

//add one history abi info
function addOldAbi(string cns_name, AbiInfo abi) private {
map_history_cns_info[cns_name].push(abi);
AddOldAbi(cns_name, abi.contractname, abi.version, abi.abi, abi.addr, abi.blocknumber, abi.timestamp);
}

//获取cns_name对应的被覆盖的abi address信息的个数
function getHistoryAbiC(string cns_name) constant public returns(uint256) {
return map_history_cns_info[cns_name].length;
}

//根据cns_name 索引号获取被覆盖的abi address信息
function getHistoryAllByIndex(string cns_name, uint256 index) constant public returns(string,address,string,string,uint256,uint256) {

if(index < map_history_cns_info[cns_name].length) {
return (map_history_cns_info[cns_name][index].abi,
map_history_cns_info[cns_name][index].addr,
map_history_cns_info[cns_name][index].contractname,
map_history_cns_info[cns_name][index].version,
map_history_cns_info[cns_name][index].blocknumber,
map_history_cns_info[cns_name][index].timestamp
);
}

return ("",0x00,"","",0,0);
}

//add one abi info, when this contract abi info is already exist , it will end with failed.
function addAbi(string name,string contractname,string version,string abi,address addr) public {
//check if this contract abi info is already exist.
uint256 old_timestamp = getTimeStamp(name);
if (old_timestamp != 0) {
//this abi info already exist;
return;
function addAbi(string cns_name,string contractname,string version,string abi,address addr) public {
//check if this contract abi info is not exist.
AbiInfo memory old = map_cur_cns_info[cns_name];
if(old.timestamp != 0) {
AbiExist(cns_name, old.contractname, old.version, old.abi, old.addr, old.blocknumber, old.timestamp);
return ;
}

names.push(name);
map_abi_infos[name] = AbiInfo(contractname,version,abi,addr,block.number,block.timestamp);
AddAbi(name,contractname,version,abi,addr,block.number,block.timestamp);
names.push(cns_name);
map_cur_cns_info[cns_name] = AbiInfo(contractname,version,abi,addr,block.number,block.timestamp);
AddAbi(cns_name,contractname,version,abi,addr,block.number,block.timestamp);
}

//update one abi info, when this contract abi info is not exist , it will end with failed.
function updateAbi(string name,string contractname,string version,string abi,address addr) public {
//check if this contract abi info is not exist.
uint256 old_timestamp = getTimeStamp(name);
if (old_timestamp == 0) {
//this abi info is not exist;
return;
function updateAbi(string cns_name,string contractname,string version,string abi,address addr) public {
//check if this contract abi info is already exist.
AbiInfo memory old = map_cur_cns_info[cns_name];
if(old.timestamp == 0) {
AbiNotExist(cns_name, contractname, version);
return ;
}

map_abi_infos[name] = AbiInfo(contractname,version,abi,addr,block.number,block.timestamp);
UpdateAbi(name,contractname,version,abi,addr,block.number,block.timestamp);
addOldAbi(cns_name, old);
map_cur_cns_info[cns_name] = AbiInfo(contractname,version,abi,addr,block.number,block.timestamp);
UpdateAbi(cns_name,contractname,version,abi,addr,block.number,block.timestamp);
}

//get member address
function getAddr(string name) constant public returns(address){
return map_abi_infos[name].addr;
function getAddr(string cns_name) constant public returns(address) {
return map_cur_cns_info[cns_name].addr;
}

//get member abi
function getAbi(string name) constant public returns(string){
return map_abi_infos[name].abi;
function getAbi(string cns_name) constant public returns(string) {
return map_cur_cns_info[cns_name].abi;
}

//get member contract name
function getContractName(string name) constant public returns(string){
return map_abi_infos[name].contractname;
function getContractName(string cns_name) constant public returns(string) {
return map_cur_cns_info[cns_name].contractname;
}

//get member version
function getVersion(string name) constant public returns(string){
return map_abi_infos[name].version;
function getVersion(string cns_name) constant public returns(string) {
return map_cur_cns_info[cns_name].version;
}

//get member blocknumber
function getBlockNumber(string name) constant public returns(uint256){
return map_abi_infos[name].blocknumber;
function getBlockNumber(string cns_name) constant public returns(uint256) {
return map_cur_cns_info[cns_name].blocknumber;
}

//get member timestamp
function getTimeStamp(string name) constant public returns(uint256){
return map_abi_infos[name].timestamp;
function getTimeStamp(string cns_name) constant public returns(uint256) {
return map_cur_cns_info[cns_name].timestamp;
}

//get length of names
function getAbiCount() constant public returns(uint256){
function getAbiCount() constant public returns(uint256) {
return names.length;
}

//get all members by name
function getAll(string name) constant public returns(string,address,string,string,uint256,uint256){
return (map_abi_infos[name].abi,
map_abi_infos[name].addr,
map_abi_infos[name].contractname,
map_abi_infos[name].version,
map_abi_infos[name].blocknumber,
map_abi_infos[name].timestamp
function getAll(string cns_name) constant public returns(string,address,string,string,uint256,uint256) {
return (map_cur_cns_info[cns_name].abi,
map_cur_cns_info[cns_name].addr,
map_cur_cns_info[cns_name].contractname,
map_cur_cns_info[cns_name].version,
map_cur_cns_info[cns_name].blocknumber,
map_cur_cns_info[cns_name].timestamp
);
}

//get all members by index
function getAllByIndex(uint256 index) constant public returns(string,address,string,string,uint256,uint256){
function getAllByIndex(uint256 index) constant public returns(string,address,string,string,uint256,uint256) {
if(index < names.length){
return (map_abi_infos[names[index]].abi,
map_abi_infos[names[index]].addr,
map_abi_infos[names[index]].contractname,
map_abi_infos[names[index]].version,
map_abi_infos[names[index]].blocknumber,
map_abi_infos[names[index]].timestamp
return (map_cur_cns_info[names[index]].abi,
map_cur_cns_info[names[index]].addr,
map_cur_cns_info[names[index]].contractname,
map_cur_cns_info[names[index]].version,
map_cur_cns_info[names[index]].blocknumber,
map_cur_cns_info[names[index]].timestamp
);
}

Expand Down
45 changes: 40 additions & 5 deletions systemcontractv2/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,50 @@ function getAbi0(file){
var ContractAbiMgrReicpt= await web3sync.rawDeploy(config.account, config.privKey, "ContractAbiMgr");
var ContractAbiMgr=web3.eth.contract(getAbi("ContractAbiMgr")).at(ContractAbiMgrReicpt.contractAddress);

console.log("注册ContractAbiMgr abi address信息到管理合约....");
console.log("注册系统合约中部署的合约的信息到CNS管理合约");

var func = "addAbi(string,string,string,string,address)";
//ContractAbiMgr
var abi = getAbi0("ContractAbiMgr");
//var version = ContractAbiMgr.getVersion();
//var name = ("" == version ? "ContractAbiMgr" : "ContractAbiMgr" + "/" + version);
var params = ["ContractAbiMgr","ContractAbiMgr","",abi,ContractAbiMgrReicpt.contractAddress];
console.log("contract abi manager ,params =>" + params.toString());
var receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);


//SystemProxy
abi = getAbi0("SystemProxy");
params = ["SystemProxy","SystemProxy","",abi,SystemProxyReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//TransactionFilterChain
abi = getAbi0("TransactionFilterChain");
params = ["TransactionFilterChain","TransactionFilterChain","",abi,TransactionFilterChainReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//AuthorityFilter
abi = getAbi0("AuthorityFilter");
params = ["AuthorityFilter","AuthorityFilter","",abi,AuthorityFilterReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//Group
abi = getAbi0("Group");
params = ["Group","Group","",abi,GroupReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//CAAction
abi = getAbi0("CAAction");
params = ["CAAction","CAAction","",abi,CAActionReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//ConfigAction
abi = getAbi0("ConfigAction");
params = ["ConfigAction","ConfigAction","",abi,ConfigActionReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

//NodeAction
abi = getAbi0("NodeAction");
params = ["NodeAction","NodeAction","",abi,NodeActionReicpt.contractAddress];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, ContractAbiMgrReicpt.contractAddress, func, params);

console.log("注册权限AuthorityFilter到TransactionFilterChain.....");
func = "addFilter(address)";
params = [AuthorityFilter.address];
Expand Down Expand Up @@ -111,7 +146,7 @@ function getAbi0(file){
console.log("注册CAAction.....");
func = "setRoute(string,address,bool)";
params = ["CAAction", CAAction.address, false];
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, SystemProxy.address, func, params);
receipt = await web3sync.sendRawTransaction(config.account, config.privKey, SystemProxy.address, func, params);

console.log("注册ContractAbiMgr.....");
func = "setRoute(string,address,bool)";
Expand Down
2 changes: 1 addition & 1 deletion systemcontractv2/output/ContractAbiMgr.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getAll","outputs":[{"name":"","type":"string"},{"name":"","type":"address"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getContractName","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"index","type":"uint256"}],"name":"getAllByIndex","outputs":[{"name":"","type":"string"},{"name":"","type":"address"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getVersion","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"contractname","type":"string"},{"name":"version","type":"string"},{"name":"abi","type":"string"},{"name":"addr","type":"address"}],"name":"addAbi","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getAbi","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getAddr","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"contractname","type":"string"},{"name":"version","type":"string"},{"name":"abi","type":"string"},{"name":"addr","type":"address"}],"name":"updateAbi","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getTimeStamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getAbiCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"blocknumber","type":"uint256"},{"indexed":false,"name":"timestamp","type":"uint256"}],"name":"AddAbi","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"blocknumber","type":"uint256"},{"indexed":false,"name":"timestamp","type":"uint256"}],"name":"UpdateAbi","type":"event"}]
[{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getAll","outputs":[{"name":"","type":"string"},{"name":"","type":"address"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"index","type":"uint256"}],"name":"getAllByIndex","outputs":[{"name":"","type":"string"},{"name":"","type":"address"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getVersion","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getHistoryAbiC","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"cns_name","type":"string"},{"name":"contractname","type":"string"},{"name":"version","type":"string"},{"name":"abi","type":"string"},{"name":"addr","type":"address"}],"name":"addAbi","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getAbi","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getAddr","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"cns_name","type":"string"},{"name":"contractname","type":"string"},{"name":"version","type":"string"},{"name":"abi","type":"string"},{"name":"addr","type":"address"}],"name":"updateAbi","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"}],"name":"getTimeStamp","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAbiCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"cns_name","type":"string"},{"name":"index","type":"uint256"}],"name":"getHistoryAllByIndex","outputs":[{"name":"","type":"string"},{"name":"","type":"address"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"cns_name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"blocknumber","type":"uint256"},{"indexed":false,"name":"timestamp","type":"uint256"}],"name":"AddAbi","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"cns_name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"blocknumber","type":"uint256"},{"indexed":false,"name":"timestamp","type":"uint256"}],"name":"UpdateAbi","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"cns_name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"blocknumber","type":"uint256"},{"indexed":false,"name":"timestamp","type":"uint256"}],"name":"AddOldAbi","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"cns_name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"}],"name":"AbiNotExist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"cns_name","type":"string"},{"indexed":false,"name":"contractname","type":"string"},{"indexed":false,"name":"version","type":"string"},{"indexed":false,"name":"abi","type":"string"},{"indexed":false,"name":"addr","type":"address"},{"indexed":false,"name":"bn","type":"uint256"},{"indexed":false,"name":"t","type":"uint256"}],"name":"AbiExist","type":"event"}]
2 changes: 1 addition & 1 deletion systemcontractv2/output/ContractAbiMgr.bin

Large diffs are not rendered by default.

Loading

0 comments on commit ee1c098

Please sign in to comment.