├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tdp │ │ └── blockexplorer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── com │ │ │ └── tdp │ │ │ └── blockexplorer │ │ │ ├── App.java │ │ │ ├── Conf.java │ │ │ ├── adapter │ │ │ └── TransactionAdapter.java │ │ │ ├── base │ │ │ └── BaseActivity.java │ │ │ ├── been │ │ │ ├── BaseBlock.java │ │ │ ├── IBlock.java │ │ │ ├── TdpBlock.java │ │ │ ├── Transaction.java │ │ │ └── TransactionList.java │ │ │ ├── blockchain │ │ │ ├── BlockCallback.java │ │ │ ├── BlockError.java │ │ │ ├── BlockExplorer.java │ │ │ ├── BlockType.java │ │ │ └── Tdp.java │ │ │ ├── btc │ │ │ ├── Btc.java │ │ │ ├── BtcBlockExplorer.java │ │ │ ├── BtcConf.java │ │ │ └── been │ │ │ │ ├── BchTransaction.java │ │ │ │ ├── BchTransactionList.java │ │ │ │ ├── BtcBlock.java │ │ │ │ ├── BtcTransaction.java │ │ │ │ └── BtcTransactionList.java │ │ │ ├── eth │ │ │ ├── Eth.java │ │ │ ├── EthBlockExplorer.java │ │ │ ├── EthConf.java │ │ │ ├── EthParams.java │ │ │ └── been │ │ │ │ ├── EthBlock.java │ │ │ │ ├── EthTransaction.java │ │ │ │ ├── EthTransactionInfo.java │ │ │ │ └── EthTransactionInfoList.java │ │ │ ├── ltc │ │ │ ├── Ltc.java │ │ │ ├── LtcBlockExplorer.java │ │ │ └── LtcConf.java │ │ │ ├── tool │ │ │ ├── AppLoading.java │ │ │ └── BlockTool.java │ │ │ ├── ui │ │ │ ├── ExplorerActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── TransactionDetailActivity.java │ │ │ └── TransactionListActivity.java │ │ │ └── view │ │ │ └── LoadMoreRecycleView.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── app_loading_bg.9.png │ │ ├── ic_down_arrow.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_right_arrow.xml │ │ ├── shape_explorer_edit_bg.xml │ │ ├── shape_list_item_bg.xml │ │ ├── shape_tag.xml │ │ ├── shape_tx_bg.xml │ │ └── shape_tx_coinbase_bg.xml │ │ ├── layout │ │ ├── activity_explorer.xml │ │ ├── activity_main.xml │ │ ├── activity_transaction_detail.xml │ │ ├── activity_transaction_list.xml │ │ ├── dialog_loading.xml │ │ ├── layout_block_popup_item.xml │ │ ├── layout_bottom_listitem.xml │ │ ├── layout_load_more.xml │ │ ├── layout_load_none.xml │ │ ├── layout_search.xml │ │ ├── layout_transaction_list_header.xml │ │ ├── layout_transaction_list_item.xml │ │ ├── tx_coinbase.xml │ │ └── tx_item.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_right.png │ │ ├── ic_home_bg.png │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_right.png │ │ ├── ic_home_bg.png │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tdp │ └── blockexplorer │ └── ExampleUnitTest.java ├── build.gradle ├── gradlew ├── gradlew.bat ├── images ├── app-debug.apk └── blockexplorer.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlockExplorer 2 | A BlockChain Explorer(一款区块链简易浏览器-已经实现了ETH,BTC,BCH等区块链) 3 | 4 | **效果** 5 | 6 | ![](https://github.com/wulijie/BlockExplorer/blob/master/images/blockexplorer.gif) 7 | 8 | **[Demo下载地址](https://github.com/wulijie/BlockExplorer/blob/master/images/app-debug.apk)** 9 | 10 | ![](https://ws4.sinaimg.cn/large/006tKfTcly1frtfdexgyhj307o07rwed.jpg) 11 | 12 | **相关技术参考** 13 | 14 | - [Android使用Infura、web3j接入以太坊区块链](https://github.com/wulijie/AndroidNotes/blob/master/BlockChain/%E4%BD%BF%E7%94%A8Infura%E3%80%81Web3j%E6%8E%A5%E5%85%A5%E4%BB%A5%E5%A4%AA%E5%9D%8A%E5%8C%BA%E5%9D%97%E9%93%BE.md) 15 | - [Android使用Insight开发比特币区块链浏览器](https://github.com/wulijie/AndroidNotes/blob/master/BlockChain/Android%E4%BD%BF%E7%94%A8Insight%E5%BC%80%E5%8F%91%E6%AF%94%E7%89%B9%E5%B8%81%E5%8C%BA%E5%9D%97%E9%93%BE%E6%B5%8F%E8%A7%88%E5%99%A8.md) 16 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | defaultConfig { 6 | applicationId "com.tdp.blockexplorer" 7 | minSdkVersion 19 8 | targetSdkVersion 25 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:25+' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:0.5' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' 28 | implementation 'com.android.support:recyclerview-v7:25+' 29 | implementation 'org.xutils:xutils:3.5.0' 30 | implementation 'com.google.code.gson:gson:2.8.2' 31 | // //集成bitcoin库 解决Base58的问题 无奈之举 总不能复制源码进来吧 32 | // implementation 'org.bitcoinj:bitcoinj-core:0.14.4' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tdp/blockexplorer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.tdp.blockexplorer", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 27 | 28 | 33 | 34 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kumaleap/BlockExplorer/47b08bd0803eb01d74c9cc4cdb1b403dac66587b/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/App.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer; 2 | 3 | import android.app.Application; 4 | 5 | import org.xutils.x; 6 | 7 | /** 8 | * Created by wulijie on 2018/4/11. 9 | */ 10 | public class App extends Application { 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | x.Ext.init(this); 15 | x.Ext.setDebug(Conf.isDebug); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/Conf.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | */ 6 | 7 | public interface Conf { 8 | boolean isDebug = true; 9 | 10 | // 11 | String test_block_hash = "0x4d14ba3c9007f7e48993d4d2a52262acf71fd125d55d82d4c660b2a512e20f7f"; 12 | 13 | //比特币的交易地址 14 | String test_btc_address = "1EruNcryxv71TTMvBJC2w7kYm8NPZ8Sapv"; 15 | 16 | //莱特币的交易hash 17 | String test_ltc_transaction = "de35e5fc72844991804314c6f0e0e46ff8dbe2edd090d3209250875afe664ca1"; 18 | //比特币的交易hash 19 | String test_btc_tx = "0a37339bfe54474095e96b83ded45aa1f745beee4faf55039f25087858d5c2cf"; 20 | //BCH交易hash 21 | String test_bch_tx = "f069b92f317b15293b4c73108361b6bf1d07b5a46c28dbdb2cc7ac113c8e5698"; 22 | //ETH交易hash 23 | String test_eth_tx = "0x2cb58f20647c1944251b5213c193680537ec1821c572c34f26f93e10357f3ddf"; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/adapter/TransactionAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Color; 6 | import android.text.Spanned; 7 | import android.text.TextUtils; 8 | import android.view.View; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.LayoutInflater; 11 | import android.view.ViewGroup; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.RelativeLayout; 15 | import android.widget.TextView; 16 | 17 | import com.tdp.blockexplorer.R; 18 | import com.tdp.blockexplorer.been.Transaction; 19 | import com.tdp.blockexplorer.blockchain.BlockType; 20 | import com.tdp.blockexplorer.tool.BlockTool; 21 | 22 | import java.math.BigInteger; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * Created by LPC43 on 2018/4/12. 28 | */ 29 | 30 | public class TransactionAdapter extends RecyclerView.Adapter { 31 | 32 | private Context mContext; 33 | private final static int HEADER_TYPE = 0;//头布局 34 | private final static int DATA_TYPE = 1;//列表数据 35 | private final static int BOTTOM_TYPE = 2;//脚布局 36 | 37 | private String address,balance,count; 38 | private BlockType blockType; 39 | 40 | private String btcIn = "",btcOut = ""; 41 | 42 | private boolean hasMore; //有没有更多 43 | 44 | public boolean isHasMore() { 45 | return hasMore; 46 | } 47 | 48 | public void setHasMore(boolean hasMore) { 49 | this.hasMore = hasMore; 50 | if (!hasMore) { 51 | notifyItemChanged(getItemCount() - 1); 52 | } 53 | } 54 | 55 | public void setHeaderData(BlockType blockType,String address,String balance,String count){ 56 | 57 | this.blockType = blockType; 58 | this.address = address; 59 | this.balance = balance; 60 | this.count = count; 61 | setHeaderView(); 62 | } 63 | 64 | public void setBtcIn(String in){ 65 | this.btcIn = in; 66 | headerViewHolder.layout_in.setVisibility(View.VISIBLE); 67 | Spanned spanned = BlockTool.fromHtml(BlockTool.parseBtc(btcIn), "#999999",BlockTool.getUnit(),""); 68 | headerViewHolder.tv_in.setText(spanned); 69 | } 70 | 71 | public void setBtcOut(String out){ 72 | this.btcOut = out; 73 | headerViewHolder.layout_out.setVisibility(View.VISIBLE); 74 | Spanned spanned = BlockTool.fromHtml(BlockTool.parseBtc(btcOut), "#999999",BlockTool.getUnit(),""); 75 | headerViewHolder.tv_out.setText(spanned); 76 | } 77 | 78 | private List dataList = new ArrayList<>(); 79 | 80 | public List getDataList() { 81 | return dataList; 82 | } 83 | 84 | public void setDataList(BlockType blockType,List dataList,String address,String count) { 85 | this.blockType = blockType; 86 | this.dataList = dataList; 87 | this.address = address; 88 | if(!TextUtils.isEmpty(count)) 89 | this.count = count; 90 | } 91 | 92 | 93 | public TransactionAdapter(Context context,BlockType blockType) { 94 | this.mContext = context; 95 | this.blockType = blockType; 96 | } 97 | 98 | private View.OnClickListener mOnClickListener; 99 | 100 | 101 | public void setOnClickListener(View.OnClickListener onClickListener) { 102 | this.mOnClickListener = onClickListener; 103 | } 104 | 105 | @Override 106 | public int getItemCount() { 107 | return dataList == null || dataList.isEmpty() ? 1: dataList.size() + 2; 108 | } 109 | 110 | @Override 111 | public int getItemViewType(int position) { 112 | 113 | if (position == 0) 114 | return HEADER_TYPE; 115 | if(position == dataList.size() + 1) 116 | return BOTTOM_TYPE; 117 | return DATA_TYPE; 118 | } 119 | 120 | @Override 121 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 122 | View view; 123 | RecyclerView.ViewHolder holer = null; 124 | switch (viewType) { 125 | 126 | case HEADER_TYPE://头步局 127 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_transaction_list_header, parent, false); 128 | holer = new HeaderViewHolder(view); 129 | break; 130 | case BOTTOM_TYPE://脚步局 131 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_bottom_listitem, parent, false); 132 | holer = new FootViewHolder(view); 133 | break; 134 | case DATA_TYPE://列表数据 135 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_transaction_list_item, parent, false); 136 | holer = new DataViewHolder(view); 137 | break; 138 | } 139 | return holer; 140 | } 141 | 142 | HeaderViewHolder headerViewHolder; 143 | @Override 144 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 145 | switch (getItemViewType(position)) { 146 | 147 | case DATA_TYPE: 148 | 149 | DataViewHolder dataViewHolder = (DataViewHolder) holder; 150 | setListView(dataViewHolder,dataList.get(position-1)); 151 | 152 | break; 153 | case HEADER_TYPE: 154 | headerViewHolder = (HeaderViewHolder) holder; 155 | setHeaderView(); 156 | break; 157 | 158 | case BOTTOM_TYPE: 159 | FootViewHolder footViewHolder = (FootViewHolder) holder; 160 | if (hasMore) { 161 | footViewHolder.more_foot_view.setVisibility(View.VISIBLE); 162 | footViewHolder.nothing_foot_view.setVisibility(View.GONE); 163 | } else { 164 | footViewHolder.more_foot_view.setVisibility(View.GONE); 165 | footViewHolder.nothing_foot_view.setVisibility(View.VISIBLE); 166 | } 167 | break; 168 | } 169 | } 170 | 171 | private void setHeaderView(){ 172 | 173 | headerViewHolder.tv_type.setText(blockType+""); 174 | if(!TextUtils.isEmpty(address)) 175 | headerViewHolder.tv_address.setText(address); 176 | Spanned spanned; 177 | switch (blockType) { 178 | case BTC: 179 | case BCH: 180 | headerViewHolder.layout_in.setVisibility(View.VISIBLE); 181 | headerViewHolder.layout_out.setVisibility(View.VISIBLE); 182 | spanned = BlockTool.fromHtml(BlockTool.parseBtc(btcOut), "#999999",BlockTool.getUnit(),""); 183 | headerViewHolder.tv_out.setText(spanned); 184 | spanned = BlockTool.fromHtml(BlockTool.parseBtc(btcIn), "#999999",BlockTool.getUnit(),""); 185 | headerViewHolder.tv_in.setText(spanned); 186 | if(!TextUtils.isEmpty(balance)){ 187 | spanned = BlockTool.fromHtml(BlockTool.parseBtc(balance), "#999999",BlockTool.getUnit(),""); 188 | headerViewHolder.tv_balance.setText(spanned); 189 | }else { 190 | headerViewHolder.tv_balance.setText(""); 191 | } 192 | break; 193 | case ETH: 194 | 195 | headerViewHolder.layout_out.setVisibility(View.GONE); 196 | headerViewHolder.layout_in.setVisibility(View.GONE); 197 | if(!TextUtils.isEmpty(balance)){ 198 | if(balance.startsWith("0x")||balance.startsWith("0X")){ 199 | spanned = BlockTool.fromHtml(BlockTool.parseEth(balance), "#999999",BlockTool.getUnit(),""); 200 | headerViewHolder.tv_balance.setText(spanned); 201 | }else { 202 | spanned = BlockTool.fromHtml(balance, "#999999",BlockTool.getUnit(),""); 203 | headerViewHolder.tv_balance.setText(spanned); 204 | } 205 | }else { 206 | headerViewHolder.tv_balance.setText(""); 207 | } 208 | break; 209 | default: 210 | headerViewHolder.layout_out.setVisibility(View.GONE); 211 | headerViewHolder.layout_in.setVisibility(View.GONE); 212 | break; 213 | } 214 | 215 | if(!TextUtils.isEmpty(count)) 216 | headerViewHolder.tv_deal_count.setText(Long.decode(count)+""); 217 | else 218 | headerViewHolder.tv_deal_count.setText(""); 219 | 220 | headerViewHolder.btn_search.setTag(headerViewHolder.et_hash); 221 | headerViewHolder.btn_search.setOnClickListener(mOnClickListener); 222 | headerViewHolder.tv_type.setOnClickListener(mOnClickListener); 223 | } 224 | 225 | 226 | private void setListView(final DataViewHolder holder, final Transaction transaction){ 227 | if(transaction==null) 228 | return; 229 | holder.tv_hash.setText(transaction.hash); 230 | 231 | Spanned spanned = null; 232 | String price = ""; 233 | StringBuilder value = new StringBuilder(); 234 | 235 | switch (blockType) { 236 | case ETH: 237 | BigInteger gas = new BigInteger(transaction.gas); 238 | BigInteger gasPrice = new BigInteger(transaction.gasPrice); 239 | BigInteger result = gas.multiply(gasPrice); 240 | price = BlockTool.parseEth(result.toString(10)); 241 | spanned = BlockTool.fromHtml(price, "#999999",BlockTool.getUnit(),""); 242 | holder.tv_fee.setText(spanned); 243 | if(transaction.from.equals(address)) 244 | value.append("- "); 245 | else 246 | value.append("+ "); 247 | value.append(BlockTool.parseEth2(transaction.value)); 248 | holder.tv_value.setText(value); 249 | break; 250 | case BTC: 251 | price = transaction.fees; 252 | spanned = BlockTool.fromHtml(price, "#999999",BlockTool.getUnit(),""); 253 | holder.tv_fee.setText(spanned); 254 | value.append(transaction.btcValue); 255 | holder.tv_value.setText(value + BlockTool.getUnit()); 256 | break; 257 | case BCH: 258 | price = transaction.fees; 259 | spanned = BlockTool.fromHtml(price, "#999999",BlockTool.getUnit(),""); 260 | holder.tv_fee.setText(spanned); 261 | value.append("- "); 262 | value.append(transaction.value); 263 | holder.tv_value.setText(value + BlockTool.getUnit()); 264 | break; 265 | } 266 | 267 | if(!TextUtils.isEmpty(transaction.blockNumber)){ 268 | 269 | holder.tv_height.setText(Long.decode(transaction.blockNumber)+ ""); 270 | } 271 | long timestamp = Long.decode(transaction.timestamp); 272 | String time = BlockTool.timestampToDate(timestamp); 273 | holder.tv_time.setText(time); 274 | 275 | holder.tv_hash.setTag(transaction.hash); 276 | holder.tv_hash.setOnClickListener(mOnClickListener); 277 | 278 | } 279 | 280 | 281 | //头部布局的viewHolder 282 | public static class HeaderViewHolder extends RecyclerView.ViewHolder { 283 | public final View mView; 284 | private TextView tv_type,tv_address,tv_balance,tv_deal_count; 285 | private EditText et_hash; 286 | private Button btn_search;; 287 | private RelativeLayout layout_in,layout_out; 288 | private TextView tv_in,tv_out; 289 | public HeaderViewHolder(View view) { 290 | super(view); 291 | mView = view; 292 | tv_type = (TextView) view.findViewById(R.id.tv_type); 293 | tv_address = (TextView) view.findViewById(R.id.tv_address); 294 | tv_balance = (TextView) view.findViewById(R.id.tv_balance); 295 | tv_deal_count = (TextView) view.findViewById(R.id.tv_deal_count); 296 | et_hash = (EditText) view.findViewById(R.id.et_hash); 297 | btn_search = (Button) view.findViewById(R.id.btn_search); 298 | layout_in = (RelativeLayout) view.findViewById(R.id.layout_in); 299 | layout_out = (RelativeLayout) view.findViewById(R.id.layout_out); 300 | tv_in = (TextView) view.findViewById(R.id.tv_in); 301 | tv_out = (TextView) view.findViewById(R.id.tv_out); 302 | } 303 | } 304 | 305 | public TextView getTypeTextView(){ 306 | if(headerViewHolder!=null) 307 | return headerViewHolder.tv_type; 308 | else return null; 309 | } 310 | 311 | //底部布局的viewHolder 312 | public static class FootViewHolder extends RecyclerView.ViewHolder { 313 | public final View mView, more_foot_view, nothing_foot_view; 314 | 315 | public FootViewHolder(View view) { 316 | super(view); 317 | mView = view; 318 | more_foot_view = view.findViewById(R.id.layout_load_more); 319 | nothing_foot_view = view.findViewById(R.id.layout_load_none); 320 | } 321 | } 322 | 323 | public static class DataViewHolder extends RecyclerView.ViewHolder { 324 | public View mView; 325 | private TextView tv_hash,tv_height,tv_fee,tv_time,tv_value; 326 | 327 | public DataViewHolder(View view) { 328 | super(view); 329 | mView = view; 330 | tv_hash = (TextView) view.findViewById(R.id.tv_hash); 331 | tv_height = (TextView) view.findViewById(R.id.tv_height); 332 | tv_fee = (TextView) view.findViewById(R.id.tv_fee); 333 | tv_time = (TextView) view.findViewById(R.id.tv_time); 334 | tv_value = (TextView) view.findViewById(R.id.tv_value); 335 | 336 | } 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import org.xutils.x; 8 | 9 | /** 10 | * Created by wulijie on 2018/4/11. 11 | */ 12 | 13 | public class BaseActivity extends AppCompatActivity { 14 | @Override 15 | protected void onCreate(@Nullable Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | x.view().inject(this); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/been/BaseBlock.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.been; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/12. 5 | * 区块链浏览器的实体类的基类 6 | */ 7 | public abstract class BaseBlock implements IBlock { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/been/IBlock.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.been; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockType; 4 | 5 | /** 6 | * Created by wulijie on 2018/4/12. 7 | * 定义实体类的转换行为 8 | */ 9 | public interface IBlock { 10 | /** 11 | * 解析Json 根据货币类型 12 | * 13 | * @param json 14 | */ 15 | T parse(BlockType type, int extra, String json); 16 | 17 | /** 18 | * 解析Json 根据货币类型 19 | * 20 | * @param json 21 | */ 22 | T parse(BlockType type, String json); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/been/TdpBlock.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.been; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockType; 4 | 5 | import org.json.JSONObject; 6 | 7 | /** 8 | * Created by wulijie on 2018/4/12. 9 | */ 10 | 11 | public class TdpBlock extends BaseBlock { 12 | 13 | 14 | public String timestamp; 15 | public String difficulty; 16 | public String totalDifficulty; 17 | 18 | 19 | @Override 20 | public TdpBlock parse(BlockType type, int extra, String json) { 21 | switch (type) { 22 | case BTC: 23 | break; 24 | case ETH: 25 | try { 26 | JSONObject jsonObject = new JSONObject(json); 27 | JSONObject result = jsonObject.getJSONObject("result"); 28 | this.timestamp = result.optString("timestamp"); 29 | this.difficulty = result.optString("difficulty"); 30 | this.totalDifficulty = result.optString("totalDifficulty"); 31 | } catch (Exception e) { 32 | } 33 | break; 34 | } 35 | return this; 36 | } 37 | 38 | @Override 39 | public TdpBlock parse(BlockType type, String json) { 40 | return parse(type, 0, json); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/been/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.been; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockType; 4 | import com.tdp.blockexplorer.btc.been.BchTransaction; 5 | import com.tdp.blockexplorer.btc.been.BtcTransaction; 6 | import com.tdp.blockexplorer.eth.been.EthTransaction; 7 | import com.tdp.blockexplorer.eth.been.EthTransactionInfo; 8 | 9 | import java.util.List; 10 | 11 | 12 | /** 13 | * Created by LPC43 on 2018/4/12. 14 | */ 15 | 16 | public class Transaction extends BaseBlock { 17 | 18 | public String blockHash;//区块哈希值 19 | public String blockNumber;//区块高度 20 | public String from;//交易发送方 21 | public String to;//交易接收方 22 | public String gas;//交易发起者提供的gas 23 | public String gasPrice;//交易发起者配置的gas价格,单位是wei 24 | public String hash;//交易hash 25 | public String input;//交易附带的数据 26 | public String nonce;//交易的发起者在之前进行过的交易数量 27 | public String transactionIndex;//整数。交易在区块中的序号 28 | public String value;//交易附带的货币量,单位为Wei。 29 | public String timestamp; 30 | 31 | 32 | //BTC 33 | public String fees;//BTC 矿工费 34 | public List fromList; 35 | public List toList; 36 | public String size; 37 | public String btcValue; 38 | public boolean isCoinBase;//是否是挖币所得 39 | public String valueIn; 40 | public String valueOut; 41 | 42 | @Override 43 | public Transaction parse(BlockType type, int extra, String json) { 44 | Transaction transaction = null; 45 | switch (type) { 46 | case ETH: 47 | if (extra == 0) 48 | transaction = new EthTransaction().parse(json); 49 | else 50 | transaction = new EthTransactionInfo().parse(json); 51 | break; 52 | case BTC: 53 | transaction = new BtcTransaction().parse(json); 54 | break; 55 | case BCH: 56 | transaction = new BchTransaction().parse(json); 57 | break; 58 | } 59 | return transaction; 60 | } 61 | 62 | @Override 63 | public Transaction parse(BlockType type, String json) { 64 | return parse(type, 0, json); 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/been/TransactionList.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.been; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockType; 4 | import com.tdp.blockexplorer.btc.been.BchTransactionList; 5 | import com.tdp.blockexplorer.btc.been.BtcTransactionList; 6 | import com.tdp.blockexplorer.eth.been.EthTransaction; 7 | import com.tdp.blockexplorer.eth.been.EthTransactionInfo; 8 | import com.tdp.blockexplorer.eth.been.EthTransactionInfoList; 9 | 10 | import java.util.List; 11 | 12 | 13 | /** 14 | * Created by LPC43 on 2018/4/12. 15 | */ 16 | 17 | public class TransactionList extends BaseBlock{ 18 | 19 | public List result; 20 | 21 | public int totalItems; 22 | 23 | @Override 24 | public Object parse(BlockType type, int extra, String json) { 25 | return null; 26 | } 27 | 28 | @Override 29 | public Object parse(BlockType type, String json) { 30 | TransactionList transactionList = null; 31 | switch (type) { 32 | case ETH: 33 | transactionList = new EthTransactionInfoList().parse(json); 34 | break; 35 | case BTC: 36 | transactionList = new BtcTransactionList().parse(json); 37 | break; 38 | case BCH: 39 | transactionList = new BchTransactionList().parse(json); 40 | break; 41 | } 42 | return transactionList; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/blockchain/BlockCallback.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.blockchain; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | */ 6 | 7 | public interface BlockCallback { 8 | void onSuccess(String result); 9 | 10 | void onError(BlockError error); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/blockchain/BlockError.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.blockchain; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | */ 6 | 7 | public class BlockError { 8 | public String error; 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/blockchain/BlockExplorer.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.blockchain; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | * 区块浏览接口 6 | */ 7 | public interface BlockExplorer { 8 | /** 9 | * 根据交易哈希值获取交易数据 10 | * 11 | * @param hash 12 | * @param callback 13 | */ 14 | void getTransactionByHash(String hash, BlockCallback callback); 15 | 16 | /** 17 | * 指定地址余额 18 | * 19 | * @param address 20 | * @param callback 21 | */ 22 | void getBalance(String address, BlockCallback callback); 23 | 24 | /** 25 | * 指定地址的交易数量 26 | * 27 | * @param address 28 | * @param callback 29 | */ 30 | void getTransactionCount(String address, BlockCallback callback); 31 | 32 | /** 33 | * 根据block 哈希值 获取 block对象 对象内包含所有交易信息哦 34 | * 35 | * @param hash 36 | * @param callback 37 | */ 38 | void getBlockByHash(String hash, BlockCallback callback); 39 | 40 | /** 41 | * 根据账户地址 获取该地址下的所有交易记录 42 | * 43 | * @param address 44 | * @param callback 45 | * @param page 46 | */ 47 | void getTransactionsByAddress(String address, int page, BlockCallback callback); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/blockchain/BlockType.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.blockchain; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | */ 6 | 7 | public enum BlockType { 8 | ETH, BTC, BCH, LTC 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/blockchain/Tdp.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.blockchain; 2 | 3 | import com.tdp.blockexplorer.btc.BtcBlockExplorer; 4 | import com.tdp.blockexplorer.eth.EthBlockExplorer; 5 | import com.tdp.blockexplorer.ltc.LtcBlockExplorer; 6 | 7 | /** 8 | * Created by wulijie on 2018/4/11. 9 | */ 10 | 11 | public class Tdp { 12 | public static BlockType blockType = BlockType.BTC;//当前的搜索类型 13 | 14 | public static BlockType[] blockTypes = {BlockType.BTC, BlockType.BCH, BlockType.ETH}; 15 | 16 | private Tdp() { 17 | } 18 | 19 | public static BlockExplorer get(BlockType type) { 20 | blockType = type; 21 | BlockExplorer explorer = null; 22 | switch (type) { 23 | case BTC: 24 | explorer = new BtcBlockExplorer(); 25 | break; 26 | case BCH: 27 | explorer = new BtcBlockExplorer();//因为只是改下接口地址 所以复用了btc的逻辑处理 28 | break; 29 | case ETH: 30 | explorer = new EthBlockExplorer(); 31 | break; 32 | case LTC: 33 | explorer = new LtcBlockExplorer(); 34 | break; 35 | } 36 | return explorer; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/Btc.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockError; 5 | 6 | import org.xutils.common.Callback; 7 | import org.xutils.common.util.LogUtil; 8 | import org.xutils.http.RequestParams; 9 | import org.xutils.x; 10 | 11 | /** 12 | * Created by wulijie on 2018/4/16. 13 | */ 14 | 15 | public class Btc { 16 | 17 | public void get(RequestParams params, final BlockCallback callback) { 18 | x.http().get(params, new Callback.CommonCallback() { 19 | @Override 20 | public void onSuccess(String result) { 21 | LogUtil.e("BTC onSuccess =" + result); 22 | callback.onSuccess(result); 23 | } 24 | 25 | @Override 26 | public void onError(Throwable ex, boolean isOnCallback) { 27 | LogUtil.e("BTC onError =" + ex.toString()); 28 | BlockError error = new BlockError(); 29 | error.error = ex.toString(); 30 | callback.onError(error); 31 | } 32 | 33 | @Override 34 | public void onCancelled(CancelledException cex) { 35 | 36 | } 37 | 38 | @Override 39 | public void onFinished() { 40 | 41 | } 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/BtcBlockExplorer.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockExplorer; 5 | import com.tdp.blockexplorer.blockchain.BlockType; 6 | import com.tdp.blockexplorer.blockchain.Tdp; 7 | 8 | import org.xutils.common.util.LogUtil; 9 | import org.xutils.http.RequestParams; 10 | 11 | /** 12 | * Created by wulijie on 2018/4/16. 13 | * 获取比特币区块链信息的实际操作类 14 | */ 15 | public class BtcBlockExplorer extends Btc implements BlockExplorer { 16 | //基于Insight开源框架 接入比特币 17 | String INSIGHT_URL = "https://insight.bitpay.com/api"; 18 | String BCH_INSIGHT_URL = "https://bch-insight.bitpay.com/api"; 19 | String URL = Tdp.blockType == BlockType.BTC ? INSIGHT_URL : BCH_INSIGHT_URL; 20 | @Override 21 | public void getTransactionByHash(String hash, BlockCallback callback) { 22 | RequestParams params = new RequestParams(URL+BtcConf.GET_TX.replace("{hash}", hash)); 23 | LogUtil.e("BTC Url =" + params.getUri()); 24 | get(params, callback); 25 | } 26 | 27 | @Override 28 | public void getBalance(String address, BlockCallback callback) { 29 | RequestParams params = new RequestParams(URL+BtcConf.GET_BALANCE.replace("{address}", address)); 30 | LogUtil.e("BTC Url =" + params.getUri()); 31 | get(params, callback); 32 | } 33 | 34 | @Override 35 | public void getTransactionCount(String address, BlockCallback callback) { 36 | //可以直接用 getTransactionsByAddress 接口返回参数中有交易总数 37 | RequestParams params = new RequestParams(URL+BtcConf.GET_TXS.replace("{address}", address)); 38 | params.addQueryStringParameter("from", "0");//默认每次取10条 39 | params.addQueryStringParameter("to", "1"); 40 | params.addQueryStringParameter("noAsm", "1"); 41 | params.addQueryStringParameter("noScriptSig", "1"); 42 | params.addQueryStringParameter("noSpent", "1"); 43 | get(params, callback); 44 | } 45 | 46 | @Override 47 | public void getBlockByHash(String hash, BlockCallback callback) { 48 | RequestParams params = new RequestParams(URL+BtcConf.GET_BLOCK.replace("{hash}", hash)); 49 | LogUtil.e("BTC Url =" + params.getUri()); 50 | get(params, callback); 51 | } 52 | 53 | @Override 54 | public void getTransactionsByAddress(String address, int page, BlockCallback callback) { 55 | RequestParams params = new RequestParams(URL+BtcConf.GET_TXS.replace("{address}", address)); 56 | int from = page * 10; 57 | int to = from + 10;//TODO:test 58 | params.addQueryStringParameter("from", String.valueOf(from));//默认每次取10条 59 | params.addQueryStringParameter("to", String.valueOf(to)); 60 | params.addQueryStringParameter("noAsm", "1"); 61 | params.addQueryStringParameter("noScriptSig", "1"); 62 | params.addQueryStringParameter("noSpent", "1"); 63 | LogUtil.e("BTC Url =" + params.getUri()); 64 | get(params, callback); 65 | } 66 | 67 | /** 68 | * 获取某个地址下接收总量 69 | * 70 | * @param address 71 | * @param callback 72 | */ 73 | public void getTransactionTotalReceived(String address, BlockCallback callback) { 74 | RequestParams params = new RequestParams(URL+BtcConf.GET_TOTALRECEIVED.replace("{address}", address)); 75 | LogUtil.e("BTC Url =" + params.getUri()); 76 | get(params, callback); 77 | } 78 | 79 | /** 80 | * 获取某个地址下的发送总量 81 | * 82 | * @param address 83 | * @param callback 84 | */ 85 | public void getTransactionTotalSent(String address, BlockCallback callback) { 86 | RequestParams params = new RequestParams(URL+BtcConf.GET_TOTALSENT.replace("{address}", address)); 87 | LogUtil.e("BTC Url =" + params.getUri()); 88 | get(params, callback); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/BtcConf.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/16. 5 | */ 6 | public interface BtcConf { 7 | 8 | //基于BlockHash 获取block 9 | String GET_BLOCK = "/block/{hash}"; 10 | //基于交易Hash 获取交易信息 11 | String GET_TX = "/tx/{hash}"; 12 | //获取交易列表 13 | String GET_TXS = "/addrs/{address}/txs";//?addr 14 | //获取地址余额 15 | String GET_BALANCE = "/addr/{address}/balance"; 16 | //获取地址下的接收总量 17 | String GET_TOTALRECEIVED = "/addr/{address}/totalReceived"; 18 | //获取地址下的发送总量 19 | String GET_TOTALSENT = "/addr/{address}/totalSent"; 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/been/BchTransaction.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc.been; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.google.gson.Gson; 6 | import com.tdp.blockexplorer.been.Transaction; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by LPC43 on 2018/4/16. 13 | */ 14 | 15 | public class BchTransaction implements BtcBlock { 16 | 17 | public String txid; 18 | public int version; 19 | public String locktime; 20 | public boolean isCoinBase; 21 | public String blockhash; 22 | public String blockheight; 23 | public String blocktime; 24 | public String confirmations; 25 | public String time; 26 | public String valueOut; 27 | public String valueIn; 28 | public String size; 29 | public List vin; 30 | public List vout; 31 | public String fees; 32 | 33 | 34 | public static class Vin { 35 | public String txid; 36 | public String vout; 37 | public String sequence; 38 | public String n; 39 | public String addr; 40 | public String valueSat; 41 | public String value; 42 | public String doubleSpentTxID; 43 | } 44 | 45 | public static class Vout { 46 | public String value; 47 | public String n; 48 | public ScriptPubKey scriptPubKey; 49 | } 50 | 51 | public static class ScriptPubKey { 52 | public String hex; 53 | public List addresses; 54 | public String type; 55 | } 56 | 57 | @Override 58 | public Transaction parse(String json) { 59 | 60 | BchTransaction btcTransaction = new Gson().fromJson(json, BchTransaction.class); 61 | //转换 62 | Transaction transaction = new Transaction(); 63 | transaction.blockHash = btcTransaction.blockhash; 64 | transaction.blockNumber = btcTransaction.blockheight; 65 | transaction.hash = btcTransaction.txid; 66 | transaction.timestamp = btcTransaction.blocktime; 67 | transaction.size = btcTransaction.size; 68 | transaction.isCoinBase = btcTransaction.isCoinBase; 69 | transaction.value = btcTransaction.valueIn; 70 | transaction.valueIn = btcTransaction.valueIn; 71 | transaction.valueOut = btcTransaction.valueOut; 72 | transaction.fees = btcTransaction.fees; 73 | 74 | if (btcTransaction.vin != null && btcTransaction.vin.size() != 0) { 75 | List fromList = new ArrayList<>(); 76 | for (Vin in : btcTransaction.vin) { 77 | if (TextUtils.isEmpty(in.addr) || TextUtils.isEmpty(in.value)) { 78 | fromList.add(""); 79 | } else { 80 | fromList.add(in.addr + "," + in.value); 81 | } 82 | } 83 | transaction.fromList = fromList; 84 | } 85 | 86 | if (btcTransaction.vout != null && btcTransaction.vout.size() != 0) { 87 | List toList = new ArrayList<>(); 88 | for (Vout out : btcTransaction.vout) { 89 | ScriptPubKey sp = out.scriptPubKey; 90 | String outString = ""; 91 | if (sp != null && sp.addresses != null && sp.addresses.size() != 0) 92 | outString = sp.addresses.get(0) + "," + out.value; 93 | toList.add(outString); 94 | } 95 | transaction.toList = toList; 96 | } 97 | return transaction; 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/been/BchTransactionList.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc.been; 2 | 3 | import com.google.gson.Gson; 4 | import com.tdp.blockexplorer.been.Transaction; 5 | import com.tdp.blockexplorer.been.TransactionList; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by LPC43 on 2018/4/16. 12 | */ 13 | 14 | public class BchTransactionList implements BtcBlock{ 15 | 16 | public int totalItems; 17 | public String from; 18 | public String to; 19 | public List items; 20 | 21 | @Override 22 | public TransactionList parse(String json) { 23 | 24 | BchTransactionList btcTransactionList = new Gson().fromJson(json, BchTransactionList.class); 25 | //转换 26 | TransactionList transactionList = new TransactionList(); 27 | transactionList.result = new ArrayList<>(); 28 | for(BchTransaction info : btcTransactionList.items){ 29 | 30 | Transaction transaction = new Transaction(); 31 | transaction.hash = info.txid; 32 | transaction.blockHash = info.blockhash; 33 | transaction.blockNumber = info.blockheight; 34 | transaction.timestamp = info.time; 35 | transaction.value = info.valueOut; 36 | transaction.fees = info.size; 37 | // transaction.btcValue = info.value 38 | transactionList.result.add(transaction); 39 | } 40 | transactionList.totalItems = btcTransactionList.totalItems; 41 | 42 | return transactionList; 43 | } 44 | 45 | public TransactionList parse(String json,String address) { 46 | 47 | BchTransactionList btcTransactionList = new Gson().fromJson(json, BchTransactionList.class); 48 | //转换 49 | TransactionList transactionList = new TransactionList(); 50 | transactionList.result = new ArrayList<>(); 51 | for(BchTransaction info : btcTransactionList.items){ 52 | 53 | Transaction transaction = new Transaction(); 54 | transaction.hash = info.txid; 55 | transaction.blockHash = info.blockhash; 56 | transaction.blockNumber = info.blockheight; 57 | transaction.timestamp = info.time; 58 | transaction.value = info.valueOut; 59 | transaction.fees = "0.00000"; 60 | 61 | transaction.btcValue = searchBchValue(info,address); 62 | transactionList.result.add(transaction); 63 | } 64 | transactionList.totalItems = btcTransactionList.totalItems; 65 | 66 | return transactionList; 67 | } 68 | 69 | public String searchBchValue(BchTransaction transaction,String address){ 70 | 71 | String btcValue = ""; 72 | 73 | for(BchTransaction.Vout vout: transaction.vout){ 74 | for(String addresssOut: vout.scriptPubKey.addresses){ 75 | if(address.equals(addresssOut)){ 76 | btcValue = vout.value; 77 | return "+ " + btcValue; 78 | } 79 | } 80 | } 81 | return btcValue; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/been/BtcBlock.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc.been; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/12. 5 | */ 6 | 7 | public interface BtcBlock { 8 | 9 | public abstract T parse(String json); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/been/BtcTransaction.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc.been; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.google.gson.Gson; 6 | import com.tdp.blockexplorer.been.Transaction; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by LPC43 on 2018/4/16. 13 | */ 14 | 15 | public class BtcTransaction implements BtcBlock { 16 | 17 | public String txid; 18 | public int version; 19 | public String locktime; 20 | public String blockhash; 21 | public String blockheight; 22 | public String confirmations; 23 | public String time; 24 | public String blocktime; 25 | public String valueOut; 26 | public String valueIn; 27 | public String size; 28 | public String fees; 29 | public List vin; 30 | public List vout; 31 | 32 | public static class Vin { 33 | public String txid; 34 | public String vout; 35 | public String sequence; 36 | public String n; 37 | public String addr; 38 | public String valueSat; 39 | public String value; 40 | public String doubleSpentTxID; 41 | } 42 | 43 | public static class Vout { 44 | public String value; 45 | public String n; 46 | public ScriptPubKey scriptPubKey; 47 | } 48 | 49 | public static class ScriptPubKey { 50 | public String hex; 51 | public List addresses; 52 | public String type; 53 | } 54 | 55 | @Override 56 | public Transaction parse(String json) { 57 | 58 | BtcTransaction btcTransaction = new Gson().fromJson(json, BtcTransaction.class); 59 | //转换 60 | Transaction transaction = new Transaction(); 61 | transaction.blockHash = btcTransaction.blockhash; 62 | transaction.blockNumber = btcTransaction.blockheight; 63 | transaction.fees = btcTransaction.fees; 64 | transaction.hash = btcTransaction.txid; 65 | transaction.timestamp = btcTransaction.blocktime; 66 | transaction.value = btcTransaction.valueIn; 67 | transaction.size = btcTransaction.size; 68 | transaction.valueOut = btcTransaction.valueOut; 69 | transaction.valueIn = btcTransaction.valueIn; 70 | 71 | if (btcTransaction.vin != null && btcTransaction.vin.size() != 0) { 72 | List fromList = new ArrayList<>(); 73 | for (Vin in : btcTransaction.vin) { 74 | if (TextUtils.isEmpty(in.addr) || TextUtils.isEmpty(in.value)) { 75 | fromList.add(""); 76 | } else { 77 | fromList.add(in.addr + "," + in.value); 78 | } 79 | } 80 | transaction.fromList = fromList; 81 | } 82 | 83 | if (btcTransaction.vout != null && btcTransaction.vout.size() != 0) { 84 | List toList = new ArrayList<>(); 85 | for (Vout out : btcTransaction.vout) { 86 | ScriptPubKey sp = out.scriptPubKey; 87 | String outString = ""; 88 | if (sp != null && sp.addresses != null && sp.addresses.size() != 0) 89 | outString = sp.addresses.get(0) + "," + out.value; 90 | toList.add(outString); 91 | } 92 | transaction.toList = toList; 93 | } 94 | return transaction; 95 | 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/btc/been/BtcTransactionList.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.btc.been; 2 | 3 | import com.google.gson.Gson; 4 | import com.tdp.blockexplorer.been.Transaction; 5 | import com.tdp.blockexplorer.been.TransactionList; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by LPC43 on 2018/4/16. 12 | */ 13 | 14 | public class BtcTransactionList implements BtcBlock{ 15 | 16 | public int totalItems; 17 | public String from; 18 | public String to; 19 | public List items; 20 | 21 | @Override 22 | public TransactionList parse(String json) { 23 | 24 | BtcTransactionList btcTransactionList = new Gson().fromJson(json, BtcTransactionList.class); 25 | //转换 26 | TransactionList transactionList = new TransactionList(); 27 | transactionList.result = new ArrayList<>(); 28 | for(BtcTransaction info : btcTransactionList.items){ 29 | 30 | Transaction transaction = new Transaction(); 31 | transaction.hash = info.txid; 32 | transaction.blockHash = info.blockhash; 33 | // transaction.from = info.from;//示例 34 | // transaction.to = info.to;//示例 35 | transaction.blockNumber = info.blockheight; 36 | transaction.timestamp = info.time; 37 | //TODO 38 | transaction.value = info.valueIn; 39 | transaction.fees = info.fees; 40 | // transaction.btcValue = info.value 41 | transactionList.result.add(transaction); 42 | } 43 | transactionList.totalItems = btcTransactionList.totalItems; 44 | 45 | return transactionList; 46 | } 47 | 48 | public TransactionList parse(String json,String address) { 49 | 50 | BtcTransactionList btcTransactionList = new Gson().fromJson(json, BtcTransactionList.class); 51 | //转换 52 | TransactionList transactionList = new TransactionList(); 53 | transactionList.result = new ArrayList<>(); 54 | for(BtcTransaction info : btcTransactionList.items){ 55 | 56 | Transaction transaction = new Transaction(); 57 | transaction.hash = info.txid; 58 | transaction.blockHash = info.blockhash; 59 | // transaction.from = info.from;//示例 60 | // transaction.to = info.to;//示例 61 | transaction.blockNumber = info.blockheight; 62 | transaction.timestamp = info.time; 63 | //TODO 64 | transaction.value = info.valueIn; 65 | transaction.fees = info.fees; 66 | 67 | transaction.btcValue = searchBtcValue(info,address); 68 | transactionList.result.add(transaction); 69 | } 70 | transactionList.totalItems = btcTransactionList.totalItems; 71 | 72 | return transactionList; 73 | } 74 | 75 | public String searchBtcValue(BtcTransaction transaction,String address){ 76 | 77 | String btcValue = ""; 78 | for(BtcTransaction.Vin vin: transaction.vin){ 79 | if(address.equals(vin.addr)){ 80 | 81 | btcValue = vin.value; 82 | return "- " + btcValue; 83 | } 84 | } 85 | for(BtcTransaction.Vout vout: transaction.vout){ 86 | for(String addresssOut: vout.scriptPubKey.addresses){ 87 | if(address.equals(addresssOut)){ 88 | btcValue = vout.value; 89 | return "+ " + btcValue; 90 | } 91 | } 92 | } 93 | return btcValue; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/Eth.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockError; 5 | 6 | import org.xutils.common.Callback; 7 | import org.xutils.common.util.LogUtil; 8 | import org.xutils.http.RequestParams; 9 | import org.xutils.x; 10 | 11 | /** 12 | * Created by wulijie on 2018/4/11. 13 | */ 14 | public class Eth { 15 | /** 16 | * 执行post请求 17 | * 18 | * @param params 19 | * @param blockCallback 20 | */ 21 | public void post(EthParams params, final BlockCallback blockCallback) { 22 | RequestParams requestParams = new RequestParams(EthConf.url); 23 | String json = params.toJson(); 24 | requestParams.setAsJsonContent(true); 25 | requestParams.setBodyContent(json); 26 | x.http().post(requestParams, new Callback.CommonCallback() { 27 | @Override 28 | public void onSuccess(String result) { 29 | LogUtil.e("class Eth onSuccess >>>>>" + result); 30 | blockCallback.onSuccess(result); 31 | } 32 | 33 | @Override 34 | public void onError(Throwable ex, boolean isOnCallback) { 35 | BlockError error = new BlockError(); 36 | error.error = ex.toString(); 37 | LogUtil.e("class Eth onError >>>>>" + error.error); 38 | blockCallback.onError(error); 39 | } 40 | 41 | @Override 42 | public void onCancelled(CancelledException cex) { 43 | } 44 | 45 | @Override 46 | public void onFinished() { 47 | } 48 | }); 49 | } 50 | 51 | /** 52 | * get请求 去访问EtherScan的api 获取列表 53 | * 54 | * @param params 55 | * @param callback 56 | */ 57 | public void get(RequestParams params, final BlockCallback callback) { 58 | x.http().get(params, new Callback.CommonCallback() { 59 | @Override 60 | public void onSuccess(String result) { 61 | LogUtil.e("class Eth onSuccess >>>>>" + result); 62 | callback.onSuccess(result); 63 | } 64 | 65 | @Override 66 | public void onError(Throwable ex, boolean isOnCallback) { 67 | BlockError error = new BlockError(); 68 | error.error = ex.toString(); 69 | LogUtil.e("class Eth onError >>>>>" + error.error); 70 | callback.onError(error); 71 | } 72 | 73 | @Override 74 | public void onCancelled(CancelledException cex) { 75 | 76 | } 77 | 78 | @Override 79 | public void onFinished() { 80 | 81 | } 82 | }); 83 | } 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/EthBlockExplorer.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockExplorer; 5 | 6 | import org.xutils.common.util.LogUtil; 7 | import org.xutils.http.RequestParams; 8 | 9 | /** 10 | * Created by wulijie on 2018/4/11. 11 | * 以太坊区块浏览方式 12 | * sort的排序规则 13 | * HEX String - an integer block number 14 | * String "earliest" for the earliest/genesis block 15 | * String "latest" - for the latest mined block 16 | * String "pending" - for the pending state/transactions 17 | */ 18 | public class EthBlockExplorer extends Eth implements BlockExplorer { 19 | @Override 20 | public void getTransactionByHash(String hash, BlockCallback callback) { 21 | //获取交易根据交易哈希值 示例 22 | EthParams params = 23 | new EthParams("eth_getTransactionByHash") 24 | .setMethodId(1) 25 | .addParams(hash); 26 | //执行请求 27 | post(params, callback); 28 | } 29 | 30 | 31 | @Override 32 | public void getBalance(String address, BlockCallback callback) { 33 | String sort = "latest";//默认指定吧 34 | EthParams params = new EthParams("eth_getBalance") 35 | .setMethodId(1) 36 | .addParams(address) 37 | .addParams(sort);//integer block number, or the string "latest", "earliest" or "pending" 38 | post(params, callback); 39 | } 40 | 41 | @Override 42 | public void getTransactionCount(String address, BlockCallback callback) { 43 | String sort = "latest";//默认指定吧 44 | EthParams params = new EthParams("eth_getTransactionCount") 45 | .setMethodId(1) 46 | .addParams(address) 47 | .addParams(sort); 48 | post(params, callback); 49 | } 50 | 51 | @Override 52 | public void getBlockByHash(String hash, BlockCallback callback) { 53 | EthParams params = new EthParams("eth_getBlockByHash") 54 | .setMethodId(1) 55 | .addParams(hash) 56 | .addParams(true);//可选 默认值为false。true会将区块包含的所有交易作为对象返回。否则只返回交易的哈希。 57 | post(params, callback); 58 | } 59 | 60 | 61 | @Override 62 | public void getTransactionsByAddress(String address, int page, BlockCallback callback) { 63 | String url = "http://api.etherscan.io/api";// 分页加载 64 | RequestParams params = new RequestParams(url); 65 | params.addQueryStringParameter("module", "account"); 66 | params.addQueryStringParameter("action", "txlist"); 67 | params.addQueryStringParameter("address", address); 68 | params.addQueryStringParameter("startblock", "0"); 69 | params.addQueryStringParameter("endblock", "99999999"); 70 | params.addQueryStringParameter("page", String.valueOf(page)); 71 | params.addQueryStringParameter("offset", "10");//每页十条信息 72 | params.addQueryStringParameter("sort", "asc"); 73 | params.addQueryStringParameter("apikey", "YourApiKeyToken"); 74 | LogUtil.e("ETH Url =" + params.getUri()); 75 | get(params, callback); 76 | } 77 | 78 | // @Override 79 | // public void getTransactionInfoByTxHash(String txHash, BlockCallback callback) { 80 | // //(EtherScan上提供的方法)建议配合Ether官方api 使用 81 | // String url = "http://api.etherscan.io/api"; 82 | // RequestParams params = new RequestParams(url); 83 | // params.addQueryStringParameter("module", "account"); 84 | // params.addQueryStringParameter("action", "txlistinternal"); 85 | // params.addQueryStringParameter("txhash", txHash); 86 | // params.addQueryStringParameter("apikey", "YourApiKeyToken"); 87 | // get(params, callback); 88 | // //http://www.qukuai.com/search/zh-CN/ETH/0x2cb58f20647c1944251b5213c193680537ec1821c572c34f26f93e10357f3ddf/1 89 | // } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/EthConf.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/11. 5 | * eth 配置信息 6 | */ 7 | public interface EthConf { 8 | String url = "https://mainnet.infura.io/XYZOeM2B24PBYotwyLjj"; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/EthParams.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth; 2 | 3 | import com.google.gson.Gson; 4 | 5 | import org.xutils.common.util.LogUtil; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by wulijie on 2018/4/11. 14 | * Eth参数集 15 | */ 16 | public class EthParams { 17 | private Map params; 18 | 19 | private List paramsList;//参数集 20 | 21 | public EthParams(String method) { 22 | params = new HashMap<>(); 23 | paramsList = new ArrayList(); 24 | params.put("jsonrpc", "2.0"); 25 | params.put("method", method); 26 | params.put("params", paramsList); 27 | } 28 | 29 | public EthParams setMethodId(int id) { 30 | params.put("id", id); 31 | return this; 32 | } 33 | 34 | 35 | public EthParams addParams(Object value) { 36 | paramsList.add(value); 37 | return this; 38 | } 39 | 40 | 41 | public String toJson() { 42 | String json = new Gson().toJson(params); 43 | LogUtil.e(json); 44 | return json; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/been/EthBlock.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth.been; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/12. 5 | */ 6 | 7 | public abstract class EthBlock { 8 | public String jsonrpc; 9 | public int id; 10 | 11 | public abstract T parse(String json); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/been/EthTransaction.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth.been; 2 | 3 | import com.google.gson.Gson; 4 | import com.tdp.blockexplorer.been.Transaction; 5 | 6 | 7 | /** 8 | * Created by LPC43 on 2018/4/12. 9 | */ 10 | public class EthTransaction extends EthBlock { 11 | // 解析 转换 12 | public ResultEntity result; 13 | 14 | @Override 15 | public Transaction parse(String json) { 16 | //Eth的type 17 | EthTransaction ethTransaction = new Gson().fromJson(json, EthTransaction.class); 18 | //转换 19 | Transaction transaction = new Transaction(); 20 | transaction.blockHash = ethTransaction.result.blockHash; 21 | transaction.from = ethTransaction.result.from; 22 | transaction.to = ethTransaction.result.to; 23 | transaction.blockNumber = ethTransaction.result.blockNumber; 24 | transaction.gas = ethTransaction.result.gas; 25 | transaction.gasPrice = ethTransaction.result.gasPrice; 26 | transaction.hash = ethTransaction.result.hash; 27 | transaction.input = ethTransaction.result.input; 28 | transaction.nonce = ethTransaction.result.nonce; 29 | transaction.value = ethTransaction.result.value; 30 | return transaction; 31 | } 32 | 33 | 34 | public class ResultEntity { 35 | public String blockHash; 36 | public String blockNumber; 37 | public String from; 38 | public String gas; 39 | public String gasPrice; 40 | public String hash; 41 | public String input; 42 | public String nonce; 43 | public String to; 44 | public String transactionIndex; 45 | public String value; 46 | public String v; 47 | public String r; 48 | public String s; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/been/EthTransactionInfo.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth.been; 2 | 3 | import com.google.gson.Gson; 4 | import com.tdp.blockexplorer.been.Transaction; 5 | 6 | 7 | /** 8 | * Created by LPC43 on 2018/4/12. 9 | */ 10 | //EthScan API 11 | public class EthTransactionInfo extends EthBlock{ 12 | 13 | // 解析 转换 14 | public ResultEntity result; 15 | 16 | @Override 17 | public Transaction parse(String json) { 18 | //Eth的type 19 | EthTransactionInfo ethTransaction = new Gson().fromJson(json, EthTransactionInfo.class); 20 | //转换 21 | Transaction transaction = new Transaction(); 22 | if(ethTransaction.result ==null) 23 | return transaction; 24 | transaction.blockHash = null==ethTransaction.result.blockHash?"":ethTransaction.result.blockHash;//示例 25 | transaction.from = ethTransaction.result.from;//示例 26 | transaction.to = ethTransaction.result.to;//示例 27 | return transaction; 28 | } 29 | 30 | public class ResultEntity { 31 | 32 | public String blockNumber; 33 | public String timeStamp; 34 | public String hash; 35 | public String nonce; 36 | public String blockHash; 37 | public String transactionIndex; 38 | public String from; 39 | public String to; 40 | public String value; 41 | public String gas; 42 | public String gasPrice; 43 | public String isError; 44 | public String txreceipt_status; 45 | public String input; 46 | public String contractAddress; 47 | public String cumulativeGasUsed; 48 | public String gasUsed; 49 | public String confirmations; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/eth/been/EthTransactionInfoList.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.eth.been; 2 | 3 | import com.google.gson.Gson; 4 | import com.tdp.blockexplorer.been.BaseBlock; 5 | import com.tdp.blockexplorer.been.Transaction; 6 | import com.tdp.blockexplorer.been.TransactionList; 7 | import com.tdp.blockexplorer.blockchain.BlockType; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | 13 | /** 14 | * Created by LPC43 on 2018/4/12. 15 | */ 16 | 17 | public class EthTransactionInfoList extends EthBlock{ 18 | 19 | public String status; 20 | public String message; 21 | public List result; 22 | 23 | @Override 24 | public TransactionList parse(String json) { 25 | 26 | EthTransactionInfoList ethTransactionInfoList = new Gson().fromJson(json, EthTransactionInfoList.class); 27 | //转换 28 | TransactionList transactionList = new TransactionList(); 29 | transactionList.result = new ArrayList<>(); 30 | for(EthTransactionInfo.ResultEntity info : ethTransactionInfoList.result){ 31 | 32 | Transaction transaction = new Transaction(); 33 | transaction.hash = info.hash; 34 | transaction.blockHash = null==info.blockHash?"":info.blockHash; 35 | transaction.from = info.from;//示例 36 | transaction.to = info.to;//示例 37 | transaction.blockNumber = info.blockNumber; 38 | transaction.timestamp = info.timeStamp; 39 | transaction.value = info.value; 40 | transaction.gasPrice = info.gasPrice; 41 | transaction.gas = info.gas; 42 | transactionList.result.add(transaction); 43 | } 44 | 45 | return transactionList; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ltc/Ltc.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ltc; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockError; 5 | 6 | import org.xutils.common.Callback; 7 | import org.xutils.common.util.LogUtil; 8 | import org.xutils.http.RequestParams; 9 | import org.xutils.x; 10 | 11 | /** 12 | * Created by wulijie on 2018/4/13. 13 | */ 14 | public class Ltc { 15 | public void get(RequestParams params, final BlockCallback callback) { 16 | x.http().get(params, new Callback.CommonCallback() { 17 | @Override 18 | public void onSuccess(String result) { 19 | LogUtil.e("LTC onSuccess =" + result); 20 | callback.onSuccess(result); 21 | } 22 | 23 | @Override 24 | public void onError(Throwable ex, boolean isOnCallback) { 25 | LogUtil.e("LTC onError =" + ex.toString()); 26 | BlockError error = new BlockError(); 27 | error.error = ex.toString(); 28 | callback.onError(error); 29 | } 30 | 31 | @Override 32 | public void onCancelled(CancelledException cex) { 33 | 34 | } 35 | 36 | @Override 37 | public void onFinished() { 38 | 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ltc/LtcBlockExplorer.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ltc; 2 | 3 | import com.tdp.blockexplorer.blockchain.BlockCallback; 4 | import com.tdp.blockexplorer.blockchain.BlockExplorer; 5 | 6 | import org.xutils.http.RequestParams; 7 | 8 | /** 9 | * Created by wulijie on 2018/4/13. 10 | * 莱特币 11 | */ 12 | public class LtcBlockExplorer extends Ltc implements BlockExplorer { 13 | @Override 14 | public void getTransactionByHash(String hash, BlockCallback callback) { 15 | String url = LtcConf.url.replace("{address}", hash); 16 | RequestParams params = new RequestParams(url); 17 | get(params, callback); 18 | } 19 | 20 | @Override 21 | public void getBalance(String address, BlockCallback callback) { 22 | 23 | } 24 | 25 | @Override 26 | public void getTransactionCount(String address, BlockCallback callback) { 27 | 28 | } 29 | 30 | @Override 31 | public void getBlockByHash(String hash, BlockCallback callback) { 32 | 33 | } 34 | 35 | @Override 36 | public void getTransactionsByAddress(String address, int page, BlockCallback callback) { 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ltc/LtcConf.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ltc; 2 | 3 | /** 4 | * Created by wulijie on 2018/4/13. 5 | */ 6 | 7 | public interface LtcConf { 8 | //搜索地址 9 | String url = "http://www.qukuai.com/search/zh-CN/LTC/{address}/1"; 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/tool/AppLoading.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.tool; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.widget.TextView; 6 | 7 | import com.tdp.blockexplorer.R; 8 | 9 | 10 | /** 11 | * Created by wulijie on 2018/1/12. 12 | */ 13 | public class AppLoading extends Dialog { 14 | private TextView mTips; 15 | 16 | private Context mContext; 17 | 18 | private boolean isCancel; 19 | 20 | public AppLoading(Context context) { 21 | super(context, R.style.AppLoadingStyle); 22 | mContext = context; 23 | this.isCancel = true; 24 | setCancelable(isCancel); 25 | init(); 26 | } 27 | 28 | 29 | public AppLoading(Context context, boolean isCancel, int resId) { 30 | super(context, R.style.AppLoadingStyle); 31 | mContext = context; 32 | init(); 33 | setCancelable(isCancel); 34 | this.isCancel = isCancel; 35 | setTips(resId); 36 | } 37 | 38 | public AppLoading(Context context, int theme) { 39 | super(context, R.style.AppLoadingStyle); 40 | mContext = context; 41 | init(); 42 | } 43 | 44 | //设置提示文字 45 | public void setTips(int resId) { 46 | String tip = mContext.getResources().getString(resId); 47 | setTips(tip); 48 | } 49 | 50 | //设置提示文字 51 | public void setTips(String str) { 52 | mTips.setText(str); 53 | } 54 | 55 | @Override 56 | public void onBackPressed() { 57 | // if (isCancel) { 58 | // if (mContext instanceof Activity) { 59 | // Activity act = (Activity) mContext; 60 | // act.finish(); 61 | // } 62 | // return; 63 | // } 64 | super.onBackPressed(); 65 | } 66 | 67 | /** 68 | * 初始化 69 | **/ 70 | protected void init() { 71 | setContentView(R.layout.dialog_loading); 72 | mTips = (TextView) findViewById(R.id.loading_tips); 73 | } 74 | 75 | /** 76 | * show dialog with the tips 77 | * 78 | * @param tips 79 | * @return 80 | */ 81 | public AppLoading show(String tips) { 82 | setTips(tips); 83 | show(); 84 | return this; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/tool/BlockTool.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.tool; 2 | 3 | import android.text.Html; 4 | import android.text.Spanned; 5 | import android.text.TextUtils; 6 | 7 | import com.tdp.blockexplorer.blockchain.Tdp; 8 | 9 | import org.xutils.common.util.LogUtil; 10 | 11 | import java.math.BigDecimal; 12 | import java.math.BigInteger; 13 | import java.text.SimpleDateFormat; 14 | import java.util.Date; 15 | import java.util.Locale; 16 | 17 | /** 18 | * Created by wulijie on 2018/4/12. 19 | */ 20 | 21 | public class BlockTool { 22 | /** 23 | * 时间戳转为正常日期 24 | * d 25 | * 26 | * @return 27 | */ 28 | public static String timestampToDate(long timestamp) { 29 | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date(timestamp * 1000)); 30 | } 31 | 32 | /** 33 | * 解析Eth wei转换为eth的数量转换 34 | * 35 | * @param ethNum 36 | * @return 37 | */ 38 | public static String parseEth(String ethNum) { 39 | ethNum = ethNum.substring(2); 40 | BigInteger bigInteger = new BigInteger(ethNum, 16); 41 | BigDecimal bigDecimal = new BigDecimal(bigInteger); 42 | LogUtil.e("wei=" + bigInteger.toString(10)); 43 | BigDecimal result = bigDecimal.divide(new BigDecimal("1000000000000000000")); 44 | return result.toString(); 45 | } 46 | 47 | public static String parseEth2(String ethNum) { 48 | BigDecimal bigDecimal = new BigDecimal(ethNum); 49 | BigDecimal result = bigDecimal.divide(new BigDecimal("1000000000000000000")); 50 | return result.toString(); 51 | } 52 | 53 | public static String parseBtc(String btcNum) { 54 | if(TextUtils.isEmpty(btcNum)) 55 | return ""; 56 | BigDecimal bigDecimal = new BigDecimal(btcNum); 57 | BigDecimal result = bigDecimal.divide(new BigDecimal("100000000")); 58 | return result.toString().concat(""); 59 | } 60 | 61 | /** 62 | * 获取货币单位 63 | * 64 | * @return 65 | */ 66 | public static String getUnit() { 67 | switch (Tdp.blockType) { 68 | case BTC: 69 | return " BTC"; 70 | case ETH: 71 | return " ETH"; 72 | case BCH: 73 | return " BCH"; 74 | default: 75 | return ""; 76 | } 77 | } 78 | 79 | 80 | 81 | private void set(){ 82 | CharSequence charSequence; 83 | String content = "

简介:

1.nickname:wildma!

2.职业:android攻城狮

"; 84 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { 85 | charSequence = Html.fromHtml(content,Html.FROM_HTML_MODE_LEGACY); 86 | } else { 87 | charSequence = Html.fromHtml(content); 88 | } 89 | } 90 | 91 | /** 92 | * 字体颜色突出显示 93 | * @param before 94 | * 前缀字符串 95 | * @param color 96 | * 要突出字符串颜色值 97 | * @param text 98 | * 要突出的字符串 99 | * @param after 100 | * 后缀字符串 101 | * @return 处理后字符串 102 | */ 103 | public static Spanned fromHtml(String before, String color, String text, String after) { 104 | String[] strs = null; 105 | if (after.contains("\n")) { 106 | strs = null; 107 | strs = after.split("\n"); 108 | } 109 | StringBuffer strB = new StringBuffer(); 110 | if (strs != null && strs.length > 0) { 111 | for (int i = 0; i < strs.length; i++) { 112 | strB.append(strs[i]); 113 | if (i != strs.length - 1) { 114 | strB.append("
"); 115 | } 116 | } 117 | } else { 118 | strB.append(after); 119 | } 120 | return Html.fromHtml(before + "" + text + "" + strB.toString()); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ui/ExplorerActivity.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ui; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.text.TextUtils; 7 | import android.view.Gravity; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.AdapterView; 11 | import android.widget.ArrayAdapter; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.LinearLayout; 15 | import android.widget.ListPopupWindow; 16 | import android.widget.TextView; 17 | import android.widget.Toast; 18 | 19 | import com.tdp.blockexplorer.Conf; 20 | import com.tdp.blockexplorer.R; 21 | import com.tdp.blockexplorer.base.BaseActivity; 22 | import com.tdp.blockexplorer.blockchain.Tdp; 23 | 24 | import org.xutils.view.annotation.ContentView; 25 | import org.xutils.view.annotation.ViewInject; 26 | 27 | /** 28 | * Created by LPC43 on 2018/4/11. 29 | */ 30 | @ContentView(R.layout.activity_explorer) 31 | public class ExplorerActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener { 32 | 33 | @ViewInject(R.id.tv_type) 34 | private TextView tv_type; 35 | @ViewInject(R.id.btn_search) 36 | private Button btn_search; 37 | @ViewInject(R.id.et_hash) 38 | private EditText et_address; 39 | 40 | private ListPopupWindow mPopup; 41 | 42 | @Override 43 | protected void onCreate(@Nullable Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | initView(); 46 | 47 | } 48 | 49 | @Override 50 | protected void onResume() { 51 | super.onResume(); 52 | tv_type.setText(Tdp.blockType + ""); 53 | 54 | } 55 | 56 | private void initView() { 57 | tv_type.setOnClickListener(this); 58 | btn_search.setOnClickListener(this); 59 | 60 | mPopup = new ListPopupWindow(this); 61 | ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes); 62 | mPopup.setAdapter(adapter); 63 | mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); 64 | mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); 65 | mPopup.setModal(true); 66 | mPopup.setOnItemClickListener(this); 67 | } 68 | 69 | 70 | @Override 71 | public void onClick(View v) { 72 | switch (v.getId()) { 73 | case R.id.tv_type: 74 | mPopup.setAnchorView(tv_type); 75 | mPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); 76 | mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 77 | mPopup.setModal(true); 78 | mPopup.setDropDownGravity(Gravity.START | Gravity.BOTTOM); 79 | mPopup.show(); 80 | break; 81 | case R.id.btn_search: 82 | 83 | String transactionHash = et_address.getText().toString(); 84 | if (TextUtils.isEmpty(transactionHash)) { 85 | Toast.makeText(this, "请输入交易哈希", Toast.LENGTH_LONG).show(); 86 | return; 87 | } 88 | Intent intent = new Intent(this, TransactionDetailActivity.class); 89 | intent.putExtra("transactionHash", transactionHash); 90 | startActivity(intent); 91 | break; 92 | } 93 | } 94 | 95 | @Override 96 | public void onItemClick(AdapterView parent, View view, int position, long id) { 97 | Tdp.blockType = Tdp.blockTypes[position]; 98 | tv_type.setText(Tdp.blockTypes[position] + ""); 99 | test(); 100 | mPopup.dismiss(); 101 | } 102 | 103 | private void test() { 104 | if (!Conf.isDebug) return; 105 | switch (Tdp.blockType) { 106 | case BTC: 107 | et_address.setText(Conf.test_btc_tx); 108 | break; 109 | case ETH: 110 | et_address.setText(Conf.test_eth_tx); 111 | break; 112 | case BCH: 113 | et_address.setText(Conf.test_bch_tx); 114 | break; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ui; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.util.Base64; 7 | import android.view.animation.AlphaAnimation; 8 | import android.view.animation.Animation; 9 | 10 | import com.tdp.blockexplorer.R; 11 | import com.tdp.blockexplorer.base.BaseActivity; 12 | import android.view.View; 13 | 14 | public class MainActivity extends BaseActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | View root = findViewById(R.id.root); 21 | AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); 22 | alphaAnimation.setDuration(2000); 23 | alphaAnimation.setFillAfter(true); 24 | alphaAnimation.setAnimationListener(new Animation.AnimationListener() { 25 | @Override 26 | public void onAnimationStart(Animation animation) { 27 | 28 | } 29 | 30 | @Override 31 | public void onAnimationEnd(Animation animation) { 32 | startActivity(new Intent(MainActivity.this, ExplorerActivity.class)); 33 | finish(); 34 | } 35 | 36 | @Override 37 | public void onAnimationRepeat(Animation animation) { 38 | 39 | } 40 | }); 41 | root.startAnimation(alphaAnimation); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ui/TransactionDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ui; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.text.Spanned; 7 | import android.text.TextUtils; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.AdapterView; 12 | import android.widget.ArrayAdapter; 13 | import android.widget.Button; 14 | import android.widget.EditText; 15 | import android.widget.LinearLayout; 16 | import android.widget.ListPopupWindow; 17 | import android.widget.RelativeLayout; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.tdp.blockexplorer.R; 22 | import com.tdp.blockexplorer.base.BaseActivity; 23 | import com.tdp.blockexplorer.been.TdpBlock; 24 | import com.tdp.blockexplorer.been.Transaction; 25 | import com.tdp.blockexplorer.blockchain.BlockCallback; 26 | import com.tdp.blockexplorer.blockchain.BlockError; 27 | import com.tdp.blockexplorer.blockchain.BlockType; 28 | import com.tdp.blockexplorer.blockchain.Tdp; 29 | import com.tdp.blockexplorer.tool.AppLoading; 30 | import com.tdp.blockexplorer.tool.BlockTool; 31 | 32 | import org.xutils.common.util.LogUtil; 33 | import org.xutils.view.annotation.ContentView; 34 | import org.xutils.view.annotation.ViewInject; 35 | 36 | import java.math.BigInteger; 37 | import java.util.List; 38 | 39 | /** 40 | * Created by LPC43 on 2018/4/12. 41 | */ 42 | 43 | @ContentView(R.layout.activity_transaction_detail) 44 | public class TransactionDetailActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener { 45 | 46 | @ViewInject(R.id.layout_empty) 47 | private RelativeLayout layout_empty; 48 | @ViewInject(R.id.tv_type) 49 | private TextView tv_type; 50 | @ViewInject(R.id.btn_search) 51 | private Button btn_search; 52 | @ViewInject(R.id.tv_hash) 53 | private TextView tv_hash; 54 | @ViewInject(R.id.tv_from) 55 | private TextView tv_from; 56 | @ViewInject(R.id.tv_to) 57 | private TextView tv_to; 58 | @ViewInject(R.id.ethNum) 59 | private TextView ethNum; 60 | @ViewInject(R.id.tv_time) 61 | private TextView tv_time; 62 | @ViewInject(R.id.tv_number) 63 | private TextView tv_number; 64 | @ViewInject(R.id.tv_gasPrice) 65 | private TextView tv_gasPrice; 66 | @ViewInject(R.id.tv_count) 67 | private TextView tv_count;//暂时没有用 68 | @ViewInject(R.id.et_hash) 69 | private EditText et_hash; 70 | @ViewInject(R.id.tvTipTx) 71 | private TextView tvTipTx; 72 | @ViewInject(R.id.txCountRl) 73 | private RelativeLayout txCountRl; 74 | @ViewInject(R.id.ll_from) 75 | private LinearLayout ll_from; 76 | @ViewInject(R.id.ll_to) 77 | private LinearLayout ll_to; 78 | @ViewInject(R.id.valueOutRl) 79 | private View valueOutRl; 80 | @ViewInject(R.id.ethOutNum) 81 | private TextView ethOutNum; 82 | @ViewInject(R.id.tv_tag) 83 | private TextView tv_tag; 84 | 85 | private String transactionHash = ""; 86 | private Transaction transaction; 87 | private ListPopupWindow mPopup; 88 | private Spanned spanned; 89 | private AppLoading loading; 90 | 91 | @Override 92 | protected void onCreate(@Nullable Bundle savedInstanceState) { 93 | super.onCreate(savedInstanceState); 94 | init(); 95 | } 96 | 97 | private void init() { 98 | 99 | loading = new AppLoading(this, false, R.string.loading); 100 | tv_type.setText(Tdp.blockType + ""); 101 | tv_type.setOnClickListener(this); 102 | btn_search.setOnClickListener(this); 103 | tv_tag.setVisibility(View.VISIBLE); 104 | et_hash.setHint("请输入交易Hash"); 105 | 106 | mPopup = new ListPopupWindow(this); 107 | ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes); 108 | mPopup.setAdapter(adapter); 109 | mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); 110 | mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); 111 | mPopup.setModal(true); 112 | mPopup.setOnItemClickListener(this); 113 | 114 | tv_to.setOnClickListener(this); 115 | tv_from.setOnClickListener(this); 116 | transactionHash = ""; 117 | if (getIntent() != null && getIntent().hasExtra("transactionHash")) { 118 | transactionHash = getIntent().getStringExtra("transactionHash"); 119 | searchRequest(transactionHash); 120 | } 121 | } 122 | 123 | private void setView(Transaction transaction) { 124 | tv_hash.setText(transaction.hash); 125 | tv_tag.setVisibility(View.VISIBLE); 126 | //依据不同类型进行展示 127 | switch (Tdp.blockType) { 128 | case ETH: 129 | tv_from.setVisibility(View.VISIBLE); 130 | tv_to.setVisibility(View.VISIBLE); 131 | ll_from.setVisibility(View.GONE); 132 | ll_to.setVisibility(View.GONE); 133 | tv_from.setText(transaction.from); 134 | tv_to.setText(transaction.to); 135 | String eth = BlockTool.parseEth(transaction.value); 136 | spanned = BlockTool.fromHtml(eth, "#999999",BlockTool.getUnit(),""); 137 | ethNum.setText(spanned); 138 | tv_number.setText(Long.decode(transaction.blockNumber) + ""); 139 | //烦死了 这大数计算 140 | BigInteger gas = new BigInteger(transaction.gas.substring(2), 16); 141 | BigInteger gasPrice = new BigInteger(transaction.gasPrice.substring(2), 16); 142 | BigInteger result = gas.multiply(gasPrice); 143 | String price = BlockTool.parseEth("0x" + result.toString(16)); 144 | spanned = BlockTool.fromHtml(price, "#999999",BlockTool.getUnit(),""); 145 | tv_gasPrice.setText(spanned); 146 | break; 147 | case BTC: 148 | valueOutRl.setVisibility(View.VISIBLE); 149 | tv_from.setVisibility(View.GONE); 150 | tv_to.setVisibility(View.GONE); 151 | ll_from.setVisibility(View.VISIBLE); 152 | ll_to.setVisibility(View.VISIBLE); 153 | tvTipTx.setText("输入数量"); 154 | txCountRl.setVisibility(View.VISIBLE); 155 | tv_number.setText(transaction.blockNumber); 156 | String value = transaction.valueIn; 157 | String vOut = transaction.valueOut; 158 | if (TextUtils.isEmpty(value)) value = "0.00000000"; 159 | if (TextUtils.isEmpty(vOut)) vOut = "0.00000000"; 160 | spanned = BlockTool.fromHtml(value, "#999999",BlockTool.getUnit(),""); 161 | ethNum.setText(spanned); 162 | spanned = BlockTool.fromHtml(vOut, "#999999",BlockTool.getUnit(),""); 163 | ethOutNum.setText(spanned); 164 | 165 | String fees = transaction.fees; 166 | if (TextUtils.isEmpty(fees)) fees = "0.00000000"; 167 | spanned = BlockTool.fromHtml(fees, "#999999",BlockTool.getUnit(),""); 168 | tv_gasPrice.setText(spanned); 169 | int size = Integer.parseInt(transaction.size); 170 | spanned = BlockTool.fromHtml((size / 1000d)+"", "#999999"," KB",""); 171 | tv_count.setText(spanned);//交易大小 172 | long timestamp = Long.decode(transaction.timestamp); 173 | String time = BlockTool.timestampToDate(timestamp); 174 | tv_time.setText(time); 175 | // addView 176 | addView(ll_from, transaction.fromList); 177 | addView(ll_to, transaction.toList); 178 | break; 179 | case BCH: 180 | valueOutRl.setVisibility(View.VISIBLE); 181 | tv_from.setVisibility(View.GONE); 182 | tv_to.setVisibility(View.GONE); 183 | ll_from.setVisibility(View.VISIBLE); 184 | ll_to.setVisibility(View.VISIBLE); 185 | tvTipTx.setText("输入数量"); 186 | txCountRl.setVisibility(View.VISIBLE); 187 | tv_number.setText(transaction.blockNumber); 188 | String bchVin = transaction.valueIn; 189 | String bchVout = transaction.valueOut; 190 | if (TextUtils.isEmpty(bchVin)) bchVin = "0.00000000"; 191 | if (TextUtils.isEmpty(bchVout)) bchVout = "0.00000000"; 192 | spanned = BlockTool.fromHtml(bchVin, "#999999",BlockTool.getUnit(),""); 193 | ethNum.setText(spanned); 194 | spanned = BlockTool.fromHtml(bchVout, "#999999",BlockTool.getUnit(),""); 195 | ethOutNum.setText(spanned); 196 | 197 | String bchFees = transaction.fees; 198 | if (TextUtils.isEmpty(bchFees) && transaction.isCoinBase) bchFees = "0.00000000"; 199 | spanned = BlockTool.fromHtml(bchFees, "#999999",BlockTool.getUnit(),""); 200 | tv_gasPrice.setText(spanned); 201 | spanned = BlockTool.fromHtml((Integer.parseInt(transaction.size) / 1000d)+"", "#999999"," KB",""); 202 | tv_count.setText(spanned);//交易大小 203 | tv_time.setText(BlockTool.timestampToDate(Long.decode(transaction.timestamp))); 204 | // addView 205 | addView(ll_from, transaction.fromList); 206 | addView(ll_to, transaction.toList); 207 | break; 208 | } 209 | 210 | } 211 | 212 | 213 | private void addView(LinearLayout parent, List list) { 214 | if (list == null || list.size() == 0) return; 215 | for (String str : list) { 216 | if (TextUtils.isEmpty(str)) { 217 | View coinBase = View.inflate(this, R.layout.tx_coinbase, null); 218 | parent.addView(coinBase); 219 | return; 220 | } 221 | String[] addressValue = str.split(","); 222 | if (addressValue != null && addressValue.length != 0) { 223 | final String address = addressValue[0]; 224 | View item = View.inflate(this, R.layout.tx_item, null); 225 | TextView tv_address = (TextView) item.findViewById(R.id.tv_address); 226 | TextView tv_value = (TextView) item.findViewById(R.id.tv_value); 227 | tv_address.setText(address); 228 | tv_value.setText(addressValue[1] + BlockTool.getUnit()); 229 | parent.addView(item); 230 | tv_address.setOnClickListener(new View.OnClickListener() { 231 | @Override 232 | public void onClick(View v) { 233 | Intent intent = new Intent(TransactionDetailActivity.this, TransactionListActivity.class); 234 | intent.putExtra("address", address); 235 | startActivity(intent); 236 | finish(); 237 | } 238 | }); 239 | } 240 | } 241 | } 242 | 243 | 244 | private void searchRequest(String transactionHash) { 245 | loading.show("数据查询中,请稍后…"); 246 | Tdp.get(Tdp.blockType).getTransactionByHash(transactionHash, new BlockCallback() { 247 | @Override 248 | public void onSuccess(String result) { 249 | if (loading != null && loading.isShowing()) loading.dismiss(); 250 | layout_empty.setVisibility(View.GONE); 251 | transaction = new Transaction().parse(Tdp.blockType, 0, result); 252 | setView(transaction); 253 | getBlock(transaction); 254 | 255 | } 256 | 257 | @Override 258 | public void onError(BlockError error) { 259 | if (loading != null && loading.isShowing()) loading.dismiss(); 260 | layout_empty.setVisibility(View.VISIBLE); 261 | } 262 | }); 263 | } 264 | 265 | private void getBlock(final Transaction transaction) { 266 | if (Tdp.blockType != BlockType.ETH) return;//只有以太坊需要获取block块 目前 267 | Tdp.get(Tdp.blockType).getBlockByHash(transaction.blockHash, new BlockCallback() { 268 | @Override 269 | public void onSuccess(String result) { 270 | TdpBlock block = new TdpBlock().parse(Tdp.blockType, result); 271 | transaction.timestamp = block.timestamp; 272 | long timestamp = Long.decode(transaction.timestamp); 273 | String time = BlockTool.timestampToDate(timestamp); 274 | tv_time.setText(time); 275 | BigInteger difficulty = new BigInteger(block.difficulty.substring(2), 16); 276 | LogUtil.e("d =" + difficulty.toString(10)); 277 | BigInteger totalDifficulty = new BigInteger(block.totalDifficulty.substring(2), 16); 278 | LogUtil.e("d =" + totalDifficulty.toString(10)); 279 | LogUtil.e("dive" + totalDifficulty.divide(difficulty).toString(10)); 280 | } 281 | 282 | @Override 283 | public void onError(BlockError error) { 284 | 285 | } 286 | }); 287 | } 288 | 289 | @Override 290 | public void onClick(View v) { 291 | switch (v.getId()) { 292 | case R.id.tv_from: 293 | 294 | Intent intent = new Intent(this, TransactionListActivity.class); 295 | intent.putExtra("address", tv_from.getText().toString()); 296 | startActivity(intent); 297 | finish(); 298 | break; 299 | case R.id.tv_to: 300 | Intent intent1 = new Intent(this, TransactionListActivity.class); 301 | intent1.putExtra("address", tv_to.getText().toString()); 302 | startActivity(intent1); 303 | finish(); 304 | break; 305 | case R.id.btn_search: 306 | 307 | String hash = et_hash.getText().toString(); 308 | if (TextUtils.isEmpty(hash)) { 309 | Toast.makeText(this, "请输入交易Hash值", Toast.LENGTH_LONG).show(); 310 | return; 311 | } 312 | transactionHash = hash; 313 | searchRequest(transactionHash); 314 | break; 315 | case R.id.tv_type: 316 | 317 | mPopup.setAnchorView(tv_type); 318 | mPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); 319 | mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 320 | mPopup.setModal(true); 321 | mPopup.setDropDownGravity(Gravity.START | Gravity.BOTTOM); 322 | mPopup.show(); 323 | break; 324 | } 325 | } 326 | 327 | @Override 328 | public void onItemClick(AdapterView parent, View view, int position, long id) { 329 | Tdp.blockType = Tdp.blockTypes[position]; 330 | tv_type.setText(Tdp.blockTypes[position] + ""); 331 | mPopup.dismiss(); 332 | } 333 | 334 | @Override 335 | protected void onDestroy() { 336 | super.onDestroy(); 337 | if (loading != null && loading.isShowing()) loading.dismiss(); 338 | } 339 | } 340 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/ui/TransactionListActivity.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.ui; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.widget.SwipeRefreshLayout; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.Gravity; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.AdapterView; 14 | import android.widget.ArrayAdapter; 15 | import android.widget.EditText; 16 | import android.widget.LinearLayout; 17 | import android.widget.ListPopupWindow; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.tdp.blockexplorer.R; 22 | import com.tdp.blockexplorer.adapter.TransactionAdapter; 23 | import com.tdp.blockexplorer.base.BaseActivity; 24 | import com.tdp.blockexplorer.been.Transaction; 25 | import com.tdp.blockexplorer.been.TransactionList; 26 | import com.tdp.blockexplorer.blockchain.BlockCallback; 27 | import com.tdp.blockexplorer.blockchain.BlockError; 28 | import com.tdp.blockexplorer.blockchain.BlockType; 29 | import com.tdp.blockexplorer.blockchain.Tdp; 30 | import com.tdp.blockexplorer.btc.BtcBlockExplorer; 31 | import com.tdp.blockexplorer.btc.been.BchTransactionList; 32 | import com.tdp.blockexplorer.btc.been.BtcTransactionList; 33 | import com.tdp.blockexplorer.eth.been.EthTransactionInfoList; 34 | import com.tdp.blockexplorer.tool.AppLoading; 35 | import com.tdp.blockexplorer.view.LoadMoreRecycleView; 36 | 37 | import org.json.JSONObject; 38 | import org.xutils.view.annotation.ContentView; 39 | import org.xutils.view.annotation.ViewInject; 40 | 41 | import java.util.ArrayList; 42 | import java.util.List; 43 | 44 | /** 45 | * Created by LPC43 on 2018/4/12. 46 | */ 47 | 48 | @ContentView(R.layout.activity_transaction_list) 49 | public class TransactionListActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, 50 | AdapterView.OnItemClickListener { 51 | 52 | @ViewInject(R.id.refreshLayout) 53 | private SwipeRefreshLayout refreshLayout; 54 | @ViewInject(R.id.recyclerView) 55 | private LoadMoreRecycleView recyclerView; 56 | private TransactionAdapter mAdapter; 57 | private TextView tv_type; 58 | 59 | private String address = ""; 60 | private String balance = ""; 61 | private String transaction_count = ""; 62 | private int pageNum = 0; 63 | List transactionList = new ArrayList<>(); 64 | private ListPopupWindow mPopup; 65 | private AppLoading loading; 66 | private BlockType searchBlockType; 67 | 68 | @Override 69 | protected void onCreate(@Nullable Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | 72 | initView(); 73 | initData(); 74 | } 75 | 76 | private void initView() { 77 | loading = new AppLoading(this, false, R.string.loading); 78 | mPopup = new ListPopupWindow(this); 79 | ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes); 80 | mPopup.setAdapter(adapter); 81 | mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); 82 | mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); 83 | mPopup.setModal(true); 84 | mPopup.setOnItemClickListener(this); 85 | 86 | refreshLayout.setOnRefreshListener(this); 87 | LinearLayoutManager mLayoutManager = new LinearLayoutManager(recyclerView.getContext()); 88 | mAdapter = new TransactionAdapter(this, Tdp.blockType); 89 | tv_type = mAdapter.getTypeTextView(); 90 | mAdapter.setOnClickListener(this); 91 | recyclerView.setLayoutManager(mLayoutManager); 92 | recyclerView.setAdapter(mAdapter); 93 | recyclerView.setOnLoadMoreListener(mLayoutManager, mAdapter, new LoadMoreRecycleView.OnLoadMoreListener() { 94 | @Override 95 | public void loadMore() { 96 | if (mAdapter.isHasMore()) { 97 | loadData(); 98 | } 99 | } 100 | }); 101 | 102 | } 103 | 104 | private void initData() { 105 | 106 | address = ""; 107 | pageNum = 0; 108 | searchBlockType = Tdp.blockType; 109 | if (getIntent() != null && getIntent().hasExtra("address")) { 110 | address = getIntent().getStringExtra("address"); 111 | initRequest(); 112 | } 113 | } 114 | 115 | private void reloadData() { 116 | pageNum = 0; 117 | Tdp.blockType = searchBlockType; 118 | initRequest(); 119 | } 120 | 121 | private void initRequest() { 122 | searchRequest(); 123 | searchBalance(); 124 | searchCount(); 125 | searchReceived(); 126 | searchSent(); 127 | } 128 | 129 | private void loadData() { 130 | pageNum++; 131 | searchRequest(); 132 | } 133 | 134 | @Override 135 | public void onRefresh() { 136 | pageNum = 0; 137 | initRequest(); 138 | } 139 | 140 | @Override 141 | public void onClick(View v) { 142 | switch (v.getId()) { 143 | case R.id.tv_hash: 144 | 145 | String transactionHash = v.getTag().toString(); 146 | Intent intent = new Intent(this, TransactionDetailActivity.class); 147 | intent.putExtra("transactionHash", transactionHash); 148 | startActivity(intent); 149 | finish(); 150 | break; 151 | case R.id.btn_search: 152 | 153 | EditText et_hash = (EditText) v.getTag(); 154 | String transactionAddress = et_hash.getText().toString(); 155 | if (TextUtils.isEmpty(transactionAddress)) { 156 | Toast.makeText(this, "请输入交易地址", Toast.LENGTH_LONG).show(); 157 | return; 158 | } 159 | address = transactionAddress; 160 | reloadData(); 161 | break; 162 | case R.id.tv_type: 163 | 164 | mPopup.setAnchorView(v); 165 | mPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); 166 | mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 167 | mPopup.setModal(true); 168 | mPopup.setDropDownGravity(Gravity.START | Gravity.BOTTOM); 169 | mPopup.show(); 170 | break; 171 | } 172 | } 173 | 174 | private void searchRequest() { 175 | if (pageNum == 0) 176 | loading.show("数据查询中,请稍后…"); 177 | Tdp.get(Tdp.blockType).getTransactionsByAddress(address, pageNum, new BlockCallback() { 178 | @Override 179 | public void onSuccess(String result) { 180 | if (loading != null && loading.isShowing()) loading.dismiss(); 181 | refreshLayout.setRefreshing(false); 182 | recyclerView.setIsLoadingMore(false); 183 | TransactionList transactions = null; 184 | switch (Tdp.blockType) { 185 | case ETH: 186 | transactions = new EthTransactionInfoList().parse(result); 187 | break; 188 | case BTC: 189 | transactions = new BtcTransactionList().parse(result, address); 190 | break; 191 | case BCH: 192 | transactions = new BchTransactionList().parse(result, address); 193 | break; 194 | } 195 | 196 | if (pageNum == 0) 197 | transactionList.clear(); 198 | if (transactions.result != null && transactions.result.size() > 0) { 199 | transactionList.addAll(transactions.result); 200 | mAdapter.setDataList(Tdp.blockType, transactionList, address, transactions.totalItems + ""); 201 | } 202 | mAdapter.notifyDataSetChanged(); 203 | if (transactions.result == null || transactions.result.size() < 10) 204 | mAdapter.setHasMore(false); 205 | else 206 | mAdapter.setHasMore(true); 207 | 208 | } 209 | 210 | @Override 211 | public void onError(BlockError error) { 212 | if (loading != null && loading.isShowing()) loading.dismiss(); 213 | Toast.makeText(TransactionListActivity.this, "查询交易数据失败", Toast.LENGTH_SHORT).show(); 214 | if (pageNum == 0) { 215 | transactionList.clear(); 216 | mAdapter.setHeaderData(Tdp.blockType, "", "", ""); 217 | mAdapter.notifyDataSetChanged(); 218 | } 219 | 220 | } 221 | }); 222 | } 223 | 224 | private void searchBalance() { 225 | Tdp.get(Tdp.blockType).getBalance(address, new BlockCallback() { 226 | @Override 227 | public void onSuccess(String result) { 228 | try { 229 | 230 | switch (Tdp.blockType) { 231 | case ETH: 232 | JSONObject jsonObject = new JSONObject(result); 233 | balance = jsonObject.optString("result"); 234 | break; 235 | case BTC: 236 | case BCH: 237 | balance = result; 238 | break; 239 | } 240 | mAdapter.setHeaderData(Tdp.blockType, address, balance, transaction_count); 241 | } catch (Exception e) { 242 | e.printStackTrace(); 243 | } 244 | } 245 | 246 | @Override 247 | public void onError(BlockError error) { 248 | balance = ""; 249 | mAdapter.setHeaderData(Tdp.blockType, address, balance, transaction_count); 250 | } 251 | }); 252 | } 253 | 254 | private void searchCount() { 255 | 256 | if (Tdp.blockType != BlockType.ETH) 257 | return; 258 | Tdp.get(BlockType.ETH).getTransactionCount(address, new BlockCallback() { 259 | @Override 260 | public void onSuccess(String result) { 261 | try { 262 | JSONObject jsonObject = new JSONObject(result); 263 | transaction_count = jsonObject.optString("result"); 264 | mAdapter.setHeaderData(Tdp.blockType, address, balance, transaction_count); 265 | } catch (Exception e) { 266 | e.printStackTrace(); 267 | } 268 | } 269 | 270 | @Override 271 | public void onError(BlockError error) { 272 | transaction_count = ""; 273 | mAdapter.setHeaderData(Tdp.blockType, address, balance, transaction_count); 274 | 275 | } 276 | }); 277 | } 278 | 279 | //查询BTC转入总量 280 | private void searchReceived() { 281 | 282 | if (Tdp.blockType != BlockType.BTC && Tdp.blockType != BlockType.BCH) 283 | return; 284 | ((BtcBlockExplorer) Tdp.get(Tdp.blockType)).getTransactionTotalReceived(address, new BlockCallback() { 285 | @Override 286 | public void onSuccess(String result) { 287 | try { 288 | mAdapter.setBtcIn(result); 289 | } catch (Exception e) { 290 | e.printStackTrace(); 291 | } 292 | } 293 | 294 | @Override 295 | public void onError(BlockError error) { 296 | mAdapter.setBtcIn(""); 297 | } 298 | }); 299 | } 300 | 301 | //查询BTC转出总量 302 | private void searchSent() { 303 | 304 | if (Tdp.blockType != BlockType.BTC && Tdp.blockType != BlockType.BCH) 305 | return; 306 | ((BtcBlockExplorer) Tdp.get(Tdp.blockType)).getTransactionTotalSent(address, new BlockCallback() { 307 | @Override 308 | public void onSuccess(String result) { 309 | try { 310 | mAdapter.setBtcOut(result); 311 | } catch (Exception e) { 312 | e.printStackTrace(); 313 | } 314 | } 315 | 316 | @Override 317 | public void onError(BlockError error) { 318 | mAdapter.setBtcOut(""); 319 | } 320 | }); 321 | } 322 | 323 | @Override 324 | public void onItemClick(AdapterView parent, View view, int position, long id) { 325 | searchBlockType = Tdp.blockTypes[position]; 326 | if (tv_type == null) 327 | tv_type = mAdapter.getTypeTextView(); 328 | tv_type.setText(Tdp.blockTypes[position] + ""); 329 | mPopup.dismiss(); 330 | } 331 | 332 | @Override 333 | protected void onDestroy() { 334 | super.onDestroy(); 335 | if (loading != null && loading.isShowing()) loading.dismiss(); 336 | } 337 | } 338 | -------------------------------------------------------------------------------- /app/src/main/java/com/tdp/blockexplorer/view/LoadMoreRecycleView.java: -------------------------------------------------------------------------------- 1 | package com.tdp.blockexplorer.view; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | /** 8 | * Created by ninghui on 2016/4/11. 9 | */ 10 | public class LoadMoreRecycleView extends RecyclerView{ 11 | 12 | /** 13 | * 最后一个可见条目的position 14 | */ 15 | private int lastVisibleItem; 16 | /** 17 | * 是否正在执行加载更多标志,防止重复加载 18 | */ 19 | private boolean mIsLoadingMore = false; 20 | private LinearLayoutManager mLayoutManager; 21 | private Adapter mAdapter; 22 | 23 | public LoadMoreRecycleView(Context context) { 24 | super(context); 25 | } 26 | 27 | public LoadMoreRecycleView(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public LoadMoreRecycleView(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | } 34 | 35 | @Override 36 | public void onScrollStateChanged(int state) { 37 | super.onScrollStateChanged(state); 38 | if (!mIsLoadingMore && mOnLoadMoreListener != null && state == RecyclerView.SCROLL_STATE_IDLE && mAdapter != null && lastVisibleItem + 1 == mAdapter.getItemCount()) { 39 | mIsLoadingMore = true; 40 | mOnLoadMoreListener.loadMore(); 41 | } 42 | } 43 | 44 | @Override 45 | public void onScrolled(int dx, int dy) { 46 | super.onScrolled(dx, dy); 47 | if(mLayoutManager!=null){ 48 | lastVisibleItem = mLayoutManager.findLastVisibleItemPosition(); 49 | } 50 | } 51 | 52 | private OnLoadMoreListener mOnLoadMoreListener; 53 | 54 | public interface OnLoadMoreListener { 55 | void loadMore(); 56 | } 57 | 58 | public void setOnLoadMoreListener(LinearLayoutManager mLayoutManager, Adapter mAdapter, OnLoadMoreListener mOnLoadMoreListener) { 59 | this.mOnLoadMoreListener = mOnLoadMoreListener; 60 | this.mLayoutManager = mLayoutManager; 61 | this.mAdapter = mAdapter; 62 | } 63 | 64 | public void setIsLoadingMore(boolean isLoadingMore) { 65 | this.mIsLoadingMore = isLoadingMore; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/app_loading_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kumaleap/BlockExplorer/47b08bd0803eb01d74c9cc4cdb1b403dac66587b/app/src/main/res/drawable/app_loading_bg.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_down_arrow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_right_arrow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_explorer_edit_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_list_item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tx_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_tx_coinbase_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_explorer.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 22 | 23 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_transaction_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 12 | 17 | 18 | 19 | 20 | 24 | 25 | 29 | 30 | 39 | 40 | 46 | 54 | 55 | 67 | 68 | 69 | 70 | 74 | 75 | 83 | 84 | 92 | 93 | 94 | 98 | 99 | 108 | 109 | 117 | 118 | 119 | 120 | 126 | 127 | 136 | 137 | 145 | 146 | 147 | 153 | 154 | 162 | 163 | 171 | 172 | 173 | 177 | 178 | 186 | 187 | 195 | 196 | 197 | 201 | 202 | 210 | 211 | 219 | 220 | 221 | 222 | 232 | 233 | 241 | 242 | 243 | 254 | 255 | 256 | 265 | 266 | 273 | 274 | 285 | 286 | 295 | 296 | 297 | 298 | 299 | 309 | 310 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_transaction_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_block_popup_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_bottom_listitem.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 12 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_load_more.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_load_none.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_search.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 23 | 24 | 25 | 39 | 40 |