github.com/shyftnetwork/go-empyrean@v1.8.3-0.20191127201940-fbfca9338f04/shyft_documentation/source/index.html.md (about) 1 --- 2 title: Shyft Block Explorer Documentation 3 4 language_tabs: # must be one of https://git.io/vQNgJ 5 - shell: code 6 7 toc_footers: 8 - <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a> 9 10 includes: 11 - errors 12 13 search: true 14 --- 15 16 # Introduction 17 18 ### A Note From The Developers 19 20 Our goal was to avoid compromising the integrity of Geth and simply extend existing functionality to meet the specific needs of the Shyft Network. To our utmost ability we have documented, within the codebase, exactly where we have extended our functionality using the following notation: NOTE:SHYFT. This document is meant to provide a high level overview of the changes made to Geth and to provide explanations, where needed, on the changes that were made. Another benefit of this document is to allow others to quickly see the changes that were made in order to get quicker feedback on a compromising line of code. 21 22 ### Contributing To Shyft Geth 23 24 In order to successfully accept a PR the maintainers of the Shyft repositories require that this document must be updated, reflecting the changes made in the PR. Along with the documentation, we ask that contributors provide the NOTE:SHYFT. The tag could should contain a brief on the modified code. This will help with releases further down the road as we document what breaking changes have been made along the journey. 25 26 #### Linting 27 In order to successfully have a PR merged into go-empyrean your changes need to pass our TravisCI that runs every PR. One of the builds in Travis tests that you've properly linted your code. 28 The linter we are using is `gometalinter` from the following [repo.](https://github.com/alecthomas/gometalinter) The TravisCI runs the below commands: 29 30 > Gometalinter commands 31 ``` 32 gometalinter ./... --vendor --tests --deadline=2m --disable-all --enable=goimports --enable=varcheck --enable=vet --enable=gofmt --enable=misspell --exclude=core/genesis.go --exclude=eth/handler_test.go --exclude=eth/downloader/api.go --enable=goconst --min-occurrences=6 33 gometalinter --vendor --tests --deadline=10m --disable-all --exclude=ethdb/shyft_database.go --enable=gosimple ./... 34 gometalinter --vendor --tests --deadline=10m --disable-all --enable=unconvert ./... 35 ``` 36 The above commands will indicate which files need to be properly linted. Often its as simple as running the below command: 37 38 `gofmt -w <filename>` 39 40 `goimports -w <filename>` 41 42 However, sometimes you need to simplify parts of your code, for example: 43 ``` 44 A range of the form: 45 for _ = range v {...} 46 will be simplified to: 47 for range v {...} 48 ``` 49 50 Learn more through the official godocs [here.](https://golang.org/cmd/gofmt/) 51 52 # Setup 53 54 ### Dependencies 55 56 - go 1.10 57 - postgres 10 58 59 To install go please review the installation docs [here](https://golang.org/doc/install), but ensure you download version 1.10. If you would like to install go with a script please check out this repo [here](https://github.com/canha/golang-tools-install-script). 60 61 To install postgres please review the installation docs [here](https://www.postgresql.org/docs/10/static/tutorial-install.html). 62 63 To run postgres locally on Ubuntu/Debian follow the below steps: 64 65 - Install postgres [here](https://www.postgresql.org/docs/10/static/tutorial-install.html) 66 - `sudo apt update` 67 - `sudo apt install postgresql` 68 69 ### Govendor and Packages/Dependencies 70 71 > Download Go Vendor 72 73 ```shell 74 go get -u github.com/kardianos/govendor 75 ``` 76 77 > To run govendor globally, have this in your bash_profile file: 78 79 ```shell 80 export GOPATH=$HOME/go 81 export PATH=$PATH:$HOME/go/bin 82 ``` 83 84 > Then go_empyrean will need to be cloned to this directory: 85 86 ```shell 87 $GOPATH/src/github.com/ShyftNetwork/ 88 ``` 89 90 Geth uses govendor to manage packages/dependencies: [Go Vendor](https://github.com/kardianos/govendor) 91 92 This has some more information: [Ethereum Wiki](https://github.com/ShyftNetwork/go-empyrean/wiki/Developers'-Guide) 93 94 To add a new dependency, run govendor fetch <import-path> , and commit the changes to git. Then the deps will be accessible on other machines that pull from git. 95 96 <aside class="notice"> 97 GOPATH is not strictly necessary however, for govendor it is much easier to use gopath as go will look for binaries in this directory ($GOPATH/bin). To set up GOPATH, read the govendor section. 98 </aside> 99 100 ### Running Locally 101 102 To begin running locally, please ensure you have correctly installed go 1.10 and postgres (make sure postgres is running). 103 Once cloned, in a terminal window run the following command: 104 105 Before running any CLI options ensure you run **`make geth`** in the root directory. 106 107 ``.shyft-geth.sh --setup`` This sets up postgres and the shyft chain db 108 109 ``./shyft-geth.sh --start`` This starts GETH 110 111 At this point you should see GETH running in the terminal and if you opened your postgres instance you should see data being populated into the tables. It might look something similiar to the image below. 112 113 <img src="./images/geth.png" alt="Geth example"> 114 115 To stop Geth, **`crtl+C`** in the terminal window, if you proceed with the start script mentioned above the Shyft chain will begin from the last block height, if you wish to start the chain fresh from genesis follow the below steps: 116 117 ``./shyft-geth.sh --reset`` This drops postgres and chaindb data 118 119 ``./shyft-geth.sh --start`` Starts GETH 120 121 If you wish to run ShyftGeth without a postgres instance please follow the below steps: 122 123 - `cd ./shyft-cli` 124 - Open `initShyftGeth.sh` 125 - Add `--disablepg` flag to both the if and else statement, typically in front of the `--keystore` flag 126 - Open `startShyftGeth.sh` 127 - Add `--disablepg` flag to both the if and else statement, typically after the `--ws` flag 128 129 If you've followed the steps above your `initShyftGeth.sh` and `startShyftGeth.sh` should look similiar as below: 130 131 ```shell 132 #!/bin/sh 133 if [ -z "${DBENV}" ]; then 134 ./build/bin/geth --identity "ShyftTestnetNode" --disablepg --keystore ./ --datadir "./shyftData" init ./ShyftNetwork.json 135 else 136 if [ -d /go/src/ShyftNetwork/go-empyrean/shyftData/geth/chaindata ]; then 137 echo "Skipping Genesis Initialization as already completed" 138 : 139 else 140 echo "Initializing Custom Genesis Block" 141 /bin/geth --identity "ShyftTestnetNode" --disablepg --keystore ./ --datadir "./shyftData" init ShyftNetwork.json 142 fi 143 fi 144 ``` 145 146 ``` 147 #!/bin/sh 148 if [ -z "${DBENV}" ]; then 149 ./build/bin/geth --config config.toml --ws --disablepg --wsaddr="0.0.0.0" --wsorigins "*" --nat=any --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt 150 else 151 /bin/geth --config config.toml --gcmode archive --ws --disablepg --wsaddr="0.0.0.0" --wsorigins "*" --nat=any --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt 152 fi 153 ``` 154 155 <aside class="warning"> 156 The above instructions will NOT initialize a postgres instance and will not write data to the postgres instance and thus the API and block explorer UI will not be able to run properly. 157 </aside> 158 159 160 If you are installing postgresql locally for development on Ubuntu the app assumes that no password is set for the postgresql user and that the development user is provided with superuser privildges 161 - if this is not the case you will need to modify the variable `connStrDefault` in `core/db.go` accordingly. Documentation on how to set up a development user are available [here](https://www.postgresql.org/docs/10/static/app-createuser.html) 162 163 `sudo -i -u postgres` 164 165 `creatuser <dev-user> --superuser` 166 167 To see transactions being submitted on the network see the sendTransactions command in the CLI section of this readme. 168 ### Docker Images 169 Two sets of Docker Images are available for ShyftGeth, the Postgresql Database, and the Shyft Blockchain Explorer, which can be used for local development and testnet connection. The development settings are included in docker-compose.yml, the testnet settings are included in docker-compose.production.yml (shyftgeth not mining by default). To launch these containers you will need to have docker-compose installed on your computer. Installation instructions for docker-compose are available [here](https://docs.docker.com/install/). 170 171 **To build the images for the first time please run the following command:** 172 173 `./shyft-geth.sh --setup # clears persisted directories prior to docker build` 174 175 `docker-compose up --build` 176 177 If you would like to reinitialize/rebuild the docker images you can run the above mentioned command as well. 178 179 To launch ShyftGeth, PG, the ShyftBlock Explorer Api and UI anytime after initial build - issue the following commands from the root of the project directory: 180 181 `./shyft-geth.sh --setup # clears persisted directories prior to docker build` 182 183 **`docker-compose up`** 184 185 To stop/pause mining - enter: 186 187 **`docker-compose stop`** 188 189 And then just issue `docker-compose up` to continue mining. 190 ### Docker Postgresql - DB Connection 191 From your local machine you can view the database by connecting to the database in the container at 192 **``127.0.0.1:8001``** 193 194 Use the following credentials: 195 196 ``User: 'postgres'`` 197 198 ``Password: 'docker'`` 199 200 ``Database: 'shyftdb'`` 201 202 ### Docker Block Explorer Api 203 To access the shyftBlockExplorer open a browser and visit 204 205 **``http://localhost:3000``** 206 207 To rebuild any one of the services- issue the following commands: 208 209 Services: 210 211 - go-empyrean_shyftgeth 212 - go-empyrean_pg 213 - go-empyrean_shyft_block_api 214 - go-empyrean_shyft_block_ui 215 216 **`` 217 docker-compose up -d --no-deps --build <docker compose file service name> 218 ``** 219 220 ie. for shyftBlockExplorerApi: 221 222 **``docker-compose up -d --no-deps --build shyft_block_api``** 223 224 The Postgresql Database Container will persist the database data to the directory ``./pg-data`` _. So if you do want to reinitialize the database you should delete this directory as well as the blockchain data directories ``(./shyftData ./privatenet)`` prior to launching the docker containers. There is a shell script available to delete these folders to run it execute the following command: 225 226 **``./shyft-cli/resetShyftGeth.sh``** 227 228 Blockchain data is persisted to **``./ethash/.ethash and ./shyftData__``**. If you would like to reset the test blockchain you will need to delete the **``__./ethash ./shyftData & ./privatenet__``** directories. 229 230 The docker container for the ShyftBlockExplorerApi utilizes govendor to minimize its image size. **If you would like the docker image for this container to reflect any uncommitted changes which may have occurred in the go-empyrean repository, ie. changes with respect to go-empyrean core (ie. cryptographic functions and database). Prior to launching the docker containers you should rebuild the vendor directory for the shyftBlockExplorerApi - by executing the following steps:** 231 232 Remove existing shyftBlockExplorerApi vendor.json and vendored components: 233 234 **``rm -rf shyftBlockExplorerApi/vendor``** 235 236 reinitialize vendor.json 237 238 **``cd shyftBlockExplorerApi && govendor init``** 239 240 rebuild vendor.json using latest uncommitted changes 241 242 **``govendor add +external``** 243 244 Due to a bug in govendor and it not being able to pull in some dependencies that are c-header files 245 you should execute the following commands - see these issues - which whilst closed 246 appears to have not been fixed: https://github.com/kardianos/govendor/issues/124 && https://github.com/kardianos/govendor/issues/61 247 248 **``govendor remove github.com/ShyftNetwork/go-empyrean/crypto/secp256k1/^``** 249 250 **``govendor fetch github.com/ShyftNetwork/go-empyrean/crypto/secp256k1/^``** 251 252 ### Connecting to the Geth Console from Docker 253 254 If you wish to connect to the Geth console while running in docker use the below command: 255 256 **`sudo docker exec -it eedd geth attach http://localhost:8545`** 257 258 <aside class="warning"> 259 The Shyft Geth docker image size is 1+ GB so make sure you have adequate space on your disk drive 260 </aside> 261 262 ### Docker Port TroubleShooting 263 264 Stop/remove all docker containers that may be using conflicting ports - ports for each of the containers shown in the ``docker-compose.yml`` 265 266 To see which ports are being used on your machine you can run the below command in your terminals root directory: 267 268 ``netstat -a`` 269 270 271 # Shyft BlockExplorer API 272 273 In order to store the block explorer database, a custom folder was created `./shyft_schema` that contains the schema for the explorer database. 274 275 The main functions exist in `./core/shyft_database_util.go` and `./core/shyft_get_utils.go` 276 277 To run the block explorer rest api that queries the postgres instance and returns a json body, open a new terminal window, navigate to the root directory of the project and run the following command: 278 279 **``go run blockExplorerApi/*.go``** 280 281 <aside class="warning"> 282 The above command is to only be used if running locally and assumes that the block explorer API is being run from the same server. 283 </aside> 284 285 This will start a go server on port 8080 and allow you to either run the pre-existing block explorer or query the api endpoints. Its important to note, that if you have nothing in your postgres database the API will return nothing. 286 287 ## Blocks 288 289 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_block/{blockNumber}`` 290 291 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 292 293 **Description** 294 295 ```json 296 { 297 "Hash":"0x72590ac6e7626b9b1f77452d83297c0361e6ff7fa011872289224ee02b9acc8f", 298 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 299 "Age":"2018-10-01T11:15:54Z", 300 "ParentHash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 301 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 302 "Difficulty":"135005", 303 "Size":"538.00 B", 304 "Rewards":"5000000000000000000", 305 "Number":63, 306 "GasUsed":0, 307 "GasLimit":25534458, 308 "Nonce":7333650700872754740, 309 "TxCount":0, 310 "UncleCount":0 311 } 312 ``` 313 314 The above endpoint will respond with the block data for that specific block number. The table below lists the attributes that will be included in the response from this endpoint. 315 316 | Parameter | Description | 317 | --- | --- | 318 | `blockNumber` | The block height or block number | 319 320 | Attributes | Description | Type | 321 | :--- | :---: | ---: | 322 | `Hash` | Block hash | string | 323 | `Coinbase` | Address of miner | string | 324 | `Number` | Block height | number | 325 | `GasUsed` | Amount of gas used | number | 326 | `GasLimit` | Maximum amount of gas willing to be spent | number | 327 | `TxCount` | Amount of transactions included in the block | number | 328 | `UncleCount`| Amount of uncle blocks | number | 329 | `Age` | Time stamp of block creation | Timestamp| 330 | `ParentHash`| Hash of the prior block | string | 331 | `UncleHash` | Hash of a the uncle block | string | 332 | `Size` | Size of block measured in Bytes | string | 333 | `Rewards` | Block reward | string | 334 | `Nonce` | Value used for PoW | number | 335 | `Difficulty`| The difficulty for this block | string | 336 337 338 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_all_blocks`` 339 340 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 341 342 **Description** 343 344 ```json 345 [{ 346 "Hash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 347 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 348 "Age":"2018-10-01T11:15:53Z", 349 "ParentHash":"0xb0437e25e7cfb113bbea0f014883e8f441d5465bb628f9a112eb372e43055f1a", 350 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 351 "Difficulty":"134940", 352 "Size":"538.00 B", 353 "Rewards":"5000000000000000000", 354 "Number":62, 355 "GasUsed":0, 356 "GasLimit":25509548, 357 "Nonce":2307164919004664188, 358 "TxCount":0, 359 "UncleCount":0 360 }, 361 { 362 "Hash":"0x72590ac6e7626b9b1f77452d83297c0361e6ff7fa011872289224ee02b9acc8f", 363 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 364 "Age":"2018-10-01T11:15:54Z", 365 "ParentHash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 366 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 367 "Difficulty":"135005", 368 "Size":"538.00 B", 369 "Rewards":"5000000000000000000", 370 "Number":63, 371 "GasUsed":0, 372 "GasLimit":25534458, 373 "Nonce":7333650700872754740, 374 "TxCount":0, 375 "UncleCount":0 376 }] 377 ``` 378 379 The above endpoint will respond with the block data for all blocks in the postgres db. The table below lists the attributes that will be included in the response from this endpoint. 380 381 *No Parameter requirement* 382 383 | Attributes | Description | Type | 384 | :--- | :---: | ---: | 385 | `Hash` | Block hash | string | 386 | `Coinbase` | Address of miner | string | 387 | `Number` | Block height | number | 388 | `GasUsed` | Amount of gas used | number | 389 | `GasLimit` | Maximum amount of gas willing to be spent | number | 390 | `TxCount` | Amount of transactions included in the block | number | 391 | `UncleCount`| Amount of uncle blocks | number | 392 | `Age` | Time stamp of block creation | Timestamp| 393 | `ParentHash`| Hash of the prior block | string | 394 | `UncleHash` | Hash of a the uncle block | string | 395 | `Size` | Size of block measured in Bytes | string | 396 | `Rewards` | Block reward | string | 397 | `Nonce` | Value used for PoW | number | 398 | `Difficulty`| The difficulty for this block | string | 399 400 401 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_recent_block`` 402 403 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 404 405 **Description** 406 407 ```json 408 { 409 "Hash":"0x72590ac6e7626b9b1f77452d83297c0361e6ff7fa011872289224ee02b9acc8f", 410 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 411 "Age":"2018-10-01T11:15:54Z", 412 "ParentHash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 413 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 414 "Difficulty":"135005", 415 "Size":"538.00 B", 416 "Rewards":"5000000000000000000", 417 "Number":63, 418 "GasUsed":0, 419 "GasLimit":25534458, 420 "Nonce":7333650700872754740, 421 "TxCount":0, 422 "UncleCount":0 423 } 424 ``` 425 426 The above endpoint will respond with the block data from the highest block height. The table below lists the attributes that will be included in the response from this endpoint. 427 428 *No Parameter requirement* 429 430 | Attributes | Description | Type | 431 | :--- | :---: | ---: | 432 | `Hash` | Block hash | string | 433 | `Coinbase` | Address of miner | string | 434 | `Number` | Block height | number | 435 | `GasUsed` | Amount of gas used | number | 436 | `GasLimit` | Maximum amount of gas willing to be spent | number | 437 | `TxCount` | Amount of transactions included in the block | number | 438 | `UncleCount`| Amount of uncle blocks | number | 439 | `Age` | Time stamp of block creation | Timestamp| 440 | `ParentHash`| Hash of the prior block | string | 441 | `UncleHash` | Hash of a the uncle block | string | 442 | `Size` | Size of block measured in Bytes | string | 443 | `Rewards` | Block reward | string | 444 | `Nonce` | Value used for PoW | number | 445 | `Difficulty`| The difficulty for this block | string | 446 447 448 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_blocks_mined/{coinbase}`` 449 450 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 451 452 **Description** 453 454 ```json 455 [{ 456 "Hash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 457 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 458 "Age":"2018-10-01T11:15:53Z", 459 "ParentHash":"0xb0437e25e7cfb113bbea0f014883e8f441d5465bb628f9a112eb372e43055f1a", 460 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 461 "Difficulty":"134940", 462 "Size":"538.00 B", 463 "Rewards":"5000000000000000000", 464 "Number":62, 465 "GasUsed":0, 466 "GasLimit":25509548, 467 "Nonce":2307164919004664188, 468 "TxCount":0, 469 "UncleCount":0 470 }, 471 { 472 "Hash":"0x72590ac6e7626b9b1f77452d83297c0361e6ff7fa011872289224ee02b9acc8f", 473 "Coinbase":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 474 "Age":"2018-10-01T11:15:54Z", 475 "ParentHash":"0x5c1aa0559093d9e1e128b6d8ae63d5bf9a5fbf273f704afad9adac88e734c3cc", 476 "UncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 477 "Difficulty":"135005", 478 "Size":"538.00 B", 479 "Rewards":"5000000000000000000", 480 "Number":63, 481 "GasUsed":0, 482 "GasLimit":25534458, 483 "Nonce":7333650700872754740, 484 "TxCount":0, 485 "UncleCount":0 486 }] 487 ``` 488 489 The above endpoint will respond with the block data for all blocks which have been mined by the provided address. The table below lists the attributes that will be included in the response from this endpoint. 490 491 | Parameter | Description | 492 | --- | --- | 493 | `coinbase` | The miners address | 494 495 | Attributes | Description | Type | 496 | :--- | :---: | ---: | 497 | `Hash` | Block hash | string | 498 | `Coinbase` | Address of miner | string | 499 | `Number` | Block height | number | 500 | `GasUsed` | Amount of gas used | number | 501 | `GasLimit` | Maximum amount of gas willing to be spent | number | 502 | `TxCount` | Amount of transactions included in the block | number | 503 | `UncleCount`| Amount of uncle blocks | number | 504 | `Age` | Time stamp of block creation | Timestamp| 505 | `ParentHash`| Hash of the prior block | string | 506 | `UncleHash` | Hash of a the uncle block | string | 507 | `Size` | Size of block measured in Bytes | string | 508 | `Rewards` | Block reward | string | 509 | `Nonce` | Value used for PoW | number | 510 | `Difficulty`| The difficulty for this block | string | 511 512 513 ## Transactions 514 515 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_transaction/{txHash}`` 516 517 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 518 519 **Description** 520 521 ```json 522 { 523 "TxHash":"0x5bd738164c61fb50eb12e227846cbaef2de965aa0x5bd738164c61fb50eb12e227846cbaef2de965aa", 524 "To":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 525 "From":"0x007622d84a234bb8b078230fcf84b67ae9a8acae", 526 "BlockHash":"0xfa01942529ef3a4e543ef8c061c6e0cb69a61c489d3bb6891bb65651c02dafd4", 527 "BlockNumber":"2", 528 "Amount":"400000000000000000000", 529 "GasPrice":1253, 530 "Gas":12124, 531 "GasLimit":24011655, 532 "Cost":"53002", 533 "Nonce":2, 534 "Status":"SUCCESS", 535 "IsContract":false, 536 "Age":"2018-03-18T19:38:41Z", 537 "Data":"" 538 } 539 ``` 540 541 The above endpoint will respond with transaction data from the provided transaction hash. The table below lists the attributes that will be included in the response from this endpoint. 542 543 | Parameter | Description | 544 | --- | --- | 545 | `txHash` | The hash for that particular transaction | 546 547 | Attributes | Description | Type | 548 | :--- | :---: | ---: | 549 | `TxHash` | Transaction hash | string | 550 | `To` | Address of transaction receiver | string | 551 | `From` | Address of transaction sender | string | 552 | `BlockHash` | Hash of block | string | 553 | `BlockNumber`| Block height | string | 554 | `Amount` | Amount of value being transferred | string | 555 | `GasPrice` | Price of required gas | number | 556 | `Gas` | Required pricing value to process transaction | number | 557 | `GasLimit` | Maximum amount of gas willing to be spent | number | 558 | `Cost` | Hash of a the uncle block | string | 559 | `Nonce` | Number of transactions sent from a given address| number | 560 | `Status` | Whether the transaction was success or fail | string | 561 | `IsContract`| Whether the transaction was from a contract | bool | 562 | `Age` | Time stamp of transaction creation | timestamp| 563 | `Data` | Contract data in byte code | byteArray| 564 565 566 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_all_transactions`` 567 568 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 569 570 **Description** 571 572 ```json 573 [{ 574 "TxHash":"0x5bd738164c61fb50eb12e227846cbaef2de965aa0x5bd738164c61fb50eb12e227846cbaef2de965aa", 575 "To":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 576 "From":"0x007622d84a234bb8b078230fcf84b67ae9a8acae", 577 "BlockHash":"0xfa01942529ef3a4e543ef8c061c6e0cb69a61c489d3bb6891bb65651c02dafd4", 578 "BlockNumber":"2", 579 "Amount":"400000000000000000000", 580 "GasPrice":1253, 581 "Gas":12124, 582 "GasLimit":24011655, 583 "Cost":"53002", 584 "Nonce":2, 585 "Status":"SUCCESS", 586 "IsContract":false, 587 "Age":"2018-03-18T19:38:41Z", 588 "Data":"" 589 }, 590 { 591 "TxHash":"0x2f56g38164c634550eb12e222146cbaef2de965aa0x5bd738164c61fb50eb12e227846cbaef2de965aa", 592 "To":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 593 "From":"0x007622d84a234bb8b078230fcf84b67ae9a8acae", 594 "BlockHash":"0xbg01234529ef3a4e543q23061c6e0cb69a61c489d3bb6891bb65651c02dafd4", 595 "BlockNumber":"3", 596 "Amount":"100000000000000000000", 597 "GasPrice":1253, 598 "Gas":12124, 599 "GasLimit":24011655, 600 "Cost":"53002", 601 "Nonce":3, 602 "Status":"SUCCESS", 603 "IsContract":false, 604 "Age":"2018-03-18T19:40:41Z", 605 "Data":"" 606 }] 607 608 ``` 609 610 The above endpoint will respond with transaction data for all transactions in the postgres database. The table below lists the attributes that will be included in the response from this endpoint. 611 612 *No parameters required* 613 614 | Attributes | Description | Type | 615 | :--- | :---: | ---: | 616 | `TxHash` | Transaction hash | string | 617 | `To` | Address of transaction receiver | string | 618 | `From` | Address of transaction sender | string | 619 | `BlockHash` | Hash of block | string | 620 | `BlockNumber`| Block height | string | 621 | `Amount` | Amount of value being transferred | string | 622 | `GasPrice` | Price of required gas | number | 623 | `Gas` | Required pricing value to process transaction | number | 624 | `GasLimit` | Maximum amount of gas willing to be spent | number | 625 | `Cost` | Hash of a the uncle block | string | 626 | `Nonce` | Number of transactions sent from a given address| number | 627 | `Status` | Whether the transaction was success or fail | string | 628 | `IsContract`| Whether the transaction was from a contract | bool | 629 | `Age` | Time stamp of transaction creation | timestamp| 630 | `Data` | Contract data in byte code | byteArray| 631 632 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_all_transactions_from_block/{blockNumber}`` 633 634 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 635 636 **Description** 637 638 ```json 639 [{ 640 "TxHash":"0x5bd738164c61fb50eb12e227846cbaef2de965aa0x5bd738164c61fb50eb12e227846cbaef2de965aa", 641 "To":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 642 "From":"0x007622d84a234bb8b078230fcf84b67ae9a8acae", 643 "BlockHash":"0xfa01942529ef3a4e543ef8c061c6e0cb69a61c489d3bb6891bb65651c02dafd4", 644 "BlockNumber":"3", 645 "Amount":"400000000000000000000", 646 "GasPrice":1253, 647 "Gas":12124, 648 "GasLimit":24011655, 649 "Cost":"53002", 650 "Nonce":3, 651 "Status":"SUCCESS", 652 "IsContract":false, 653 "Age":"2018-03-18T19:38:41Z", 654 "Data":"" 655 }, 656 { 657 "TxHash":"0x2f56g38164c634550eb12e222146cbaef2de965aa0x5bd738164c61fb50eb12e227846cbaef2de965aa", 658 "To":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 659 "From":"0x007622d84a234bb8b078230fcf84b67ae9a8acae", 660 "BlockHash":"0xbg01234529ef3a4e543q23061c6e0cb69a61c489d3bb6891bb65651c02dafd4", 661 "BlockNumber":"3", 662 "Amount":"100000000000000000000", 663 "GasPrice":1253, 664 "Gas":12124, 665 "GasLimit":24011655, 666 "Cost":"53002", 667 "Nonce":4, 668 "Status":"SUCCESS", 669 "IsContract":false, 670 "Age":"2018-03-18T19:40:41Z", 671 "Data":"" 672 }] 673 674 ``` 675 676 The above endpoint will respond with transaction data for all transactions in the postgres database. The table below lists the attributes that will be included in the response from this endpoint. 677 678 | Parameter | Description | 679 | --- | --- | 680 | `blockNumber` | The block height or block number | 681 682 | Attributes | Description | Type | 683 | :--- | :---: | ---: | 684 | `TxHash` | Transaction hash | string | 685 | `To` | Address of transaction receiver | string | 686 | `From` | Address of transaction sender | string | 687 | `BlockHash` | Hash of block | string | 688 | `BlockNumber`| Block height | string | 689 | `Amount` | Amount of value being transferred | string | 690 | `GasPrice` | Price of required gas | number | 691 | `Gas` | Required pricing value to process transaction | number | 692 | `GasLimit` | Maximum amount of gas willing to be spent | number | 693 | `Cost` | Hash of a the uncle block | string | 694 | `Nonce` | Number of transactions sent from a given address| number | 695 | `Status` | Whether the transaction was success or fail | string | 696 | `IsContract`| Whether the transaction was from a contract | bool | 697 | `Age` | Time stamp of transaction creation | timestamp| 698 | `Data` | Contract data in byte code | byteArray| 699 700 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_account_txs/{address}`` 701 702 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 703 704 **Description** 705 706 ```json 707 [ 708 { 709 "TxHash":"0x7da80aaf6f7e382735310c725b81f790f84c75a541a5360ecba30eb2d7965395", 710 "To":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 711 "From":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 712 "BlockHash":"0x894459a52417bcf3e0eec81fce6cc0858813cbd2202711031e8c5185d9aa4d38", 713 "BlockNumber":"2", 714 "Amount":"0", 715 "GasPrice":100000000000, 716 "Gas":6721975, 717 "GasLimit":24058572, 718 "Cost":"672197500000000000", 719 "Nonce":0, 720 "Status":"SUCCESS", 721 "IsContract":true, 722 "Age":"2018-10-02T13:21:02Z", 723 "Data":"YIBgQFI0gBVhABBXYAGCY/////8WfAEAAAAAAAAAAAAAAAAAAAAAAAYQVienpyMFS8PtYkAKQ==" 724 }, 725 { 726 "TxHash":"0x2f49282ff117dd4d28f4b5a59a71fc0c3ab1cd595f6d503cd82caa88d1cc4897", 727 "To":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 728 "From":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 729 "BlockHash":"0x12b73a2ae27cb32193e8570c275b24d6a9aa9d637c61582e63afe589535f075a", 730 "BlockNumber":"4", 731 "Amount":"0", 732 "GasPrice":100000000000, 733 "Gas":6721975, 734 "GasLimit":24105581, 735 "Cost":"672197500000000000", 736 "Nonce":1, 737 "Status":"SUCCESS", 738 "IsContract":false, 739 "Age":"2018-10-02T13:21:05Z", 740 "Data":"/azVdgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB" 741 } 742 ] 743 744 ``` 745 746 The above endpoint will respond with transaction data for all transactions conducted by the provided address. The table below lists the attributes that will be included in the response from this endpoint. 747 748 | Parameter | Description | 749 | --- | --- | 750 | `address` | The address of an account | 751 752 | Attributes | Description | Type | 753 | :--- | :---: | ---: | 754 | `TxHash` | Transaction hash | string | 755 | `To` | Address of transaction receiver | string | 756 | `From` | Address of transaction sender | string | 757 | `BlockHash` | Hash of block | string | 758 | `BlockNumber`| Block height | string | 759 | `Amount` | Amount of value being transferred | string | 760 | `GasPrice` | Price of required gas | number | 761 | `Gas` | Required pricing value to process transaction | number | 762 | `GasLimit` | Maximum amount of gas willing to be spent | number | 763 | `Cost` | Hash of a the uncle block | string | 764 | `Nonce` | Number of transactions sent from a given address| number | 765 | `Status` | Whether the transaction was success or fail | string | 766 | `IsContract`| Whether the transaction was from a contract | bool | 767 | `Age` | Time stamp of transaction creation | timestamp| 768 | `Data` | Contract data in byte code | byteArray| 769 770 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_internal_transactions/{hash}`` 771 772 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 773 774 **Description** 775 776 ```json 777 [ 778 { 779 "ID":1, 780 "Hash":"0x2f49282ff117dd4d28f4b5a59a71fc0c3ab1cd595f6d503cd82caa88d1cc4897", 781 "BlockHash":"0x12b73a2ae27cb32193e8570c275b24d6a9aa9d637c61582e63afe589535f075a", 782 "Action":"CALL", 783 "From":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 784 "To":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 785 "Value":"0", 786 "Gas":6700511, 787 "GasUsed":20544, 788 "Input":"0xfdacd5760000000000000000000000000000000000000000000000000000000000000001", 789 "Output":"0x", 790 "Time":"6.950856ms" 791 } 792 ] 793 ``` 794 795 The above endpoint will respond with transaction data from the provided transaction hash. The table below lists the attributes that will be included in the response from this endpoint. 796 797 | Parameter | Description | 798 | --- | --- | 799 | `hash` | The transaction hash of the particular record | 800 801 | Attributes | Description | Type | 802 | :--- | :---: | ---: | 803 | `ID` | Incrementing integer for unique db record | number | 804 | `Hash` | Transaction hash | string | 805 | `BlockHash` | Hash of block | string | 806 | `Action` | Contract type, can be Call or Create | string | 807 | `To` | Address of transaction receiver | string | 808 | `From` | Address of transaction sender | string | 809 | `Value` | Amount of value being transferred | string | 810 | `Gas` | Required pricing value to process transaction | number | 811 | `GasUsed` | Amount of gas used | number | 812 | `Input` | Parameters passed into contract in bytecode | string | 813 | `Output` | Return values from contract in bytecode | string | 814 | `Time` | Amount of time to trace transaction | string | 815 816 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_internal_transactions`` 817 818 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 819 820 **Description** 821 822 ```json 823 [ 824 { 825 "ID":1, 826 "Hash":"0x2f49282ff117dd4d28f4b5a59a71fc0c3ab1cd595f6d503cd82caa88d1cc4897", 827 "BlockHash":"0x12b73a2ae27cb32193e8570c275b24d6a9aa9d637c61582e63afe589535f075a", 828 "Action":"CALL", 829 "From":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 830 "To":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 831 "Value":"0", 832 "Gas":6700511, 833 "GasUsed":20544, 834 "Input":"0xfdacd5760000000000000000000000000000000000000000000000000000000000000001", 835 "Output":"0x", 836 "Time":"6.950856ms" 837 }, 838 { 839 "ID":2, 840 "Hash":"0x16b218a28d48c5ef54cf09ce836e285cb23ba9c179b3c88269d61cb5bd5473db", 841 "BlockHash":"0xbdb1aca7c9aeee9f9723ea84cb8d47ff46f49e29a85d41a92b7950a0970b1d25", 842 "Action":"CALL", 843 "From":"0x43ec6d0942f7faef069f7f63d0384a27f529b062", 844 "To":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 845 "Value":"0", 846 "Gas":6700511, 847 "GasUsed":5544, 848 "Input":"0xfdacd5760000000000000000000000000000000000000000000000000000000000000002", 849 "Output":"0x", 850 "Time":"1.370835ms" 851 } 852 ] 853 ``` 854 855 The above endpoint will respond with all internal transaction data from the postgres database. The table below lists the attributes that will be included in the response from this endpoint. 856 857 *No parameters requirements* 858 859 | Attributes | Description | Type | 860 | :--- | :---: | ---: | 861 | `ID` | Incrementing integer for unique db record | number | 862 | `Hash` | Transaction hash | string | 863 | `BlockHash` | Hash of block | string | 864 | `Action` | Contract type, can be Call or Create | string | 865 | `To` | Address of transaction receiver | string | 866 | `From` | Address of transaction sender | string | 867 | `Value` | Amount of value being transferred | string | 868 | `Gas` | Required pricing value to process transaction | number | 869 | `GasUsed` | Amount of gas used | number | 870 | `Input` | Parameters passed into contract in bytecode | string | 871 | `Output` | Return values from contract in bytecode | string | 872 | `Time` | Amount of time to trace transaction | string | 873 874 875 ## Accounts 876 877 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_account/{address}`` 878 879 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 880 881 **Description** 882 883 ```json 884 { 885 "Addr":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 886 "Balance":"100000000", 887 "AccountNonce":"5" 888 } 889 ``` 890 891 The above endpoint will respond with account data from the provided address. The table below lists the attributes that will be included in the response from this endpoint. 892 893 | Parameter | Description | 894 | --- | --- | 895 | `address` | The address of an account to query| 896 897 | Attributes | Description | Type | 898 | :--- | :---: | ---: | 899 | `Addr` | Account address | string | 900 | `Balance` | Address balance in wei | string | 901 | `AccountNonce`| Number of transactions sent from a given address| string | 902 903 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_account/{address}`` 904 905 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 906 907 **Description** 908 909 ```json 910 { 911 "Addr":"0xfaeccae8c1af6bdfd71095e1b6a2f61c61c8a7e7", 912 "Balance":"100000000", 913 "AccountNonce":"5" 914 } 915 ``` 916 917 The above endpoint will respond with account data from the provided address. The table below lists the attributes that will be included in the response from this endpoint. 918 919 | Parameter | Description | 920 | --- | --- | 921 | `address` | The address of an account to query| 922 923 | Attributes | Description | Type | 924 | :--- | :---: | ---: | 925 | `Addr` | Account address | string | 926 | `Balance` | Address balance in wei | string | 927 | `AccountNonce`| Number of transactions sent from a given address| string | 928 929 <span style="color:#fff; height: 25px; width: 30px; background: blue; padding: 7px; margin-right: 5px;">**GET**</span> ``/api/get_all_accounts`` 930 931 <span style="color:#fff; height: 25px; width: 30px; background: red; padding: 7px; margin-right: 5px;">**Headers**</span> ``Content-Type: application/json`` 932 933 **Description** 934 935 ```json 936 [ 937 { 938 "Addr":"0xc04ee4131895f1d0c294d508af65d94060aa42bb", 939 "Balance":"500000000000000000000", 940 "AccountNonce":"1" 941 }, 942 { 943 "Addr":"0x07d899c4ac0c1725c35c5f816e60273b33a964f7", 944 "Balance":"100000000000000000000", 945 "AccountNonce":"1" 946 }, 947 { 948 "Addr":"0x5bd738164c61fb50eb12e227846cbaef2de965aa", 949 "Balance":"400000000000000000000", 950 "AccountNonce":"1" 951 } 952 ] 953 ``` 954 955 The above endpoint will respond with account data for all accounts in the postgres database. The table below lists the attributes that will be included in the response from this endpoint. 956 957 | Parameter | Description | 958 | --- | --- | 959 | `address` | The address of an account to query| 960 961 | Attributes | Description | Type | 962 | :--- | :---: | ---: | 963 | `Addr` | Account address | string | 964 | `Balance` | Address balance in wei | string | 965 | `AccountNonce`| Number of transactions sent from a given address| string | 966 967 968 **The above endpoints will respond with a json payload for the given request, each of these endpoints are subject to change in the future.** 969 970 # Shyft Block Explorer UI 971 972 To demonstrate the ability to create your own block explorer, a custom folder was created `./shyftBlockExplorerUI` that contains an example block explorer using react! 973 974 To run the Block Explorer UI, ensure that you have the API running as mentioned above. Then run the following command in a terminal: 975 976 ``cd shyftBlockExplorerUI`` 977 978 ``npm install`` 979 980 ``npm run start`` 981 982 <aside class="warning"> 983 The above command is to only be used if running locally and assumes that the block explorer API is being run from the same server. 984 </aside> 985 986 This will start a development server on ``port 3000`` and spin up an example block explorer that uses the API to query the postgres database. 987 988 It should look like the below image. 989 990 <img src="./images/explorerUI.png" alt="Block Explorer Example"> 991 992 # Command Line Options 993 994 Before running any CLI options ensure you run `make geth` in the root directory. 995 996 > In the root directory run `./shyft-geth.sh` with any of the following flags: 997 998 ```shell 999 --setup - Setups postgres and the shyft chain db. 1000 --start - Starts geth. 1001 --reset - Drops postgres and chain db, and instantiates both. 1002 --js <web3 filename> - Executes web3 calls with a passed file name. 1003 If the file name is sendTransactions.js: 1004 ./shyft-geth.sh --js sendTransactions 1005 ``` 1006 1007 For convenience a simple CLI was built using `shyft-geth.sh` as the executable file with some basic commands to get your environment setup. 1008 1009 This will create a new database for geth to use as well as all the necessary tables for the shyft blockexplorer. 1010 1011 # Custom Shyft Constants 1012 ### Block Rewards 1013 1014 ``./consensus/ethash/consensus.go`` 1015 1016 Shyft inflation is different than that of Ethereum, therefore the constants were changed in order to support this. 1017 1018 # Shyft Extended Functionality 1019 ### Database Functions 1020 1021 ``./core/db.go`` 1022 1023 ``./shyft_schema`` 1024 1025 ### Database instanitation 1026 1027 The local database is instantiated where Geth generates and writes the genesis state/block. 1028 ``./core/genesis.go`` 1029 1030 Specifically, the local database configuration and set up takes place in a custom database file 1031 ``./core/db.go`` 1032 ### Writing Blocks 1033 1034 In our case, we use `SWriteBlock()` for writing all our data. So far, it contains all the data that we need to store to our local block explorer database. It invokes the `SWriteTransaction()` which writes the transactions and updates accounts in the local database. This may change in the future. This function is invoked in: 1035 ``./core/blockchain.go`` 1036 1037 `SWriteBlock()` and `SWriteTransaction()` exist within: 1038 ``./core/shyft_database_util.go`` 1039 1040 ### Transaction Types Functions 1041 1042 ``./core/types/transaction.go`` 1043 1044 The existing transaction type in Geth did not allow the evm to call a helper function to retrieve the from address, essentially the sender. Therefore, we extended the functionality of the Transaction type to generate the from address through `*Transaction.From()`. 1045 1046 ``./core/shyft_database_util.go``