diff --git a/bios/bios.go b/bios/bios.go index 1b48a87..bdb42b1 100644 --- a/bios/bios.go +++ b/bios/bios.go @@ -33,6 +33,7 @@ type BIOS struct { TargetNetAPI *eos.API Snapshot Snapshot BootSequence []*OperationType + WriteActions bool Genesis *GenesisJSON @@ -231,13 +232,6 @@ func (b *BIOS) PrintProducerSchedule(orderedPeers []*Peer) { func (b *BIOS) RunBootSequence() error { b.Log.Println("START BOOT SEQUENCE...") - // keys, _ := b.TargetNetAPI.Signer.(*eos.KeyBag).AvailableKeys() - // for _, key := range keys { - // b.Log.Println("Available key in the KeyBag:", key) - // } - - // Update boot sequence HERE - ephemeralPrivateKey, err := b.GenerateEphemeralPrivKey() if err != nil { return err @@ -258,6 +252,10 @@ func (b *BIOS) RunBootSequence() error { return fmt.Errorf("ImportWIF: %s", err) } + if err := b.writeAllActionsToDisk(); err != nil { + return fmt.Errorf("writing actions to disk: %s", err) + } + genesisData := b.GenerateGenesisJSON(pubKey.String()) if len(b.Network.MyPeer.Discovery.SeedNetworkPeers) > 0 && !b.SingleOnly { @@ -375,7 +373,10 @@ func (b *BIOS) RunJoinNetwork(validate, sabotage bool) error { } b.EphemeralPublicKey = pubKey - // Create mesh network + if err := b.writeAllActionsToDisk(); err != nil { + return fmt.Errorf("writing actions to disk: %s", err) + } + otherPeers := b.computeMyMeshP2PAddresses() if err := b.DispatchJoinNetwork(b.Genesis, b.getMyPeerVariations(), otherPeers); err != nil { @@ -456,6 +457,51 @@ func (b *BIOS) RunChainValidation() (bool, error) { return true, nil } +func (b *BIOS) writeAllActionsToDisk() error { + if !b.WriteActions { + fmt.Println("Not writing actions to 'actions.jsonl'. Activate with --write-actions") + return nil + } + + fmt.Println("Writing all actions to 'actions.jsonl'...") + fl, err := os.Create("actions.jsonl") + if err != nil { + return err + } + defer fl.Close() + + for _, step := range b.BootSequence { + if b.LaunchDisco.TargetNetworkIsTest == 0 { + step.Data.ResetTestnetOptions() + } + + acts, err := step.Data.Actions(b) + if err != nil { + return fmt.Errorf("fetch step %q: %s", step.Op, err) + } + + for _, stepAction := range acts { + if stepAction == nil { + continue + } + + stepAction.SetToServer(false) + data, err := json.Marshal(stepAction) + if err != nil { + return fmt.Errorf("binary marshalling: %s", err) + } + + _, err = fl.Write(data) + if err != nil { + return err + } + _, _ = fl.Write([]byte("\n")) + } + } + + return nil +} + type ActionMap map[string]*eos.Action type ValidationError struct { diff --git a/eos-bios/cmd/common.go b/eos-bios/cmd/common.go index ded89fb..4e07568 100644 --- a/eos-bios/cmd/common.go +++ b/eos-bios/cmd/common.go @@ -94,5 +94,7 @@ func setupBIOS(net *bios.Network) (b *bios.BIOS, err error) { targetNetAPI := eos.New(targetNetHTTP) targetNetAPI.SetSigner(eos.NewKeyBag()) - return bios.NewBIOS(net.Log, net, targetNetAPI), nil + b = bios.NewBIOS(net.Log, net, targetNetAPI) + b.WriteActions = viper.GetBool("write-actions") + return b, nil } diff --git a/eos-bios/cmd/root.go b/eos-bios/cmd/root.go index 12f2cbd..694f443 100644 --- a/eos-bios/cmd/root.go +++ b/eos-bios/cmd/root.go @@ -66,11 +66,12 @@ func init() { RootCmd.PersistentFlags().StringP("seednet-keys", "", "./seed_network.keys", "File containing private keys to your account on the seed network") RootCmd.PersistentFlags().StringP("target-api", "", "", "HTTP address to reach the node you are starting (for injection and validation)") + RootCmd.PersistentFlags().BoolP("write-actions", "", false, "Write actions to actions.jsonl upon join or boot") RootCmd.PersistentFlags().StringP("cache-path", "", filepath.Join(homedir, ".eos-bios-cache"), "directory to store cached data from discovered network") RootCmd.PersistentFlags().BoolP("verbose", "v", false, "Display verbose output (also see 'output.log')") RootCmd.PersistentFlags().String("elect", "", "Force the election of the given BIOS Boot node") - for _, flag := range []string{"cache-path", "my-discovery", "ipfs", "seednet-keys", "seednet-api", "target-api", "verbose", "elect"} { + for _, flag := range []string{"cache-path", "my-discovery", "ipfs", "seednet-keys", "write-actions", "seednet-api", "target-api", "verbose", "elect"} { if err := viper.BindPFlag(flag, RootCmd.PersistentFlags().Lookup(flag)); err != nil { panic(err) }