parent
83eba88395
commit
59ffd3ccac
@ -0,0 +1,37 @@ |
||||
package explorer |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os" |
||||
) |
||||
|
||||
var ( |
||||
data = ReadFakeData() |
||||
) |
||||
|
||||
// ReadFakeData ...
|
||||
func ReadFakeData() Data { |
||||
jsonFile, err := os.Open("./fake_data.json") |
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil { |
||||
fmt.Println(err) |
||||
os.Exit(1) |
||||
} |
||||
|
||||
fmt.Println("Successfully Opened users.json") |
||||
// defer the closing of our jsonFile so that we can parse it later on
|
||||
defer jsonFile.Close() |
||||
|
||||
// read our opened xmlFile as a byte array.
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile) |
||||
|
||||
// we initialize our Users array
|
||||
var data Data |
||||
|
||||
// we unmarshal our byteArray which contains our
|
||||
// jsonFile's content into 'users' which we defined above
|
||||
json.Unmarshal(byteValue, &data) |
||||
return data |
||||
} |
@ -0,0 +1,72 @@ |
||||
{ |
||||
"blocks": [ |
||||
{ |
||||
"id": "0000000000000000001c48da2a21c9d098efcab0f4904ff4773c0896c63c62f8", |
||||
"height": "553254", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"txCount": "2985", |
||||
"size": "917273" |
||||
}, |
||||
{ |
||||
"id": "000000000000000000271c579c88555b439e108261ba096ab217c4b0e5c5a929", |
||||
"height": "553253", |
||||
"timestamp": "Dec 10, 2018 1:11:45 AM", |
||||
"txCount": "2224", |
||||
"size": "898989" |
||||
} |
||||
], |
||||
"block": { |
||||
"height": "553254", |
||||
"hash": "0000000000000000001c48da2a21c9d098efcab0f4904ff4773c0896c63c62f8", |
||||
"txCount": "2985", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"merkleRoot": "14e349accb6320743b6655b1686a883e4e40d6d36ad08f31a22a4b1d4a6495e1", |
||||
"prevBlock": { |
||||
"id": "000000000000000000271c579c88555b439e108261ba096ab217c4b0e5c5a929", |
||||
"height": "553253" |
||||
}, |
||||
"bits": "1731d97c", |
||||
"bytes": "917273", |
||||
"nextBlock": { |
||||
"id": "0000000000000000001eea8340ae29cbe73173dff65ae44f6ec204cd11c10034", |
||||
"height": "553255" |
||||
}, |
||||
"txs": [ |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0a4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3c65970996d7de5a65d66915a1772481a4a00a61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": "20" |
||||
} |
||||
] |
||||
}, |
||||
"address": { |
||||
"hash": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"balance": 0.412535411, |
||||
"txCount": 29, |
||||
"txs": [ |
||||
{ |
||||
"id": "0xc67298b46c474bdfe53e0a4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
}, |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0aa4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
}, |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0fa4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
} |
||||
] |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package explorer |
||||
|
||||
/* |
||||
* All the code here is work of progress for the sprint. |
||||
*/ |
||||
|
||||
// Data ...
|
||||
type Data struct { |
||||
Blocks []Block `json:"blocks"` |
||||
Address Address `json:"address"` |
||||
} |
||||
|
||||
// Address ...
|
||||
type Address struct { |
||||
Hash string `json:"hash"` |
||||
Balance float64 `json:"balance"` |
||||
TXCount int `json:"txCount"` |
||||
TXs []Transaction `json:"txs"` |
||||
} |
||||
|
||||
// Transaction ...
|
||||
type Transaction struct { |
||||
ID string `json:"id"` |
||||
Timestamp string `json:"timestamp"` |
||||
From string `json:"from"` |
||||
To string `json:"to"` |
||||
Value float64 `json:"value"` |
||||
} |
||||
|
||||
// Block ...
|
||||
type Block struct { |
||||
Height int `json:"height"` |
||||
Hash string `json:"hash"` |
||||
TXCount int `json:"txCount"` |
||||
Timestamp string `json:"timestamp"` |
||||
MerkleRoot string `json:"merkleRoot"` |
||||
PrevBlock RefBlock `json:"prevBlock"` |
||||
Bits string `json:"bits"` |
||||
Bytes string `json:"bytes"` |
||||
NextBlock RefBlock `json:"nextBlock"` |
||||
TXs []Transaction `json:"txs"` |
||||
} |
||||
|
||||
// RefBlock ...
|
||||
type RefBlock struct { |
||||
ID string `json:"id"` |
||||
Height int `json:"height"` |
||||
} |
@ -0,0 +1,72 @@ |
||||
{ |
||||
"blocks": [ |
||||
{ |
||||
"id": "0000000000000000001c48da2a21c9d098efcab0f4904ff4773c0896c63c62f8", |
||||
"height": "553254", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"txCount": "2985", |
||||
"size": "917273" |
||||
}, |
||||
{ |
||||
"id": "000000000000000000271c579c88555b439e108261ba096ab217c4b0e5c5a929", |
||||
"height": "553253", |
||||
"timestamp": "Dec 10, 2018 1:11:45 AM", |
||||
"txCount": "2224", |
||||
"size": "898989" |
||||
} |
||||
], |
||||
"block": { |
||||
"height": "553254", |
||||
"hash": "0000000000000000001c48da2a21c9d098efcab0f4904ff4773c0896c63c62f8", |
||||
"txCount": "2985", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"merkleRoot": "14e349accb6320743b6655b1686a883e4e40d6d36ad08f31a22a4b1d4a6495e1", |
||||
"prevBlock": { |
||||
"id": "000000000000000000271c579c88555b439e108261ba096ab217c4b0e5c5a929", |
||||
"height": "553253" |
||||
}, |
||||
"bits": "1731d97c", |
||||
"bytes": "917273", |
||||
"nextBlock": { |
||||
"id": "0000000000000000001eea8340ae29cbe73173dff65ae44f6ec204cd11c10034", |
||||
"height": "553255" |
||||
}, |
||||
"txs": [ |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0a4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3c65970996d7de5a65d66915a1772481a4a00a61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": "20" |
||||
} |
||||
] |
||||
}, |
||||
"address": { |
||||
"hash": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"balance": 0.412535411, |
||||
"txCount": 29, |
||||
"txs": [ |
||||
{ |
||||
"id": "0xc67298b46c474bdfe53e0a4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
}, |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0aa4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
}, |
||||
{ |
||||
"id": "0xc67298b46c474bd7e53e0fa4521b27e2fedc14fc6d67973c72eed4c139496c1ba", |
||||
"timestamp": "Dec 10, 2018 1:43:43 AM", |
||||
"from": "0x3C65970996D7De5a65D66915A1772481a4a00A61", |
||||
"to": "0xe6b3a12cae421d928fa1ca4fb09f2be91afdf650", |
||||
"value": 10 |
||||
} |
||||
] |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os" |
||||
|
||||
"github.com/harmony-one/harmony/services/explorer" |
||||
) |
||||
|
||||
func main() { |
||||
jsonFile, err := os.Open("./fake_data.json") |
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil { |
||||
fmt.Println(err) |
||||
os.Exit(1) |
||||
} |
||||
|
||||
fmt.Println("Successfully Opened users.json") |
||||
// defer the closing of our jsonFile so that we can parse it later on
|
||||
defer jsonFile.Close() |
||||
|
||||
// read our opened xmlFile as a byte array.
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile) |
||||
|
||||
// we initialize our Users array
|
||||
var data explorer.Data |
||||
|
||||
// we unmarshal our byteArray which contains our
|
||||
// jsonFile's content into 'users' which we defined above
|
||||
json.Unmarshal(byteValue, &data) |
||||
fmt.Println(data) |
||||
|
||||
} |
Loading…
Reference in new issue