import React, { Component } from 'react';
import { findDOMNode } from 'react-dom';
import { observable, computed, toJS } from 'mobx';
import { observer, inject } from 'mobx-react';
import nj from 'nornj';
import { registerTmpl } from 'nornj-react';
import { autobind } from 'core-decorators';
import { Col, Drawer, Row, Tabs } from 'antd';
import {tranBase58,formatBase64Data,transAuth} from '../../../utils/util';
import { BlockCollapse,BlockCollapseSmall,BlockCollapsePanel } from '../../components/blockCollapse';
import styles from './transactionInfo.m.scss';
import tmpls from './transactionInfo.t.html';
import moment from 'moment';
const { TabPane } = Tabs;
//页面容器组件
@registerTmpl('TransactionInfo')
@inject('store')
@observer
export default class TransactionInfo extends Component {
// 关闭
@autobind
onCloseblockDetails(){
return this.props.onClose(!this.props.visible);
}
transform = arr => {
return arr.map(item => transAuth(item)).join(',')
}
stateItem = state => {
let span = '';
switch(state) {
case 'READY':
case 'DECONSENSUS':
span = '共识未启动';
break;
case 'CONSENSUS':
span = '共识已启动';
break;
default:
span = '共识未启动';
break;
}
return span;
}
partItem = state => {
let span = '';
switch(state) {
case 'READY':
span = '注册参与方';
break;
case 'CONSENSUS':
span = '激活参与方';
break;
case 'DECONSENSUS':
span = '禁用参与方';
break;
default:
span = '注册参与方';
break;
}
return span;
}
argsToList(data){
let json=[];
if(data&&data.values&&data.values.length>0){
for (let i = 0; i < data.values.length; i++) {
json.push({
type:data.values[i].type,
value:formatBase64Data(data.values[i].type,data.values[i].bytes),
});
}
var str = JSON.stringify(json);
return str;
}
}
modelItem = (data) => {
return [
{data.request && JSON.stringify(data.request) != "{}" && (
{this.resItem(data.request)}
)}
{
data.result && JSON.stringify(data.result) != "{}" && (
{this.reqItem(data.result)}
)
}
]
}
resItem = data => {
return (
{
data.endpointSignatures && data.endpointSignatures.length != 0 && (
{
data.endpointSignatures.map((item, key) => (
签名: {item.digest && item.digest && item.digest || ''}
))
}
)
}
{
data.nodeSignatures && data.nodeSignatures.length != 0 && (
{
data.nodeSignatures.map((item, key) => (
签名: {item.digest && item.digest && item.digest || ''}
))
}
)
}
{
data.transactionContent && JSON.stringify(data.transactionContent) != "{}" && this.transItem(data.transactionContent)
}
)
}
transItem = content => {
return (
{
content.timestamp && (
交易时间: |
{content.timestamp && moment(content.timestamp).format('YYYY-MM-DD HH:mm:ss') || ''} |
)
}
{
content.operations && content.operations.length != 0 && content.operations.map((item, key) => this.operaItem(item))
}
)
}
operaItem = opt => {
let {
accountAddress,
accountID,
args,
chainCode,
contractAddress,
contractID,
event,
eventAccountID,
eventAddress,
events,
initSetting,
participantID,
participantName,
participantRegisterIdentity,
roles,
state,
stateUpdateIdentity,
userID,
userAddress,
certificate,
userRolesAuthorizations,
writeSet,
} = opt;
console.log(opt)
return [
initSetting && JSON.stringify(initSetting) != "{}" && (
共识供应方: |
{initSetting.consensusProvider && initSetting.consensusProvider || ''} |
{/*
共识配置: |
{initSetting.consensusSettings && initSetting.consensusSettings.value && initSetting.consensusSettings.value || ''} |
*/}
账户种子: |
{initSetting.ledgerSeed && initSetting.ledgerSeed || ''} |
账户结构版本: |
{initSetting.ledgerStructureVersion && initSetting.ledgerStructureVersion || ''} |
创建时间: |
{initSetting.createdTime && moment(initSetting.createdTime).format('YYYY-MM-DD HH:mm:ss') || ''} |
{
initSetting.consensusParticipants && initSetting.consensusParticipants.length != 0 && initSetting.consensusParticipants.map((item, key) => (
参与方地址: |
{item.address || ''} |
参与方公钥算法: |
{tranBase58(item.pubKey && item.pubKey && item.pubKey || '')} |
参与方公钥数据: |
{item.pubKey && item.pubKey && item.pubKey || ''} |
节点状态: |
{item.participantNodeState && item.participantNodeState || ''} |
))
}
{initSetting.cryptoSetting && JSON.stringify(initSetting.cryptoSetting) && (
自动校验: {initSetting.cryptoSetting.autoVerifyHash && '开启' || '关闭'}
{
initSetting.cryptoSetting.hashAlgorithm && (
哈希算法: {initSetting.cryptoSetting.hashAlgorithm && initSetting.cryptoSetting.hashAlgorithm || ''}
)
}
{
initSetting.cryptoSetting.supportedProviders && initSetting.cryptoSetting.supportedProviders.length != 0 && initSetting.cryptoSetting.supportedProviders.map((item, key) => (
{
item.algorithms && item.algorithms.length != 0 && item.algorithms.map((it, ke) => it && (
算法编号: |
{it.code && it.code || ''} |
) || null)
}
))
}
)}
) || null,
writeSet && writeSet.length != 0 && (
写入
账户地址:
{accountAddress || ''}
{
writeSet.map((item, key) => (
值:{formatBase64Data(item.value.type,item.value.bytes)}
预期版本:{item.expectedVersion}
类型:{item.value.type}
))
}
) || null,
contractID && JSON.stringify(contractID) != "{}" && (
合约地址: |
{contractID.address || ''} |
合约公钥算法: |
{tranBase58(contractID.pubKey && contractID.pubKey && contractID.pubKey || '')} |
合约公钥: |
{contractID.pubKey && contractID.pubKey && contractID.pubKey || ''} |
{chainCode && (
合约内容: |
{chainCode || ''} |
) || null}
) || null,
contractAddress && JSON.stringify(contractAddress) != "{}" && (
{args && (
合约参数: |
{this.argsToList(args)} |
) || null}
合约地址: |
{contractAddress || ''} |
{event && (
合约事件: |
{event} |
) || null}
) || null,
accountID && JSON.stringify(accountID) != "{}" && (
数据账户地址: |
{accountID.address || ''} |
账户公钥算法: |
{tranBase58(accountID.pubKey && accountID.pubKey && accountID.pubKey || '')} |
账户公钥: |
{accountID.pubKey && accountID.pubKey && accountID.pubKey || ''} |
) || null,
userID && JSON.stringify(userID) != "{}" && (
用户地址: |
{userID.address} |
用户公钥算法: |
{tranBase58(userID.pubKey && userID.pubKey && userID.pubKey || '')} |
用户公钥数据: |
{userID.pubKey && userID.pubKey && userID.pubKey || ''} |
用户证书数据: |
{certificate && certificate || ''} |
) || null,
userAddress && state && (
用户地址: |
{userAddress} |
用户状态: |
{state} |
) || null,
userAddress && certificate && (
用户地址: |
{userAddress} |
用户证书: |
{certificate} |
) || null,
!userAddress && !userID && certificate && (
) || null,
// state && (
//
//
// 状态:
// {this.stateItem(state)}
//
//
// ) || null,
// participantName && (
//
//
//
// 参与方名称: |
// {participantName} |
//
//
//
// ) || null,
participantRegisterIdentity && JSON.stringify(participantRegisterIdentity) != "{}" && (
{
participantName && (
参与方名称: |
{participantName} |
)
}
参与方地址: |
{participantRegisterIdentity.address || ''} |
参与方公钥算法: |
{tranBase58(participantRegisterIdentity.pubKey && participantRegisterIdentity.pubKey && participantRegisterIdentity.pubKey || '')} |
参与方公钥数据: |
{participantRegisterIdentity.pubKey && participantRegisterIdentity.pubKey && participantRegisterIdentity.pubKey || ''} |
) || null,
participantID && JSON.stringify(participantID) != "{}" && (
{
participantName && (
参与方名称: |
{participantName} |
)
}
参与方地址: |
{participantID.address || ''} |
参与方公钥算法: |
{tranBase58(participantID.pubKey && participantID.pubKey && participantID.pubKey || '')} |
参与方公钥数据: |
{participantID.pubKey && participantID.pubKey && participantID.pubKey || ''} |
{
state && (
状态: |
{this.stateItem(state)} |
)
}
) || null,
stateUpdateIdentity && JSON.stringify(stateUpdateIdentity) != "{}" && (
{
participantName && (
参与方名称: |
{participantName} |
)
}
参与方地址: |
{stateUpdateIdentity.address || ''} |
参与方公钥算法: |
{tranBase58(stateUpdateIdentity.pubKey && stateUpdateIdentity.pubKey && stateUpdateIdentity.pubKey || '')} |
参与方公钥数据: |
{stateUpdateIdentity.pubKey && stateUpdateIdentity.pubKey && stateUpdateIdentity.pubKey || ''} |
) || null,
eventAccountID && JSON.stringify(eventAccountID) != "{}" && (
事件账户地址: |
{eventAccountID.address || ''} |
事件账户公钥算法: |
{eventAccountID.pubKey && eventAccountID.pubKey && tranBase58(eventAccountID.pubKey) || ''} |
) || null,
(eventAddress || events) && (
事件地址: |
{eventAddress || ''} |
{
events.length != 0 && events.map((item, key) => (
事件序列: |
{item.sequence || 0} |
{item.content && [
类型: |
{item.content.type || ''} |
,
值: |
{/* formatBase64Data(item.value.type,item.value.bytes, item.value.value) */}
{formatBase64Data(item.content && item.content.type || '',
item.content && item.content.bytes || '')} |
] || null}
))
}
) || null,
roles && roles.length != 0 && (
{
roles.map((item, key) => (
可以执行的操作: |
{item.enableLedgerPermissions && this.transform(item.enableLedgerPermissions) || ''} |
{
item.disableLedgerPermissions && item.disableLedgerPermissions.length != 0 && (
不可执行的操作: |
{item.disableLedgerPermissions && this.transform(item.disableLedgerPermissions) || ''} |
)
}
可以执行的操作: |
{item.enableTransactionPermissions && this.transform(item.enableTransactionPermissions) || ''} |
{
item.disableTransactionPermissions && item.disableTransactionPermissions.length != 0 && (
不可执行的操作: |
{item.disableTransactionPermissions && this.transform(item.disableTransactionPermissions) || ''} |
)
}
))
}
) || null,
userRolesAuthorizations && userRolesAuthorizations.length != 0 && (
{userRolesAuthorizations.map((item, key) => (
用户地址: |
{item.userAddresses[0] || ''} |
用户授权的角色清单: |
{item.authorizedRoles && item.authorizedRoles.join(',') || 'DEFAULT'} |
剔除的角色清单: |
{item.unauthorizedRoles && item.unauthorizedRoles.join(',') || ''} |
要更新的多角色权限策略: |
{item.policy && item.policy || ''} |
))}
)
]
}
reqItem = data => {
let { dataSnapshot, executionState, blockHeight, transactionHash } = data
return (
区块高度: {blockHeight && blockHeight || 0}
{transactionHash && (
交易哈希: {transactionHash && transactionHash || ''}
) || null}
{
dataSnapshot && JSON.stringify(dataSnapshot) != "{}" && (
{
dataSnapshot.adminAccountHash && (
管理账户根哈希: |
{dataSnapshot.adminAccountHash || ''} |
) || null
}
{
dataSnapshot.userAccountSetHash && (
用户账户集根哈希: |
{dataSnapshot.userAccountSetHash || ''} |
) || null
}
{
dataSnapshot.dataAccountSetHash && (
数据账户集根哈希: |
{dataSnapshot.dataAccountSetHash || ''} |
) || null
}
{
dataSnapshot.contractAccountSetHash && (
合约账户集根哈希: |
{dataSnapshot.contractAccountSetHash || ''} |
) || null
}
{
dataSnapshot.systemEventSetHash && (
系统事件集根哈希: |
{dataSnapshot.systemEventSetHash || ''} |
) || null
}
{
dataSnapshot.userEventSetHash && (
用户事件集根哈希: |
{dataSnapshot.userEventSetHash || ''} |
) || null
}
)
}
运行结果: {executionState && executionState || ''}
)
}
render() {
const { data,visible} = this.props;
return tmpls.container({
components: {
'ant-Drawer': Drawer,
'BlockCollapse':BlockCollapse,
'BlockCollapseSmall':BlockCollapseSmall,
'BlockCollapsePanel':BlockCollapsePanel,
}
},this.props, this, {
styles,
data,
visible,
tranBase58,
transAuth,
moment: moment
});
}
}