Juice联盟链搭建流程

Juice联盟链搭建流程备忘录

给Juice联盟链搭建流程做个备忘录,自己使用脚本自动化部署链要用到。

主链搭建流程

创建前链验证

主要是验证链的状态信息,比如已经搭建的好的不允许再搭建。

  • URL:/nodeMainValidate.do
  • Request Data: {}
  • Response:{“ret”:0,”message”:”成功”}

提交链基本信息

  • URL:/commitChainInfo.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    {
    "blockchainName":"juice",
    "description":"",
    "orgaName":"juzix",
    "orgaShortName":"juzix1543371510879",
    "countryName":"中国",
    "province":"吉林省",
    "commonName":"juzix1543371510879"
    }
    • description: 字段后台没用到。
  • Response:{“ret”:0,”message”:”提交链信息成功”}

提交链的管理员信息

  • URL:/commitAdminInfo.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    {
    "loginName":"admin",
    "realName":"admin",
    "email":"asdfad@qq.com",
    "mobile":"13111111111",
    "pubkey":"7603b42d5c55c0385667519e499e0d15df55a6fb1d33d952e96dfb29ebd0534299f3c82b04e6edc1eac595a18b74fabc66a1acf6c57cd70e2d5903974597dbcd",
    "userAddr":"0xf683275de265aa9e1638333812bf434f16fdcd71",
    "certType":1,
    "passWord":"12345678",
    "uuid":"admin"
    }
  • Response:{“ret”:0,”message”:”提交链管理员信息成功”}

提交节点信息

  • URL:/commitNodeinfo.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    {
    "createType":"1",
    "nodeName":"admin节点",
    "nodeDescription":"",
    "nodeType":"Y",
    "accountType":"1",
    "enodeList":[
    {
    "ip":"10.10.8.168",
    "RPCPort":6789,
    "TPort":8080,
    "P2PPort":16789,
    "type":0
    },
    {
    "ip":"10.10.8.168",
    "RPCPort":6789,
    "TPort":8080,
    "P2PPort":16789,
    "type":1
    },
    {
    "ip":"10.10.8.168",
    "type":2
    },
    {
    "ip":"255.255.255.0",
    "type":3
    }
    ],
    "applyDepartment":{
    "id":"admin",
    "orgaName":"juzix",
    "departmentLevel":1,
    "commonName":"juzix1543371510879",
    "province":"吉林省",
    "countryName":"中国"
    },
    "userID":""
    }
    • nodeDescription:字段后台没用到。
  • Response:{“ret”:0,”message”:”ok”}
  • 后台流程:
    • 生成节点证书:./jutools ca create
    • 签发节点私钥:./jutools ca signcert --cn ${commonName}
    • 创建群系统公私钥:./jutools group createkeys
    • 生成钱包文件:./jutools wallet create --passwd ${password}
    • 生成network.rlp文件:./jutools wallet export --jsonfile ${add} --passwd ${password}
    • 将群系统公钥,群系统私钥写入console配置文件。
    • 后台生成链的nodeId。
    • 创建群用户私钥:./jutools group userprivkey --privatekey ${add} --userpubkey ${userpubkey}
    • 生成创世区块:./jutools genesis create --address ${address} --parameters ${initdata} --balance 100000000000000000000
    • 更新juchain.json配置文件。如:p2p-port,json-port,network。
    • 上传或者下载文件。如果是主节点,那么上传根证书,创世区块配置文件,导出数据./jutools db export --dbpath ${dbpath} --outjsonfile ${outjsonfile} --chainowner ${chainowneradddress},以及文件judatadb.json。如果是非主节点,下载主节点上传的数据导入数据./jutools db import --jsonfile ${jsonfile} --outdbpath ${outdbpath}
    • 启动jueth:./jueth --config ${juzhenjsonAdd} --genesis ${genesisadd} --pswfile ${pswfile}
    • 更新链状态,置为启动状态。

获取系统合约信息

此处在客户端调用内置合约ExtendedCall的方法initChain(string _chainId, string _chainName)初始化链。调用方法isChainOwner(address _addr)判断是不是自己,然后再请求后台获取系统合约信息。

  • URL:/deployContract.do
  • Request Data: {}
  • Response:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    {
    "ret":0,
    "data":[
    {
    "id":0,
    "contractName":"MonitorTest",
    "bin":"0x....",
    "address": "",
    "abi":"....",
    "isTrue":0
    },
    {
    "id":1,
    "contractName":"ExCall",
    "bin":"0x....",
    "address": "",
    "abi":"....",
    "isTrue":2
    }
    ],
    "message":"合约获取成功"
    }

合约部署

此处由客户端完成。经过上面步骤,客户端获取合约信息之后,使用发交易的方式将合约部署上链。

初始化合约信息

此处在客户端将合约确认发布成功之后,调用此接口从后台获取信息。客户端调用DepartmentManager,UserManager,NodeInfoManager的三个合约的insert函数,将返回的信息发送上链。

  • URL:/initContranct.do
  • Request Data: {}
  • Response:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    {
    "ret":0,
    "data":[
    {
    "departmentManager":[
    {
    "commonName":"china",
    "serialNum":"0",
    "groupPubKey":"87d600a8778ffc063f44781f3caa056d5c9da443aaa5d35883446e27c48105e447ce9bbe34a4b8b88d38e24dfb9d0db7e2a6b0aa93d6f8166629272a9bcd4d43a0d646639e5f6a69137642daec021d314d101b6890109a24bd81e7940f3d9bbab60beea63ad4c59b24174ea5764400f10a7afd468b4906b52736a85acc7bc4c4b1813c159a1fc945faadf6a546a3b0df6091b9727625037ceb91912bc57bd7478ae4dce6ea313d47ea3ac89771f4ce7045de47eb9ae6876ad5529f00e0e240f608edf52a5372cd8ff08d28f20005ae99187a188603dee6dac4b4e49b111f8bea38b5abc25c6708d02e6b9e4f61738775c226242d2ee7152fc174c9ca85095114",
    "icon":"",
    "description":"",
    "admin":"0",
    "creTime":"0",
    "type":"1",
    "parentId":"",
    "stateName":"吉林省",
    "updTime":"0",
    "name":"juzix",
    "id":"admin",
    "countryName":"中国",
    "orgaShortName":"juzix1543384413118",
    "departmentLevel":"0",
    "email":"sdfsad@qq.com",
    "status":"1"
    },
    {
    "commonName":"juzix1543384413118",
    "icon":"",
    "description":"",
    "admin":"0xb0703c9cec3cefd020cbfbff96834a6836e71131",
    "creTime":"0",
    "type":"1",
    "parentId":"admin",
    "stateName":"吉林省",
    "updTime":"0",
    "name":"juzix",
    "id":"default",
    "countryName":"中国",
    "departmentLevel":"1",
    "email":"sdfsad@qq.com",
    "status":"1"
    }
    ],
    "contractName":"DepartmentManager"
    },
    {
    "userManager":{
    "ownerAddr":"0xb0703c9cec3cefd020cbfbff96834a6836e71131",
    "certType":"0",
    "passwordStatus":"0",
    "roleIdList":"["role100000","role100001","role100002","role100003"]",
    "departmentId":"admin",
    "mobile":"13111111111",
    "icon":"",
    "userAddr":"0xb0703c9cec3cefd020cbfbff96834a6836e71131",
    "updateTime":"0",
    "remark":"",
    "publicKey":"1f504c952849f50d2d551c0b0810b204cbd1fdfda92e439642af3ff19154320ab7ba1a787c5a4327013593d1577f732863b03b026c24ae5a78393e51bcc741ba",
    "uuid":"admin",
    "accountStatus":"2",
    "loginTime":"0",
    "cipherGroupKey":"040faa9f1c75b3fd7d39a55086c506827a0c574063a74370824a9beffe21e31ef7dd54f6499c8b65a3ff58d4e0d5c00b71a6b1a5f4d8bc70b366e6597b1a9a22580153492f883b76778f18b0d78934d6b6369781cae93df3368a79f09c036c83daf6ddcbe55da83952b58e0bee438902a647d398ceb12afffd00bac406053498630ca14b4a0fc130dc01af25db930aeaa78fd892fb79b7363a448a40a9794d1817b2a36fd1199d744fad16829462a15a9fafbc7c564b28dbe4a783e1fcfda9dbdab47400385ee9a43db6f96c7b8e33b6b3d3d9e0d4",
    "createTime":"0",
    "deleteStatus":"0",
    "name":"admin",
    "state":"1",
    "account":"admin",
    "email":"sdfsad@qq.com",
    "status":"1"
    },
    "contractName":"UserManager"
    },
    {
    "nodeInfoManager":{
    "nodeName":"admin节点",
    "deptLevel":"1",
    "deptId":"default",
    "updateTime":"0",
    "nodeDescription":"",
    "type":"1",
    "nodeLAN":{
    "endIP":"0",
    "startInt":"0",
    "startIP":"0",
    "endInt":"0",
    "goByInt":"-1062711126",
    "goByIP":"10.10.8.168",
    "mastInt":"-256",
    "maskIP":"255.255.255.0"
    },
    "nodeShortName":"admin节点",
    "createTime":"0",
    "nodeAdmin":"",
    "deptCN":"juzix1543384413118",
    "nodeNAT":{
    "p2pPort":"16789",
    "ip":"10.10.8.168",
    "rpcPort":"6789",
    "nodeAddress":"0x00b20b6b6fe489a749baedb7aa389bf6806341d7",
    "tPort":"8080",
    "pubkey":"5da1a7b5282917d443ae93939fa8ae0aa7a503846a958c7ed8b7f4fe436ef62a77265b0c3e782c7057a778842cb0684e04648d90a8162e60a045978a60d7c91a",
    "activated":"1"
    },
    "disabled":0,
    "state":"1",
    "nodeId":"00093b2e308a4bae8df3eaba31f5d18f"
    },
    "contractName":"NodeInfoManager"
    }
    ],
    "message":"初始化成功"
    }

后台刷新合约

此处主要给后台调用。

  • URL:/reloadContract.do
  • Request Data: {}
  • Response:{“ret”:0,”message”:”web3j重载合约成功”}

登陆流程

客户端验证私钥的密码是否正确之后,调用合约 UserManager 的接口 findByUuid 查询是否存在。如果两者条件都满足,则认为登陆成功。

角色合约过滤器

登陆进去之后,调用合约 RoleFilterManager 的接口 listAll() 可查询用户的注册的模块信息。

加入链流程

选择组织

通过合约 DepartmentManager 的接口 pageByNameAndStatus(string _parentId,uint _status, string _name, uint _pageNum, uint _pageSize) 接口,获取可用的组织列表。

注册用户

调用合约 RegisterApplyManager 的接口 insert(string _json) 注册用户。

用户审核

此处用主链账号登陆之后进行审核。通过调用合约 RoleManager,RoleFilterManager,DepartmentManager 的 listAll() 接口查询相关信息,显示菜单。通过 DepartmentManager 的接口 pageByNameAndStatus(string _parentId,uint _status, string _name, uint _pageNum, uint _pageSize) 接口,获取可用的组织列表组织菜单。通过 UserManager 接口 findByDepartmentIdTreeAndContion(string _json) 获取用户信息。 再通过 UserManager 合约接口 update(string _userJson) 更新用户注册的信息。更新完成之后可调用 findByDepartmentIdTreeAndContion(string _json) 再做确认是否更新成功。

提交新注册信息给后台

  • URL:/commitAdminInfo.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    {
    "loginName":"node1",
    "realName":"node1",
    "email":"adsfsd@qq.com",
    "mobile":"13211111111",
    "pubkey":"9f88b2d386321f17f4b6b1166bae837e72e58f732f0e87dfc3dd693ae085ba9b725f49f8f1c64661e5591e29e76df0d5cce034f09d8d8a53f92d98985c0ee8f5",
    "userAddr":"0x609677e01c1f90d0f90e31386a09fc26d91758d0",
    "certType":"1",
    "passWord":"12345678",
    "uuid":"node1",
    "userID":""
    }
  • Response:{“ret”:0,”message”:”提交链管理员信息成功”}

提交节点信息启动加入链

  • URL:/commitNodeinfo.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    {
    "createType":"2",
    "nodeName":"node1",
    "nodeDescription":"",
    "nodeType":"N",
    "accountType":"1",
    "enodeList":[
    {
    "ip":"10.10.8.169",
    "RPCPort":6789,
    "TPort":8080,
    "P2PPort":16789,
    "type":0
    },
    {
    "ip":"10.10.8.169",
    "RPCPort":6789,
    "TPort":8080,
    "P2PPort":16789,
    "type":1
    },
    {
    "ip":"10.10.8.169",
    "type":2
    },
    {
    "ip":"255.255.255.0",
    "type":3
    }
    ],
    "applyDepartment":{
    "id":"default",
    "orgaName":"juzix",
    "departmentLevel":"1",
    "commonName":"juzix1543384413118",
    "province":"吉林省",
    "countryName":"中国"
    },
    "userID":""
    }
  • Response:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    {
    "ret":0,
    "data":{
    "applyUser":{
    "passwordStatus":0,
    "departmentId":"default",
    "sex":0,
    "mobile":"13211111111",
    "userAddr":"0x609677e01c1f90d0f90e31386a09fc26d91758d0",
    "publicKey":"1dce282240f373463e7dc45b8cb2bc24adcc8cc9e335ee68978acfd21a46c2726fdbb4941fa50ae51a4a43cb49f5aeed3a10f60b94f2e375642465010c54a931",
    "accountStatus":1,
    "cipherGroupKey":" ",
    "deleteStatus":0,
    "name":"node1",
    "id":"6315c84901cd460ab6e4267073f6805c",
    "account":"node1",
    "email":"adsfsd@qq.com"
    },
    "createTime":1543395564113,
    "applyDepartment":{
    "commonName":"juzix1543384413118",
    "serialNum":0,
    "departmentId":"default",
    "deptId":"default",
    "description":"",
    "type":1,
    "parentId":"admin",
    "orgaName":"juzix",
    "province":"吉林省",
    "stateName":"吉林省",
    "name":"juzix",
    "countryName":"中国",
    "id":"default",
    "orgaShortName":"juzix",
    "departmentLevel":1,
    "email":""
    },
    "applyNodeIPList":[
    {
    "TPort":8080,
    "uintIP":168429737,
    "ip":"10.10.8.169",
    "type":0,
    "P2PPort":16789,
    "RPCPort":6789
    },
    {
    "TPort":8080,
    "uintIP":0,
    "ip":"10.10.8.169",
    "type":1,
    "P2PPort":16789,
    "RPCPort":6789
    },
    {
    "TPort":0,
    "uintIP":168429737,
    "ip":"10.10.8.169",
    "type":2,
    "P2PPort":0,
    "RPCPort":0
    },
    {
    "TPort":0,
    "uintIP":-256,
    "ip":"255.255.255.0",
    "type":3,
    "P2PPort":0,
    "RPCPort":0
    }
    ],
    "applyNodeInfo":{
    "nodeName":"node1",
    "deptLevel":1,
    "ip":"10.10.8.169",
    "deptId":"default",
    "nodeDescription":"",
    "nodeType":"N",
    "type":1,
    "nodeAddress":"0x002566a7a94203639b08ddb4e12fc1680942564c",
    "nodeShortName":"",
    "port":16789,
    "deptCN":"juzix1543384413118",
    "nodeAdmin":"0x609677e01c1f90d0f90e31386a09fc26d91758d0",
    "state":1,
    "nodeId":"695d7557f93b480dba43d1e3b2dfef67",
    "activated":0,
    "pubkey":"1dce282240f373463e7dc45b8cb2bc24adcc8cc9e335ee68978acfd21a46c2726fdbb4941fa50ae51a4a43cb49f5aeed3a10f60b94f2e375642465010c54a931"
    },
    "id":"916e49a2713141d8a83e47400aabcccc",
    "state":0,
    "applyTime":1543395564113
    }
    }
  • 后台流程:

    • 更新 initInfo.properties 文件。
    • 生成钱包文件:./jutools wallet create --passwd ${password}
    • 生成network.rlp文件:./jutools wallet export --jsonfile ${add} --passwd ${password}

节点信息上链

此处用新注册用户进行登陆之后进行操作。设计调用的有 DepartmentManager 合约接口 findById(string _id),UserManager 合约的接口 findByUuid(string _uuid)。收集完数据之后,调用合约 NodeApplyManager 的接口 insert(string _json)将申请的节点信息上链。节点信息就是上面调用 commitNodeinfo.do 返回的信息。

节点互连

  • URL:/connectnode.do
  • Request Data:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    {
    "mainEnodeList":[
    {
    "ip":"10.10.8.168",
    "TPort":"8080",
    "type":1
    }
    ]
    }
  • Response:{“ret”:0,”message”:”成功”}

加入链的启动

经过上述步骤,已经将加入链的信息写入了合约,同时,也将链启动的信息写到了initInfo.properties配置文件里面。console在启动的时候,会启动一项轮询任务,实现在NodeApplyJob.java的doJob()里面。当满足创建加入链的时候,会将链启动起来。

加入链状态

  • URL:/nodeValidate.do
  • Request Data: { }
  • Response:{“ret”:0,”message”:”欢迎使用,请填写加入链信息!!”}
您的支持将鼓励我继续创作!
0%