Documentation
¶
Overview ¶
Copyright © 2022 Polygon <engineering@polygon.technology>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Variables
- func GenerateRandomBlock(number uint64) *edgetypes.Block
- func IsEmptyAddress(addr []byte) bool
- func NewEdgeBlockchain() (*edgeBlockchainHandle, error)
- func PolyBlockToEdge(polyBlock rpctypes.PolyBlock) *edgetypes.Block
- func ReadProtoFromFile(filepath string) ([][]byte, error)
- type BlockReader
- type JSONBlockReader
- type JSONReceiptReader
- type ProtoBlockReader
- type ReceiptReader
Constants ¶
This section is empty.
Variables ¶
var (
BlockReadEOF = errors.New("no more blocks to read")
)
var ForgeCmd = &cobra.Command{ Use: "forge", Short: "A utility for generating blockchain data either for testing or migration", Long: `A utility for generating blockchain data either for testing or migration. Here is an example usage: # In this case local host is running a POA Core Archive node. polycli dumpblocks http://127.0.0.1:8545 0 100000 --filename poa-core.0.to.100k --dump-receipts=false # Even with disabling receipts, edge's eth_getBlockByNumber returns transactions. # This needs to be done only if using json mode. Filter them out before forging: cat poa-core.0.to.100k | grep '"difficulty"' > poa-core.0.to.100k.blocks polycli forge --genesis genesis.json --mode json --blocks poa-core.0.to.100k.blocks --count 99999`, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("forge called") blockchain, err := NewEdgeBlockchain() if err != nil { return err } blockReader, err := OpenBlockReader(inputForge.BlocksFile, inputForge.Mode) if err != nil { return err } receiptReader, err := OpenReceiptReader(inputForge.ReceiptsFile, inputForge.Mode) if inputForge.IncludeTxFees && err != nil { return err } err = readAllBlocksToChain(blockchain, blockReader, receiptReader) return err }, Args: func(cmd *cobra.Command, args []string) error { if inputForge.Client != "edge" { return fmt.Errorf("the client %s is not supported. Only Edge is supported", inputForge.Client) } if !slices.Contains([]string{"json", "proto"}, inputForge.Mode) { return fmt.Errorf("output format must one of [json, proto]") } f, err := os.Open(inputForge.GenesisFile) if err != nil { return fmt.Errorf("unable to open genesis file: %w", err) } genesisData, err := io.ReadAll(f) if err != nil { return fmt.Errorf("unable to read genesis file data: %w", err) } inputForge.GenesisData = genesisData zerolog.SetGlobalLevel(zerolog.TraceLevel) log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) log.Debug().Msg("Starting logger in console mode") return nil }, }
forgeCmd represents the forge command
Functions ¶
func GenerateRandomBlock ¶
GenerateRandomBlock in most cases we can use existing blocks and transactions for forgeries and testing, but at some point we might want to generate complete random blocks especially if we want to model state size after 10 - 20 years of operation
func IsEmptyAddress ¶
IsEmptyAddress will just check a slice of bytes to check if it's all zeros or not.
func NewEdgeBlockchain ¶
func NewEdgeBlockchain() (*edgeBlockchainHandle, error)
func PolyBlockToEdge ¶
PolyBlockToEdge will take the generic PolyBlock interface and convert it into an Edge compatible block.
func ReadProtoFromFile ¶
Types ¶
type BlockReader ¶
func OpenBlockReader ¶
func OpenBlockReader(file string, mode string) (BlockReader, error)
OpenBlockReader returns a block reader object which can be used to read the file. It will return a mode specific block reader.
type JSONBlockReader ¶
type JSONBlockReader struct {
// contains filtered or unexported fields
}
type JSONReceiptReader ¶ added in v0.1.17
type JSONReceiptReader struct {
// contains filtered or unexported fields
}
func (*JSONReceiptReader) ReadReceipt ¶ added in v0.1.17
func (receiptsReader *JSONReceiptReader) ReadReceipt() (*rpctypes.RawTxReceipt, error)
type ProtoBlockReader ¶
type ProtoBlockReader struct {
// contains filtered or unexported fields
}
type ReceiptReader ¶ added in v0.1.17
type ReceiptReader interface {
ReadReceipt() (*rpctypes.RawTxReceipt, error)
}
func OpenReceiptReader ¶ added in v0.1.17
func OpenReceiptReader(file string, mode string) (ReceiptReader, error)
OpenReceiptReader returns a receipt reader object which can be used to read the file. It will return a mode specific receipt reader.