Documentation ¶
Overview ¶
Package cmd
Copyright © 2022 Isaac ¶
This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Header ¶
type Header struct { // These field are taken from gorm.Model, but omitting the ID field. We'll use Hash instead. CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // Block is a pointer to the block this header belongs to. // We'll need to this from the server. Block *types.Block `json:"-" gorm:"-"` // Hash is the SAME VALUE as Header.Hash(), but we get to tell gorm that it must be unique. Hash string `gorm:"unique;index;primaryKey;" json:"hash"` /* > https://gorm.io/docs/many_to_many.html#Override-Foreign-Key type User struct { gorm.Model Profiles []Profile `gorm:"many2many:user_profiles;foreignKey:Refer;joinForeignKey:UserReferID;References:UserRefer;joinReferences:ProfileRefer"` Refer uint `gorm:"index:,unique"` } type Profile struct { gorm.Model Name string UserRefer uint `gorm:"index:,unique"` } // Which creates join table: user_profiles // foreign key: user_refer_id, reference: users.refer // foreign key: profile_refer, reference: profiles.user_refer */ Txes []Tx `gorm:"many2many:header_txes;foreignKey:Hash;references:Hash" json:"txes,omitempty"` // types.Header: ParentHash string `json:"parentHash"` UncleHash string `json:"sha3Uncles"` Coinbase string `json:"miner"` Root string `json:"stateRoot"` TxHash string `json:"transactionsRoot" gorm:"column:txes_root"` ReceiptHash string `json:"receiptsRoot"` Difficulty string `json:"difficulty"` Number uint64 `json:"number"` GasLimit uint64 `json:"gasLimit"` GasUsed uint64 `json:"gasUsed"` Time uint64 `json:"timestamp"` Extra []byte `json:"extraData"` MixDigest string `json:"mixHash"` Nonce string `json:"nonce"` BaseFee string `json:"baseFeePerGas,omitempty"` // BaseFee was added by EIP-1559 and is ignored in legacy headers. // Uncle1 and Uncle2 are optionally filled fields. // The Ethereum protocol only allows blocks to cite 2 uncles at most. Uncle1 string `json:"uncle1,omitempty"` Uncle2 string `json:"uncle2,omitempty"` // Orphan is a flag indicating whether this header is an orphan. Orphan bool `gorm:"default:false" json:"orphan"` // UncleBy is the hash of the block/header listing this uncle as an uncle. // If empty, it was not recorded as an uncle. UncleBy string `json:"uncleBy"` // Error describes any error that took place while fetching/filling/handling this header. // Errors could be from fetching the block (to get the transactions), for example. // We persist errors because it is most important to us that we store // all block records. We should not abort saving if a non-critical errors occurrs // along the way. Better to save a header without the transactions, but with the error, // than to save no header at all. Error string `json:"error"` }
Header is our app representation of a block header. We have to reinvent the wheel because we want to play nice with the database, and the database doesn't have a model *big.Ints or common.Hash or block.Nonce, etc. All *big.Ints are stored as strings in the database unless they are safely converted to uint64s (ie block number). All common.Hashes are stored as strings.
func (*Header) CreateOrUpdate ¶
CreateOrUpdate creates or updates a header, returning any error. assignCols should be any of "uncle" or "orphan"; these are the fields which are permitted to be updated in case the record already exists.
type ServerStatus ¶
type Tx ¶
type Tx struct { // These field are taken from gorm.Model, but omitting the ID field. We'll use Hash instead. CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` Hash string `json:"hash" gorm:"unique;index;primaryKey"` Headers []*Header `gorm:"many2many:header_txes;foreignKey:Hash;references:Hash" json:"headers,omitempty"` From string `json:"from"` To string `json:"to"` Data string `json:"data"` GasPrice string `json:"gasPrice"` GasLimit string `json:"gasLimit"` Value string `json:"value"` Nonce uint64 `json:"nonce"` }