native

package
v0.0.0-...-f94ef0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MainRoleManagementId            = int32(-8)
	MainBrdgeConractDepositPrefix   = 0x01
	MainBridgeContractValidatorsKey = 0x03
	MainStateValidatorRoleValue     = 0x04

	PUSHINT8                         = 0
	PUSHINT16                        = 1
	PUSH0                            = 16
	PUSH1                            = 17
	PUSH16                           = 32
	PUSHDATA1                        = 12
	SYSCALL                          = 65
	SystemCryptoCheckSig      uint32 = 666101590
	SystemCryptoCheckMultisig uint32 = 987549854
)
View Source
const (
	PrefixHeader                     = 0x00
	PrefixStateRoot                  = 0x01
	ValidatorsKey                    = 0x02
	PrefixMainStateValidatorsAddress = 0x03
	PrefixDepositId                  = 0x04
	LockIdKey                        = 0x05
	PrefixLock                       = 0x06

	JointHeadersKey    = 0x11
	JointStateRootsKey = 0x12
)
View Source
const (
	DefaultFeePerByte uint64 = 1000
	DefaultGasPrice   uint64 = 10000000000 //10GWei

	PrefixFeePerByte    byte = 0x01
	PrefixGasPrice      byte = 0x08
	PrefixBlockedAcount byte = 0x11
)
View Source
const (
	GASDecimal = 18
)
View Source
const (
	MaxNodeCount = 21
)

Variables

View Source
var (
	ErrInvalidSignature           = errors.New("invalid signature")
	ErrInvalidHeader              = errors.New("invalid header")
	ErrInvalidStateRoot           = errors.New("invalid state root")
	ErrHeaderNotFound             = errors.New("header not found")
	ErrStateRootNotFound          = errors.New("state root not found")
	ErrTxInexistent               = errors.New("tx inexistent")
	ErrAlreadySynced              = errors.New("already synced")
	ErrAlreadyMinted              = errors.New("already minted")
	ErrInvalidMPTProof            = errors.New("invalid mpt proof")
	ErrTxIdNotMatchDepositedState = errors.New("txid and deposited state unmatch")
	ErrValidatorsOutdated         = errors.New("synced validators outdated")
	ErrInvalidMainValidatorsState = errors.New("invalid main validators state")
	ErrUnreachThreshold           = errors.New("mint amount unreach threshold")

	BridgeAddress  common.Address = common.Address(common.BytesToAddress([]byte{nativeids.Bridge}))
	MintThreashold                = big.NewInt(100000000) //1GAS
	BaseBonous                    = big.NewInt(3000000)   //0.03GAS

)
View Source
var (
	ErrEmptyInput                = errors.New("empty input")
	ErrInvalidInput              = errors.New("invalid input")
	ErrInvalidMethodID           = errors.New("invalid method id")
	ErrEmptyNodeList             = errors.New("node list is empty")
	ErrLargeNodeList             = errors.New("node list is too large")
	ErrInvalidRole               = errors.New("invalid role")
	ErrInvalidSender             = errors.New("sender check failed")
	ErrNoBlock                   = errors.New("no persisting block in the context")
	ErrInitialize                = errors.New("initialize should only execute in genesis block")
	ErrInvalidContractCallInputs = errors.New("need at least 1 for InteropContext in contract call")
	ErrInvalidContractCallReturn = errors.New("invalid return value in contract call")
)
View Source
var (
	PolicyAddress      = common.Address(common.BytesToAddress([]byte{nativeids.Policy}))
	ErrAccountBlocked  = errors.New("account blocked")
	ErrContractBlocked = errors.New("contract blocked")
)

Functions

func MakeContractKey

func MakeContractKey(h common.Address) []byte

Types

type Bridge

type Bridge struct {
	state.NativeContract
	// contains filtered or unexported fields
}

func NewBridge

func NewBridge(cs *Contracts, cfg config.ProtocolConfiguration) *Bridge

func (*Bridge) ContractCall_Payable_lock

func (b *Bridge) ContractCall_Payable_lock(ic InteropContext, to common.Address) error

func (*Bridge) ContractCall__View_getMinted

func (b *Bridge) ContractCall__View_getMinted(ic InteropContext, depositId int64) ([]byte, error)

func (*Bridge) ContractCall_requestMint

func (b *Bridge) ContractCall_requestMint(
	ic InteropContext,
	headerIndex uint32,
	txid *big.Int,
	txProof []byte,
	stateIndex uint32,
	stateProof []byte) error

func (*Bridge) ContractCall_syncHeader

func (b *Bridge) ContractCall_syncHeader(ic InteropContext, rawHeader []byte) error

func (*Bridge) ContractCall_syncStateRoot

func (b *Bridge) ContractCall_syncStateRoot(ic InteropContext, rawStateroot []byte) error

func (*Bridge) ContractCall_syncStateRootValidatorsAddress

func (b *Bridge) ContractCall_syncStateRootValidatorsAddress(
	ic InteropContext,
	headerIndex uint32,
	txid *big.Int,
	txProof []byte,
	stateIndex uint32,
	stateProof []byte) error

func (*Bridge) ContractCall_syncValidators

func (b *Bridge) ContractCall_syncValidators(
	ic InteropContext,
	headerIndex uint32,
	txid *big.Int,
	txProof []byte,
	stateIndex uint32,
	stateProof []byte) error

func (*Bridge) GetMinted

func (b *Bridge) GetMinted(d *dao.Simple, depositId int64) (common.Hash, error)

func (*Bridge) RequiredGas

func (d *Bridge) RequiredGas(ic InteropContext, input []byte) uint64

func (*Bridge) Run

func (d *Bridge) Run(ic InteropContext, input []byte) ([]byte, error)

type Contracts

type Contracts struct {
	GAS        *GAS
	Ledger     *Ledger
	Designate  *Designate
	Management *Management
	Policy     *Policy
	Bridge     *Bridge
	Contracts  []state.NativeContract
}

func NewContracts

func NewContracts(cfg config.ProtocolConfiguration) *Contracts

func (*Contracts) ByName

func (cs *Contracts) ByName(name string) *state.NativeContract

func (*Contracts) OnPersist

func (cs *Contracts) OnPersist(d *dao.Simple, block *block.Block) error

func (*Contracts) PostPersist

func (cs *Contracts) PostPersist(d *dao.Simple, block *block.Block) error

type Designate

type Designate struct {
	state.NativeContract
	StandbyValidators keys.PublicKeys
	// contains filtered or unexported fields
}

func NewDesignate

func NewDesignate(cfg config.ProtocolConfiguration) *Designate

func (*Designate) ContractCall_initialize

func (d *Designate) ContractCall_initialize(ic InteropContext) error

func (*Designate) GetConsensusAddress

func (d *Designate) GetConsensusAddress(s *dao.Simple, index uint32) (common.Address, error)

func (*Designate) GetDesignatedByRole

func (d *Designate) GetDesignatedByRole(s *dao.Simple, r noderoles.Role, index uint32) (keys.PublicKeys, uint32, error)

func (*Designate) GetDesignatedByRoleFromStorage

func (d *Designate) GetDesignatedByRoleFromStorage(s *dao.Simple, r noderoles.Role, index uint32) (keys.PublicKeys, uint32, error)

func (*Designate) GetSysAddresses

func (d *Designate) GetSysAddresses(s *dao.Simple, index uint32) ([]common.Address, error)

func (*Designate) GetValidators

func (d *Designate) GetValidators(s *dao.Simple, index uint32) (keys.PublicKeys, error)

func (*Designate) PostPersist

func (d *Designate) PostPersist(s *dao.Simple, _ *block.Block) error

func (*Designate) RequiredGas

func (d *Designate) RequiredGas(ic InteropContext, input []byte) uint64

func (*Designate) Run

func (d *Designate) Run(ic InteropContext, input []byte) ([]byte, error)

func (*Designate) UpdateCache

func (d *Designate) UpdateCache(s *dao.Simple) error

type DesignationCache

type DesignationCache struct {
	// contains filtered or unexported fields
}

type GAS

type GAS struct {
	state.NativeContract
	// contains filtered or unexported fields
}

func NewGAS

func NewGAS(cs *Contracts, init uint64) *GAS

func (*GAS) AddBalance

func (g *GAS) AddBalance(d *dao.Simple, h common.Address, amount *big.Int)

func (*GAS) Burn

func (g *GAS) Burn(d *dao.Simple, address common.Address, amount *big.Int) error

func (*GAS) ContractCall_initialize

func (g *GAS) ContractCall_initialize(ic InteropContext) error

func (*GAS) GetBalance

func (g *GAS) GetBalance(d *dao.Simple, h common.Address) *big.Int

func (*GAS) Mint

func (g *GAS) Mint(d *dao.Simple, address common.Address, amount *big.Int) error

func (*GAS) OnPersist

func (g *GAS) OnPersist(d *dao.Simple, block *block.Block) error

func (*GAS) RequiredGas

func (g *GAS) RequiredGas(ic InteropContext, input []byte) uint64

func (*GAS) Run

func (g *GAS) Run(ic InteropContext, input []byte) ([]byte, error)

func (*GAS) SubBalance

func (g *GAS) SubBalance(d *dao.Simple, h common.Address, amount *big.Int)

type GasState

type GasState struct {
	Balance *big.Int
}

func (*GasState) DecodeBinary

func (g *GasState) DecodeBinary(br *io.BinReader)

func (*GasState) EncodeBinary

func (g *GasState) EncodeBinary(bw *io.BinWriter)

type InteropContext

type InteropContext interface {
	Log(*types.Log)
	Sender() common.Address
	Dao() *dao.Simple
	Container() *transaction.Transaction
	PersistingBlock() *block.Block
}

type Ledger

type Ledger struct {
	state.NativeContract
}

func NewLedger

func NewLedger() *Ledger

func (*Ledger) GetNonce

func (l *Ledger) GetNonce(s *dao.Simple, h common.Address) uint64

func (*Ledger) SetNonce

func (l *Ledger) SetNonce(s *dao.Simple, h common.Address, nonce uint64)

type Management

type Management struct {
	state.NativeContract
	// contains filtered or unexported fields
}

func NewManagement

func NewManagement(cs *Contracts) *Management

func (*Management) ContractCall_initialize

func (m *Management) ContractCall_initialize(ic InteropContext) error

func (*Management) Destroy

func (m *Management) Destroy(s *dao.Simple, addr common.Address) bool

func (*Management) GetCode

func (m *Management) GetCode(s *dao.Simple, addr common.Address) []byte

func (*Management) GetCodeHash

func (m *Management) GetCodeHash(s *dao.Simple, addr common.Address) common.Hash

func (*Management) GetCodeSize

func (m *Management) GetCodeSize(s *dao.Simple, addr common.Address) int

func (*Management) GetContract

func (m *Management) GetContract(s *dao.Simple, addr common.Address) *state.Contract

func (*Management) RequiredGas

func (m *Management) RequiredGas(ic InteropContext, input []byte) uint64

func (*Management) Run

func (m *Management) Run(ic InteropContext, input []byte) ([]byte, error)

func (*Management) SetCode

func (m *Management) SetCode(s *dao.Simple, addr common.Address, code []byte)

type Policy

type Policy struct {
	state.NativeContract
	// contains filtered or unexported fields
}

func NewPolicy

func NewPolicy(cs *Contracts) *Policy

func (*Policy) ContractCall_blockAccount

func (p *Policy) ContractCall_blockAccount(ic InteropContext, address common.Address) error

func (*Policy) ContractCall_initialize

func (p *Policy) ContractCall_initialize(ic InteropContext) error

func (*Policy) ContractCall_setFeePerByte

func (p *Policy) ContractCall_setFeePerByte(ic InteropContext, fee uint64) error

func (*Policy) ContractCall_setGasPrice

func (p *Policy) ContractCall_setGasPrice(ic InteropContext, gasPrice uint64) error

func (*Policy) ContractCall_unblockAccount

func (p *Policy) ContractCall_unblockAccount(ic InteropContext, address common.Address) error

func (*Policy) GetFeePerByte

func (p *Policy) GetFeePerByte(s *dao.Simple) uint64

func (*Policy) GetFeePerByteFromStorage

func (p *Policy) GetFeePerByteFromStorage(s *dao.Simple) uint64

func (*Policy) GetGasPrice

func (p *Policy) GetGasPrice(s *dao.Simple) *big.Int

func (*Policy) GetGasPriceFromStorage

func (p *Policy) GetGasPriceFromStorage(s *dao.Simple) *big.Int

func (*Policy) IsBlocked

func (p *Policy) IsBlocked(d *dao.Simple, address common.Address) bool

func (*Policy) PostPersist

func (p *Policy) PostPersist(d *dao.Simple, _ *block.Block) error

func (*Policy) RequiredGas

func (p *Policy) RequiredGas(ic InteropContext, input []byte) uint64

func (*Policy) Run

func (p *Policy) Run(ic InteropContext, input []byte) ([]byte, error)

func (*Policy) UpdateCache

func (p *Policy) UpdateCache(d *dao.Simple) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL