accountmanager

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDescriptionLength uint64 = 255

Variables

View Source
var (
	ErrInsufficientBalance    = errors.New("insufficient balance")
	ErrNewAccountErr          = errors.New("new account err")
	ErrAssetIDInvalid         = errors.New("asset id invalid")
	ErrCreateAccountError     = errors.New("create account error")
	ErrAccountInvaid          = errors.New("account not permission")
	ErrAccountIsExist         = errors.New("account is exist")
	ErrNameIsExist            = errors.New("name is exist")
	ErrAccountIsDestroy       = errors.New("account is destroy")
	ErrAccountNotExist        = errors.New("account not exist")
	ErrHashIsEmpty            = errors.New("hash is empty")
	ErrkeyNotSame             = errors.New("key not same")
	ErrAccountNameInvalid     = errors.New("account name is Invalid")
	ErrInvalidPubKey          = errors.New("invalid public key")
	ErrAccountIsNil           = errors.New("account object is empty")
	ErrCodeIsEmpty            = errors.New("code is empty")
	ErrAmountValueInvalid     = errors.New("amount value is invalid")
	ErrAccountAssetNotExist   = errors.New("account asset not exist")
	ErrUnkownTxType           = errors.New("not support action type")
	ErrTimeInvalid            = errors.New("input time invalid ")
	ErrTimeTypeInvalid        = errors.New("get snapshot time type invalid ")
	ErrChargeRatioInvalid     = errors.New("charge ratio value invalid ")
	ErrSnapshotTimeNotExist   = errors.New("next snapshot time not exist")
	ErrAccountManagerNotExist = errors.New("account manager name not exist")
	ErrAmountMustZero         = errors.New("amount must be zero")
	ErrToNameInvalid          = errors.New("action to name(Recipient) invalid")
	ErrCounterNotExist        = errors.New("account global counter not exist")
	ErrAccountIdInvalid       = errors.New("account id invalid")
	ErrInvalidReceiptAsset    = errors.New("invalid receipt of asset")
	ErrInvalidReceipt         = errors.New("invalid receipt")
	ErrNegativeValue          = errors.New("negative value")
	ErrNegativeAmount         = errors.New("negative amount")
	ErrAmountMustBeZero       = errors.New("amount must be zero")
	ErrAssetOwnerInvaild      = errors.New("asset owner invalid")
)

Functions

func GetAccountNameLevel added in v0.0.22

func GetAccountNameLevel(accountName common.Name) (uint64, error)

func GetAcountNameLength added in v0.0.16

func GetAcountNameLength() uint64

func GetAcountNameRegExp added in v0.0.9

func GetAcountNameRegExp() *regexp.Regexp

func GetAcountNameRegExpFork1 added in v0.0.22

func GetAcountNameRegExpFork1() *regexp.Regexp

func SetAccountNameConfig added in v0.0.7

func SetAccountNameConfig(config *Config) bool

func SetAcctMangerName added in v0.0.7

func SetAcctMangerName(name common.Name)

SetAcctMangerName set the global account manager name

Types

type Account

type Account struct {
	//LastTime *big.Int
	AcctName  common.Name `json:"accountName"`
	Founder   common.Name `json:"founder"`
	AccountID uint64      `json:"accountID"`
	Number    uint64      `json:"number"`
	//ChargeRatio           uint64      `json:"chargeRatio"`
	Nonce                 uint64      `json:"nonce"`
	Code                  []byte      `json:"code"`
	CodeHash              common.Hash `json:"codeHash"`
	CodeSize              uint64      `json:"codeSize"`
	Threshold             uint64      `json:"threshold"`
	UpdateAuthorThreshold uint64      `json:"updateAuthorThreshold"`
	AuthorVersion         common.Hash `json:"authorVersion"`
	//sort by asset id asc
	Balances []*AssetBalance `json:"balances"`
	//realated account, pubkey and address
	Authors []*common.Author `json:"authors"`
	//code Suicide
	Suicide bool `json:"suicide"`
	//account destroy
	Destroy     bool   `json:"destroy"`
	Description string `json:"description"`
}

Account account object

func NewAccount

func NewAccount(accountName common.Name, founderName common.Name, pubkey common.PubKey, description string) (*Account, error)

NewAccount create a new account object.

func (*Account) AddAuthor added in v0.0.7

func (a *Account) AddAuthor(author *common.Author) error

func (*Account) AddBalanceByID

func (a *Account) AddBalanceByID(assetID uint64, value *big.Int) (bool, error)

AddBalanceByID add balance by assetID

func (*Account) AddNewAssetByAssetID

func (a *Account) AddNewAssetByAssetID(p int64, assetID uint64, amount *big.Int)

AddNewAssetByAssetID add a new asset to balance list

func (*Account) DeleteAuthor added in v0.0.7

func (a *Account) DeleteAuthor(author *common.Author) error

func (*Account) EnoughAccountBalance

func (a *Account) EnoughAccountBalance(assetID uint64, value *big.Int) error

EnoughAccountBalance check account have enough asset balance

func (*Account) GetAccountID added in v0.0.7

func (a *Account) GetAccountID() uint64

GetAccountID return account object id

func (*Account) GetAccountNumber added in v0.0.7

func (a *Account) GetAccountNumber() uint64

GetAccountNumber return account object number

func (*Account) GetAllBalances

func (a *Account) GetAllBalances() (map[uint64]*big.Int, error)

GetAllBalances get all balance list

func (*Account) GetAuthorVersion added in v0.0.7

func (a *Account) GetAuthorVersion() common.Hash

GetAuthorVersion get author version

func (*Account) GetBalanceByID

func (a *Account) GetBalanceByID(assetID uint64) (*big.Int, error)

GetBalanceByID get balance by asset id

func (*Account) GetBalancesList

func (a *Account) GetBalancesList() []*AssetBalance

GetBalancesList get all balance list

func (*Account) GetCode

func (a *Account) GetCode() ([]byte, error)

GetCode get code

func (*Account) GetCodeHash

func (a *Account) GetCodeHash() (common.Hash, error)

GetCodeHash get code hash

func (*Account) GetCodeSize

func (a *Account) GetCodeSize() uint64

GetCodeSize get code size

func (*Account) GetFounder

func (a *Account) GetFounder() common.Name

GetFounder return account object founder

func (*Account) GetName

func (a *Account) GetName() common.Name

GetName return account object name

func (*Account) GetNonce

func (a *Account) GetNonce() uint64

GetNonce get nonce

func (*Account) GetThreshold added in v0.0.7

func (a *Account) GetThreshold() uint64

func (*Account) GetUpdateAuthorThreshold added in v0.0.7

func (a *Account) GetUpdateAuthorThreshold() uint64

func (*Account) HaveCode added in v0.0.7

func (a *Account) HaveCode() bool

HaveCode check account have code

func (*Account) IsDestroyed added in v0.0.7

func (a *Account) IsDestroyed() bool

IsDestroyed is destroyed

func (*Account) IsEmpty

func (a *Account) IsEmpty() bool

IsEmpty check account empty

func (*Account) IsSuicided

func (a *Account) IsSuicided() bool

IsSuicided suicide

func (*Account) SetAccountID added in v0.0.7

func (a *Account) SetAccountID(id uint64)

SetAccountID set account object id

func (*Account) SetAccountNumber added in v0.0.7

func (a *Account) SetAccountNumber(number uint64)

SetAccountNumber set account object number

func (*Account) SetAuthorVersion added in v0.0.7

func (a *Account) SetAuthorVersion()

SetAuthorVersion set author version

func (*Account) SetBalance

func (a *Account) SetBalance(assetID uint64, amount *big.Int) error

SetBalance set amount to balance

func (*Account) SetCode

func (a *Account) SetCode(code []byte) error

SetCode set code

func (*Account) SetDestroy added in v0.0.7

func (a *Account) SetDestroy()

SetDestroy set destroy

func (*Account) SetFounder

func (a *Account) SetFounder(f common.Name)

SetFounder set account object founder

func (*Account) SetNonce

func (a *Account) SetNonce(nonce uint64)

SetNonce set nonce

func (*Account) SetSuicide

func (a *Account) SetSuicide()

SetSuicide set setSuicide

func (*Account) SetThreshold added in v0.0.7

func (a *Account) SetThreshold(t uint64)

func (*Account) SetUpdateAuthorThreshold added in v0.0.7

func (a *Account) SetUpdateAuthorThreshold(t uint64)

func (*Account) SubBalanceByID

func (a *Account) SubBalanceByID(assetID uint64, value *big.Int) error

SubBalanceByID sub balance by assetID

func (*Account) UpdateAuthor added in v0.0.7

func (a *Account) UpdateAuthor(author *common.Author) error

type AccountAuthorAction added in v0.0.7

type AccountAuthorAction struct {
	Threshold             uint64          `json:"threshold,omitempty"`
	UpdateAuthorThreshold uint64          `json:"updateAuthorThreshold,omitempty"`
	AuthorActions         []*AuthorAction `json:"authorActions,omitempty"`
}

type AccountManager

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

AccountManager represents account management model.

func NewAccountManager

func NewAccountManager(db *state.StateDB) (*AccountManager, error)

NewAccountManager create new account manager

func (*AccountManager) AccountHaveCode added in v0.0.7

func (am *AccountManager) AccountHaveCode(accountName common.Name) (bool, error)

AccountHaveCode check account have code

func (*AccountManager) AccountIsEmpty

func (am *AccountManager) AccountIsEmpty(accountName common.Name) (bool, error)

AccountIsEmpty check account is empty

func (*AccountManager) AccountIsExist

func (am *AccountManager) AccountIsExist(accountName common.Name) (bool, error)

AccountIsExist check account is exist.

func (*AccountManager) AccountIsExistByID added in v0.0.16

func (am *AccountManager) AccountIsExistByID(accountID uint64) (bool, error)

AccountIsExistByID check account is exist by ID.

func (*AccountManager) AddAccountBalanceByID

func (am *AccountManager) AddAccountBalanceByID(accountName common.Name, assetID uint64, value *big.Int) error

AddAccountBalanceByID add balance by assetID

func (*AccountManager) AddAccountBalanceByName

func (am *AccountManager) AddAccountBalanceByName(accountName common.Name, assetName string, value *big.Int) error

AddAccountBalanceByName add balance by name

func (*AccountManager) CanTransfer

func (am *AccountManager) CanTransfer(accountName common.Name, assetID uint64, value *big.Int) (bool, error)

CanTransfer check if can transfer.

func (*AccountManager) CheckAssetContract added in v0.0.16

func (am *AccountManager) CheckAssetContract(contract common.Name, owner common.Name, from ...common.Name) bool

func (*AccountManager) CreateAccount

func (am *AccountManager) CreateAccount(fromName common.Name, accountName common.Name, founderName common.Name, number uint64, curForkID uint64, pubkey common.PubKey, detail string) error

CreateAccount create account

func (*AccountManager) DeleteAccountByName

func (am *AccountManager) DeleteAccountByName(accountName common.Name) error

DeleteAccountByName delete account

func (*AccountManager) EnoughAccountBalance

func (am *AccountManager) EnoughAccountBalance(accountName common.Name, assetID uint64, value *big.Int) error

func (*AccountManager) GetAccountBalanceByID

func (am *AccountManager) GetAccountBalanceByID(accountName common.Name, assetID uint64, typeID uint64) (*big.Int, error)

GetAccountBalanceByID get account balance by ID

func (*AccountManager) GetAccountById added in v0.0.7

func (am *AccountManager) GetAccountById(id uint64) (*Account, error)

GetAccountById get account by account id

func (*AccountManager) GetAccountByName

func (am *AccountManager) GetAccountByName(accountName common.Name) (*Account, error)

GetAccountByName get account by name

func (*AccountManager) GetAccountByTime

func (am *AccountManager) GetAccountByTime(accountName common.Name, time uint64) (*Account, error)

GetAccountByTime get account by name and time

func (*AccountManager) GetAccountIDByName added in v0.0.7

func (am *AccountManager) GetAccountIDByName(accountName common.Name) (uint64, error)

GetAccountIDByName get account id by account name

func (*AccountManager) GetAccountLastChange

func (am *AccountManager) GetAccountLastChange(accountName common.Name) (uint64, error)

GetAccountLastChange account balance last change time

func (*AccountManager) GetAllAssetbyAssetId added in v0.0.7

func (am *AccountManager) GetAllAssetbyAssetId(acct *Account, assetId uint64) (map[uint64]*big.Int, error)

GetAllAssetbyAssetId get accout asset and subAsset Info

func (*AccountManager) GetAllBalancebyAssetID added in v0.0.7

func (am *AccountManager) GetAllBalancebyAssetID(acct *Account, assetID uint64) (*big.Int, error)

GetAllBalancebyAssetID get account balance, balance(asset) = asset + subAsset

func (*AccountManager) GetAssetAmountByTime

func (am *AccountManager) GetAssetAmountByTime(assetID uint64, time uint64) (*big.Int, error)

GetAssetAmountByTime get asset amount by time

func (*AccountManager) GetAssetFounder

func (am *AccountManager) GetAssetFounder(assetID uint64) (common.Name, error)

GetAssetFounder Get Asset Founder

func (*AccountManager) GetAssetInfoByID

func (am *AccountManager) GetAssetInfoByID(assetID uint64) (*asset.AssetObject, error)

GetAssetInfoByID get asset info by assetID

func (*AccountManager) GetAssetInfoByName

func (am *AccountManager) GetAssetInfoByName(assetName string) (*asset.AssetObject, error)

GetAssetInfoByName get asset info by asset name.

func (*AccountManager) GetAuthorVersion added in v0.0.7

func (am *AccountManager) GetAuthorVersion(accountName common.Name) (common.Hash, error)

GetAuthorVersion returns the account author version

func (*AccountManager) GetBalanceByTime

func (am *AccountManager) GetBalanceByTime(accountName common.Name, assetID uint64, typeID uint64, time uint64) (*big.Int, error)

GetBalanceByTime get account balance by Time

func (*AccountManager) GetCode

func (am *AccountManager) GetCode(accountName common.Name) ([]byte, error)

func (*AccountManager) GetCodeSize

func (am *AccountManager) GetCodeSize(accountName common.Name) (uint64, error)

GetCodeSize get code size

func (*AccountManager) GetFounder

func (am *AccountManager) GetFounder(accountName common.Name) (common.Name, error)

GetFounder Get Account Founder

func (*AccountManager) GetNonce

func (am *AccountManager) GetNonce(accountName common.Name) (uint64, error)

GetNonce get nonce

func (*AccountManager) GetSnapshotTime

func (am *AccountManager) GetSnapshotTime(num uint64, time uint64) (uint64, error)

GetSnapshotTime get snapshot time num = 0 current snapshot time , 1 preview snapshot time , 2 next snapshot time

func (*AccountManager) IncAsset2Acct

func (am *AccountManager) IncAsset2Acct(fromName common.Name, toName common.Name, assetID uint64, amount *big.Int) error

IncAsset2Acct increase asset and add amount to accout balance

func (*AccountManager) IsValidSign

func (am *AccountManager) IsValidSign(accountName common.Name, pub common.PubKey) error

IsValidSign

func (*AccountManager) IssueAsset

func (am *AccountManager) IssueAsset(fromName common.Name, asset IssueAsset, number uint64, curForkID uint64) (uint64, error)

IssueAsset issue asset

func (*AccountManager) Process

func (am *AccountManager) Process(accountManagerContext *types.AccountManagerContext) ([]*types.InternalAction, error)

Process account action

func (*AccountManager) RecoverTx

func (am *AccountManager) RecoverTx(signer types.Signer, tx *types.Transaction) error

RecoverTx Make sure the transaction is signed properly and validate account authorization.

func (*AccountManager) SetAccount

func (am *AccountManager) SetAccount(acct *Account) error

SetAccount store account object to db

func (*AccountManager) SetCode added in v0.0.16

func (am *AccountManager) SetCode(accountName common.Name, code []byte) (bool, error)

SetCode set contract code

func (*AccountManager) SetNonce

func (am *AccountManager) SetNonce(accountName common.Name, nonce uint64) error

SetNonce set nonce

func (*AccountManager) SubAccountBalanceByID

func (am *AccountManager) SubAccountBalanceByID(accountName common.Name, assetID uint64, value *big.Int) error

SubAccountBalanceByID sub balance by assetID

func (*AccountManager) TransferAsset

func (am *AccountManager) TransferAsset(fromAccount common.Name, toAccount common.Name, assetID uint64, value *big.Int, fromAccountExtra ...common.Name) error

TransferAsset transfer asset

func (*AccountManager) UpdateAccount

func (am *AccountManager) UpdateAccount(accountName common.Name, accountAction *UpdataAccountAction) error

UpdateAccount update the pubkey of the account

func (*AccountManager) UpdateAccountAuthor added in v0.0.7

func (am *AccountManager) UpdateAccountAuthor(accountName common.Name, acctAuth *AccountAuthorAction) error

func (*AccountManager) ValidOneSign added in v0.0.7

func (am *AccountManager) ValidOneSign(acct *Account, index uint64, pub common.PubKey, recoverRes *recoverActionResult) error

func (*AccountManager) ValidSign added in v0.0.7

func (am *AccountManager) ValidSign(accountName common.Name, pub common.PubKey, index []uint64, recoverRes *recoverActionResult) error

ValidSign check the sign

type AssetBalance

type AssetBalance struct {
	AssetID uint64   `json:"assetID"`
	Balance *big.Int `json:"balance"`
}

AssetBalance asset and balance struct

type AuthorAction added in v0.0.7

type AuthorAction struct {
	ActionType AuthorActionType
	Author     *common.Author
}

type AuthorActionType added in v0.0.7

type AuthorActionType uint64
const (
	AddAuthor AuthorActionType = iota
	UpdateAuthor
	DeleteAuthor
)

type Config added in v0.0.7

type Config struct {
	AccountNameLevel         uint64 `json:"accountNameLevel"`
	AccountNameMaxLength     uint64 `json:"accountNameMaxLength"`
	MainAccountNameMinLength uint64 `json:"mainAccountNameMinLength"`
	MainAccountNameMaxLength uint64 `json:"mainAccountNameMaxLength"`
	SubAccountNameMinLength  uint64 `json:"subAccountNameMinLength"`
	SubAccountNameMaxLength  uint64 `json:"subAccountNameMaxLength"`
}

Config Account Level

type CreateAccountAction added in v0.0.11

type CreateAccountAction struct {
	AccountName common.Name   `json:"accountName,omitempty"`
	Founder     common.Name   `json:"founder,omitempty"`
	PublicKey   common.PubKey `json:"publicKey,omitempty"`
	Description string        `json:"description,omitempty"`
}

type IAccount

type IAccount interface {
	//newAccount(accountName common.Name, pubkey common.PubKey) (*Account, error)
	GetName() common.Name
	//nonce
	GetNonce() uint64
	SetNonce(nonce uint64)
	//code
	GetCode() ([]byte, error)
	SetCode(code []byte) (bool, error)
	GetCodeHash() (common.Hash, error)
	GetCodeSize() (uint64, error)
	//
	GetPubKey() common.PubKey
	SetPubKey(pubkey common.PubKey)
	//asset
	GetBalancesList() ([]*AssetBalance, error)
	GetAllAccountBalance() (map[uint64]*big.Int, error)
	AddBalanceByID(assetID uint64, value *big.Int) error
	SubBalanceByID(assetID uint64, value *big.Int) error
	EnoughAccountBalance(assetID uint64, value *big.Int) error
	//
	IsSuicided() bool
	SetSuicide()
	//
	IsDestroyed()
	SetDestroy()
}

type IAccountManager

type IAccountManager interface {
	//account
	AccountIsExist(accountName common.Name) (bool, error)
	AccountIsEmpty(accountName common.Name) (bool, error)
	CreateAccount(accountName common.Name, pubkey common.PubKey) error
	DeleteAccountByName(accountName common.Name) error
	GetAccountByName(accountName common.Name) (*Account, error)
	SetAccount(acct *Account) error
	//sign
	RecoverTx(signer types.Signer, tx *types.Transaction) error
	IsValidSign(accountName common.Name, aType types.ActionType, pub common.PubKey) error
	//asset
	IssueAsset(asset *asset.AssetObject) error
	IncreaseAsset(accountName common.Name, assetID uint64, amount *big.Int) error
	//
	CanTransfer(accountName common.Name, assetId uint64, value *big.Int) (bool, error)
	TransferAsset(fromAccount common.Name, toAccount common.Name, assetID uint64, value *big.Int) error
	IncAsset2Acct(fromName common.Name, toName common.Name, assetId uint64, amount *big.Int) error
	AddBalanceByName(accountName common.Name, assetID uint64, amount *big.Int) error
	Process(action *types.Action) error
}

type IncAsset

type IncAsset struct {
	AssetId uint64      `json:"assetId,omitempty"`
	Amount  *big.Int    `json:"amount,omitempty"`
	To      common.Name `json:"acceptor,omitempty"`
}

type IssueAsset added in v0.0.9

type IssueAsset struct {
	AssetName   string      `json:"assetName"`
	Symbol      string      `json:"symbol"`
	Amount      *big.Int    `json:"amount"`
	Decimals    uint64      `json:"decimals"`
	Founder     common.Name `json:"founder"`
	Owner       common.Name `json:"owner"`
	UpperLimit  *big.Int    `json:"upperLimit"`
	Contract    common.Name `json:"contract"`
	Description string      `json:"description"`
}

type SdbIf

type SdbIf interface {
	Put(account string, key string, value []byte)
	Get(account string, key string) ([]byte, error)
	// GetSnapshot(accountName string, key string, time uint64) ([]byte, error)
	// GetSnapshotLast() (uint64, error)
	// GetSnapshotPrev(time uint64) (uint64, error)
	// Snapshot() int
	RevertToSnapshot(revid int)
}

import

type UpdataAccountAction added in v0.0.11

type UpdataAccountAction struct {
	Founder common.Name `json:"founder,omitempty"`
}

type UpdateAsset added in v0.0.9

type UpdateAsset struct {
	AssetID uint64      `json:"assetId,omitempty"`
	Founder common.Name `json:"founder"`
}

type UpdateAssetContract added in v0.0.16

type UpdateAssetContract struct {
	AssetID  uint64      `json:"assetId,omitempty"`
	Contract common.Name `json:"contract"`
}

type UpdateAssetOwner added in v0.0.11

type UpdateAssetOwner struct {
	AssetID uint64      `json:"assetId,omitempty"`
	Owner   common.Name `json:"owner"`
}

Jump to

Keyboard shortcuts

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