mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 03:51:20 +00:00
49 lines
742 B
Go
49 lines
742 B
Go
|
package torrent
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
var DefaultSnapshotMode = SnapshotMode{}
|
||
|
|
||
|
type SnapshotMode struct {
|
||
|
Headers bool
|
||
|
Bodies bool
|
||
|
State bool
|
||
|
Receipts bool
|
||
|
}
|
||
|
|
||
|
func (m SnapshotMode) ToString() string {
|
||
|
var mode string
|
||
|
if m.Headers {
|
||
|
mode += "h"
|
||
|
}
|
||
|
if m.Bodies {
|
||
|
mode += "b"
|
||
|
}
|
||
|
if m.State {
|
||
|
mode += "s"
|
||
|
}
|
||
|
if m.Receipts {
|
||
|
mode += "r"
|
||
|
}
|
||
|
return mode
|
||
|
}
|
||
|
|
||
|
func SnapshotModeFromString(flags string) (SnapshotMode, error) {
|
||
|
mode := SnapshotMode{}
|
||
|
for _, flag := range flags {
|
||
|
switch flag {
|
||
|
case 'h':
|
||
|
mode.Headers = true
|
||
|
case 'b':
|
||
|
mode.Bodies = true
|
||
|
case 's':
|
||
|
mode.State = true
|
||
|
case 'r':
|
||
|
mode.Receipts = true
|
||
|
default:
|
||
|
return mode, fmt.Errorf("unexpected flag found: %c", flag)
|
||
|
}
|
||
|
}
|
||
|
return mode, nil
|
||
|
}
|