2021-07-14 16:13:27 +01:00
|
|
|
# Nimbus
|
2024-02-13 17:49:41 +08:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2021-07-14 16:13:27 +01:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2023-02-14 21:27:17 +01:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2021-07-14 16:13:27 +01:00
|
|
|
import
|
2024-12-13 12:12:57 +07:00
|
|
|
../../common/common
|
2022-12-02 11:35:41 +07:00
|
|
|
|
|
|
|
export
|
|
|
|
common
|
2021-07-14 16:13:27 +01:00
|
|
|
|
|
|
|
type
|
2022-12-02 11:35:41 +07:00
|
|
|
ChainRef* = ref object of RootRef
|
|
|
|
com: CommonRef
|
|
|
|
## common block chain configuration
|
|
|
|
## used throughout entire app
|
2022-05-09 15:04:48 +01:00
|
|
|
|
2021-07-14 16:13:27 +01:00
|
|
|
extraValidation: bool ##\
|
2021-07-30 15:06:51 +01:00
|
|
|
## Trigger extra validation, currently within `persistBlocks()`
|
|
|
|
## function only.
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public constructors
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-16 03:22:06 +00:00
|
|
|
func newChain*(com: CommonRef,
|
2024-12-13 12:12:57 +07:00
|
|
|
extraValidation: bool): ChainRef =
|
2022-12-05 18:25:44 +07:00
|
|
|
## Constructor for the `Chain` descriptor object.
|
|
|
|
## The argument `extraValidation` enables extra block
|
2021-07-30 15:06:51 +01:00
|
|
|
## chain validation if set `true`.
|
2023-10-05 10:04:12 +07:00
|
|
|
ChainRef(
|
|
|
|
com: com,
|
2024-12-13 12:12:57 +07:00
|
|
|
extraValidation: extraValidation
|
2023-10-05 10:04:12 +07:00
|
|
|
)
|
2021-07-30 15:06:51 +01:00
|
|
|
|
2024-10-08 09:37:36 +07:00
|
|
|
proc newChain*(com: CommonRef): ChainRef =
|
2021-07-30 15:06:51 +01:00
|
|
|
## Constructor for the `Chain` descriptor object. All sub-object descriptors
|
|
|
|
## are initialised with defaults. So is extra block chain validation
|
2024-11-07 08:24:21 +07:00
|
|
|
let header = com.db.getCanonicalHead().expect("canonical head exists")
|
|
|
|
let extraValidation = com.proofOfStake(header)
|
|
|
|
return ChainRef(
|
|
|
|
com: com,
|
|
|
|
extraValidation: extraValidation,
|
|
|
|
)
|
2024-11-07 10:43:25 +07:00
|
|
|
|
2021-07-14 16:13:27 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public `Chain` getters
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-10-05 10:04:12 +07:00
|
|
|
|
2024-06-16 03:22:06 +00:00
|
|
|
func db*(c: ChainRef): CoreDbRef =
|
2021-07-14 16:13:27 +01:00
|
|
|
## Getter
|
2022-12-02 11:35:41 +07:00
|
|
|
c.com.db
|
2021-07-14 16:13:27 +01:00
|
|
|
|
2024-06-16 03:22:06 +00:00
|
|
|
func com*(c: ChainRef): CommonRef =
|
2022-09-16 11:23:25 +07:00
|
|
|
## Getter
|
2022-12-02 11:35:41 +07:00
|
|
|
c.com
|
2022-09-16 11:23:25 +07:00
|
|
|
|
2024-06-16 03:22:06 +00:00
|
|
|
func extraValidation*(c: ChainRef): bool =
|
2021-07-14 16:13:27 +01:00
|
|
|
## Getter
|
2022-12-02 11:35:41 +07:00
|
|
|
c.extraValidation
|
2021-07-14 16:13:27 +01:00
|
|
|
|
2021-07-30 15:06:51 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public `Chain` setters
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-16 03:22:06 +00:00
|
|
|
func `extraValidation=`*(c: ChainRef; extraValidation: bool) =
|
2021-07-30 15:06:51 +01:00
|
|
|
## Setter. If set `true`, the assignment value `extraValidation` enables
|
|
|
|
## extra block chain validation.
|
|
|
|
c.extraValidation = extraValidation
|
|
|
|
|
2021-07-14 16:13:27 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|