Skip to content

Commit

Permalink
Add block_index in tbl_tx_detail_index
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Feb 4, 2024
1 parent fc50044 commit e0f6aab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table `tbl_address_daily_summary` add index contract_address_index(`contract_hash`, `address`);

ALTER TABLE tbl_tx_detail_index ADD COLUMN `block_index` int(11) NOT NULL COMMENT '交易在区块里的索引' AFTER `tx_hash`;
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<if test="assetName != '' and assetName != null">
AND asset_name = #{assetName}
</if>
ORDER BY desc_block_height, tx_hash, tx_index
ORDER BY desc_block_height, block_index
LIMIT #{startIndex}, #{pageSize}
) idx ON idx.hash = d.tx_hash
LEFT JOIN tbl_contract c ON d.contract_hash = c.contract_hash
Expand All @@ -166,7 +166,7 @@
AND d.asset_name = #{assetName}
</if>
AND d.event_type IN (2, 3)
ORDER BY block_height DESC, block_index, tx_hash, tx_index
ORDER BY block_height DESC, block_index, tx_index
</select>

<select id="selectTransferTxsByTime" resultType="com.github.ontio.model.dto.TransferTxDto">
Expand All @@ -183,9 +183,9 @@
<if test="assetName != '' and assetName != null">
AND asset_name = #{assetName}
</if>
ORDER BY desc_block_height, tx_hash, tx_index
ORDER BY desc_block_height, block_index
) idx ON idx.hash = d.tx_hash AND idx.`index` = d.tx_index
ORDER BY block_height DESC, block_index
ORDER BY block_height DESC, block_index, tx_index
</select>


Expand Down Expand Up @@ -451,13 +451,13 @@
ON o.contract_hash = idx.called_contract_hash
WHERE idx.address = #{address}
AND o.audit_flag = 1
ORDER BY idx.desc_block_height, idx.tx_hash, idx.tx_index
ORDER BY idx.desc_block_height, idx.block_index
LIMIT #{startIndex}, #{pageSize}
) idx ON idx.hash = d.tx_hash
WHERE d.from_address = #{address}
OR d.to_address = #{address}
AND d.event_type IN (2, 3)
ORDER BY block_height DESC, block_index, tx_hash, tx_index
ORDER BY block_height DESC, block_index, tx_index
</select>

<select id="selectCalledContractHashesOfTokenType" resultType="java.lang.String">
Expand Down Expand Up @@ -599,12 +599,12 @@
</foreach>
)
</if>
ORDER BY idx.desc_block_height, idx.tx_hash, idx.tx_index
ORDER BY idx.desc_block_height, idx.block_index
LIMIT #{startIndex}, #{pageSize}
) idx ON idx.hash = d.tx_hash
WHERE (d.from_address = #{address}
OR d.to_address = #{address})
ORDER BY block_height DESC, block_index, tx_hash, tx_index
ORDER BY block_height DESC, block_index, tx_index
</select>

<select id="selectPayerByHash" resultType="String">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ private void handleUnauditedOrcTransferTx(String evmStates, int txType, String t
String contractHash = (String) result.get("contractHash");
String assetName = (String) result.get("assetName");
if (assetName == null) {
throw new RuntimeException("cannot get assetName,not orc20");
assetName = "ORC-20 TOKEN";
}
TxDetail txDetail = generateTransaction(fromAddress, toAddress, assetName, amount, txType, txHash, blockHeight, blockTime, indexInBlock, confirmFlag, txAction, gasConsumed, indexInTx, eventType, contractHash, payer, calledContractHash);
ConstantParam.BATCHBLOCKDTO.getTxDetails().add(txDetail);
Expand All @@ -1566,7 +1566,7 @@ private void handleUnauditedOrcTransferTx(String evmStates, int txType, String t
String contractHash = (String) result.get("contractHash");
String assetName = (String) result.get("assetName");
if (assetName == null) {
throw new RuntimeException("cannot get assetName,not orc721");
assetName = "ORC-721 NFT";
}
TxDetail txDetail = generateTransaction(fromAddress, toAddress, assetName, BigDecimal.ONE, txType, txHash, blockHeight, blockTime, indexInBlock, confirmFlag, txAction, gasConsumed, indexInTx, eventType, contractHash, payer, calledContractHash);
ConstantParam.BATCHBLOCKDTO.getTxDetails().add(txDetail);
Expand All @@ -1584,7 +1584,7 @@ private void handleUnauditedOrcTransferTx(String evmStates, int txType, String t
String contractHash = (String) result.get("contractHash");
String assetName = (String) result.get("assetName");
if (assetName == null) {
throw new RuntimeException("cannot get assetName,not orc1155");
assetName = "ORC-1155 NFT";
}
if (tokenIds instanceof String) {
String tokenId = (String) tokenIds;
Expand All @@ -1609,15 +1609,17 @@ private void handleUnauditedOrcTransferTx(String evmStates, int txType, String t
}
} else {
// other
String contractHash = ConstantParam.EVM_ADDRESS_PREFIX + Helper.reverse(contractAddress);
TxDetail txDetail = generateTransaction(ConstantParam.EMPTY, ConstantParam.EMPTY, ConstantParam.EMPTY, ConstantParam.ZERO, txType, txHash, blockHeight,
blockTime, indexInBlock, confirmFlag, ConstantParam.EMPTY, gasConsumed, indexInTx, EventTypeEnum.Others.type(), contractAddress, payer, calledContractHash);
blockTime, indexInBlock, confirmFlag, ConstantParam.EMPTY, gasConsumed, indexInTx, EventTypeEnum.Others.type(), contractHash, payer, calledContractHash);
ConstantParam.BATCHBLOCKDTO.getTxDetails().add(txDetail);
ConstantParam.BATCHBLOCKDTO.getTxDetailDailys().add(TxDetail.toTxDetailDaily(txDetail));
}
} catch (Exception e) {
log.error("handleUnAuditedOrcTransferTx error", e);
String contractHash = ConstantParam.EVM_ADDRESS_PREFIX + Helper.reverse(contractAddress);
TxDetail txDetail = generateTransaction(ConstantParam.EMPTY, ConstantParam.EMPTY, ConstantParam.EMPTY, ConstantParam.ZERO, txType, txHash, blockHeight,
blockTime, indexInBlock, confirmFlag, ConstantParam.EMPTY, gasConsumed, indexInTx, EventTypeEnum.Others.type(), contractAddress, payer, calledContractHash);
blockTime, indexInBlock, confirmFlag, ConstantParam.EMPTY, gasConsumed, indexInTx, EventTypeEnum.Others.type(), contractHash, payer, calledContractHash);
ConstantParam.BATCHBLOCKDTO.getTxDetails().add(txDetail);
ConstantParam.BATCHBLOCKDTO.getTxDetailDailys().add(TxDetail.toTxDetailDaily(txDetail));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<insert id="buildTxDetailIndexForFromAddress">
INSERT INTO tbl_tx_detail_index
(address, desc_block_height, tx_hash, tx_index, called_contract_hash, tx_time, asset_name, tx_direction)
SELECT from_address, (~0 >> 33) - block_height, tx_hash, tx_index, called_contract_hash, tx_time, asset_name, 0
(address, desc_block_height, tx_hash, block_index, tx_index, called_contract_hash, tx_time, asset_name, tx_direction)
SELECT from_address, (~0 >> 33) - block_height, tx_hash, block_index, tx_index, called_contract_hash, tx_time, asset_name, 0
FROM tbl_tx_detail
WHERE block_height BETWEEN #{beginHeight} AND #{endHeight} AND from_address &lt;&gt; '' AND event_type IN (2, 3)
<if test="contractHash != null and contractHash != ''">
Expand All @@ -17,8 +17,8 @@

<insert id="buildTxDetailIndexForToAddress">
INSERT INTO tbl_tx_detail_index
(address, desc_block_height, tx_hash, tx_index, called_contract_hash, tx_time, asset_name, tx_direction)
SELECT to_address, (~0 >> 33) - block_height, tx_hash, tx_index, called_contract_hash, tx_time, asset_name, 1
(address, desc_block_height, tx_hash, block_index, tx_index, called_contract_hash, tx_time, asset_name, tx_direction)
SELECT to_address, (~0 >> 33) - block_height, tx_hash, block_index, tx_index, called_contract_hash, tx_time, asset_name, 1
FROM tbl_tx_detail
WHERE block_height BETWEEN #{beginHeight} AND #{endHeight} AND to_address &lt;&gt; '' AND event_type IN (2, 3)
<if test="contractHash != null and contractHash != ''">
Expand Down

0 comments on commit e0f6aab

Please sign in to comment.