Documentation ¶
Index ¶
- Constants
- Variables
- func AbsolutePath(datadir string, filename string) string
- func Bytes2Hex(d []byte) string
- func FileExist(filePath string) bool
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func IsHexAddress(s string) bool
- func LoadJSON(file string, val interface{}) error
- func ParseHexOrString(str string) ([]byte, error)
- type Address
- type Bytes
- type ChainConfig
- func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool
- func (c *ChainConfig) IsBerlin(num *big.Int) bool
- func (c *ChainConfig) IsByzantium(num *big.Int) bool
- func (c *ChainConfig) IsConstantinople(num *big.Int) bool
- func (c *ChainConfig) IsEIP150(num *big.Int) bool
- func (c *ChainConfig) IsEIP155(num *big.Int) bool
- func (c *ChainConfig) IsEIP158(num *big.Int) bool
- func (c *ChainConfig) IsHomestead(num *big.Int) bool
- func (c *ChainConfig) IsIstanbul(num *big.Int) bool
- func (c *ChainConfig) IsLondon(num *big.Int) bool
- func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool
- func (c *ChainConfig) IsPetersburg(num *big.Int) bool
- func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules
- type Hash
- type HashStruct
- type MixedcaseAddress
- func (ma *MixedcaseAddress) Address() Address
- func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)
- func (ma *MixedcaseAddress) Original() string
- func (ma *MixedcaseAddress) String() string
- func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error
- func (ma *MixedcaseAddress) ValidChecksum() bool
- type PrettyDuration
- type Rules
- type StateAccount
- type UnprefixedAddress
Constants ¶
const ( // hash长度 HashLength = 32 // 地址值长度 AddressLength = 20 )
定义hash和地址长度byte
const ( GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1). GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. CallStipend uint64 = 2300 // Free gas given at beginning of call. Keccak256Gas uint64 = 30 // Once per KECCAK256 operation. Keccak256WordGas uint64 = 6 // Once per word of the KECCAK256 operation's data. SstoreSetGas uint64 = 20000 // Once per SSTORE operation. SstoreResetGas uint64 = 5000 // Once per SSTORE operation if the zeroness changes from zero. SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change. SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero. NetSstoreNoopGas uint64 = 200 // Once per SSTORE operation if the value doesn't change. NetSstoreInitGas uint64 = 20000 // Once per SSTORE operation from clean zero. NetSstoreCleanGas uint64 = 5000 // Once per SSTORE operation from clean non-zero. NetSstoreDirtyGas uint64 = 200 // Once per SSTORE operation from dirty. NetSstoreClearRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value SstoreSentryGasEIP2200 uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed SstoreSetGasEIP2200 uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero SstoreResetGasEIP2200 uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else SstoreClearsScheduleRefundEIP2200 uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot ColdAccountAccessCostEIP2929 = uint64(2600) // COLD_ACCOUNT_ACCESS_COST ColdSloadCostEIP2929 = uint64(2100) // COLD_SLOAD_COST WarmStorageReadCostEIP2929 = uint64(100) // WARM_STORAGE_READ_COST // In EIP-2200: SstoreResetGas was 5000. // In EIP-2929: SstoreResetGas was changed to '5000 - COLD_SLOAD_COST'. // In EIP-3529: SSTORE_CLEARS_SCHEDULE is defined as SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST // Which becomes: 5000 - 2100 + 1900 = 4800 SstoreClearsScheduleRefundEIP3529 uint64 = SstoreResetGasEIP2200 - ColdSloadCostEIP2929 + TxAccessListStorageKeyGas JumpdestGas uint64 = 1 // Once per JUMPDEST operation. EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. CreateDataGas uint64 = 200 // CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. ExpGas uint64 = 10 // Once per EXP instruction LogGas uint64 = 375 // Per LOG* operation. CopyGas uint64 = 3 // StackLimit uint64 = 1024 // Maximum size of VM stack allowed. TierStepGas uint64 = 0 // Once per operation, for a selection of them. LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. Create2Gas uint64 = 32000 // Once per CREATE2 operation SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation. MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. TxDataNonZeroGasFrontier uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. TxDataNonZeroGasEIP2028 uint64 = 16 // Per byte of non zero data attached to a transaction after EIP 2028 (part in Istanbul) TxAccessListAddressGas uint64 = 2400 // Per address specified in EIP 2930 access list TxAccessListStorageKeyGas uint64 = 1900 // Per storage key specified in EIP 2930 access list // These have been changed during the course of the chain CallGasFrontier uint64 = 40 // Once per CALL operation & message call transaction. CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine) BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine BalanceGasEIP1884 uint64 = 700 // The cost of a BALANCE operation after EIP 1884 (part of Istanbul) ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine) ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine) SloadGasFrontier uint64 = 50 SloadGasEIP150 uint64 = 200 SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul) SloadGasEIP2200 uint64 = 800 // Cost of SLOAD after EIP 2200 (part of Istanbul) ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople) ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul) SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine) // EXP has a dynamic portion depending on the size of the exponent ExpByteFrontier uint64 = 10 // was set to 10 in Frontier ExpByteEIP158 uint64 = 50 // was raised to 50 during Eip158 (Spurious Dragon) // Extcodecopy has a dynamic AND a static cost. This represents only the // static portion of the gas. It was changed during EIP 150 (Tangerine) ExtcodeCopyBaseFrontier uint64 = 20 ExtcodeCopyBaseEIP150 uint64 = 700 // CreateBySelfdestructGas is used when the refunded account is one that does // not exist. This logic is similar to call. // Introduced in Tangerine Whistle (Eip 150) CreateBySelfdestructGas uint64 = 25000 BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks. ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have. InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks. MaxCodeSize = 24576 // Maximum bytecode to permit for a contract EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation IdentityBaseGas uint64 = 15 // Base price for a data copy operation IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation Bn256AddGasByzantium uint64 = 500 // Byzantium gas needed for an elliptic curve addition Bn256AddGasIstanbul uint64 = 150 // Gas needed for an elliptic curve addition Bn256ScalarMulGasByzantium uint64 = 40000 // Byzantium gas needed for an elliptic curve scalar multiplication Bn256ScalarMulGasIstanbul uint64 = 6000 // Gas needed for an elliptic curve scalar multiplication Bn256PairingBaseGasByzantium uint64 = 100000 // Byzantium base price for an elliptic curve pairing check Bn256PairingBaseGasIstanbul uint64 = 45000 // Base price for an elliptic curve pairing check Bn256PairingPerPointGasByzantium uint64 = 80000 // Byzantium per-point price for an elliptic curve pairing check Bn256PairingPerPointGasIstanbul uint64 = 34000 // Per-point price for an elliptic curve pairing check Bls12381G1AddGas uint64 = 600 // Price for BLS12-381 elliptic curve G1 point addition Bls12381G1MulGas uint64 = 12000 // Price for BLS12-381 elliptic curve G1 point scalar multiplication Bls12381G2AddGas uint64 = 4500 // Price for BLS12-381 elliptic curve G2 point addition Bls12381G2MulGas uint64 = 55000 // Price for BLS12-381 elliptic curve G2 point scalar multiplication Bls12381PairingBaseGas uint64 = 115000 // Base gas price for BLS12-381 elliptic curve pairing check Bls12381PairingPerPairGas uint64 = 23000 // Per-point pair gas price for BLS12-381 elliptic curve pairing check Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 RefundQuotient uint64 = 2 RefundQuotientEIP3529 uint64 = 5 Cao = 1 Gcao = 1e9 Octcao = 1e18 )
const ( // CHTFrequency是创建CHT的块频率 CHTFrequency = 32768 // FullImmutabilityThreshold是链段被视为不可变的块数(即软终结性)。 //它被下载程序用作针对深层祖先的硬限制,被区块链用作针对深层reorgs的硬限制, //被冻结器用作截止阈值,被集团用作快照信任限制。 FullImmutabilityThreshold = 90000 // LightImmutabilityThreshold是块数,在该块数之后,头链段对于light客户端是不可变的(即软终结性)。 //它被下载程序用作针对深层祖先的硬限制,被区块链用作针对深层REORG的硬限制,被轻型剪枝器用作剪枝有效性保证。 LightImmutabilityThreshold = 30000 )
Variables ¶
var ( DifficultyBoundDivisor = big.NewInt(2048) // 难度的界限除数,用于更新计算。 GenesisDifficulty = big.NewInt(131072) //创世区块难度值 MinimumDifficulty = big.NewInt(131072) // 困难可能达到的最低限度。 DurationLimit = big.NewInt(13) // blocktime持续时间上的决策边界,用于确定是否应该提高难度。 AllOctellProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, ""} )
var DAOForkExtraRange = big.NewInt(10)
DAOFOKEXTRANGE是从DAO分叉点开始的连续块数,用于覆盖中的额外数据以防止无分叉攻击。
Functions ¶
func AbsolutePath ¶
AbsolutePath返回datadir+filename,如果是绝对值,则返回filename。
func ParseHexOrString ¶
ParseHexOrString尝试对b进行hexdecode,但如果缺少前缀,则只返回原始字节
Types ¶
type Address ¶
type Address [AddressLength]byte
定义地址字节类型
func BigToAddress ¶
BigToAddress返回字节值为b的地址。如果b大于len(h),则从左侧裁剪b。
func HexToAddress ¶
HexToAddress返回字节值为s的地址。如果s大于len(h),则s将从左侧裁剪。
type ChainConfig ¶
type ChainConfig struct { ChainID *big.Int `json:"chainId"` // chainId标识当前链并用于重播保护 HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // 宅地开关块(无=无叉,0=已宅地) DAOForkBlock *big.Int `json:"daoForkBlock,omitempty"` // DAO硬拨叉开关块(无=无拨叉) DAOForkSupport bool `json:"daoForkSupport,omitempty"` // 节点是否支持或反对刀硬叉 // EIP150实现gas价格变化 EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF块(无=无叉) EIP150Hash Hash `json:"eip150Hash,omitempty"` // EIP150 HF散列(仅表头客户端需要,因为仅gas定价已更改) EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF块 EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF块 ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // 拜占庭开关块(nil=无分叉,0=已在拜占庭上) ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // 君士坦丁堡开关块(nil=无叉,0=已激活) PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // 彼得堡开关柜(无=与君士坦丁堡相同) IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // 伊斯坦布尔开关块(无=无分叉,0=已在伊斯坦布尔) MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384(炸弹延迟)开关块(无=无分叉,0=已激活) BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin开关块(无=无叉,0=已在Berlin上) LondonBlock *big.Int `json:"londonBlock,omitempty"` // 伦敦道岔闭塞(无=无分叉,0=已在伦敦) ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345(炸弹延迟)开关块(无=无分叉,0=已激活) MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // 合并后用作网络拆分器的虚拟分叉 // TerminalTotalDifficity是触发一致升级的网络达到的总难度。 TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"` // 各种共识引擎 Engine string `json:"ethash,omitempty"` }
func (*ChainConfig) IsArrowGlacier ¶
func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool
IsArrowGlacier返回num是否等于Arrow Glacier(EIP-4345)分叉块或更大。
func (*ChainConfig) IsBerlin ¶
func (c *ChainConfig) IsBerlin(num *big.Int) bool
IsBerlin返回num是否等于Berlin fork块或更大。
func (*ChainConfig) IsByzantium ¶
func (c *ChainConfig) IsByzantium(num *big.Int) bool
IsByzantium返回num是否等于或大于Byzantium fork块。
func (*ChainConfig) IsConstantinople ¶
func (c *ChainConfig) IsConstantinople(num *big.Int) bool
IsConstantinople返回num是否等于或大于君士坦丁堡叉块。
func (*ChainConfig) IsEIP150 ¶
func (c *ChainConfig) IsEIP150(num *big.Int) bool
IsEIP150返回num是否等于EIP150 fork块或更大。
func (*ChainConfig) IsEIP155 ¶
func (c *ChainConfig) IsEIP155(num *big.Int) bool
IsEIP155返回num是否等于EIP155 fork块或更大。
func (*ChainConfig) IsEIP158 ¶
func (c *ChainConfig) IsEIP158(num *big.Int) bool
IsEIP158返回num是否等于EIP158 fork块或更大。
func (*ChainConfig) IsHomestead ¶
func (c *ChainConfig) IsHomestead(num *big.Int) bool
IsHomestead返回num是否等于homestead块或更大。
func (*ChainConfig) IsIstanbul ¶
func (c *ChainConfig) IsIstanbul(num *big.Int) bool
IsIstanbul返回num是否等于或大于伊斯坦布尔分叉块。
func (*ChainConfig) IsLondon ¶
func (c *ChainConfig) IsLondon(num *big.Int) bool
IsLondon返回num是否等于或大于London fork块。
func (*ChainConfig) IsMuirGlacier ¶
func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool
IsMuirGlacier返回num是否等于Muir Glacier(EIP-2384)分叉块或更大。
func (*ChainConfig) IsPetersburg ¶
func (c *ChainConfig) IsPetersburg(num *big.Int) bool
IsPetersburg返回num是-等于或大于PetersburgBlock fork block -还是nil,并且君士坦丁堡处于活动状态
type Hash ¶
type Hash [HashLength]byte
定义hash字节类型
func BytesToHash ¶
func (*Hash) UnmarshalText ¶
UnmarshalText以十六进制语法解析哈希。
type HashStruct ¶
type HashStruct struct {
Hash Hash
}
type MixedcaseAddress ¶
type MixedcaseAddress struct {
// contains filtered or unexported fields
}
MixedcaseAddress保留原始字符串,该字符串可能正确校验和,也可能不正确校验和
func NewMixedcaseAddress ¶
func NewMixedcaseAddress(addr Address) MixedcaseAddress
NewMixedcaseAddress构造函数(主要用于测试)
func NewMixedcaseAddressFromString ¶
func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error)
NewMixedcaseAddressFromString is mainly meant for unit-testing
func (*MixedcaseAddress) Address ¶
func (ma *MixedcaseAddress) Address() Address
Address returns the address
func (*MixedcaseAddress) MarshalJSON ¶
func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)
MarshalJSON marshals the original value
func (*MixedcaseAddress) Original ¶
func (ma *MixedcaseAddress) Original() string
Original returns the mixed-case input string
func (*MixedcaseAddress) String ¶
func (ma *MixedcaseAddress) String() string
String implements fmt.Stringer
func (*MixedcaseAddress) UnmarshalJSON ¶
func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error
MarshalJSON解析MixedcaseAddress
func (*MixedcaseAddress) ValidChecksum ¶
func (ma *MixedcaseAddress) ValidChecksum() bool
ValidChecksum returns true if the address has valid checksum
type PrettyDuration ¶
PrettyDuration是一个时间的打印版本。持续时间值,用于从格式化的文本表示中去除不必要的精度。
type Rules ¶
type Rules struct { ChainID *big.Int IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsBerlin, IsLondon bool IsMerge bool }
规则包装ChainConfig,只是语法糖,或者可以用于不包含或不需要有关块的信息的函数。 规则是一次性接口,这意味着它不应该在过渡阶段之间使用。
type StateAccount ¶
type StateAccount struct { Nonce uint64 Balance *big.Int //账户余额 Root Hash // 存储trie的merkle根 CodeHash []byte }
账户结构体
type UnprefixedAddress ¶
type UnprefixedAddress Address
UnprefixedAddress allows marshaling an Address without 0x prefix.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bitutil implements fast bitwise operations.
|
Package bitutil implements fast bitwise operations. |
Package forkid implements EIP-2124 (https://eips.ethereum.org/EIPS/eip-2124).
|
Package forkid implements EIP-2124 (https://eips.ethereum.org/EIPS/eip-2124). |
Package hexutil implements hex encoding with 0x prefix.
|
Package hexutil implements hex encoding with 0x prefix. |
Package math provides integer math utilities.
|
Package math provides integer math utilities. |
Package mclock is a wrapper for a monotonic clock source
|
Package mclock is a wrapper for a monotonic clock source |
Package prque implements a priority queue data structure supporting arbitrary value types and int64 priorities.
|
Package prque implements a priority queue data structure supporting arbitrary value types and int64 priorities. |