Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Read genesis data from the blockchain properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed May 8, 2018
1 parent 8be0fe9 commit 618478c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
18 changes: 13 additions & 5 deletions bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

type BIOS struct {
Network *Network
Network *Network
SingleOnly bool

LaunchDisco *disco.Discovery
Expand Down Expand Up @@ -382,23 +382,31 @@ func (b *BIOS) pollGenesisData() (genesis *GenesisJSON) {

bootNode := b.ShuffledProducers[0]

fmt.Printf("Polling..")
fmt.Printf("Polling...\n")
for {
time.Sleep(500 * time.Millisecond)
fmt.Printf(".")

genesisData, err := b.Network.PollGenesisTable(bootNode.Discovery.SeedNetworkAccountName)
if err != nil {
fmt.Printf("e")
fmt.Printf("- data not ready: %s\n", err)
continue
}

if len(genesisData) == 0 {
fmt.Printf("- data still empty\n")
}

err = json.Unmarshal([]byte(genesisData), &genesis)
if err != nil {
fmt.Printf("\ninvalid genesis data read from BIOS boot! (err=%s, content=%q)", err, genesisData)
fmt.Printf("- data not valid: %q (err=%s)\n", err, genesisData)
continue
}

fmt.Println("Got genesis data:")
fmt.Println("")
fmt.Println(" ", genesisData)
fmt.Println("")

return
}
}
Expand Down
7 changes: 4 additions & 3 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bios

import (
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -266,16 +267,16 @@ func (net *Network) PollGenesisTable(account eos.AccountName) (data string, err
if err != nil {
return "", err
}
accountHex := hex.EncodeToString(accountRaw)
accountInt := binary.LittleEndian.Uint64(accountRaw)
rowsJSON, err := net.SeedNetAPI.GetTableRows(
eos.GetTableRowsRequest{
JSON: true,
Scope: net.seedNetContract,
Code: net.seedNetContract,
Table: "genesis",
TableKey: "id",
LowerBound: accountHex,
UpperBound: accountHex,
LowerBound: fmt.Sprintf("%d", accountInt),
UpperBound: fmt.Sprintf("%d", accountInt+1),
Limit: 1,
},
)
Expand Down
1 change: 1 addition & 0 deletions sample_config/hook_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
echo "Starting $1 operation"

docker kill nodeos-bios || true
docker rm nodeos-bios || true
2 changes: 1 addition & 1 deletion sample_config/my_discovery_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ seed_network_peers:
comment: "They are better"
weight: 20

seed_network_launch_block: 5000 # Block on the SEED EOS network before we orchestrate the TARGET network launch. Putting a past block will start orchestration right away.
seed_network_launch_block: 551 # Block on the SEED EOS network before we orchestrate the TARGET network launch. Putting a past block will start orchestration right away.

urls:
- https://website.com
Expand Down
1 change: 1 addition & 0 deletions sample_config/privkey-GDW5CV.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

0 comments on commit 618478c

Please sign in to comment.