account

package
v1.0.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package account implements Account used in Kaia.

Inside the package, types, structures, functions, and interfaces associated with the Account are defined.

Type of Account

There are three types of Accounts used in Kaia.

  • LegacyAccountType
  • ExternallyOwnedAccountType
  • SmartContractAccountType

AccountCommon implements the structure and functions common to Kaia account, which also implements the Account interface.

EOA (ExternallyOwnedAccount) and SCA (SmartContractAccount) are implemented in a structure that includes AccountCommon.

LegacyAccount is implemented separately according to the account interface.

Source Files

Account related functions and variables are defined in the files listed below.

  • account.go : Defines types, interfaces and functions associated with the Account.
  • account_common.go : Data structures and functions that are common to EOA (ExternallyOwnedAccount) and SCA (SmartContractAccount) are defined as AccountCommon.
  • account_serializer.go : AccountSerializer is defined for serializing Account.
  • externally_owned_account.go : ExternallyOwnedAccount containing an AccountCommon is defined.
  • legacy_account.go : LegacyAccount that implements the Account interface is defined.
  • smart_contract_account.go : SmartContractAccount containing an AccountCommon is defined.

For more information on Account, please refer to the document below. https://docs.kaia.io/docs/learn/accounts/#kaia-accounts-

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUndefinedAccountType    = errors.New("undefined account type")
	ErrAccountKeyNotModifiable = errors.New("account key is not modifiable")
)

Functions

func UnextendSerializedAccount

func UnextendSerializedAccount(b []byte) (result []byte)

UnextendSerializedAccount unextends ExtHash fields within an RLP-encoded account. If the supplied bytes is not an RLP-encoded account, or does not contain any ExtHash, then return the supplied bytes unchanged.

Types

type Account

type Account interface {
	Type() AccountType

	GetNonce() uint64
	GetBalance() *big.Int
	GetHumanReadable() bool

	SetNonce(n uint64)
	SetBalance(b *big.Int)
	SetHumanReadable(b bool)

	// UpdateKey updates the account's key with the given key.
	UpdateKey(newKey accountkey.AccountKey, currentBlockNumber uint64) error

	// Empty returns whether the account is considered empty.
	// The "empty" account may be defined differently depending on the actual account type.
	// An example of an empty account could be described as the one that satisfies the following conditions:
	// - nonce is zero
	// - balance is zero
	// - codeHash is the same as emptyCodeHash
	Empty() bool

	// Equal returns true if all the attributes are exactly same. Otherwise, returns false.
	Equal(Account) bool

	// DeepCopy copies all the attributes.
	DeepCopy() Account

	// String returns all attributes of this object as a string.
	String() string
}

Account is the Kaia consensus representation of accounts. These objects are stored in the main account trie.

func NewAccountWithMap

func NewAccountWithMap(t AccountType, values map[AccountValueKeyType]interface{}) (Account, error)

NewAccountWithType creates an Account object initialized with the given map.

func NewAccountWithType

func NewAccountWithType(t AccountType) (Account, error)

NewAccountWithType creates an Account object with the given type.

type AccountCommon

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

AccountCommon represents the common data structure of a Kaia account.

func (*AccountCommon) DecodeRLP

func (e *AccountCommon) DecodeRLP(s *rlp.Stream) error

func (*AccountCommon) DeepCopy

func (e *AccountCommon) DeepCopy() *AccountCommon

func (*AccountCommon) Empty

func (e *AccountCommon) Empty() bool

func (*AccountCommon) EncodeRLP

func (e *AccountCommon) EncodeRLP(w io.Writer) error

func (*AccountCommon) Equal

func (e *AccountCommon) Equal(ta *AccountCommon) bool

func (*AccountCommon) GetBalance

func (e *AccountCommon) GetBalance() *big.Int

func (*AccountCommon) GetHumanReadable

func (e *AccountCommon) GetHumanReadable() bool

func (*AccountCommon) GetKey

func (e *AccountCommon) GetKey() accountkey.AccountKey

func (*AccountCommon) GetNonce

func (e *AccountCommon) GetNonce() uint64

func (*AccountCommon) MarshalJSON

func (e *AccountCommon) MarshalJSON() ([]byte, error)

func (*AccountCommon) ReplaceKey

func (e *AccountCommon) ReplaceKey(newKey accountkey.AccountKey, currentBlockNumber uint64) error

func (*AccountCommon) SetBalance

func (e *AccountCommon) SetBalance(b *big.Int)

func (*AccountCommon) SetHumanReadable

func (e *AccountCommon) SetHumanReadable(h bool)

func (*AccountCommon) SetKey

func (e *AccountCommon) SetKey(k accountkey.AccountKey)

func (*AccountCommon) SetNonce

func (e *AccountCommon) SetNonce(n uint64)

func (*AccountCommon) String

func (e *AccountCommon) String() string

func (*AccountCommon) UnmarshalJSON

func (e *AccountCommon) UnmarshalJSON(b []byte) error

func (*AccountCommon) UpdateKey

func (e *AccountCommon) UpdateKey(newKey accountkey.AccountKey, currentBlockNumber uint64) error

type AccountSerializer

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

AccountSerializer serializes an Account object using RLP/JSON.

func NewAccountSerializer

func NewAccountSerializer() *AccountSerializer

NewAccountSerializer creates a new AccountSerializer object with default values. This returned object will be used for decoding.

func NewAccountSerializerExt

func NewAccountSerializerExt() *AccountSerializer

NewAccountSerializer creates a new AccountSerializer object with default values. This returned object will be used for decoding.

func NewAccountSerializerExtWithAccount

func NewAccountSerializerExtWithAccount(a Account) *AccountSerializer

NewAccountSerializerWithAccount creates a new AccountSerializer object with the given account.

func NewAccountSerializerWithAccount

func NewAccountSerializerWithAccount(a Account) *AccountSerializer

NewAccountSerializerWithAccount creates a new AccountSerializer object with the given account.

func (*AccountSerializer) DecodeRLP

func (ser *AccountSerializer) DecodeRLP(s *rlp.Stream) error

func (*AccountSerializer) EncodeRLP

func (ser *AccountSerializer) EncodeRLP(w io.Writer) error

func (*AccountSerializer) GetAccount

func (ser *AccountSerializer) GetAccount() Account

func (*AccountSerializer) MarshalJSON

func (ser *AccountSerializer) MarshalJSON() ([]byte, error)

func (*AccountSerializer) UnmarshalJSON

func (ser *AccountSerializer) UnmarshalJSON(b []byte) error

type AccountType

type AccountType uint8
const (
	LegacyAccountType AccountType = iota
	ExternallyOwnedAccountType
	SmartContractAccountType
)

func (AccountType) String

func (a AccountType) String() string

type AccountValueKeyType

type AccountValueKeyType uint
const (
	AccountValueKeyNonce AccountValueKeyType = iota
	AccountValueKeyBalance
	AccountValueKeyStorageRoot
	AccountValueKeyCodeHash
	AccountValueKeyHumanReadable
	AccountValueKeyAccountKey
	AccountValueKeyCodeInfo
)

type AccountWithKey

type AccountWithKey interface {
	Account

	GetKey() accountkey.AccountKey
	SetKey(key accountkey.AccountKey)
}

func GetAccountWithKey

func GetAccountWithKey(a Account) AccountWithKey

type ExternallyOwnedAccount

type ExternallyOwnedAccount struct {
	*AccountCommon
}

ExternallyOwnedAccount represents a Kaia account used by a user.

func (*ExternallyOwnedAccount) DeepCopy

func (e *ExternallyOwnedAccount) DeepCopy() Account

func (*ExternallyOwnedAccount) Dump

func (e *ExternallyOwnedAccount) Dump()

func (*ExternallyOwnedAccount) Equal

func (e *ExternallyOwnedAccount) Equal(a Account) bool

func (*ExternallyOwnedAccount) String

func (e *ExternallyOwnedAccount) String() string

func (*ExternallyOwnedAccount) Type

type LegacyAccount

type LegacyAccount struct {
	Nonce    uint64
	Balance  *big.Int
	Root     common.Hash // merkle root of the storage trie
	CodeHash []byte
}

LegacyAccount is the Kaia consensus representation of legacy accounts. These objects are stored in the main account trie.

func (*LegacyAccount) DeepCopy

func (a *LegacyAccount) DeepCopy() Account

func (*LegacyAccount) Dump

func (a *LegacyAccount) Dump()

func (*LegacyAccount) Empty

func (a *LegacyAccount) Empty() bool

func (*LegacyAccount) Equal

func (a *LegacyAccount) Equal(b Account) bool

func (*LegacyAccount) GetBalance

func (a *LegacyAccount) GetBalance() *big.Int

func (*LegacyAccount) GetCodeHash

func (a *LegacyAccount) GetCodeHash() []byte

func (*LegacyAccount) GetHumanReadable

func (a *LegacyAccount) GetHumanReadable() bool

func (*LegacyAccount) GetNonce

func (a *LegacyAccount) GetNonce() uint64

func (*LegacyAccount) GetStorageRoot

func (a *LegacyAccount) GetStorageRoot() common.Hash

func (*LegacyAccount) SetBalance

func (a *LegacyAccount) SetBalance(b *big.Int)

func (*LegacyAccount) SetCodeHash

func (a *LegacyAccount) SetCodeHash(h []byte)

func (*LegacyAccount) SetHumanReadable

func (a *LegacyAccount) SetHumanReadable(b bool)

func (*LegacyAccount) SetNonce

func (a *LegacyAccount) SetNonce(n uint64)

func (*LegacyAccount) SetStorageRoot

func (a *LegacyAccount) SetStorageRoot(h common.Hash)

func (*LegacyAccount) String

func (a *LegacyAccount) String() string

func (*LegacyAccount) Type

func (a *LegacyAccount) Type() AccountType

func (*LegacyAccount) UpdateKey

func (a *LegacyAccount) UpdateKey(newKey accountkey.AccountKey, currentBlockNumber uint64) error

type ProgramAccount

type ProgramAccount interface {
	Account

	GetStorageRoot() common.ExtHash
	GetCodeHash() []byte
	GetCodeFormat() params.CodeFormat
	GetVmVersion() params.VmVersion

	SetStorageRoot(h common.ExtHash)
	SetCodeHash(h []byte)
	SetCodeInfo(codeInfo params.CodeInfo)

	// A variant of EncodeRLP that preserves ExtHash fields as-is.
	// In contrast, vanilla EncodeRLP must unextend ExtHash when encoding.
	EncodeRLPExt(w io.Writer) error
}

ProgramAccount is an interface of an account having a program (code + storage). This interface is implemented by LegacyAccount and SmartContractAccount.

func GetProgramAccount

func GetProgramAccount(a Account) ProgramAccount

type SmartContractAccount

type SmartContractAccount struct {
	*AccountCommon
	// contains filtered or unexported fields
}

SmartContractAccount represents a smart contract account containing storage root and code hash.

func (*SmartContractAccount) DecodeRLP

func (sca *SmartContractAccount) DecodeRLP(s *rlp.Stream) error

func (*SmartContractAccount) DeepCopy

func (sca *SmartContractAccount) DeepCopy() Account

func (*SmartContractAccount) Empty

func (sca *SmartContractAccount) Empty() bool

func (*SmartContractAccount) EncodeRLP

func (sca *SmartContractAccount) EncodeRLP(w io.Writer) error

func (*SmartContractAccount) EncodeRLPExt

func (sca *SmartContractAccount) EncodeRLPExt(w io.Writer) error

func (*SmartContractAccount) Equal

func (sca *SmartContractAccount) Equal(a Account) bool

func (*SmartContractAccount) GetCodeFormat

func (sca *SmartContractAccount) GetCodeFormat() params.CodeFormat

func (*SmartContractAccount) GetCodeHash

func (sca *SmartContractAccount) GetCodeHash() []byte

func (*SmartContractAccount) GetStorageRoot

func (sca *SmartContractAccount) GetStorageRoot() common.ExtHash

func (*SmartContractAccount) GetVmVersion

func (sca *SmartContractAccount) GetVmVersion() params.VmVersion

func (*SmartContractAccount) MarshalJSON

func (sca *SmartContractAccount) MarshalJSON() ([]byte, error)

func (*SmartContractAccount) SetCodeHash

func (sca *SmartContractAccount) SetCodeHash(h []byte)

func (*SmartContractAccount) SetCodeInfo

func (sca *SmartContractAccount) SetCodeInfo(ci params.CodeInfo)

func (*SmartContractAccount) SetStorageRoot

func (sca *SmartContractAccount) SetStorageRoot(h common.ExtHash)

func (*SmartContractAccount) String

func (sca *SmartContractAccount) String() string

func (*SmartContractAccount) Type

func (sca *SmartContractAccount) Type() AccountType

func (*SmartContractAccount) UnmarshalJSON

func (sca *SmartContractAccount) UnmarshalJSON(b []byte) error

func (*SmartContractAccount) UpdateKey

func (sca *SmartContractAccount) UpdateKey(newKey accountkey.AccountKey, currentBlockNumber uint64) error

Jump to

Keyboard shortcuts

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